diff --git a/client/src/utils/notify.js b/client/src/utils/notify.js index aa0686b..9a1a7ef 100644 --- a/client/src/utils/notify.js +++ b/client/src/utils/notify.js @@ -1,9 +1,8 @@ import { request } from './api' -import { getToken } from './api' -// 订阅消息模板ID(微信公众平台→订阅消息→我的模板) +// 订阅消息模板ID(通过 VITE_NOTIFY_TMPL 环境变量注入;未配置时不请求) const TMPL_IDS = [ - (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.VITE_NOTIFY_TMPL) || '', + (import.meta && import.meta.env && import.meta.env.VITE_NOTIFY_TMPL) || '', ].filter(Boolean) /** @@ -23,8 +22,12 @@ export async function askSubscribe() { }) if (!res) return 0 const accepted = TMPL_IDS.filter(id => res[id] === 'accept').length - if (accepted > 0 && getToken()) { - request('PUT', '/api/auth/subscribe-report', { accepted }, getToken()).catch(() => {}) + if (accepted > 0) { + try { + const { useUserStore } = await import('../stores/user') + const token = useUserStore().token + if (token) request('PUT', '/api/auth/subscribe-report', { accepted }, token).catch(() => {}) + } catch { /* store 不可用时静默 */ } } return accepted } catch { return 0 }