import { defineStore } from 'pinia';

export const useGlobalStore = defineStore('global', {
  state: () => ({
    authCode: null,
    zjhm: null,
    userName: null,
  }),
  actions: {
    setAuthCode(authCode) {
      this.authCode = authCode;
      localStorage.setItem('authCode', authCode);
    },
    setZjhm(zjhm) {
      this.zjhm = zjhm;
      localStorage.setItem('zjhm', zjhm);
    },
    setUserName(userName) {
      this.userName = userName;
      localStorage.setItem('userName', userName);
    },
    loadFromLocalStorage() {
      this.authCode = localStorage.getItem('authCode');
      this.zjhm = localStorage.getItem('zjhm');
      this.userName = localStorage.getItem('userName');
    },
  },
});