推拿小程序前端代码仓库
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.

182 lines
3.8 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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. const ROLE_TYPE_AND_DESC_FIELDS_MAPPING = {
  6. default: 'member-personal',
  7. 0: 'member-personal', //个人会员
  8. 1: 'member-business', //企业会员
  9. }
  10. //Vuex.Store 构造器选项
  11. const store = new Vuex.Store({
  12. state: {
  13. configList: {}, //配置列表
  14. userInfo: {}, //用户信息
  15. vipInfo: {},
  16. riceInfo: {}, //用户相关信息
  17. payOrderProduct: [], //支付订单中的商品
  18. },
  19. getters: {
  20. role(state) {
  21. const { validTime, massageVipCombo } = state.vipInfo || {}
  22. if (!validTime || new Date().getTime() > new Date(validTime).getTime()) {
  23. return ''
  24. }
  25. const { type } = massageVipCombo || {}
  26. return ROLE_TYPE_AND_DESC_FIELDS_MAPPING[type] || ROLE_TYPE_AND_DESC_FIELDS_MAPPING.default
  27. },
  28. },
  29. mutations: {
  30. // 初始化配置
  31. initConfig(state) {
  32. api('getConfig', res => {
  33. const configList = {
  34. ...state.configList,
  35. }
  36. if (res.code == 200) {
  37. res.result.records.forEach(n => {
  38. configList[n.paramCode] = n.paramValueImage || n.paramValueText || n.paramValueArea;
  39. // configList[n.paramCode + '_keyValue'] = n.keyValue;
  40. });
  41. }
  42. state.configList = configList
  43. uni.$emit('initConfig', state.configList)
  44. })
  45. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  46. // config.forEach(k => {
  47. // api(k, res => {
  48. // if (res.code == 200) {
  49. // state.configList[k] = res.result
  50. // }
  51. // })
  52. // })
  53. },
  54. login(state, config) {
  55. uni.showLoading({
  56. title: '登录中...'
  57. })
  58. uni.login({
  59. success(res) {
  60. if (res.errMsg != "login:ok") {
  61. return
  62. }
  63. let data = {
  64. code: res.code,
  65. }
  66. if (uni.getStorageSync('shareId')) {
  67. data.shareId = uni.getStorageSync('shareId')
  68. }
  69. api('wxLogin', data, res => {
  70. uni.hideLoading()
  71. if (res.code != 200) {
  72. return
  73. }
  74. Vue.set(state, 'userInfo', res.result.userInfo)
  75. uni.setStorageSync('token', res.result.token)
  76. if (!state.userInfo.nickName ||
  77. !state.userInfo.headImage ||
  78. !state.userInfo.phone
  79. ) {
  80. uni.navigateTo({
  81. url: '/pages_order/auth/wxUserInfo'
  82. })
  83. } else {
  84. uni.navigateBack(-1)
  85. }
  86. })
  87. }
  88. })
  89. },
  90. getUserInfo(state) {
  91. api('getInfo', res => {
  92. if (res.code == 200) {
  93. Vue.set(state, 'userInfo', res.result)
  94. if (!state.userInfo.nickName ||
  95. !state.userInfo.headImage ||
  96. !state.userInfo.phone
  97. ) {
  98. uni.showModal({
  99. title: '申请获取您的信息!',
  100. cancelText: '稍后补全',
  101. confirmText: '现在补全',
  102. success(e) {
  103. if (e.confirm) {
  104. uni.navigateTo({
  105. url: '/pages_order/auth/wxUserInfo'
  106. })
  107. }
  108. }
  109. })
  110. }
  111. }
  112. })
  113. },
  114. getUserCenterInfo(state) {
  115. api('getUserCenterData', res => {
  116. if (res.code == 200) {
  117. Vue.set(state, 'vipInfo', res.result?.vipInfo || {})
  118. }
  119. })
  120. },
  121. getRiceInfo(state) {
  122. // todo
  123. return
  124. api('getRiceInfo', {
  125. token: uni.getStorageSync('token') || ''
  126. }, res => {
  127. if (res.code == 200) {
  128. state.riceInfo = res.result
  129. }
  130. })
  131. },
  132. // 退出登录
  133. logout(state, reLaunch = false) {
  134. // uni.showModal({
  135. // title: '确认退出登录吗',
  136. // success(r) {
  137. // if (r.confirm) {
  138. // state.userInfo = {}
  139. // uni.removeStorageSync('token')
  140. // uni.reLaunch({
  141. // url: '/pages/index/index'
  142. // })
  143. // }
  144. // }
  145. // })
  146. state.userInfo = {}
  147. uni.removeStorageSync('token')
  148. if(reLaunch){
  149. uni.reLaunch({
  150. url: '/pages/index/index'
  151. })
  152. }
  153. },
  154. // 设置支付订单中的商品
  155. setPayOrderProduct(state, data) {
  156. state.payOrderProduct = data
  157. },
  158. },
  159. actions: {},
  160. })
  161. export default store