鸿宇研学生前端代码
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.

159 lines
3.3 KiB

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. 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. userCenterData: {},
  13. travelerList: null,
  14. orderInfo: null,
  15. couponInfo: null,
  16. memberInfo: null,
  17. liveInfo: null,
  18. },
  19. getters: {
  20. // 角色 true为水洗店 false为酒店 : 身份判断如果不需要,可以删除
  21. userShop(state){
  22. return state.shop
  23. }
  24. },
  25. mutations: {
  26. // 初始化配置
  27. async initConfig(state) {
  28. const records = (await fetch('getConfig'))?.records
  29. const configList = {
  30. ...state.configList,
  31. }
  32. records.forEach(n => {
  33. configList[n.paramCode] = n.paramImage || n.paramText || n.paramTextarea;
  34. });
  35. const periodList = (await fetch('queryPeriodList')).records
  36. configList['periodList'] = periodList
  37. const commentOptionList = (await fetch('queryCommentOptionList')).records
  38. configList['commentOptionList'] = commentOptionList
  39. const experienceQuestionList = (await fetch('queryExperienceQuestionList')).records
  40. configList['experienceQuestionList'] = experienceQuestionList
  41. state.configList = configList
  42. uni.$emit('initConfig', state.configList)
  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. getUserCenterData(state){
  84. api('queryUserCenterData', res => {
  85. if(res.code == 200){
  86. state.userCenterData = res.result
  87. }
  88. })
  89. },
  90. // 退出登录
  91. logout(state){
  92. uni.showModal({
  93. title: '确认退出登录吗',
  94. success(r) {
  95. if(r.confirm){
  96. state.userInfo = {}
  97. state.role = false
  98. uni.removeStorageSync('token')
  99. uni.reLaunch({
  100. url: '/pages/index/index'
  101. })
  102. }
  103. }
  104. })
  105. },
  106. setTravelerList(state, data) {
  107. state.travelerList = data
  108. },
  109. setOrderInfo(state, data) {
  110. state.orderInfo = data
  111. },
  112. setCouponInfo(state, data) {
  113. state.couponInfo = data
  114. },
  115. setMemberInfo(state, data) {
  116. state.memberInfo = data
  117. },
  118. setLiveInfo(state, data) {
  119. console.log('liveInfo', data)
  120. state.liveInfo = data
  121. },
  122. },
  123. actions: {
  124. async collect(state, activityId) {
  125. console.log('collect', activityId)
  126. try {
  127. await fetch('collectionActivity', { activityId })
  128. uni.showToast({
  129. icon: 'success',
  130. title: '已收藏',
  131. });
  132. return true
  133. } catch (err) {
  134. console.log('collect err', err)
  135. return false
  136. }
  137. },
  138. },
  139. })
  140. export default store