修复鉴权:401拦截器加refresh重试 + admin refresh接口 + 路由守卫完善

根因:access_token每2小时过期,前端收到401直接清token跳登录,没有用refresh_token续期

后端修复:
- adminauth模块新增 POST /admin/auth/refresh 接口
- Service 注入 JWTManager,支持 admin refresh token 换新 token pair
- Refresh 方法验证 subjectType=admin + tokenType=refresh

前端修复:
- 401 拦截器核心改造:收到401先调 refresh 接口续期
- 加 isRefreshing 锁 + pendingRequests 队列防止并发刷新
- refresh 用原生 axios.post 避免拦截器递归
- 成功则更新 localStorage + 重试原请求,失败才清 token 跳登录
- 排除 /auth/refresh 自身避免死循环
- 支持 /admin/ 请求独立 token 管理
- auth.ts/adminAuth.ts 新增手动 refreshUserToken/refreshAdminSession
- 路由守卫给所有需登录路由添加 meta.requiresAuth
- 守卫同时支持 PC 端 /login 和移动端 /m/login
This commit is contained in:
yml2213
2026-05-24 07:00:13 +08:00
parent 3631e70321
commit cdee93c7c5
61 changed files with 1735 additions and 722 deletions
+43 -80
View File
@@ -5,14 +5,8 @@ import { computed, onMounted, reactive, ref } from 'vue'
import { fetchAdminListings, type Listing } from '@/api/listings'
import {
formatMoney,
formatRatio,
getAdminListingPricing,
listingAssetTags,
listingBadgeTags,
listingBuyerPrice,
listingDisplayTitle,
listingResourceTags,
listingRiskTags,
listingSellerPrice,
ownerName,
} from '@/views/admin/listingAdminDisplay'
@@ -21,11 +15,13 @@ import { formatDateTime } from '@/utils/time'
const loading = ref(false)
const listings = ref<Listing[]>([])
const currentPage = ref(1)
const currentPageSize = ref(20)
const total = ref(0)
const filters = reactive({
owner_id: '',
status: '',
review_status: '',
limit: 200,
})
const publishedCount = computed(() => listings.value.filter((item) => item.status === 'published').length)
@@ -37,7 +33,14 @@ onMounted(loadListings)
async function loadListings() {
loading.value = true
try {
listings.value = await fetchAdminListings(filters)
const query = {
...filters,
page: currentPage.value,
page_size: currentPageSize.value,
}
const result = await fetchAdminListings(query)
listings.value = result.items
total.value = result.total
} finally {
loading.value = false
}
@@ -47,10 +50,15 @@ function resetFilters() {
filters.owner_id = ''
filters.status = ''
filters.review_status = ''
filters.limit = 200
currentPage.value = 1
void loadListings()
}
function handleSizeChange() {
currentPage.value = 1
loadListings()
}
function statusType(status: string) {
if (status === 'published') return 'success'
if (status === 'rented') return 'warning'
@@ -72,7 +80,7 @@ function reviewType(status: string) {
<div class="page-header">
<p class="eyebrow">Listings</p>
<h1>商品管理</h1>
<p>查看全部租号商品号主区服平台价格押金上架状态和审核状态</p>
<p>查看全部租号商品号主价格押金上架状态和审核状态</p>
</div>
<div class="toolbar-actions">
<el-button @click="resetFilters">重置</el-button>
@@ -82,8 +90,8 @@ function reviewType(status: string) {
<div class="metric-grid">
<div class="metric-card">
<span>当前结果</span>
<strong>{{ listings.length }} </strong>
<span>总条数</span>
<strong>{{ total }} </strong>
</div>
<div class="metric-card">
<span>已上架</span>
@@ -120,81 +128,21 @@ function reviewType(status: string) {
<el-option label="已拒绝" value="rejected" />
</el-select>
</el-form-item>
<el-form-item label="查询条数">
<el-input-number v-model="filters.limit" :min="20" :max="500" :step="20" class="full-control" />
</el-form-item>
</el-form>
<el-table v-loading="loading" class="table-panel" :data="listings">
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="商品" min-width="270" fixed="left">
<el-table-column label="商品" min-width="220" fixed="left">
<template #default="{ row }">
<strong>{{ listingDisplayTitle(row) }}</strong>
<span class="table-subtext">账号 ID: {{ row.account_id }}</span>
<div v-if="listingBadgeTags(row).length" class="admin-tag-row compact">
<el-tag
v-for="tag in listingBadgeTags(row)"
:key="`${row.id}-${tag}`"
size="small"
:type="tag === '特惠' ? 'danger' : 'warning'"
effect="plain"
>
{{ tag }}
</el-tag>
</div>
<span class="table-subtext">{{ row.game_name }}</span>
</template>
</el-table-column>
<el-table-column label="号主" min-width="150">
<el-table-column label="号主" min-width="130">
<template #default="{ row }">
<strong>{{ ownerName(row) }}</strong>
<span class="table-subtext">ID: {{ row.owner_id }}</span>
</template>
</el-table-column>
<el-table-column label="资产配置" min-width="260">
<template #default="{ row }">
<div class="admin-tag-row">
<el-tag v-for="tag in listingAssetTags(row).slice(0, 8)" :key="`${row.id}-${tag}`" size="small" effect="plain">
{{ tag }}
</el-tag>
</div>
</template>
</el-table-column>
<el-table-column label="资源" min-width="220">
<template #default="{ row }">
<div v-if="listingResourceTags(row).length" class="admin-tag-row">
<el-tag v-for="tag in listingResourceTags(row)" :key="`${row.id}-${tag}`" size="small" type="info" effect="plain">
{{ tag }}
</el-tag>
</div>
<span v-else class="table-subtext">无额外资源</span>
</template>
</el-table-column>
<el-table-column label="交接风控" min-width="230">
<template #default="{ row }">
<div class="admin-tag-row">
<el-tag v-for="tag in listingRiskTags(row)" :key="`${row.id}-${tag}`" size="small" type="info" effect="plain">
{{ tag }}
</el-tag>
</div>
<span class="table-subtext">{{ row.server_region }} / {{ row.login_platform }}</span>
</template>
</el-table-column>
<el-table-column label="价格" min-width="170">
<template #default="{ row }">
<strong>{{ listingBuyerPrice(row) }}</strong>
<span class="table-subtext">卖家 {{ listingSellerPrice(row) }}</span>
<span class="table-subtext">
卖家 {{ formatRatio(getAdminListingPricing(row).sellerRatio) }} / 买家 {{ formatRatio(getAdminListingPricing(row).buyerRatio) }}
</span>
<span v-if="getAdminListingPricing(row).platformMarkup > 0" class="table-subtext">
平台加价 {{ formatMoney(getAdminListingPricing(row).platformMarkup) }}
</span>
</template>
</el-table-column>
<el-table-column label="押金" width="100">
<template #default="{ row }">{{ formatMoney(row.deposit_amount) }}</template>
</el-table-column>
<el-table-column label="商品状态" width="110">
<el-table-column label="状态" width="110">
<template #default="{ row }">
<el-tag :type="statusType(row.status)">{{ listingStatusLabel(row.status) }}</el-tag>
</template>
@@ -204,11 +152,14 @@ function reviewType(status: string) {
<el-tag :type="reviewType(row.review_status)">{{ listingReviewStatusLabel(row.review_status) }}</el-tag>
</template>
</el-table-column>
<el-table-column label="上架时间" min-width="180">
<template #default="{ row }">{{ formatDateTime(row.published_at) }}</template>
<el-table-column label="价格(租金/押金)" min-width="170">
<template #default="{ row }">
<strong>{{ listingBuyerPrice(row) }}</strong>
<span class="table-subtext">卖家 {{ listingSellerPrice(row) }} · 押金 {{ formatMoney(row.deposit_amount) }}</span>
</template>
</el-table-column>
<el-table-column label="更新时间" min-width="180">
<template #default="{ row }">{{ formatDateTime(row.updated_at) }}</template>
<el-table-column label="创建时间" min-width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
<el-table-column label="操作" width="110">
<template #default="{ row }">
@@ -218,5 +169,17 @@ function reviewType(status: string) {
</template>
</el-table-column>
</el-table>
<div class="pagination-wrap" v-if="total > 0">
<el-pagination
v-model:current-page="currentPage"
v-model:page-size="currentPageSize"
:total="total"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next"
@current-change="loadListings"
@size-change="handleSizeChange"
/>
</div>
</section>
</template>