7299166e96
范围:src 里原生 <select> 由 36 处清零(含全站共享分页条),15 个页面 + 1 个组件。
换法统一:class="admin-filter"(main.css 皮肤 42px/9px/#f8fbfd/focus ring)+
aria-label 定位 + el-option 显式 label;「全部 XX」空值行与 value 形状逐字保留
('' / null / String(id) / '1'/'0' / `${source}|${deviceId}` 等,下游查询参数与后端枚举不动)。
- OldPagination:每页条数下拉换 el-select(局部 import,挂载测试单 mount 也能渲染),壳压回分页条 30px/8px 档
- account 三页(菜单类型/密钥状态/分组)+ GroupsPage/UsersPage 清死 select 规则
- asin 三页(国家/弹窗分组):弹窗分组用 placeholder+clearable+:value-on-clear 钉回 null,守 number|null 契约
- patent 页(国家/分组)
- records 两页(来源/用户/终端覆盖):终端覆盖 value 仍 source|deviceId
- tasks 四页 + 任务看板(业务/状态/类型/来源/店铺/分组/场景):BrandGating/DuplicateCheck/KeywordUsage 三页本地是 34px 紧凑档,
故把 el-select 壳压回本地 34px/7px 与同行输入框齐高(否则高 8px 错位)
测试:mount 全量 21 文件 164 passed;node --test 1924 例 1922 passed(2 红为在册:
date-range-order 环境红、company-config-entry-super-only 由 ee613db0 引入与本次无关);
vue-tsc rc=0。新增 account-select-el / records-select-el 两支换壳契约(值形状 + 空值行 + 点开→点选项)。
417 lines
12 KiB
Vue
417 lines
12 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, ref, watch } from 'vue'
|
||
|
||
import OldPagination from '@/components/OldPagination.vue'
|
||
import { orderedPair, todayDateInput } from '@/utils/datetime'
|
||
import {
|
||
fetchUserSecretUsage,
|
||
type AdminUserSecretUsageRow,
|
||
} from '@/api/user-secret-usage'
|
||
import type { GroupOption } from '@/api/user-secrets'
|
||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||
|
||
const session = useAdminSessionStore()
|
||
const companyTab = useCompanyTabStore()
|
||
/** 仅超管需要分组维度:非超管数据由后端裁剪到本人分组,分组筛选/列一律不展示。 */
|
||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||
|
||
const loading = ref(false)
|
||
const loadFailure = ref('')
|
||
const rows = ref<AdminUserSecretUsageRow[]>([])
|
||
const total = ref(0)
|
||
const page = ref(1)
|
||
const pageSize = ref(15)
|
||
const keyword = ref('')
|
||
const startDate = ref(todayDateInput())
|
||
const endDate = ref(todayDateInput())
|
||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||
function clampDatePair(): void {
|
||
const [s, e] = orderedPair(startDate.value, endDate.value)
|
||
startDate.value = s
|
||
endDate.value = e
|
||
}
|
||
|
||
const groupFilter = ref<number | null>(null)
|
||
const groupOptions = ref<GroupOption[]>([])
|
||
|
||
/** 所选范围内三类总次数(后端按筛选条件统计,不分页)。 */
|
||
const summary = ref({ totalCalls: 0, similarAsinCalls: 0, appearancePatentCalls: 0, proxyCalls: 0 })
|
||
|
||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||
|
||
function formatCount(value: number | undefined) {
|
||
const num = Number(value || 0)
|
||
return num.toLocaleString('zh-CN')
|
||
}
|
||
|
||
async function load() {
|
||
loading.value = true
|
||
loadFailure.value = ''
|
||
try {
|
||
const result = await fetchUserSecretUsage({
|
||
startDate: startDate.value || undefined,
|
||
endDate: endDate.value || undefined,
|
||
keyword: keyword.value.trim() || undefined,
|
||
groupId: groupFilter.value || undefined,
|
||
companyId: companyTab.requestCompanyId,
|
||
page: page.value,
|
||
pageSize: pageSize.value,
|
||
})
|
||
rows.value = result?.items || []
|
||
total.value = Number(result?.total || 0)
|
||
groupOptions.value = result?.groupOptions || []
|
||
summary.value = {
|
||
totalCalls: Number(result?.totalCalls || 0),
|
||
similarAsinCalls: Number(result?.similarAsinCalls || 0),
|
||
appearancePatentCalls: Number(result?.appearancePatentCalls || 0),
|
||
proxyCalls: Number(result?.proxyCalls || 0),
|
||
}
|
||
} catch (error) {
|
||
loadFailure.value = error instanceof Error ? error.message : '加载失败'
|
||
showAdminFeedback(loadFailure.value, 'error')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。
|
||
watch(() => companyTab.activeId, () => void load())
|
||
|
||
function search() {
|
||
page.value = 1
|
||
load()
|
||
}
|
||
|
||
function reset() {
|
||
keyword.value = ''
|
||
startDate.value = todayDateInput()
|
||
endDate.value = todayDateInput()
|
||
groupFilter.value = null
|
||
page.value = 1
|
||
load()
|
||
}
|
||
|
||
function changePage(next: number) {
|
||
if (next < 1 || next > totalPages.value) return
|
||
page.value = next
|
||
load()
|
||
}
|
||
|
||
function changeSize(size: number) {
|
||
pageSize.value = size
|
||
page.value = 1
|
||
load()
|
||
}
|
||
|
||
onMounted(load)
|
||
</script>
|
||
|
||
<template>
|
||
<div class="secret-usage-view">
|
||
<section class="panel-box">
|
||
<div class="usage-head">
|
||
<h3>密钥用量统计</h3>
|
||
<span class="usage-note">口径:真实对外请求次数(LLM 每次请求、代理每次成功提取)</span>
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-card">
|
||
<div class="summary-label">总调用次数</div>
|
||
<div class="summary-value">{{ formatCount(summary.totalCalls) }}</div>
|
||
</div>
|
||
<div class="summary-card">
|
||
<div class="summary-label">货源查询密钥</div>
|
||
<div class="summary-value">{{ formatCount(summary.similarAsinCalls) }}</div>
|
||
</div>
|
||
<div class="summary-card">
|
||
<div class="summary-label">外观专利密钥</div>
|
||
<div class="summary-value">{{ formatCount(summary.appearancePatentCalls) }}</div>
|
||
</div>
|
||
<div class="summary-card">
|
||
<div class="summary-label">代理提取</div>
|
||
<div class="summary-value">{{ formatCount(summary.proxyCalls) }}</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-row usage-filter-row">
|
||
<div class="form-group" style="min-width: 160px">
|
||
<label>开始日期</label>
|
||
<input v-model="startDate" type="date" :max="endDate" @change="clampDatePair" />
|
||
</div>
|
||
<div class="form-group" style="min-width: 160px">
|
||
<label>结束日期</label>
|
||
<input v-model="endDate" type="date" :min="startDate" @change="clampDatePair" />
|
||
</div>
|
||
<div class="form-group" style="min-width: 200px">
|
||
<label>用户名</label>
|
||
<input v-model="keyword" type="text" placeholder="模糊搜索用户名" @keyup.enter="search" />
|
||
</div>
|
||
<div class="form-group" v-if="isSuperAdmin && groupOptions.length" style="min-width: 170px">
|
||
<label>分组</label>
|
||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板),组多时可搜。
|
||
「全部分组」的值仍是 null(下游 groupId 照旧 `|| undefined`),空档时由
|
||
placeholder 显示同一句文案。 -->
|
||
<el-select v-model="groupFilter" class="admin-filter" filterable placeholder="全部分组" aria-label="筛选分组">
|
||
<el-option label="全部分组" :value="null" />
|
||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
|
||
</el-select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label> </label>
|
||
<div class="filter-actions">
|
||
<button class="btn" type="button" @click="search">查询</button>
|
||
<button class="btn btn-ghost" type="button" @click="reset">重置</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||
<div class="usage-table-scroll">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th style="width: 58px">序号</th>
|
||
<th style="width: 220px">用户</th>
|
||
<th v-if="isSuperAdmin" style="width: 130px">分组</th>
|
||
<th style="width: 170px">货源查询密钥</th>
|
||
<th style="width: 170px">外观专利密钥</th>
|
||
<th style="width: 150px">代理提取</th>
|
||
<th style="width: 130px">合计</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<template v-if="rows.length">
|
||
<tr v-for="(row, index) in rows" :key="row.userId">
|
||
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
|
||
<td>
|
||
<span class="user-name">{{ row.username || `UID ${row.userId}` }}</span>
|
||
</td>
|
||
<td v-if="isSuperAdmin">
|
||
<span class="group-name">{{ row.groups?.length ? row.groups.join('、') : '—' }}</span>
|
||
</td>
|
||
<td><span class="count-value">{{ formatCount(row.similarAsinCount) }}</span></td>
|
||
<td><span class="count-value">{{ formatCount(row.appearancePatentCount) }}</span></td>
|
||
<td><span class="count-value">{{ formatCount(row.proxyCount) }}</span></td>
|
||
<td><span class="count-value count-total">{{ formatCount(row.totalCount) }}</span></td>
|
||
</tr>
|
||
</template>
|
||
<tr v-else-if="loading">
|
||
<td :colspan="isSuperAdmin ? 7 : 6" class="empty-tip">加载中...</td>
|
||
</tr>
|
||
<tr v-else>
|
||
<td :colspan="isSuperAdmin ? 7 : 6" class="empty-tip">
|
||
{{ keyword || groupFilter ? '暂无匹配记录' : '暂无用量记录' }}
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||
</section>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
/* 与密钥管理页保持同一视觉语言(像素复刻后台面板风格)。 */
|
||
.secret-usage-view {
|
||
font-family: inherit;
|
||
color: #24384d;
|
||
}
|
||
.panel-box {
|
||
width: 100%;
|
||
min-width: 0;
|
||
padding: 20px 22px 24px;
|
||
border: 1px solid #d8e3ee;
|
||
border-radius: 14px;
|
||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||
}
|
||
h3 {
|
||
margin: 0;
|
||
font-size: 15px;
|
||
font-weight: 650;
|
||
color: #24384d;
|
||
letter-spacing: 0.2px;
|
||
}
|
||
.usage-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
margin-bottom: 16px;
|
||
}
|
||
.usage-note {
|
||
color: #7d8fa2;
|
||
font-size: 12px;
|
||
}
|
||
.summary-row {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
margin-bottom: 16px;
|
||
}
|
||
.summary-card {
|
||
flex: 1 1 160px;
|
||
min-width: 150px;
|
||
padding: 12px 16px;
|
||
border: 1px solid #dbe5ee;
|
||
border-radius: 10px;
|
||
background: #f7fafd;
|
||
}
|
||
.summary-label {
|
||
color: #5b6f83;
|
||
font-size: 12.5px;
|
||
font-weight: 600;
|
||
}
|
||
.summary-value {
|
||
margin-top: 6px;
|
||
color: #2f5d8b;
|
||
font-size: 22px;
|
||
font-weight: 700;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.usage-filter-row {
|
||
margin: 0 0 16px;
|
||
}
|
||
.form-row {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: flex-end;
|
||
gap: 14px 18px;
|
||
}
|
||
.form-group {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 7px;
|
||
margin-bottom: 0;
|
||
}
|
||
.form-group label {
|
||
color: #5b6f83;
|
||
font-size: 12.5px;
|
||
font-weight: 600;
|
||
}
|
||
.form-group input {
|
||
min-width: 0;
|
||
min-height: 42px;
|
||
padding: 8px 12px;
|
||
border: 1px solid #cbd9e6;
|
||
border-radius: 9px;
|
||
background: #f8fbfd;
|
||
color: #24384d;
|
||
font-size: 13.5px;
|
||
font-family: inherit;
|
||
color-scheme: light;
|
||
outline: none;
|
||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||
}
|
||
.form-group input:hover {
|
||
border-color: #9fb7cd;
|
||
}
|
||
.form-group input:focus {
|
||
background: #ffffff;
|
||
border-color: #5f85ad;
|
||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||
}
|
||
.filter-actions {
|
||
display: flex;
|
||
gap: 10px;
|
||
}
|
||
.btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 8px;
|
||
min-height: 42px;
|
||
padding: 9px 18px;
|
||
border: 1px solid #4f78a5;
|
||
border-radius: 9px;
|
||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||
color: #ffffff;
|
||
font-family: inherit;
|
||
font-size: 13.5px;
|
||
cursor: pointer;
|
||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||
}
|
||
.btn:hover:not(:disabled) {
|
||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||
}
|
||
.btn-ghost {
|
||
background: #ffffff;
|
||
border-color: #c7d7e5;
|
||
color: #4f78a5;
|
||
box-shadow: none;
|
||
}
|
||
.btn-ghost:hover:not(:disabled) {
|
||
background: #edf5fb;
|
||
border-color: #95b1cb;
|
||
color: #2f5d8b;
|
||
}
|
||
.usage-table-scroll {
|
||
width: 100%;
|
||
min-width: 0;
|
||
overflow-x: auto;
|
||
border: 1px solid #dbe5ee;
|
||
border-radius: 10px;
|
||
background: #ffffff;
|
||
}
|
||
.usage-table-scroll table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
table-layout: fixed;
|
||
min-width: 1020px;
|
||
}
|
||
.usage-table-scroll th,
|
||
.usage-table-scroll td {
|
||
padding: 10px 12px;
|
||
text-align: left;
|
||
font-size: 13.5px;
|
||
line-height: 1.5;
|
||
border-bottom: 1px solid #e0e8ef;
|
||
vertical-align: middle;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.usage-table-scroll th {
|
||
background: #edf4fa;
|
||
color: #4e6479;
|
||
border-bottom-color: #d5e1eb;
|
||
font-size: 12.5px;
|
||
font-weight: 600;
|
||
letter-spacing: 0.4px;
|
||
}
|
||
.usage-table-scroll tbody tr:hover td {
|
||
background: #f1f7fb;
|
||
}
|
||
.usage-table-scroll tbody tr:last-child td {
|
||
border-bottom: 0;
|
||
}
|
||
.user-name {
|
||
color: #24384d;
|
||
font-weight: 600;
|
||
white-space: normal;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
.group-name {
|
||
color: #5b6f83;
|
||
font-size: 12.5px;
|
||
}
|
||
.count-value {
|
||
color: #2f5d8b;
|
||
font-variant-numeric: tabular-nums;
|
||
font-size: 13.5px;
|
||
}
|
||
.count-total {
|
||
font-weight: 700;
|
||
}
|
||
.empty-tip {
|
||
color: #8293a5;
|
||
text-align: center;
|
||
}
|
||
</style>
|