Files
tangzhuan-yu/frontend/services/feedback.ts
T
jinghui b3377dccd6 feat: 躺赚鱼 v3.6.2 —— xianyu-auto-reply 深度定制版首发
新增: 实时热卖榜(11分类/想要人数排序/热门搜索词热度)、价格监控(目标价通知/卖家信用筛选/销量下限/AI精准监控)、
一键转卖(收藏自动加载/改价直发/详情直达)、AI回复免费token(ai.88531.cn)、API密钥掩码、
推理模型兼容修复、商品本地编辑、授权系统接入(在线人数/版本/公告)、品牌更名躺赚鱼。

README 重写为项目介绍(改动清单/优势/真实截图/两种安装方式/体验地址 tzy.88531.cn/使用引导),
原版 README 完整保留为 README.upstream.md。
2026-11-16 01:00:59 +08:00

56 lines
1.7 KiB
TypeScript

export type FeedbackType = 'success' | 'error' | 'warning' | 'info';
export interface FeedbackEventDetail {
id: string;
message: string;
type: FeedbackType;
}
export interface ConfirmEventDetail {
message: string;
title: string;
confirmLabel: string;
cancelLabel: string;
danger: boolean;
resolve: (confirmed: boolean) => void;
}
export const FEEDBACK_EVENT = 'app:feedback';
export const CONFIRM_EVENT = 'app:confirm';
const inferType = (message: string): FeedbackType => {
if (/失败|错误|异常|无法|error|fail/i.test(message)) return 'error';
if (/警告|注意|请输入|请选择|warning/i.test(message)) return 'warning';
if (/成功|完成|已新增|已保存|已删除|success/i.test(message)) return 'success';
return 'info';
};
export const notify = (message: unknown, type?: FeedbackType) => {
const normalized = String(message ?? '').trim();
if (!normalized) return;
window.dispatchEvent(new CustomEvent<FeedbackEventDetail>(FEEDBACK_EVENT, {
detail: {
id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
message: normalized,
type: type || inferType(normalized),
},
}));
};
export const confirmAction = (
message: string,
options: Partial<Pick<ConfirmEventDetail, 'title' | 'confirmLabel' | 'cancelLabel' | 'danger'>> = {},
) => new Promise<boolean>((resolve) => {
window.dispatchEvent(new CustomEvent<ConfirmEventDetail>(CONFIRM_EVENT, {
detail: {
message,
title: options.title || '确认操作',
confirmLabel: options.confirmLabel || '确认',
cancelLabel: options.cancelLabel || '取消',
danger: options.danger ?? true,
resolve,
},
}));
});