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

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