Files
frontend_hmi_station/src/store/user.ts

23 lines
538 B
TypeScript
Raw Normal View History

2025-12-17 17:00:29 +08:00
import { defineStore } from 'pinia';
import Cookies from 'js-cookie';
const USERNAME_KEY = 'username';
export const useUserStore = defineStore('user', {
state: () => ({
username: Cookies.get(USERNAME_KEY) || null,
}),
actions: {
async fetchUserInfo() {
// Simulate API call
const fetchedUsername = 'mock_user';
this.username = fetchedUsername;
Cookies.set(USERNAME_KEY, fetchedUsername);
},
clearUserInfo() {
this.username = null;
Cookies.remove(USERNAME_KEY);
},
},
});