裂变星小程序-25.03.04
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.

109 lines
2.2 KiB

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