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

162 lines
3.3 KiB

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