艺易修小程序24.08.21
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.6 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex); //vue的插件机制
  4. import api from '@/api/api.js'
  5. //Vuex.Store 构造器选项
  6. const store = new Vuex.Store({
  7. state: {
  8. configList: {}, //配置对象
  9. userInfo : {},
  10. },
  11. getters: {
  12. getConfig(state){
  13. return state.configList
  14. }
  15. },
  16. mutations: {
  17. // 初始化配置
  18. initConfig(state) {
  19. let config = ['preferential', 'wx']
  20. config.forEach(k => {
  21. api('getConfig', {
  22. keyValue : k
  23. }, res => {
  24. if (res.code == 200) {
  25. state.configList[k] = res.result
  26. }
  27. })
  28. })
  29. let apiConfig = [ 'getPrivacyPolicy' , 'getUserAgreement' ] //需要访问不同接口才能得到的配置数据
  30. let key = ['privacyAgreement','userAgreement']
  31. apiConfig.forEach((item,index) => {
  32. api(item,res => {
  33. state.configList[key[index]] = res.result
  34. })
  35. })
  36. },
  37. login(state) {
  38. uni.login({
  39. success(res) {
  40. if (res.errMsg != "login:ok") {
  41. return
  42. }
  43. api('loginLogin', {
  44. code: res.code
  45. }, res => {
  46. if (res.code != 200) {
  47. return
  48. }
  49. state.userInfo = res.result.userInfo
  50. uni.setStorageSync('token', res.result.token)
  51. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  52. uni.navigateTo({
  53. url: '/pages/login/wxUserInfo'
  54. })
  55. }else{
  56. uni.switchTab({
  57. url: '/pages/repair/repair'
  58. })
  59. }
  60. })
  61. },
  62. fail(err) {
  63. console.error(err)
  64. }
  65. })
  66. },
  67. getUserInfo(state) {
  68. api('getInfo', res => {
  69. if(res.code == 200){
  70. state.userInfo = res.result
  71. }
  72. })
  73. },
  74. },
  75. actions: {},
  76. })
  77. export default store