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

110 lines
2.1 KiB

8 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
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. api('wxLogin', {
  48. code : res.code
  49. }, res => {
  50. uni.hideLoading()
  51. if(res.code != 200){
  52. return
  53. }
  54. state.userInfo = res.result.userInfo
  55. uni.setStorageSync('token', res.result.token)
  56. if(!state.userInfo.nickName || !state.userInfo.headImage){
  57. uni.navigateTo({
  58. url: '/pages_order/auth/wxUserInfo'
  59. })
  60. }else{
  61. uni.navigateBack(-1)
  62. }
  63. })
  64. }
  65. })
  66. },
  67. getUserInfo(state){
  68. api('getInfo', res => {
  69. if(res.code == 200){
  70. state.userInfo = res.result
  71. if(!state.userInfo.nickName || !state.userInfo.headImage){
  72. uni.navigateTo({
  73. url: '/pages_order/auth/wxUserInfo'
  74. })
  75. }
  76. }
  77. })
  78. },
  79. // 获取城市
  80. getCityList(state){
  81. api('getCityList', res => {
  82. if(res.code == 200){
  83. state.cityList = res.result
  84. state.city = res.result[0] || {}
  85. }
  86. })
  87. },
  88. // 获取动态分类
  89. getCategory(state){
  90. // 发起请求
  91. api('getClassInfo', res => {
  92. if(res.code == 200){
  93. state.category = res.result
  94. }
  95. })
  96. },
  97. },
  98. actions: {},
  99. })
  100. export default store