refactor(group): Refactor grouping to add logic and optimize validation rules.
- Remove direct database operations and use groupRepository instead. - Use notifyStore to unify notification messages.
This commit is contained in:
37
src/components/notify/notificationProvider.vue
Normal file
37
src/components/notify/notificationProvider.vue
Normal file
@@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<div>
|
||||
<v-snackbar
|
||||
v-for="(item, index) in notifyQueue"
|
||||
:key="item.id"
|
||||
v-model="visible[item.id]"
|
||||
:timeout="item.timeout"
|
||||
:color="item.color"
|
||||
:variant="item.variant"
|
||||
top
|
||||
right
|
||||
:style="{
|
||||
zIndex: 9999,
|
||||
marginTop: `${index * 70 + 16}px` // 每条通知向下偏移
|
||||
}"
|
||||
>
|
||||
{{ item.message }}
|
||||
</v-snackbar>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, watch } from 'vue'
|
||||
import { notifyQueue } from './notifyStore'
|
||||
|
||||
const visible: Record<number, boolean> = reactive({})
|
||||
|
||||
watch(
|
||||
() => notifyQueue.slice(),
|
||||
(queue) => {
|
||||
queue.forEach(item => {
|
||||
if (visible[item.id] === undefined) visible[item.id] = true
|
||||
})
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
39
src/components/notify/notifyStore.ts
Normal file
39
src/components/notify/notifyStore.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { reactive } from 'vue'
|
||||
|
||||
export interface NotifyOptions {
|
||||
color?: string
|
||||
timeout?: number
|
||||
variant?: string
|
||||
}
|
||||
|
||||
// 通知对象
|
||||
export interface NotifyItem {
|
||||
id: number
|
||||
message: string
|
||||
color: string
|
||||
timeout: number
|
||||
variant: string
|
||||
}
|
||||
|
||||
// 队列状态
|
||||
export const notifyQueue = reactive<NotifyItem[]>([])
|
||||
|
||||
// 全局可调用 notify
|
||||
let nextId = 1
|
||||
export function notify(message: string, options?: NotifyOptions) {
|
||||
const id = nextId++
|
||||
const item: NotifyItem = {
|
||||
id,
|
||||
message,
|
||||
color: options?.color ?? 'success',
|
||||
timeout: options?.timeout ?? 3000,
|
||||
variant: options?.variant ?? 'outlined'
|
||||
}
|
||||
notifyQueue.push(item)
|
||||
|
||||
// 自动移除
|
||||
setTimeout(() => {
|
||||
const index = notifyQueue.findIndex(i => i.id === id)
|
||||
if (index !== -1) notifyQueue.splice(index, 1)
|
||||
}, item.timeout)
|
||||
}
|
||||
Reference in New Issue
Block a user