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

166 lines
3.4 KiB

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