diff --git a/src/layout/AdminLayout.vue b/src/layout/AdminLayout.vue index c5dd0e6..51c7bb9 100644 --- a/src/layout/AdminLayout.vue +++ b/src/layout/AdminLayout.vue @@ -1,6 +1,9 @@ diff --git a/src/stores/systemLog.ts b/src/stores/systemLog.ts new file mode 100644 index 0000000..c368996 --- /dev/null +++ b/src/stores/systemLog.ts @@ -0,0 +1,63 @@ +import { defineStore } from 'pinia' + +interface LogEntry { + id: number; + type: string; + user: string; + action: string; + ip: string; + status: string; + detail: string; + createTime: string; +} + +export const useSystemLogStore = defineStore('systemLog', { + state: () => ({ + logs: [] as LogEntry[] + }), + + actions: { + // 添加日志 + addLog(log: Omit) { + const newLog: LogEntry = { + ...log, + id: Date.now(), + createTime: new Date().toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false + }).replace(/\//g, '-') + }; + + this.logs.unshift(newLog); + this.saveLogs(); + }, + + // 加载日志 + loadLogs() { + const savedLogs = localStorage.getItem('systemLogs'); + if (savedLogs) { + this.logs = JSON.parse(savedLogs); + } + }, + + // 保存日志到localStorage + saveLogs() { + localStorage.setItem('systemLogs', JSON.stringify(this.logs)); + }, + + // 清空日志 + clearLogs() { + this.logs = []; + this.saveLogs(); + } + }, + + getters: { + getLogs: (state) => state.logs + } +}) \ No newline at end of file diff --git a/src/stores/user.ts b/src/stores/user.ts new file mode 100644 index 0000000..fbd21fa --- /dev/null +++ b/src/stores/user.ts @@ -0,0 +1,44 @@ +import { defineStore } from 'pinia' + +interface UserState { + token: string | null; + userInfo: { + username: string; + role: string; + } | null; +} + +export const useUserStore = defineStore('user', { + state: (): UserState => ({ + token: localStorage.getItem('token'), + userInfo: null + }), + + actions: { + // 登录 + async login(username: string, password: string) { + if (username === 'admin' && password === '123456') { + this.token = 'demo-token'; + this.userInfo = { + username: 'admin', + role: '管理员' + }; + localStorage.setItem('token', this.token); + return true; + } + return false; + }, + + // 退出登录 + logout() { + this.token = null; + this.userInfo = null; + localStorage.removeItem('token'); + } + }, + + getters: { + isLoggedIn: (state) => !!state.token, + username: (state) => state.userInfo?.username + } +}) \ No newline at end of file diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 8d76b6e..9813993 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,22 +1,75 @@