风险测评小程序前端代码仓库
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.

110 lines
2.2 KiB

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