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

204 lines
4.2 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
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('getInfo', res => {
  93. if (res.code == 200) {
  94. state.userInfo = res.result
  95. if (!state.userInfo.nickName ||
  96. !state.userInfo.headImage ||
  97. !state.userInfo.phone
  98. ) {
  99. uni.showModal({
  100. title: '申请获取您的信息!',
  101. cancelText: '稍后补全',
  102. confirmText: '现在补全',
  103. success(e) {
  104. if (e.confirm) {
  105. uni.navigateTo({
  106. url: '/pages_order/auth/wxUserInfo'
  107. })
  108. }
  109. }
  110. })
  111. }
  112. }
  113. })
  114. },
  115. getRiceInfo(state) {
  116. api('getRiceInfo', {
  117. token: uni.getStorageSync('token') || ''
  118. }, res => {
  119. if (res.code == 200) {
  120. state.riceInfo = res.result
  121. }
  122. })
  123. },
  124. // 退出登录
  125. logout(state, reLaunch = false) {
  126. // uni.showModal({
  127. // title: '确认退出登录吗',
  128. // success(r) {
  129. // if (r.confirm) {
  130. // state.userInfo = {}
  131. // uni.removeStorageSync('token')
  132. // uni.reLaunch({
  133. // url: '/pages/index/index'
  134. // })
  135. // }
  136. // }
  137. // })
  138. state.userInfo = {}
  139. uni.removeStorageSync('token')
  140. if(reLaunch){
  141. uni.reLaunch({
  142. url: '/pages/index/category'
  143. })
  144. }
  145. },
  146. getQrCode(state) {
  147. let that = this;
  148. // 注释掉登录检查
  149. if(!uni.getStorageSync('token')){
  150. return
  151. }
  152. uni.getImageInfo({
  153. src: `${Vue.prototype.$config.baseUrl}/info_common/getInviteCode?token=${uni.getStorageSync('token')}`,
  154. success : res => {
  155. that.commit('setPromotionUrl', res.path)
  156. },
  157. fail : err => {
  158. }
  159. })
  160. },
  161. // 查询分类接口
  162. getCategoryList(state) {
  163. api('queryCategoryList', {
  164. pageNo : 1,
  165. pageSize : 99999,
  166. }, res => {
  167. if (res.code == 200) {
  168. state.category = res.result.records
  169. }
  170. })
  171. },
  172. // 设置支付订单中的商品
  173. setPayOrderProduct(state, data) {
  174. state.payOrderProduct = data
  175. },
  176. setPromotionUrl(state, data){
  177. state.promotionUrl = data
  178. },
  179. },
  180. actions: {},
  181. })
  182. export default store