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

95 lines
1.7 KiB

8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
7 months ago
7 months ago
7 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 : true,
  10. userInfo : {}, //用户信息
  11. shopData : {},
  12. buy : {},
  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, form){
  38. uni.showLoading({
  39. title: '登录中...'
  40. })
  41. api('loginUser', form, res => {
  42. uni.hideLoading()
  43. if(res.code != 200){
  44. return
  45. }
  46. state.userInfo = res.result.userInfo
  47. state.buy = res.result.buy
  48. state.shop = res.result.shop
  49. uni.setStorageSync('token', res.result.token)
  50. if(!state.shop && !state.buy){
  51. uni.reLaunch({
  52. url: '/pages_order/auth/selectionIdentity?back=no&'
  53. })
  54. }else{
  55. uni.reLaunch({
  56. url: '/pages/index/index'
  57. })
  58. }
  59. })
  60. },
  61. getUserInfo(state){
  62. api('infoGetInfo', res => {
  63. if(res.code == 200){
  64. state.userInfo = res.result
  65. }
  66. })
  67. },
  68. logout(state){
  69. uni.showModal({
  70. title: '确认退出登录吗',
  71. success(r) {
  72. if(r.confirm){
  73. state.userInfo = {}
  74. state.role = false
  75. uni.removeStorageSync('token')
  76. uni.redirectTo({
  77. url: '/pages/index/index'
  78. })
  79. }
  80. }
  81. })
  82. },
  83. },
  84. actions: {},
  85. })
  86. export default store