From f2fa96b81b6a9941a0eeaf39df164dfa113ee4a2 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sat, 19 Sep 2026 19:32:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20notify.js=E6=94=B9=E7=94=A8userStore?= =?UTF-8?q?=E5=8F=96token=EF=BC=88api.js=E6=97=A0getToken=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/utils/notify.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 }