useUserStore.js 560 B

123456789101112131415161718192021222324252627282930
  1. import {defineStore} from "pinia";
  2. import storage from "@/utils/storage";
  3. export const useUserStore = defineStore({
  4. id: 'user',
  5. state: () => ({
  6. mac: null,
  7. token: null,
  8. }),
  9. getters: {},
  10. actions: {
  11. _init() {
  12. this.checkLogin()
  13. this.getMachineInfo()
  14. },
  15. checkLogin() {
  16. let token = storage.getKey('LOGIN_TEACHER_TOKEN')
  17. if (token) {
  18. this.token = token
  19. this.getMachineInfo()
  20. }
  21. },
  22. logout() {
  23. this.token = null
  24. },
  25. getMachineInfo() {
  26. this.mac = '123'
  27. },
  28. }
  29. })