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

141 lines
2.7 KiB

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