敢为人鲜小程序前端代码仓库
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.

207 lines
4.4 KiB

10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
7 months ago
7 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 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. levelInfo: {}, //团员等级信息
  12. riceInfo: {}, //用户相关信息
  13. category: [], //分类信息
  14. payOrderProduct: [], //支付订单中的商品
  15. promotionUrl : '',//分享二维码
  16. },
  17. getters: {},
  18. mutations: {
  19. // 初始化配置
  20. initConfig(state) {
  21. api('getConfig', res => {
  22. const configList = {
  23. ...state.configList,
  24. }
  25. if (res.code == 200) {
  26. res.result.records.forEach(n => {
  27. state.configList[n.paramCode] = n.paramValueText ||
  28. n.paramValue ||
  29. n.paramValueImage
  30. });
  31. console.log('configList', state.configList);
  32. }
  33. // state.configList = configList
  34. uni.$emit('initConfig', state.configList)
  35. })
  36. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  37. // config.forEach(k => {
  38. // api(k, res => {
  39. // if (res.code == 200) {
  40. // state.configList[k] = res.result
  41. // }
  42. // })
  43. // })
  44. },
  45. login(state, config = {}) {
  46. uni.showLoading({
  47. title: '登录中...'
  48. })
  49. uni.login({
  50. success : res => {
  51. if (res.errMsg != "login:ok") {
  52. return
  53. }
  54. let data = {
  55. code: res.code,
  56. }
  57. // 如果通过分享者链接进入小程序时,会将分享者ID存储在本地
  58. if (uni.getStorageSync('shareId')) {
  59. data.shareId = uni.getStorageSync('shareId')
  60. }
  61. api('wxLogin', data, res => {
  62. uni.hideLoading()
  63. if (res.code != 200) {
  64. return
  65. }
  66. state.userInfo = res.result.userInfo
  67. uni.setStorageSync('token', res.result.token)
  68. if(config.path){
  69. let path = config.path
  70. delete config.path
  71. delete config.shareId
  72. let para = utils.objectToUrlParams(config)
  73. uni.reLaunch({
  74. url: `${path}?${para}`,
  75. })
  76. return
  77. }
  78. if (!state.userInfo.nickName ||
  79. !state.userInfo.headImage ||
  80. !state.userInfo.phone
  81. ) {
  82. uni.navigateTo({
  83. url: '/pages_order/auth/wxUserInfo'
  84. })
  85. } else {
  86. // 直接登录成功
  87. store.commit('getUserInfo')
  88. utils.navigateBack(-1)
  89. }
  90. })
  91. }
  92. })
  93. },
  94. getUserInfo(state) {
  95. api('getUserCenterData', res => {
  96. if (res.code == 200) {
  97. state.userInfo = res.result.member
  98. state.levelInfo = res.result.level
  99. // console.log(state.levelInfo);
  100. if (!state.userInfo.nickName ||
  101. !state.userInfo.headImage ||
  102. !state.userInfo.phone
  103. ) {
  104. uni.showModal({
  105. title: '申请获取您的信息!',
  106. cancelText: '稍后补全',
  107. confirmText: '现在补全',
  108. success(e) {
  109. if (e.confirm) {
  110. uni.navigateTo({
  111. url: '/pages_order/auth/wxUserInfo'
  112. })
  113. }
  114. }
  115. })
  116. }
  117. }
  118. })
  119. },
  120. getRiceInfo(state) {
  121. api('getRiceInfo', {
  122. token: uni.getStorageSync('token') || ''
  123. }, res => {
  124. if (res.code == 200) {
  125. state.riceInfo = res.result
  126. }
  127. })
  128. },
  129. // 退出登录
  130. logout(state, reLaunch = false) {
  131. // uni.showModal({
  132. // title: '确认退出登录吗',
  133. // success(r) {
  134. // if (r.confirm) {
  135. // state.userInfo = {}
  136. // uni.removeStorageSync('token')
  137. // uni.reLaunch({
  138. // url: '/pages/index/index'
  139. // })
  140. // }
  141. // }
  142. // })
  143. state.userInfo = {}
  144. state.levelInfo = {}
  145. uni.removeStorageSync('token')
  146. if(reLaunch){
  147. uni.reLaunch({
  148. url: '/pages/index/category'
  149. })
  150. }
  151. },
  152. getQrCode(state) {
  153. let that = this;
  154. // 注释掉登录检查
  155. if(!uni.getStorageSync('token')){
  156. return
  157. }
  158. uni.getImageInfo({
  159. src: `${Vue.prototype.$config.baseUrl}/info_common/getInviteCode?token=${uni.getStorageSync('token')}`,
  160. success : res => {
  161. that.commit('setPromotionUrl', res.path)
  162. },
  163. fail : err => {
  164. }
  165. })
  166. },
  167. // 查询分类接口
  168. getCategoryList(state) {
  169. api('queryCategoryList', { }, res => {
  170. if (res.code == 200) {
  171. state.category = res.result.records
  172. }
  173. })
  174. },
  175. // 设置支付订单中的商品
  176. setPayOrderProduct(state, data) {
  177. state.payOrderProduct = data
  178. },
  179. setPromotionUrl(state, data){
  180. state.promotionUrl = data
  181. },
  182. },
  183. actions: {},
  184. })
  185. export default store