Files
device-voice-h5/store/asset.js
luo da95a914e3
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 2m59s
fix: some
2026-10-13 14:53:19 +08:00

59 lines
1.5 KiB
JavaScript

import { reactive } from 'vue';
import { isCurrentSession } from '@/utils/session-context.js';
import { getShanghaiDay, normalizeExpiryReminder } from '@/utils/expiry-reminder.js';
const receivedReminders = new Set();
const state = reactive({
assetInfo: null,
deviceRealtime: null,
currentPackage: null,
expiryReminder: null
});
export const useAssetStore = () => {
const receiveExpiryReminder = (context, value) => {
const reminder = normalizeExpiryReminder(value);
if (!reminder || !isCurrentSession(context)) return;
const day = getShanghaiDay();
const key = JSON.stringify([context.token, context.identifier, day]);
if (receivedReminders.has(key)) return;
receivedReminders.add(key);
state.expiryReminder = { ...context, day, reminder, shown: false };
};
const markExpiryReminderShown = () => {
if (state.expiryReminder) state.expiryReminder.shown = true;
};
const dismissExpiryReminder = () => { state.expiryReminder = null; };
const setAssetInfo = (info) => {
state.assetInfo = info;
};
const setDeviceRealtime = (realtime) => {
state.deviceRealtime = realtime;
};
const setCurrentPackage = (pkg) => {
state.currentPackage = pkg;
};
const clearAsset = () => {
state.assetInfo = null;
state.deviceRealtime = null;
state.currentPackage = null;
state.expiryReminder = null;
receivedReminders.clear();
};
return {
state,
setAssetInfo,
setDeviceRealtime,
setCurrentPackage,
receiveExpiryReminder,
markExpiryReminderShown,
dismissExpiryReminder,
clearAsset
};
};