铝交易,微信公众号
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.

98 lines
1.8 KiB

11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 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. shopData : {},
  12. buy : {},
  13. },
  14. getters: {
  15. // 角色 true 为供应商 false 为采购商
  16. userShop(state){
  17. return state.shop
  18. },
  19. userInfo(state){
  20. return state.userInfo
  21. },
  22. },
  23. mutations: {
  24. // 初始化配置
  25. initConfig(state){
  26. // api('getConfig', res => {
  27. // if(res.code == 200){
  28. // state.configList = res.result
  29. // }
  30. // })
  31. let config = ['getPrivacyPolicy', 'getUserAgreement']
  32. config.forEach(k => {
  33. api(k, res => {
  34. if (res.code == 200) {
  35. state.configList[k] = res.result
  36. }
  37. })
  38. })
  39. },
  40. login(state, form){
  41. uni.showLoading({
  42. title: '登录中...'
  43. })
  44. api('loginUser', form, res => {
  45. uni.hideLoading()
  46. if(res.code != 200){
  47. return
  48. }
  49. state.userInfo = res.result.userInfo
  50. state.buy = res.result.buy
  51. state.shop = res.result.shop
  52. uni.setStorageSync('token', res.result.token)
  53. if(!state.shop && !state.buy){
  54. uni.reLaunch({
  55. url: '/pages_order/auth/selectionIdentity?back=no&'
  56. })
  57. }else{
  58. uni.reLaunch({
  59. url: '/pages/index/index'
  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. logout(state){
  72. uni.showModal({
  73. title: '确认退出登录吗',
  74. success(r) {
  75. if(r.confirm){
  76. state.userInfo = {}
  77. state.role = false
  78. uni.removeStorageSync('token')
  79. uni.redirectTo({
  80. url: '/pages/index/index'
  81. })
  82. }
  83. }
  84. })
  85. },
  86. },
  87. actions: {},
  88. })
  89. export default store