fix: notify.js改用userStore取token(api.js无getToken导出)

This commit is contained in:
Hermes Agent
2026-09-19 19:32:16 +08:00
parent 6d463b9296
commit f2fa96b81b
+8 -5
View File
@@ -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 }