侧栏动作排撤掉重启图标,内核状态(圆点加版本号)本身变成按钮:悬停 换层显示「重启内核」,不在线时只当状态看。行高压成 1 修掉圆点和等宽 字体不居中的问题。 四个页面的一次性反馈(保存、删除、更新订阅、断开连接、测延迟结论) 全部改走 toast,commit() 改返回成败给「失败不关对话框」用;持续状态 (连接页轮询失败、请求页日志流失败)留在页内,会自动消失的提示装不下 需要一直可见的信息。toast 加 info 类别给中性结论用。 GEO 每行的更新改成单独下载那一个文件:内核只有全量更新的口子,单文件 只能服务端自己下(POST /api/geo/sync),代价是只有形状校验(MaxMind 末尾标记、geodata 首字节,shared/geo.ts 带测试)且内核重启后才换用新 文件;「更新全部」文字按钮保留内核的全量口子,有完整校验和热加载。 上传两行的按钮改「选择或拖放文件」,投放区拖入高亮,恢复策略挪到 恢复行下方。
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
/**
|
|
* 右上角的轻提示(成就弹窗式):从右滑入一行字,几秒后上移淡出。
|
|
*
|
|
* 模块级单例,谁都能发;渲染在外壳的 ToastHost 里。适合「动作已完成/失败」
|
|
* 这类看一眼就行的反馈;需要用户处理的内容(表单校验、带重试的错误)
|
|
* 仍然留在页面里,不进这里。
|
|
*/
|
|
import { ref } from 'vue'
|
|
import { ApiError } from './api'
|
|
|
|
export type ToastKind = 'ok' | 'error' | 'info'
|
|
|
|
export interface Toast {
|
|
id: number
|
|
kind: ToastKind
|
|
message: string
|
|
hint: string
|
|
}
|
|
|
|
export const toasts = ref<Toast[]>([])
|
|
|
|
let nextId = 1
|
|
|
|
export function toast(message: string, opts?: { kind?: ToastKind; hint?: string }): void {
|
|
const item: Toast = {
|
|
id: nextId++,
|
|
kind: opts?.kind ?? 'ok',
|
|
message,
|
|
hint: opts?.hint ?? '',
|
|
}
|
|
toasts.value = [...toasts.value, item]
|
|
// 错误多留一会儿,看清 hint 里的下一步
|
|
const ttl = item.kind === 'error' ? 8000 : 4000
|
|
setTimeout(() => dismiss(item.id), ttl)
|
|
}
|
|
|
|
export function dismiss(id: number): void {
|
|
toasts.value = toasts.value.filter((t) => t.id !== id)
|
|
}
|
|
|
|
/** 接口报错的统一出口:message 说发生了什么,hint 说下一步。 */
|
|
export function toastError(error: unknown): void {
|
|
if (error instanceof ApiError) toast(error.message, { kind: 'error', hint: error.hint })
|
|
else toast(String(error), { kind: 'error' })
|
|
}
|