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

196 lines
4.0 KiB

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
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
10 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
9 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. 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/category'
  140. })
  141. }
  142. },
  143. getQrCode(state) {
  144. let that = this;
  145. // 注释掉登录检查
  146. /*
  147. if(!uni.getStorageSync('token')){
  148. return
  149. }
  150. */
  151. uni.getImageInfo({
  152. src: `${Vue.prototype.$config.baseUrl}/info_common/getInviteCode?token=${uni.getStorageSync('token')}`,
  153. success : res => {
  154. that.commit('setPromotionUrl', res.path)
  155. },
  156. fail : err => {
  157. }
  158. })
  159. },
  160. // 查询分类接口
  161. getCategoryList(state) {
  162. api('getCategoryPidList', res => {
  163. if (res.code == 200) {
  164. state.category = res.result
  165. }
  166. })
  167. },
  168. // 设置支付订单中的商品
  169. setPayOrderProduct(state, data) {
  170. state.payOrderProduct = data
  171. },
  172. setPromotionUrl(state, data){
  173. state.promotionUrl = data
  174. },
  175. },
  176. actions: {},
  177. })
  178. export default store