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

102 lines
1.9 KiB

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
  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. category : [],//动态分类
  13. },
  14. getters: {
  15. // 角色 true为水洗店 false为酒店
  16. userShop(state){
  17. return state.shop
  18. }
  19. },
  20. mutations: {
  21. // 初始化配置
  22. initConfig(state){
  23. // api('getConfig', res => {
  24. // if(res.code == 200){
  25. // state.configList = res.result
  26. // }
  27. // })
  28. let config = ['getPrivacyPolicy', 'getUserAgreement']
  29. config.forEach(k => {
  30. api(k, res => {
  31. if (res.code == 200) {
  32. state.configList[k] = res.result
  33. }
  34. })
  35. })
  36. },
  37. login(state){
  38. uni.showLoading({
  39. title: '登录中...'
  40. })
  41. uni.login({
  42. success(res) {
  43. if(res.errMsg != "login:ok"){
  44. return
  45. }
  46. api('wxLogin', {
  47. code : res.code
  48. }, res => {
  49. uni.hideLoading()
  50. if(res.code != 200){
  51. return
  52. }
  53. state.userInfo = res.result.userInfo
  54. uni.setStorageSync('token', res.result.token)
  55. // if(!state.userInfo.nickName || !state.userInfo.headImage){
  56. // uni.navigateTo({
  57. // url: '/pages_order/auth/wxUserInfo'
  58. // })
  59. // }else{
  60. uni.navigateBack(-1)
  61. // }
  62. })
  63. }
  64. })
  65. },
  66. getUserInfo(state){
  67. api('infoGetInfo', res => {
  68. if(res.code == 200){
  69. state.userInfo = res.result
  70. }
  71. })
  72. },
  73. // 获取城市
  74. getCityList(state){
  75. api('getCityList', res => {
  76. if(res.code == 200){
  77. state.city = res.result
  78. }
  79. })
  80. },
  81. // 获取动态分类
  82. getCategory(state){
  83. // 发起请求
  84. api('getClassInfo', res => {
  85. if(res.code == 200){
  86. state.category = res.result
  87. }
  88. })
  89. },
  90. },
  91. actions: {},
  92. })
  93. export default store