index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Vue from "vue"
  2. import Vuex from "vuex"
  3. import getters from './getters'
  4. Vue.use(Vuex)
  5. const store = new Vuex.Store({
  6. state: {
  7. Token: uni.getStorageSync('xj-storage_token'),
  8. users:uni.getStorageSync('xj-storage_users'),
  9. auths:uni.getStorageSync('xj-storage_auth') || [],
  10. dataArray:[],
  11. doneBack:false
  12. },
  13. actions: {
  14. setToken({
  15. commit,
  16. state
  17. }, token) {
  18. commit("SETTOKEN", token)
  19. },
  20. setUsers({
  21. commit,
  22. state
  23. }, users) {
  24. commit("SETUSERS", users)
  25. },
  26. setAuths({
  27. commit,
  28. state
  29. }, auths) {
  30. commit("SETAUTHS", auths)
  31. },
  32. setObj({
  33. commit,
  34. state
  35. }, dataArray) {
  36. commit("SETOBJ", dataArray)
  37. },
  38. setDoneBack({
  39. commit,
  40. state
  41. }, doneBack) {
  42. commit("SETBACK", doneBack)
  43. },
  44. },
  45. mutations: {
  46. SETBACK: (state, doneBack) => {
  47. state.doneBack = doneBack
  48. },
  49. SETOBJ: (state, dataArray) => {
  50. state.dataArray = dataArray
  51. },
  52. SETTOKEN: (state, token) => {
  53. state.Token = token
  54. uni.setStorageSync("xj-storage_token", token)
  55. },
  56. SETUSERS:(state,users) =>{
  57. state.users = users
  58. uni.setStorageSync("xj-storage_users", users)
  59. },
  60. SETAUTHS:(state,auths) =>{
  61. state.auths = auths
  62. uni.setStorageSync("xj-storage_auth", auths)
  63. }
  64. },
  65. getters
  66. })
  67. export default store