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

154 lines
3.1 KiB

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