商城类、订单类uniapp模板,多角色
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.

83 lines
1.5 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 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. },
  12. getters: {
  13. // 角色 true为水洗店 false为酒店
  14. userShop(state){
  15. return state.shop
  16. }
  17. },
  18. mutations: {
  19. // 初始化配置
  20. initConfig(state){
  21. // api('getConfig', res => {
  22. // if(res.code == 200){
  23. // state.configList = res.result
  24. // }
  25. // })
  26. let config = ['getPrivacyPolicy', 'getUserAgreement']
  27. config.forEach(k => {
  28. api(k, res => {
  29. if (res.code == 200) {
  30. state.configList[k] = res.result
  31. }
  32. })
  33. })
  34. },
  35. login(state){
  36. uni.showLoading({
  37. title: '登录中...'
  38. })
  39. uni.login({
  40. success(res) {
  41. if(res.errMsg != "login:ok"){
  42. return
  43. }
  44. api('wxLogin', {
  45. code : res.code
  46. }, res => {
  47. uni.hideLoading()
  48. if(res.code != 200){
  49. return
  50. }
  51. state.userInfo = res.result.userInfo
  52. uni.setStorageSync('token', res.result.token)
  53. if(!state.userInfo.nickName || !state.userInfo.headImage){
  54. uni.navigateTo({
  55. url: '/pages_order/auth/wxUserInfo'
  56. })
  57. }else{
  58. uni.navigateBack(-1)
  59. }
  60. })
  61. }
  62. })
  63. },
  64. getUserInfo(state){
  65. api('infoGetInfo', res => {
  66. if(res.code == 200){
  67. state.userInfo = res.result
  68. }
  69. })
  70. },
  71. },
  72. actions: {},
  73. })
  74. export default store