@@ -1,71 +1,5 @@
|
||||
export const PACKAGE_AUDIT_CHANGED_EVENT = 'admin:package-audit-changed';
|
||||
export const AUDIT_NOTICE_CHANGED_EVENT = 'dukang:audit-notice-changed';
|
||||
export const BIG_SCREEN_DEMO_CHANNEL = 'dukang-big-screen';
|
||||
export const BIG_SCREEN_DEMO_STORAGE_KEY = 'dukang:big-screen-demo';
|
||||
|
||||
export type BigScreenDemoOrder = {
|
||||
payAmount: number;
|
||||
items: string;
|
||||
userPhoneMasked: string;
|
||||
};
|
||||
|
||||
export type BigScreenDemoPayload = {
|
||||
type: 'demo';
|
||||
id: string;
|
||||
at: number;
|
||||
orders: BigScreenDemoOrder[];
|
||||
};
|
||||
|
||||
export function buildBigScreenDemoPayload(): BigScreenDemoPayload {
|
||||
return {
|
||||
type: 'demo',
|
||||
id: `demo-${Date.now()}`,
|
||||
at: Date.now(),
|
||||
orders: [
|
||||
{ payAmount: 1288, items: '杜康君酿 · 浓香型 × 6瓶', userPhoneMasked: '138****8888' },
|
||||
{ payAmount: 688, items: '杜康君酿 · 浓香型 × 2瓶', userPhoneMasked: '139****6666' },
|
||||
{ payAmount: 188, items: '杜康君酿 · 浓香型 × 1瓶', userPhoneMasked: '137****1888' },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export function triggerBigScreenDemo() {
|
||||
const payload = buildBigScreenDemoPayload();
|
||||
try {
|
||||
localStorage.setItem(BIG_SCREEN_DEMO_STORAGE_KEY, JSON.stringify(payload));
|
||||
} catch {
|
||||
/* ignore quota */
|
||||
}
|
||||
try {
|
||||
const ch = new BroadcastChannel(BIG_SCREEN_DEMO_CHANNEL);
|
||||
ch.postMessage(payload);
|
||||
ch.close();
|
||||
} catch {
|
||||
/* BroadcastChannel 不可用时靠 localStorage 冷启动 */
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
export function readPendingBigScreenDemo(maxAgeMs = 8000): BigScreenDemoPayload | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(BIG_SCREEN_DEMO_STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as BigScreenDemoPayload;
|
||||
if (parsed?.type !== 'demo' || !parsed.id || !Array.isArray(parsed.orders)) return null;
|
||||
if (Date.now() - Number(parsed.at || 0) > maxAgeMs) return null;
|
||||
return parsed;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearPendingBigScreenDemo() {
|
||||
try {
|
||||
localStorage.removeItem(BIG_SCREEN_DEMO_STORAGE_KEY);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function notifyPackageAuditChanged() {
|
||||
window.dispatchEvent(new Event(PACKAGE_AUDIT_CHANGED_EVENT));
|
||||
|
||||
Reference in New Issue
Block a user