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

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