前端重构 Vite
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export interface Notification {
|
||||
id: number
|
||||
message: string
|
||||
type: 'info' | 'success' | 'error' | 'warning'
|
||||
timestamp: Date
|
||||
visible: boolean
|
||||
}
|
||||
|
||||
export interface AppUser {
|
||||
id: number
|
||||
username: string
|
||||
full_name: string | null
|
||||
is_superuser: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore('app', () => {
|
||||
const user = ref<AppUser | null>(null)
|
||||
const token = ref<string | null>(null)
|
||||
const loading = ref(false)
|
||||
const notifications = ref<Notification[]>([])
|
||||
const initialized = ref(false)
|
||||
|
||||
function dismissNotification(id: number) {
|
||||
const index = notifications.value.findIndex(n => n.id === id)
|
||||
if (index > -1) notifications.value.splice(index, 1)
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
token,
|
||||
loading,
|
||||
notifications,
|
||||
initialized,
|
||||
dismissNotification,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user