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

141 lines
2.9 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 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. 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. content: '确认要退出登录吗',
  89. cancelColor: '#393939',
  90. confirmColor: '#7451DE',
  91. success(r) {
  92. if(r.confirm){
  93. state.userInfo = {}
  94. state.role = false
  95. uni.removeStorageSync('token')
  96. uni.reLaunch({
  97. url: '/pages/index/index'
  98. })
  99. }
  100. }
  101. })
  102. },
  103. addCart(state, data) {
  104. // todo: fetch
  105. console.log('addCart', data)
  106. },
  107. setAddressInfo(state, data) {
  108. state.addressInfo = data
  109. },
  110. // 设置支付订单中的商品
  111. setPayOrderProduct(state, data) {
  112. state.payOrderProduct = data
  113. },
  114. createOrder(state, data) {
  115. state.payOrderProduct = data
  116. // todo: create order
  117. uni.navigateTo({
  118. url: '/pages_order/order/orderConfirm/index'
  119. })
  120. },
  121. setApplyServiceProduct(state, data) {
  122. state.applyServiceProduct = data
  123. },
  124. },
  125. actions: {},
  126. })
  127. export default store