珠宝小程序前端代码
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.

173 lines
3.5 KiB

5 months ago
5 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
5 months ago
5 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
5 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. state.configList = configList
  30. uni.$emit('initConfig', state.configList)
  31. })
  32. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  33. // config.forEach(k => {
  34. // api(k, res => {
  35. // if (res.code == 200) {
  36. // state.configList[k] = res.result
  37. // }
  38. // })
  39. // })
  40. },
  41. login(state, config) {
  42. uni.showLoading({
  43. title: '登录中...'
  44. })
  45. uni.login({
  46. success(res) {
  47. if (res.errMsg != "login:ok") {
  48. return
  49. }
  50. let data = {
  51. code: res.code,
  52. }
  53. if (uni.getStorageSync('shareId')) {
  54. data.shareId = uni.getStorageSync('shareId')
  55. }
  56. api('wxLogin', data, res => {
  57. uni.hideLoading()
  58. if (res.code != 200) {
  59. return
  60. }
  61. state.userInfo = res.result.userInfo
  62. uni.setStorageSync('token', res.result.token)
  63. if (!state.userInfo.nickName ||
  64. !state.userInfo.headImage ||
  65. !state.userInfo.phone
  66. ) {
  67. uni.navigateTo({
  68. url: '/pages_order/auth/wxUserInfo'
  69. })
  70. } else {
  71. uni.navigateBack(-1)
  72. }
  73. })
  74. }
  75. })
  76. },
  77. getUserInfo(state) {
  78. api('getInfo', res => {
  79. if (res.code == 200) {
  80. state.userInfo = res.result
  81. if (!state.userInfo.nickName ||
  82. !state.userInfo.headImage ||
  83. !state.userInfo.phone
  84. ) {
  85. uni.showModal({
  86. title: '申请获取您的信息!',
  87. cancelText: '稍后补全',
  88. confirmText: '现在补全',
  89. success(e) {
  90. if (e.confirm) {
  91. uni.navigateTo({
  92. url: '/pages_order/auth/wxUserInfo'
  93. })
  94. }
  95. }
  96. })
  97. }
  98. }
  99. })
  100. },
  101. getRiceInfo(state) {
  102. api('getRiceInfo', {
  103. token: uni.getStorageSync('token') || ''
  104. }, res => {
  105. if (res.code == 200) {
  106. state.riceInfo = res.result
  107. }
  108. })
  109. },
  110. // 退出登录
  111. logout(state, reLaunch = false) {
  112. // uni.showModal({
  113. // title: '确认退出登录吗',
  114. // success(r) {
  115. // if (r.confirm) {
  116. // state.userInfo = {}
  117. // uni.removeStorageSync('token')
  118. // uni.reLaunch({
  119. // url: '/pages/index/index'
  120. // })
  121. // }
  122. // }
  123. // })
  124. state.userInfo = {}
  125. uni.removeStorageSync('token')
  126. if(reLaunch){
  127. uni.reLaunch({
  128. url: '/pages/index/index'
  129. })
  130. }
  131. },
  132. getQrCode(state) {
  133. api('getInviteCode', res => {
  134. if (res.code == 200) {
  135. state.promotionUrl = Vue.prototype.$config.aliOss.url + res.result.url
  136. }
  137. uni.hideLoading()
  138. })
  139. },
  140. // 查询分类接口
  141. getCategoryList(state) {
  142. api('getCategoryPidList', res => {
  143. if (res.code == 200) {
  144. state.category = res.result
  145. }
  146. })
  147. },
  148. // 设置支付订单中的商品
  149. setPayOrderProduct(state, data) {
  150. state.payOrderProduct = data
  151. },
  152. setPromotionUrl(state, data){
  153. state.promotionUrl = data
  154. },
  155. },
  156. actions: {},
  157. })
  158. export default store