feat: 更新 ESLint 配置以放宽不安全参数传递的限制;在 API 查询中添加 Bili-Auth 支持;优化路由参数传递逻辑

This commit is contained in:
Megghy
2025-10-10 13:25:07 +08:00
parent a9453aa919
commit c9ec427692
6 changed files with 25 additions and 12 deletions

View File

@@ -85,6 +85,7 @@ export default antfu(
'ts/restrict-template-expressions': 'off', // 允许模板字符串表达式不受限制 'ts/restrict-template-expressions': 'off', // 允许模板字符串表达式不受限制
'perfectionist/sort-imports': 'off', 'perfectionist/sort-imports': 'off',
'ts/no-unsafe-argument': 'off', // 允许不安全的参数传递
// JSON 相关规则 // JSON 相关规则
'jsonc/sort-keys': 'off', // 关闭 JSON key 排序要求 'jsonc/sort-keys': 'off', // 关闭 JSON key 排序要求

View File

@@ -1,6 +1,7 @@
import type { APIRoot, PaginationResponse } from './api-models' import type { APIRoot, PaginationResponse } from './api-models'
import { apiFail } from '@/data/constants' import { apiFail } from '@/data/constants'
import { cookie } from './account' import { cookie } from './account'
import { useBiliAuth } from '@/store/useBiliAuth';
export async function QueryPostAPI<T>( export async function QueryPostAPI<T>(
urlString: string, urlString: string,
@@ -57,6 +58,10 @@ async function QueryPostAPIWithParamsInternal<T>(
h[header[0]] = header[1] h[header[0]] = header[1]
}) })
if (cookie.value.cookie) h.Authorization = `Bearer ${cookie.value.cookie}` if (cookie.value.cookie) h.Authorization = `Bearer ${cookie.value.cookie}`
const biliAuth = useBiliAuth();
if (biliAuth.currentToken) {
h['Bili-Auth'] = biliAuth.currentToken;
}
// 当使用FormData时不手动设置Content-Type让浏览器自动添加boundary // 当使用FormData时不手动设置Content-Type让浏览器自动添加boundary
if (!(body instanceof FormData)) { if (!(body instanceof FormData)) {
@@ -117,6 +122,10 @@ async function QueryGetAPIInternal<T>(
if (cookie.value.cookie) { if (cookie.value.cookie) {
h.Authorization = `Bearer ${cookie.value.cookie}` h.Authorization = `Bearer ${cookie.value.cookie}`
} }
const biliAuth = useBiliAuth();
if (biliAuth.currentToken) {
h['Bili-Auth'] = biliAuth.currentToken;
}
return await QueryAPIInternal<T>(url, { method: 'get', headers: h }) return await QueryAPIInternal<T>(url, { method: 'get', headers: h })
} catch (err) { } catch (err) {
console.log(`url:${urlString}, error:${err}`) console.log(`url:${urlString}, error:${err}`)

10
src/components.d.ts vendored
View File

@@ -19,23 +19,13 @@ declare module 'vue' {
LiveInfoContainer: typeof import('./components/LiveInfoContainer.vue')['default'] LiveInfoContainer: typeof import('./components/LiveInfoContainer.vue')['default']
MonacoEditorComponent: typeof import('./components/MonacoEditorComponent.vue')['default'] MonacoEditorComponent: typeof import('./components/MonacoEditorComponent.vue')['default']
NAlert: typeof import('naive-ui')['NAlert'] NAlert: typeof import('naive-ui')['NAlert']
NAvatar: typeof import('naive-ui')['NAvatar']
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard']
NDataTable: typeof import('naive-ui')['NDataTable']
NEllipsis: typeof import('naive-ui')['NEllipsis'] NEllipsis: typeof import('naive-ui')['NEllipsis']
NEmpty: typeof import('naive-ui')['NEmpty'] NEmpty: typeof import('naive-ui')['NEmpty']
NFlex: typeof import('naive-ui')['NFlex'] NFlex: typeof import('naive-ui')['NFlex']
NFormItemGi: typeof import('naive-ui')['NFormItemGi'] NFormItemGi: typeof import('naive-ui')['NFormItemGi']
NGridItem: typeof import('naive-ui')['NGridItem'] NGridItem: typeof import('naive-ui')['NGridItem']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
NScrollbar: typeof import('naive-ui')['NScrollbar'] NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpace: typeof import('naive-ui')['NSpace']
NTag: typeof import('naive-ui')['NTag'] NTag: typeof import('naive-ui')['NTag']
NText: typeof import('naive-ui')['NText']
NTime: typeof import('naive-ui')['NTime']
PointGoodsItem: typeof import('./components/manage/PointGoodsItem.vue')['default'] PointGoodsItem: typeof import('./components/manage/PointGoodsItem.vue')['default']
PointHistoryCard: typeof import('./components/manage/PointHistoryCard.vue')['default'] PointHistoryCard: typeof import('./components/manage/PointHistoryCard.vue')['default']
PointOrderCard: typeof import('./components/manage/PointOrderCard.vue')['default'] PointOrderCard: typeof import('./components/manage/PointOrderCard.vue')['default']

View File

@@ -116,6 +116,19 @@ const router = createRouter({
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
useLoadingBarStore().loadingBar?.start() useLoadingBarStore().loadingBar?.start()
// 保留 as 参数(如果存在)
if (from.query.as && !to.query.as) {
next({
...to,
query: {
...to.query,
as: from.query.as,
},
})
return
}
next() next()
}) })
router.afterEach(() => { router.afterEach(() => {

View File

@@ -110,7 +110,7 @@ export const useBiliAuth = defineStore('BiliAuth', () => {
return [] return []
} }
try { try {
const resp = await QueryGetAPI<ResponsePointGoodModel[]>(`${POINT_API_URL}get-goods`, { const resp = await QueryBiliAuthGetAPI<ResponsePointGoodModel[]>(`${POINT_API_URL}get-goods`, {
id, id,
}) })
if (resp.code == 200) { if (resp.code == 200) {

View File

@@ -1027,7 +1027,7 @@ onMounted(() => { })
</NTooltip> </NTooltip>
</NText> </NText>
<NRadioGroup <NRadioGroup
:value="currentGoodsModel.goods.setting?.allowGuardLevel ?? 0" :value="currentGoodsModel.goods.setting?.allowGuardLevel ?? 0"
@update:value="(v) => { @update:value="(v) => {
if (!currentGoodsModel.goods.setting) { if (!currentGoodsModel.goods.setting) {