瑶都万能墙
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.

150 lines
3.0 KiB

11 months ago
9 months ago
11 months ago
10 months ago
10 months ago
10 months ago
9 months ago
9 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
9 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. city : {},//当前城市
  12. cityList : [],//城市列表
  13. category : [],//动态分类
  14. headInfo : [],//首页配置
  15. vipLogList : [],//当前用户vip开通记录,用于计算结束时间
  16. },
  17. getters: {
  18. // 角色 true为水洗店 false为酒店
  19. userShop(state){
  20. return state.shop
  21. }
  22. },
  23. mutations: {
  24. // 初始化配置
  25. initConfig(state){
  26. // api('getConfig', res => {
  27. // if(res.code == 200){
  28. // state.configList = res.result
  29. // }
  30. // })
  31. let config = ['getPrivacyPolicy', 'getUserAgreement']
  32. config.forEach(k => {
  33. api(k, res => {
  34. if (res.code == 200) {
  35. state.configList[k] = res.result
  36. }
  37. })
  38. })
  39. },
  40. login(state){
  41. uni.showLoading({
  42. title: '登录中...'
  43. })
  44. uni.login({
  45. success(res) {
  46. if(res.errMsg != "login:ok"){
  47. return
  48. }
  49. let data = {
  50. code : res.code
  51. }
  52. if(uni.getStorageSync('shareId')){
  53. data.shareId = uni.getStorageSync('shareId')
  54. }
  55. api('wxLogin', data, 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. getUserInfo(state){
  74. api('getInfo', res => {
  75. if(res.code == 200){
  76. state.userInfo = res.result
  77. if(!state.userInfo.nickName || !state.userInfo.headImage){
  78. uni.navigateTo({
  79. url: '/pages_order/auth/wxUserInfo'
  80. })
  81. }
  82. }
  83. })
  84. },
  85. // 获取城市
  86. getCityList(state){
  87. api('getCityList', res => {
  88. if(res.code == 200){
  89. state.cityList = res.result
  90. state.city = res.result[0] || {}
  91. }
  92. })
  93. },
  94. // 获取动态分类
  95. getCategory(state){
  96. // 发起请求
  97. api('getClassInfo', res => {
  98. if(res.code == 200){
  99. state.category = res.result
  100. }
  101. })
  102. },
  103. // 退出登录
  104. logout(state){
  105. uni.showModal({
  106. title: '确认退出登录吗',
  107. success(r) {
  108. if(r.confirm){
  109. state.userInfo = {}
  110. state.role = false
  111. uni.removeStorageSync('token')
  112. uni.redirectTo({
  113. url: '/pages/index/index'
  114. })
  115. }
  116. }
  117. })
  118. },
  119. // 获取小程序首页配置
  120. getIndexHeaderInfo(state){
  121. api('getIndexHeaderInfo', res =>{
  122. if(res.code == 200){
  123. state.headInfo = res.result
  124. }
  125. })
  126. },
  127. // 查询当前开通会员以及过期时间
  128. getMemberInfo(state){
  129. api('getMemberInfo', res =>{
  130. if(res.code == 200){
  131. state.vipLogList = res.result
  132. }
  133. })
  134. },
  135. },
  136. actions: {},
  137. })
  138. export default store