发布 0.1.0:通知渠道、告警规则与多项体验修复
This commit is contained in:
@@ -4,6 +4,17 @@ import { h, ref, type Ref, type VNodeChild } from 'vue'
|
||||
type ToastKind = 'error' | 'warning'
|
||||
|
||||
const AUTO_CLOSE_MS = 8000
|
||||
/** 超过此长度的消息自动折叠成「标题 + 展开详情」 */
|
||||
const LONG_TEXT = 64
|
||||
|
||||
/** 长错误提炼标题:优先 hint 分隔符(request.ts 的「hint|error」),次选首个冒号操作前缀,兜底截断 */
|
||||
function summarize(text: string): string {
|
||||
const bar = text.indexOf('|')
|
||||
if (bar > 0 && bar <= 40) return text.slice(0, bar)
|
||||
const colon = text.search(/:|: /)
|
||||
if (colon > 0 && colon <= 40) return text.slice(0, colon)
|
||||
return [...text].slice(0, 40).join('') + '…'
|
||||
}
|
||||
|
||||
function renderDetail(kind: ToastKind, detail: string, copied: Ref<boolean>): VNodeChild {
|
||||
return h('div', { class: 'toast-code' }, [
|
||||
@@ -51,6 +62,11 @@ export function useToast() {
|
||||
const message = useMessage()
|
||||
|
||||
function show(kind: ToastKind, text: string, detail?: string) {
|
||||
// 未显式给 detail 的超长消息(如 OCI 透传错误)自动折叠,避免整段撑爆 toast
|
||||
if (!detail && text.length > LONG_TEXT) {
|
||||
detail = text
|
||||
text = summarize(text)
|
||||
}
|
||||
if (!detail) {
|
||||
message[kind](text)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user