普兆健康管家前端代码仓库
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.

138 lines
2.8 KiB

1 month ago
1 month ago
1 month 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. shop : false,//身份判断如果不需要,可以删除
  10. userInfo : {}, //用户信息
  11. payOrderProduct: [], //支付订单中的商品applyServiceProduct
  12. applyServiceProduct: [], // 售后服务商品
  13. addressInfo: null,
  14. },
  15. getters: {
  16. // 角色 true为水洗店 false为酒店 : 身份判断如果不需要,可以删除
  17. userShop(state){
  18. return state.shop
  19. }
  20. },
  21. mutations: {
  22. // 初始化配置
  23. initConfig(state){
  24. api('getConfig', res => {
  25. const configList = {
  26. ...state.configList,
  27. }
  28. if (res.code == 200) {
  29. res.result.forEach(n => {
  30. configList[n.keyName] = n.keyContent;
  31. configList[n.keyName + '_keyValue'] = n.keyValue;
  32. });
  33. }
  34. state.configList = configList
  35. uni.$emit('initConfig', state.configList)
  36. })
  37. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  38. // config.forEach(k => {
  39. // api(k, res => {
  40. // if (res.code == 200) {
  41. // state.configList[k] = res.result
  42. // }
  43. // })
  44. // })
  45. },
  46. // 微信登录
  47. login(state){
  48. uni.showLoading({
  49. title: '登录中...'
  50. })
  51. uni.login({
  52. success(res) {
  53. if(res.errMsg != "login:ok"){
  54. return
  55. }
  56. api('wxLogin', {
  57. code : res.code
  58. }, res => {
  59. uni.hideLoading()
  60. if(res.code != 200){
  61. return
  62. }
  63. state.userInfo = res.result.userInfo
  64. uni.setStorageSync('token', res.result.token)
  65. if(!state.userInfo.nickName || !state.userInfo.headImage){
  66. uni.navigateTo({
  67. url: '/pages_order/auth/wxUserInfo'
  68. })
  69. }else{
  70. uni.navigateBack(-1)
  71. }
  72. })
  73. }
  74. })
  75. },
  76. // 获取用户个人信息
  77. getUserInfo(state){
  78. api('getInfo', res => {
  79. if(res.code == 200){
  80. state.userInfo = res.result
  81. }
  82. })
  83. },
  84. // 退出登录
  85. logout(state){
  86. uni.showModal({
  87. title: '确认退出登录吗',
  88. success(r) {
  89. if(r.confirm){
  90. state.userInfo = {}
  91. state.role = false
  92. uni.removeStorageSync('token')
  93. uni.reLaunch({
  94. url: '/pages/index/index'
  95. })
  96. }
  97. }
  98. })
  99. },
  100. addCart(state, data) {
  101. // todo: fetch
  102. console.log('addCart', data)
  103. },
  104. setAddressInfo(state, data) {
  105. state.addressInfo = data
  106. },
  107. // 设置支付订单中的商品
  108. setPayOrderProduct(state, data) {
  109. state.payOrderProduct = data
  110. },
  111. createOrder(state, data) {
  112. state.payOrderProduct = data
  113. // todo: create order
  114. uni.navigateTo({
  115. url: '/pages_order/order/orderConfirm/index'
  116. })
  117. },
  118. setApplyServiceProduct(state, data) {
  119. state.applyServiceProduct = data
  120. },
  121. },
  122. actions: {},
  123. })
  124. export default store