艺易修小程序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.

85 lines
1.7 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 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. console.log(res);
  41. if (res.errMsg != "login:ok") {
  42. return
  43. }
  44. api('loginLogin', {
  45. code: res.code
  46. }, res => {
  47. if (res.code != 200) {
  48. return
  49. }
  50. state.userInfo = res.result.userInfo
  51. uni.setStorageSync('token', res.result.token)
  52. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  53. uni.navigateTo({
  54. url: '/pages/login/wxUserInfo'
  55. })
  56. }else{
  57. uni.switchTab({
  58. url: '/pages/repair/repair'
  59. })
  60. }
  61. })
  62. },
  63. fail(err) {
  64. console.error(err)
  65. }
  66. })
  67. },
  68. getUserInfo(state) {
  69. api('infoGetInfo', res => {
  70. if(res.code == 200){
  71. state.userInfo = res.result
  72. }
  73. })
  74. },
  75. },
  76. actions: {},
  77. })
  78. export default store