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

246 lines
5.2 KiB

5 months ago
5 months ago
5 months ago
5 months ago
4 weeks 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
3 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
4 weeks ago
5 months ago
4 weeks ago
5 months ago
5 months ago
5 months ago
4 months ago
4 weeks ago
4 weeks ago
5 months ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import utils from '../utils/utils.js'
  4. import cartNum from '@/store/modules/cartNum.js'
  5. Vue.use(Vuex); //vue的插件机制
  6. import api from '@/api/api.js'
  7. //Vuex.Store 构造器选项
  8. const store = new Vuex.Store({
  9. modules: {
  10. cartNum
  11. },
  12. state: {
  13. configList: {}, //配置列表
  14. userInfo: {}, //用户信息
  15. levelInfo: {}, //团员等级信息
  16. cartData: [], //购物车数据
  17. riceInfo: {}, //用户相关信息
  18. category: [], //分类信息
  19. payOrderProduct: [], //支付订单中的商品
  20. promotionUrl : '',//分享二维码
  21. couponData: {} //选中的优惠券数据
  22. },
  23. getters: {},
  24. mutations: {
  25. // 初始化配置
  26. initConfig(state) {
  27. api('getConfig', res => {
  28. const configList = {
  29. ...state.configList,
  30. }
  31. if (res.code == 200) {
  32. res.result.records.forEach(n => {
  33. state.configList[n.paramCode] = n.paramValueText ||
  34. n.paramValue ||
  35. n.paramValueImage || n.paramValueArea
  36. });
  37. console.log('configList', state.configList);
  38. }
  39. // state.configList = configList
  40. uni.$emit('initConfig', state.configList)
  41. })
  42. },
  43. login(state, config = {}) {
  44. uni.showLoading({
  45. title: '登录中...'
  46. })
  47. uni.login({
  48. success : res => {
  49. if (res.errMsg != "login:ok") {
  50. return
  51. }
  52. let data = {
  53. code: res.code,
  54. }
  55. // 如果通过分享者链接进入小程序时,会将分享者ID存储在本地
  56. if (uni.getStorageSync('shareId')) {
  57. data.shareId = uni.getStorageSync('shareId')
  58. }
  59. api('wxLogin', data, res => {
  60. uni.hideLoading()
  61. if (res.code != 200) {
  62. return
  63. }
  64. state.userInfo = res.result.userInfo
  65. uni.setStorageSync('token', res.result.token)
  66. if(config.path){
  67. let path = config.path
  68. delete config.path
  69. delete config.shareId
  70. let para = utils.objectToUrlParams(config)
  71. uni.reLaunch({
  72. url: `${path}?${para}`,
  73. })
  74. return
  75. }
  76. if (!state.userInfo.nickName ||
  77. !state.userInfo.headImage ||
  78. !state.userInfo.phone
  79. ) {
  80. uni.navigateTo({
  81. url: '/pages_order/auth/wxUserInfo'
  82. })
  83. } else {
  84. // 直接登录成功
  85. store.commit('getUserInfo')
  86. utils.navigateBack(-1)
  87. }
  88. })
  89. }
  90. })
  91. },
  92. getUserInfo(state) {
  93. api('getUserCenterData', res => {
  94. if (res.code == 200) {
  95. state.userInfo = res.result.member
  96. state.levelInfo = res.result.level
  97. // console.log(state.levelInfo);
  98. if (!state.userInfo.nickName ||
  99. !state.userInfo.headImage ||
  100. !state.userInfo.phone
  101. ) {
  102. uni.showModal({
  103. title: '申请获取您的信息!',
  104. cancelText: '稍后补全',
  105. confirmText: '现在补全',
  106. success(e) {
  107. if (e.confirm) {
  108. uni.navigateTo({
  109. url: '/pages_order/auth/wxUserInfo'
  110. })
  111. }
  112. }
  113. })
  114. }
  115. }
  116. })
  117. },
  118. getRiceInfo(state) {
  119. api('getRiceInfo', {
  120. token: uni.getStorageSync('token') || ''
  121. }, res => {
  122. if (res.code == 200) {
  123. state.riceInfo = res.result
  124. }
  125. })
  126. },
  127. // 退出登录
  128. logout(state, reLaunch = false) {
  129. // uni.showModal({
  130. // title: '确认退出登录吗',
  131. // success(r) {
  132. // if (r.confirm) {
  133. // state.userInfo = {}
  134. // uni.removeStorageSync('token')
  135. // uni.reLaunch({
  136. // url: '/pages/index/index'
  137. // })
  138. // }
  139. // }
  140. // })
  141. state.userInfo = {}
  142. state.levelInfo = {}
  143. uni.removeStorageSync('token')
  144. if(reLaunch){
  145. uni.reLaunch({
  146. url: '/pages/index/index'
  147. })
  148. }
  149. },
  150. getQrCode(state) {
  151. let that = this;
  152. // 注释掉登录检查
  153. if(!uni.getStorageSync('token')){
  154. return
  155. }
  156. uni.getImageInfo({
  157. src: `${Vue.prototype.$config.baseUrl}/info_common/getInviteCode?token=${uni.getStorageSync('token')}`,
  158. success : res => {
  159. that.commit('setPromotionUrl', res.path)
  160. },
  161. fail : err => {
  162. }
  163. })
  164. },
  165. // 查询分类接口
  166. getCategoryList(state, fn) {
  167. api('queryCategoryList', {
  168. pageNo: 1,
  169. pageSize: 9999,
  170. }, res => {
  171. if (res.code == 200) {
  172. state.category = res.result.records
  173. fn && fn(state.category)
  174. }
  175. })
  176. },
  177. // 设置支付订单中的商品
  178. setPayOrderProduct(state, data) {
  179. state.payOrderProduct = data
  180. },
  181. setPromotionUrl(state, data){
  182. state.promotionUrl = data
  183. },
  184. // 设置购物车数据
  185. setCartData(state, data){
  186. console.log('data', data)
  187. state.cartData = data
  188. },
  189. // 检查绑定团长与否
  190. checkBindLeader(){
  191. api('queryMyLeader', {}, res => {
  192. if(res.code == 500 || !res.result) {
  193. uni.showModal({
  194. title: '提示',
  195. content: '您还未绑定团长,请先绑定团长',
  196. confirmText: '去绑定',
  197. showCancel: false,
  198. success: (res) => {
  199. if (res.confirm) {
  200. uni.navigateTo({
  201. url: '/pages_order/mine/unbindTeam'
  202. })
  203. }
  204. }
  205. })
  206. }else {
  207. return res.result
  208. }
  209. })
  210. },
  211. // 设置选中的优惠券数据
  212. setCouponData(state, data){
  213. state.couponData = data
  214. },
  215. // 清除选中的优惠卷数据
  216. clearCouponData(state){
  217. state.couponData = {}
  218. }
  219. },
  220. actions: {},
  221. })
  222. export default store