珠宝小程序前端代码
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.

150 lines
3.0 KiB

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