fix: notify.js改用userStore取token(api.js无getToken导出)
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import { request } from './api'
|
import { request } from './api'
|
||||||
import { getToken } from './api'
|
|
||||||
|
|
||||||
// 订阅消息模板ID(微信公众平台→订阅消息→我的模板)
|
// 订阅消息模板ID(通过 VITE_NOTIFY_TMPL 环境变量注入;未配置时不请求)
|
||||||
const TMPL_IDS = [
|
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)
|
].filter(Boolean)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,8 +22,12 @@ export async function askSubscribe() {
|
|||||||
})
|
})
|
||||||
if (!res) return 0
|
if (!res) return 0
|
||||||
const accepted = TMPL_IDS.filter(id => res[id] === 'accept').length
|
const accepted = TMPL_IDS.filter(id => res[id] === 'accept').length
|
||||||
if (accepted > 0 && getToken()) {
|
if (accepted > 0) {
|
||||||
request('PUT', '/api/auth/subscribe-report', { accepted }, getToken()).catch(() => {})
|
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
|
return accepted
|
||||||
} catch { return 0 }
|
} catch { return 0 }
|
||||||
|
|||||||
Reference in New Issue
Block a user