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

139 lines
2.9 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 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. userInfoVip : {}, //用户Vip信息
  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. let data = {
  55. code: res.code,
  56. }
  57. if (uni.getStorageSync('shareId')) {
  58. data.shareId = uni.getStorageSync('shareId')
  59. }
  60. if (uni.getStorageSync('id')) {
  61. data.id = uni.getStorageSync('id')
  62. }
  63. if (uni.getStorageSync('state')) {
  64. data.state = uni.getStorageSync('state')
  65. }
  66. api('wxLogin', data, res => {
  67. uni.hideLoading()
  68. if(res.code != 200){
  69. return
  70. }
  71. Vue.set(state, 'userInfo', res.result.userInfo)
  72. uni.setStorageSync('token', res.result.token)
  73. if(!state.userInfo.nickName || !state.userInfo.headImage){
  74. uni.navigateTo({
  75. url: '/pages_order/auth/wxUserInfo'
  76. })
  77. }else{
  78. uni.navigateBack({
  79. delta: 1,
  80. fail: () => {
  81. uni.reLaunch({
  82. url: '/pages/index/index'
  83. })
  84. }
  85. });
  86. }
  87. })
  88. }
  89. })
  90. },
  91. // 获取用户个人信息
  92. getUserInfo(state){
  93. api('getInfo', res => {
  94. if(res.code == 200){
  95. Vue.set(state, 'userInfo', res.result)
  96. }
  97. })
  98. },
  99. // 获取用户个人信息
  100. getUserInfoVip(state){
  101. api('getUserInfoVip', res => {
  102. if(res.code == 200){
  103. Vue.set(state, 'userInfoVip', res.result)
  104. }
  105. })
  106. },
  107. // 退出登录
  108. logout(state){
  109. uni.showModal({
  110. title: '确认退出登录吗',
  111. success(r) {
  112. if(r.confirm){
  113. Vue.set(state, 'userInfo', {})
  114. state.role = false
  115. uni.removeStorageSync('token')
  116. uni.reLaunch({
  117. url: '/pages/index/index'
  118. })
  119. }
  120. }
  121. })
  122. },
  123. },
  124. actions: {},
  125. })
  126. export default store