feat:项目界面补充
This commit is contained in:
@@ -15,6 +15,7 @@ type ToastStore = {
|
||||
}
|
||||
|
||||
let toastTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let toastRemoveTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
export function resolveToastMessage(source: unknown, fallback = '') {
|
||||
if (typeof source === 'string' && source.trim()) {
|
||||
@@ -37,18 +38,44 @@ export const useToastStore = create<ToastStore>((set) => ({
|
||||
if (toastTimer) {
|
||||
clearTimeout(toastTimer)
|
||||
}
|
||||
if (toastRemoveTimer) {
|
||||
clearTimeout(toastRemoveTimer)
|
||||
}
|
||||
|
||||
set({
|
||||
toast: {
|
||||
message,
|
||||
type,
|
||||
visible: true,
|
||||
visible: false,
|
||||
},
|
||||
})
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
set((state) => state.toast
|
||||
? {
|
||||
toast: {
|
||||
...state.toast,
|
||||
visible: true,
|
||||
},
|
||||
}
|
||||
: state)
|
||||
})
|
||||
|
||||
toastTimer = setTimeout(() => {
|
||||
set({toast: null})
|
||||
set((state) => state.toast
|
||||
? {
|
||||
toast: {
|
||||
...state.toast,
|
||||
visible: false,
|
||||
},
|
||||
}
|
||||
: state)
|
||||
toastTimer = null
|
||||
|
||||
toastRemoveTimer = setTimeout(() => {
|
||||
set({toast: null})
|
||||
toastRemoveTimer = null
|
||||
}, 220)
|
||||
}, 2000)
|
||||
},
|
||||
clearToast: () => {
|
||||
@@ -56,6 +83,10 @@ export const useToastStore = create<ToastStore>((set) => ({
|
||||
clearTimeout(toastTimer)
|
||||
toastTimer = null
|
||||
}
|
||||
if (toastRemoveTimer) {
|
||||
clearTimeout(toastRemoveTimer)
|
||||
toastRemoveTimer = null
|
||||
}
|
||||
set({toast: null})
|
||||
},
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user