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

201 lines
4.3 KiB

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