index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const store = new Vuex.Store({
  5. state: {
  6. // 判断登录状态
  7. hasLogin: !!uni.getStorageSync('token'),
  8. // 设置登录token
  9. token: uni.getStorageSync('token') || '',
  10. // 存储用户信息
  11. userInfo: uni.getStorageSync('userInfo') || {},
  12. // 企业token
  13. enToken: uni.getStorageSync('enToken') || '',
  14. //企业信息
  15. enterprise: uni.getStorageSync('enterprise') || '',
  16. /*
  17. * 登录者权限
  18. * isAdministrator是否为超级管理员 true是,false不是
  19. * dataField 数据域权限
  20. * custom 节点权限
  21. */
  22. access: uni.getStorageSync('access') || '',
  23. // 企业基本设置
  24. basicSet: uni.getStorageSync('basicSet') || '',
  25. },
  26. mutations: {
  27. // 企业基本设置
  28. commit_basicSet(state, basicSet) {
  29. state.basicSet = basicSet
  30. uni.setStorageSync('basicSet', basicSet);
  31. },
  32. // 登录者权限
  33. commit_access(state, access) {
  34. state.access = access
  35. uni.setStorageSync('access', access);
  36. },
  37. // 企业信息
  38. commit_enterprise(state, enterprise) {
  39. state.enterprise = enterprise
  40. uni.setStorageSync('enterprise', enterprise);
  41. },
  42. // 企业token
  43. commit_enToken(state, enToken) {
  44. state.enToken = enToken
  45. uni.setStorageSync('enToken', enToken);
  46. },
  47. // 存储用户信息
  48. commit_userInfo(state, userInfo) {
  49. state.userInfo = userInfo
  50. uni.setStorageSync('userInfo', userInfo);
  51. },
  52. // 设置登录token
  53. commit_token(state, token) {
  54. state.token = token
  55. uni.setStorageSync('token', token);
  56. },
  57. // 判断登录状态
  58. commit_hasLogin(state, hasLogin) {
  59. state.hasLogin = hasLogin
  60. },
  61. },
  62. actions: {
  63. logout({
  64. commit
  65. }) {
  66. uni.clearStorageSync();
  67. commit("commit_hasLogin", false);
  68. commit("commit_token", '');
  69. commit("commit_userInfo", '');
  70. commit("commit_enToken", '');
  71. commit("commit_enterprise", '');
  72. commit("commit_access", '');
  73. commit("commit_basicSet", '');
  74. uni.reLaunch({
  75. url: '/pages/login/index'
  76. })
  77. }
  78. }
  79. })
  80. export default store