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

177 lines
3.6 KiB

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