裂变星小程序-25.03.04
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.

128 lines
2.7 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month 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. shop : false,//身份判断如果不需要,可以删除
  10. userInfo : {}, //用户信息
  11. userInfoVip : {}, //用户Vip信息
  12. },
  13. getters: {
  14. // 角色 true为水洗店 false为酒店 : 身份判断如果不需要,可以删除
  15. userShop(state){
  16. return state.shop
  17. }
  18. },
  19. mutations: {
  20. // 初始化配置
  21. initConfig(state){
  22. api('getConfig', res => {
  23. const configList = {
  24. ...state.configList,
  25. }
  26. if (res.code == 200) {
  27. res.result.forEach(n => {
  28. configList[n.keyName] = n.keyContent;
  29. configList[n.keyName + '_keyValue'] = n.keyValue;
  30. });
  31. }
  32. state.configList = configList
  33. uni.$emit('initConfig', state.configList)
  34. })
  35. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  36. // config.forEach(k => {
  37. // api(k, res => {
  38. // if (res.code == 200) {
  39. // state.configList[k] = res.result
  40. // }
  41. // })
  42. // })
  43. },
  44. // 微信登录
  45. login(state){
  46. uni.showLoading({
  47. title: '登录中...'
  48. })
  49. uni.login({
  50. success(res) {
  51. if(res.errMsg != "login:ok"){
  52. return
  53. }
  54. let data = {
  55. code: res.code,
  56. }
  57. if (uni.getStorageSync('shareId')) {
  58. data.shareId = uni.getStorageSync('shareId')
  59. }
  60. if (uni.getStorageSync('state')) {
  61. data.state = uni.getStorageSync('state')
  62. }
  63. api('wxLogin', data, res => {
  64. uni.hideLoading()
  65. if(res.code != 200){
  66. return
  67. }
  68. Vue.set(state, 'userInfo', res.result.userInfo)
  69. uni.setStorageSync('token', res.result.token)
  70. if(!state.userInfo.nickName || !state.userInfo.headImage){
  71. uni.navigateTo({
  72. url: '/pages_order/auth/wxUserInfo'
  73. })
  74. }else{
  75. uni.navigateBack(-1)
  76. }
  77. })
  78. }
  79. })
  80. },
  81. // 获取用户个人信息
  82. getUserInfo(state){
  83. api('getInfo', res => {
  84. if(res.code == 200){
  85. Vue.set(state, 'userInfo', res.result)
  86. }
  87. })
  88. },
  89. // 获取用户个人信息
  90. getUserInfoVip(state){
  91. api('getUserInfoVip', res => {
  92. if(res.code == 200){
  93. Vue.set(state, 'userInfoVip', res.result)
  94. }
  95. })
  96. },
  97. // 退出登录
  98. logout(state){
  99. uni.showModal({
  100. title: '确认退出登录吗',
  101. success(r) {
  102. if(r.confirm){
  103. Vue.set(state, 'userInfo', {})
  104. state.role = false
  105. uni.removeStorageSync('token')
  106. uni.reLaunch({
  107. url: '/pages/index/index'
  108. })
  109. }
  110. }
  111. })
  112. },
  113. },
  114. actions: {},
  115. })
  116. export default store