Files
crawler-plugin/admin-frontend-vue/src/pages/tasks/KeywordUsagePage.vue
T
huangzd1997 7299166e96 style(admin): 全站原生下拉统一换 el-select——弹层圆角与亚马逊面一致(2026-11-17 用户口径「样式咋不是圆角 和亚马逊不统一 其他地方也要看看」)
范围: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 两支换壳契约(值形状 + 空值行 + 点开→点选项)。
2026-11-17 13:49:39 +08:00

562 lines
17 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* 关键词使用记录(独立菜单 admin_keyword_usage):只读展示 keyword_usage / keyword_add_log /
* keyword_delete_log,按公司 tab 取数。口径对齐独立小网页后台 v1.2.6g。
*/
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { formatDateTime } from '@/utils/datetime'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
import { actionableErrorText } from '@/components/admin-feedback'
import OldPagination from '@/components/OldPagination.vue'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
import { createLatestRequestGate } from '@/utils/latest-request'
import {
KEYWORD_USAGE_PAGE_SIZE,
KEYWORD_USAGE_SCENES,
createKeywordUsageFilter,
keywordUsageCountsText,
keywordUsageSceneLabel,
type KeywordUsageCounts,
type KeywordUsageFilter,
type KeywordUsageOverview,
type KeywordUsageRow,
} from './keyword-usage-model.ts'
import {
fetchKeywordUsage,
fetchKeywordUsageDeletes,
fetchKeywordUsageOverview,
} from './keyword-usage-api.ts'
const companyTab = useCompanyTabStore()
const session = useAdminSessionStore()
const me = computed(() => session.user?.username || '')
const filter = reactive<KeywordUsageFilter>(createKeywordUsageFilter())
const activeTab = ref<'usage' | 'deletes'>('usage')
const loadError = ref('')
const overview = ref<KeywordUsageOverview | null>(null)
const overviewLoading = ref(false)
const usageRows = ref<KeywordUsageRow[]>([])
const usageTotal = ref(0)
const usagePage = ref(1)
const usagePageSize = ref(KEYWORD_USAGE_PAGE_SIZE)
const usageCounts = ref<KeywordUsageCounts>({ copy: 0, copyExisting: 0, copyDeleted: 0, add: 0 })
const usageLoading = ref(false)
const deleteRows = ref<KeywordUsageRow[]>([])
const deleteTotal = ref(0)
const deletePage = ref(1)
const deletePageSize = ref(KEYWORD_USAGE_PAGE_SIZE)
const deleteLoading = ref(false)
// 切公司/快速改筛选时,先发的请求可能后返回;每个加载口径各一个序号闸(CR-27)
const overviewGate = createLatestRequestGate()
const usageGate = createLatestRequestGate()
const deleteGate = createLatestRequestGate()
const statsCards = computed(() => {
const stats = overview.value?.stats
return [
{ label: '复制关键词', value: stats?.used ?? 0, tone: 'primary' },
{ label: '现存词', value: stats?.exist ?? 0, tone: 'ok' },
{ label: '已删除词留痕', value: stats?.deletedKw ?? 0, tone: 'danger' },
{ label: '添加关键词', value: stats?.added ?? 0, tone: 'info' },
{ label: '使用记录合计', value: stats?.totalUse ?? 0, tone: '' },
{ label: '删除记录', value: stats?.deletes ?? 0, tone: 'violet' },
]
})
const userOptions = computed(() => overview.value?.users ?? [])
const countryOptions = computed(() => overview.value?.countries ?? [])
const usageSummary = computed(() => keywordUsageCountsText(usageCounts.value, usageTotal.value))
function queryParams() {
return {
companyId: companyTab.requestCompanyId,
user: filter.user,
country: filter.country,
keyword: filter.keyword.trim(),
scene: filter.scene,
}
}
async function loadOverview(): Promise<void> {
const token = overviewGate.begin()
overviewLoading.value = true
try {
const result = await fetchKeywordUsageOverview({ companyId: companyTab.requestCompanyId })
if (!overviewGate.isCurrent(token)) return
overview.value = result
} catch (error) {
if (!overviewGate.isCurrent(token)) return
loadError.value = actionableErrorText(error)
} finally {
if (overviewGate.isCurrent(token)) overviewLoading.value = false
}
}
async function loadUsage(page = usagePage.value): Promise<void> {
const token = usageGate.begin()
usageLoading.value = true
try {
const result = await fetchKeywordUsage({ ...queryParams(), page, pageSize: usagePageSize.value })
if (!usageGate.isCurrent(token)) return
usageRows.value = result.rows
usageTotal.value = result.total
usageCounts.value = result.counts
usagePage.value = page
} catch (error) {
if (!usageGate.isCurrent(token)) return
loadError.value = actionableErrorText(error)
} finally {
if (usageGate.isCurrent(token)) usageLoading.value = false
}
}
async function loadDeletes(page = deletePage.value): Promise<void> {
const token = deleteGate.begin()
deleteLoading.value = true
try {
const result = await fetchKeywordUsageDeletes({ ...queryParams(), page, pageSize: deletePageSize.value })
if (!deleteGate.isCurrent(token)) return
deleteRows.value = result.rows
deleteTotal.value = result.total
deletePage.value = page
} catch (error) {
if (!deleteGate.isCurrent(token)) return
loadError.value = actionableErrorText(error)
} finally {
if (deleteGate.isCurrent(token)) deleteLoading.value = false
}
}
async function reload(): Promise<void> {
loadError.value = ''
await Promise.all([loadOverview(), loadUsage(1), loadDeletes(1)])
}
function query(): void {
loadError.value = ''
void Promise.all([loadUsage(1), loadDeletes(1)])
}
function reset(): void {
Object.assign(filter, createKeywordUsageFilter())
query()
}
function changeUsagePageSize(size: number): void {
usagePageSize.value = size
void loadUsage(1)
}
function changeDeletePageSize(size: number): void {
deletePageSize.value = size
void loadDeletes(1)
}
watch(() => companyTab.activeId, () => {
filter.user = ''
filter.country = ''
usagePage.value = 1
deletePage.value = 1
void reload()
})
onMounted(() => {
void reload()
})
</script>
<template>
<div class="kw-page">
<LoadFailureBar v-if="loadError" :message="loadError" @retry="reload" />
<section class="kw-cards" v-loading="overviewLoading">
<div v-for="card in statsCards" :key="card.label" class="kw-card" :class="card.tone">
<div class="kw-n">{{ card.value.toLocaleString() }}</div>
<div class="kw-t">{{ card.label }}</div>
</div>
</section>
<section class="kw-panel">
<div class="kw-panel-head">筛选条件</div>
<div class="kw-panel-body">
<div class="kw-filters">
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
「全部 XX」空值行保留。 -->
<label class="kw-field">
<span>使用者</span>
<el-select v-model="filter.user" class="admin-filter" filterable aria-label="筛选使用者">
<el-option value="" label="全部使用者" />
<el-option v-for="user in userOptions" :key="user" :value="user" :label="user" />
</el-select>
</label>
<label class="kw-field">
<span>国家</span>
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
<el-option value="" label="全部国家" />
<el-option v-for="country in countryOptions" :key="country" :value="country" :label="country" />
</el-select>
</label>
<label class="kw-field kw-field-wide">
<span>关键词</span>
<input v-model="filter.keyword" placeholder="搜索关键词" @keyup.enter="query" />
</label>
<label class="kw-field">
<span>场景</span>
<el-select v-model="filter.scene" class="admin-filter" aria-label="筛选场景">
<el-option value="" label="全部场景" />
<el-option v-for="scene in KEYWORD_USAGE_SCENES" :key="scene" :value="scene" :label="scene" />
</el-select>
</label>
<div class="kw-actions">
<button class="kw-btn kw-btn-primary" type="button" @click="query">查询</button>
<button class="kw-btn kw-btn-ghost" type="button" @click="reset">重置</button>
</div>
</div>
</div>
</section>
<div class="kw-tabs">
<button class="kw-tab" :class="{ active: activeTab === 'usage' }" type="button" @click="activeTab = 'usage'">使用记录</button>
<button class="kw-tab" :class="{ active: activeTab === 'deletes' }" type="button" @click="activeTab = 'deletes'">删除记录</button>
</div>
<section v-show="activeTab === 'usage'" class="kw-panel">
<div class="kw-panel-head">
使用记录
<span class="kw-sub">复制关键词 + 添加关键词,按时间倒序;绿色为本人的记录</span>
</div>
<div class="kw-panel-body">
<div class="kw-table-wrap" v-loading="usageLoading">
<table v-if="usageRows.length" class="kw-table">
<thead>
<tr>
<th style="width: 130px">使用者</th>
<th style="width: 90px">国家</th>
<th>关键词</th>
<th style="width: 140px">使用场景</th>
<th style="width: 170px">使用时间</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in usageRows" :key="`usage-${row.time}-${index}`" :class="{ mine: row.userName === me }">
<td class="kw-user">{{ row.userName || '—' }}</td>
<td>{{ row.country || '—' }}</td>
<td class="kw-keyword">{{ row.keyword || '—' }}</td>
<td>
<span class="kw-tag" :class="row.scene === '添加关键词' ? 'add' : 'copy'">
{{ keywordUsageSceneLabel(row.scene) }}
</span>
</td>
<td class="kw-time">{{ formatDateTime(row.time) }}</td>
</tr>
</tbody>
</table>
<div v-else-if="!usageLoading" class="kw-empty">暂无使用记录</div>
</div>
<div class="kw-footer">
<span class="kw-summary">{{ usageSummary }}</span>
<OldPagination
v-if="usageTotal"
:total="usageTotal"
:page="usagePage"
:page-size="usagePageSize"
@change="loadUsage"
@size-change="changeUsagePageSize"
/>
</div>
</div>
</section>
<section v-show="activeTab === 'deletes'" class="kw-panel">
<div class="kw-panel-head">
删除记录
<span class="kw-sub">只读、不可删除、永久留痕可追溯;红色为本人的记录</span>
</div>
<div class="kw-panel-body">
<div class="kw-table-wrap" v-loading="deleteLoading">
<table v-if="deleteRows.length" class="kw-table">
<thead>
<tr>
<th style="width: 130px">删除者</th>
<th style="width: 90px">国家</th>
<th>关键词</th>
<th style="width: 170px">删除时间</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in deleteRows" :key="`delete-${row.time}-${index}`" :class="{ mine: row.userName === me }">
<td class="kw-user">{{ row.userName || '—' }}</td>
<td>{{ row.country || '—' }}</td>
<td class="kw-keyword">{{ row.keyword || '—' }}</td>
<td class="kw-time">{{ formatDateTime(row.time) }}</td>
</tr>
</tbody>
</table>
<div v-else-if="!deleteLoading" class="kw-empty">暂无删除记录</div>
</div>
<div class="kw-footer">
<span class="kw-summary">共 {{ deleteTotal }} 条删除记录 · 只读留痕</span>
<OldPagination
v-if="deleteTotal"
:total="deleteTotal"
:page="deletePage"
:page-size="deletePageSize"
@change="loadDeletes"
@size-change="changeDeletePageSize"
/>
</div>
</div>
</section>
</div>
</template>
<style scoped>
.kw-page {
display: flex;
flex-direction: column;
gap: 14px;
}
.kw-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
}
.kw-card {
background: #fff;
border: 1px solid #e5e9f0;
border-top: 3px solid #9ca3af;
border-radius: 10px;
box-shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 4px 18px rgba(20, 30, 60, 0.06);
padding: 12px 14px;
}
.kw-card.primary { border-top-color: #2e5be6; }
.kw-card.ok { border-top-color: #1f9d62; }
.kw-card.danger { border-top-color: #d63a4a; }
.kw-card.info { border-top-color: #0d9488; }
.kw-card.violet { border-top-color: #7c5cd6; }
.kw-card .kw-n {
font-size: 24px;
font-weight: 700;
color: #1c2230;
font-variant-numeric: tabular-nums;
line-height: 1.2;
}
.kw-card .kw-t {
margin-top: 3px;
font-size: 11.5px;
color: #98a1b1;
}
.kw-panel {
background: #fff;
border: 1px solid #e5e9f0;
border-radius: 10px;
box-shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 4px 18px rgba(20, 30, 60, 0.06);
overflow: hidden;
}
.kw-panel-head {
padding: 11px 15px;
background: #fafbfd;
border-bottom: 1px solid #e9edf3;
font-size: 13px;
font-weight: 700;
color: #1c2230;
}
.kw-panel-head::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
border-radius: 2px;
background: #2dd4bf;
margin-right: 8px;
vertical-align: 1px;
}
.kw-sub {
margin-left: 8px;
font-size: 11.5px;
font-weight: 400;
color: #98a1b1;
}
.kw-panel-body {
padding: 14px 15px;
}
.kw-filters {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 10px 12px;
}
.kw-field {
display: flex;
flex-direction: column;
gap: 5px;
min-width: 150px;
}
.kw-field-wide {
min-width: 220px;
}
.kw-field > span {
font-size: 12px;
color: #5a6474;
}
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter,这里只留原生输入框。 */
.kw-field input {
height: 34px;
padding: 0 10px;
border: 1px solid #d7dce5;
border-radius: 7px;
background: #fbfcfe;
color: #1c2230;
font-family: inherit;
font-size: 13px;
outline: none;
}
.kw-field input:focus {
border-color: #2e5be6;
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
background: #fff;
}
/* 本页筛选行是 34px 紧凑档(关键词输入框 34px、7px 圆角、蓝色 focus)。
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会与同行输入框错位
⇒ 在本页把壳压回本地档位(scoped 下 :deep 穿透 EP 内部结构)。 */
.kw-field :deep(.el-select__wrapper) {
min-height: 34px;
padding: 0 10px;
border-radius: 7px;
background: #fbfcfe;
box-shadow: 0 0 0 1px #d7dce5 inset;
font-size: 13px;
}
.kw-field :deep(.el-select__wrapper.is-focused) {
background: #fff;
box-shadow: 0 0 0 1px #2e5be6 inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
}
.kw-actions {
display: flex;
gap: 8px;
}
.kw-btn {
height: 34px;
padding: 0 15px;
border: 1px solid transparent;
border-radius: 7px;
font-family: inherit;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.kw-btn-primary {
background: #2e5be6;
border-color: #2e5be6;
color: #fff;
}
.kw-btn-primary:hover { background: #1e4bd8; border-color: #1e4bd8; }
.kw-btn-ghost {
background: #fff;
border-color: #d7dce5;
color: #5a6474;
}
.kw-btn-ghost:hover { border-color: #2e5be6; color: #2e5be6; }
.kw-tabs {
display: flex;
gap: 4px;
background: #fff;
border: 1px solid #e5e9f0;
border-radius: 9px;
padding: 4px;
align-self: flex-start;
}
.kw-tab {
padding: 7px 18px;
border: none;
border-radius: 7px;
background: none;
color: #5a6474;
font-family: inherit;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.kw-tab:hover { color: #2e5be6; }
.kw-tab.active { background: #2e5be6; color: #fff; }
.kw-table-wrap {
overflow-x: auto;
border: 1px solid #e5e9f0;
border-radius: 9px;
min-height: 90px;
}
.kw-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
font-size: 12.5px;
}
.kw-table th {
position: sticky;
top: 0;
z-index: 1;
padding: 10px;
background: #f7f9fc;
border-bottom: 1px solid #e5e9f0;
color: #5a6474;
font-size: 12px;
font-weight: 600;
text-align: left;
white-space: nowrap;
}
.kw-table td {
padding: 9px 10px;
border-bottom: 1px solid #eff2f7;
color: #1c2230;
white-space: nowrap;
}
.kw-table tbody tr:hover td { background: #f7faff; }
.kw-table tbody tr:last-child td { border-bottom: none; }
.kw-table tr.mine td { color: #0f9d58; font-weight: 600; }
.kw-user { font-weight: 500; }
.kw-keyword { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.kw-time { color: #5a6474; font-size: 11.5px; }
.kw-tag {
display: inline-block;
padding: 2px 8px;
border-radius: 6px;
font-size: 11px;
font-weight: 600;
white-space: nowrap;
}
.kw-tag.copy { background: #e8f7f4; color: #0d9488; }
.kw-tag.add { background: #eff6ff; color: #2563eb; }
.kw-empty {
padding: 42px 16px;
text-align: center;
color: #98a1b1;
font-size: 13px;
}
.kw-footer {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
}
.kw-summary {
font-size: 11.5px;
color: #98a1b1;
}
</style>