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

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