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

132 lines
2.5 KiB

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