9b2469ec33
V175 把品牌Gating库从数据管理组迁到店铺管理组(排序85),并在其后新增 关键词使用记录独立菜单(排序86)。后端新增只读查询模块,按公司范围读取 keyword_usage/keyword_add_log/keyword_delete_log,前端提供使用/删除记录、 统计卡与筛选。
529 lines
15 KiB
Vue
529 lines
15 KiB
Vue
<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 {
|
||
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(15)
|
||
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(15)
|
||
const deleteLoading = ref(false)
|
||
|
||
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> {
|
||
overviewLoading.value = true
|
||
try {
|
||
overview.value = await fetchKeywordUsageOverview({ companyId: companyTab.requestCompanyId })
|
||
} catch (error) {
|
||
loadError.value = actionableErrorText(error)
|
||
} finally {
|
||
overviewLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadUsage(page = usagePage.value): Promise<void> {
|
||
usageLoading.value = true
|
||
try {
|
||
const result = await fetchKeywordUsage({ ...queryParams(), page, pageSize: usagePageSize.value })
|
||
usageRows.value = result.rows
|
||
usageTotal.value = result.total
|
||
usageCounts.value = result.counts
|
||
usagePage.value = page
|
||
} catch (error) {
|
||
loadError.value = actionableErrorText(error)
|
||
} finally {
|
||
usageLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadDeletes(page = deletePage.value): Promise<void> {
|
||
deleteLoading.value = true
|
||
try {
|
||
const result = await fetchKeywordUsageDeletes({ ...queryParams(), page, pageSize: deletePageSize.value })
|
||
deleteRows.value = result.rows
|
||
deleteTotal.value = result.total
|
||
deletePage.value = page
|
||
} catch (error) {
|
||
loadError.value = actionableErrorText(error)
|
||
} finally {
|
||
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">
|
||
<label class="kw-field">
|
||
<span>使用者</span>
|
||
<select v-model="filter.user">
|
||
<option value="">全部使用者</option>
|
||
<option v-for="user in userOptions" :key="user" :value="user">{{ user }}</option>
|
||
</select>
|
||
</label>
|
||
<label class="kw-field">
|
||
<span>国家</span>
|
||
<select v-model="filter.country">
|
||
<option value="">全部国家</option>
|
||
<option v-for="country in countryOptions" :key="country" :value="country">{{ country }}</option>
|
||
</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>
|
||
<select v-model="filter.scene">
|
||
<option value="">全部场景</option>
|
||
<option v-for="scene in KEYWORD_USAGE_SCENES" :key="scene" :value="scene">{{ scene }}</option>
|
||
</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;
|
||
}
|
||
.kw-field input,
|
||
.kw-field select {
|
||
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,
|
||
.kw-field select:focus {
|
||
border-color: #2e5be6;
|
||
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||
background: #fff;
|
||
}
|
||
.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>
|