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

153 lines
3.0 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
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
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. let config = ['getPrivacyPolicy', 'getUserAgreement']
  35. config.forEach(k => {
  36. api(k, res => {
  37. if (res.code == 200) {
  38. state.configList[k] = res.result
  39. }
  40. })
  41. })
  42. },
  43. login(state){
  44. uni.showLoading({
  45. title: '登录中...'
  46. })
  47. uni.login({
  48. success(res) {
  49. if(res.errMsg != "login:ok"){
  50. return
  51. }
  52. let data = {
  53. code : res.code
  54. }
  55. if(uni.getStorageSync('shareId')){
  56. data.shareId = uni.getStorageSync('shareId')
  57. }
  58. api('wxLogin', data, res => {
  59. uni.hideLoading()
  60. if(res.code != 200){
  61. return
  62. }
  63. state.userInfo = res.result.userInfo
  64. uni.setStorageSync('token', res.result.token)
  65. if(!state.userInfo.nickName || !state.userInfo.headImage){
  66. uni.navigateTo({
  67. url: '/pages_order/auth/wxUserInfo'
  68. })
  69. }else{
  70. uni.navigateBack(-1)
  71. }
  72. })
  73. }
  74. })
  75. },
  76. getUserInfo(state){
  77. api('getInfo', res => {
  78. if(res.code == 200){
  79. state.userInfo = res.result
  80. if(!state.userInfo.nickName || !state.userInfo.headImage){
  81. uni.navigateTo({
  82. url: '/pages_order/auth/wxUserInfo'
  83. })
  84. }
  85. }
  86. })
  87. },
  88. // 获取城市
  89. getCityList(state){
  90. api('getCityList', res => {
  91. if(res.code == 200){
  92. state.cityList = res.result
  93. state.city = res.result[0] || {}
  94. }
  95. })
  96. },
  97. // 获取动态分类
  98. getCategory(state){
  99. // 发起请求
  100. api('getClassInfo', res => {
  101. if(res.code == 200){
  102. state.category = res.result
  103. }
  104. })
  105. },
  106. // 退出登录
  107. logout(state){
  108. uni.showModal({
  109. title: '确认退出登录吗',
  110. success(r) {
  111. if(r.confirm){
  112. state.userInfo = {}
  113. state.role = false
  114. uni.removeStorageSync('token')
  115. uni.redirectTo({
  116. url: '/pages/index/index'
  117. })
  118. }
  119. }
  120. })
  121. },
  122. // 获取小程序首页配置
  123. getIndexHeaderInfo(state){
  124. api('getIndexHeaderInfo', res =>{
  125. if(res.code == 200){
  126. state.headInfo = res.result
  127. }
  128. })
  129. },
  130. // 查询当前开通会员以及过期时间
  131. getMemberInfo(state){
  132. api('getMemberInfo', res =>{
  133. if(res.code == 200){
  134. state.vipLogList = res.result
  135. }
  136. })
  137. },
  138. },
  139. actions: {},
  140. })
  141. export default store