fix(common-tools): 关键词共享按后端真实返回接统计四段与日志字段
/stats-grouped 是四段各自 GROUP BY(对齐桌面版弹窗),前端原先按 「国家×一级类目」交叉表建模 ⇒ 弹窗恒为暂无数据;/logs 返回 userName/time 而表格读 operator/createdAt ⇒ 两列恒为占位符。改为 API 层映射 + 四段渲染, 日志去掉后端不产出的「说明」列。
This commit is contained in:
@@ -77,17 +77,15 @@
|
||||
<span class="stat-label">跨国重复</span>
|
||||
<strong class="stat-value">{{ stats.dup }}</strong>
|
||||
</div>
|
||||
<button type="button" class="btn-ghost" @click="openStatsDialog">词库统计</button>
|
||||
<button type="button" class="btn-ghost" @click="statsDialogVisible = true">词库统计</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 操作区 -->
|
||||
<section class="ks-toolbar">
|
||||
<button type="button" class="btn-run" @click="openAddDialog">添加</button>
|
||||
<button type="button" class="btn-ghost" :disabled="randomLoading" @click="openRandomDialog">
|
||||
{{ randomLoading ? '抽词中...' : '随机抽词' }}
|
||||
</button>
|
||||
<button type="button" class="btn-ghost" @click="openLogsDialog">团队共享记录</button>
|
||||
<button type="button" class="btn-run" @click="addDialogVisible = true">添加</button>
|
||||
<button type="button" class="btn-ghost" @click="randomDialogVisible = true">随机抽词</button>
|
||||
<button type="button" class="btn-ghost" @click="logsDialogVisible = true">团队共享记录</button>
|
||||
</section>
|
||||
|
||||
<!-- 列表 -->
|
||||
@@ -134,119 +132,15 @@
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- 添加弹窗 -->
|
||||
<el-dialog v-model="addDialogVisible" title="添加关键词" width="640px" append-to-body>
|
||||
<div class="add-rows">
|
||||
<div v-for="(item, index) in addRows" :key="index" class="add-row">
|
||||
<el-select v-model="item.country" placeholder="国家" class="add-country">
|
||||
<el-option v-for="name in countries" :key="name" :label="name" :value="name" />
|
||||
</el-select>
|
||||
<el-input v-model="item.keyword" placeholder="关键词" class="add-keyword" />
|
||||
<el-input v-model="item.chinese" placeholder="中文(可空)" class="add-chinese" />
|
||||
<button
|
||||
type="button"
|
||||
class="link-danger"
|
||||
:disabled="addRows.length <= 1"
|
||||
@click="removeAddRow(index)"
|
||||
>删除行</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-btn-row">
|
||||
<button type="button" class="btn-ghost" @click="addAddRow">再加一行</button>
|
||||
<button type="button" class="btn-run" :disabled="addSubmitting" @click="submitAdd">
|
||||
{{ addSubmitting ? '提交中...' : '批量添加' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="addResultText" class="dialog-result">{{ addResultText }}</p>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 词库统计弹窗 -->
|
||||
<el-dialog v-model="statsDialogVisible" title="词库统计(国家 × 一级类目)" width="560px" append-to-body>
|
||||
<div v-if="!statsGroupedRows.length" class="dialog-empty">暂无统计数据</div>
|
||||
<el-table v-else :data="pagedStatsGrouped" class="ks-table" height="420">
|
||||
<el-table-column prop="country" label="国家" width="120" />
|
||||
<el-table-column prop="category" label="一级类目" min-width="160" />
|
||||
<el-table-column prop="count" label="关键词数" width="120" align="right" />
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="statsGroupedRows.length > STATS_PAGE_SIZE"
|
||||
class="ks-pagination"
|
||||
layout="total, prev, pager, next"
|
||||
:total="statsGroupedRows.length"
|
||||
:page-size="STATS_PAGE_SIZE"
|
||||
v-model:current-page="statsPage"
|
||||
/>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 随机抽词弹窗 -->
|
||||
<el-dialog v-model="randomDialogVisible" title="随机抽词(10 条)" width="760px" append-to-body>
|
||||
<div v-if="!randomRows.length" class="dialog-empty">暂无可抽取的关键词</div>
|
||||
<el-table v-else :data="randomRows" class="ks-table" height="420" row-key="id">
|
||||
<el-table-column prop="keyword" label="关键词" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column prop="chinese" label="中文" min-width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.chinese || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="country" label="国家" width="90" />
|
||||
<el-table-column label="使用状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<span :class="row.used ? 'used' : 'unused'">{{ row.used ? '✓已使用' : '未使用' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="dialog-btn-row">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-run"
|
||||
:disabled="!randomMarkableRows.length || randomMarking"
|
||||
@click="markRandomRows"
|
||||
>
|
||||
{{ randomMarking ? '标记中...' : `一键标记已使用(${randomMarkableRows.length})` }}
|
||||
</button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 团队共享记录弹窗 -->
|
||||
<el-dialog v-model="logsDialogVisible" title="团队共享记录" width="720px" append-to-body>
|
||||
<div class="logs-tabs">
|
||||
<button
|
||||
v-for="tab in LOG_TYPE_TABS"
|
||||
:key="tab.value"
|
||||
type="button"
|
||||
class="logs-tab"
|
||||
:class="{ 'logs-tab--active': logType === tab.value }"
|
||||
@click="switchLogType(tab.value)"
|
||||
>{{ tab.label }}</button>
|
||||
</div>
|
||||
<div v-if="!logRows.length" class="dialog-empty">暂无记录</div>
|
||||
<el-table v-else :data="logRows" class="ks-table" height="380">
|
||||
<el-table-column prop="createdAt" label="时间" width="170" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.createdAt || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="类型" width="90">
|
||||
<template #default="{ row }">{{ formatLogType(row.type) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="country" label="国家" width="90" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.country || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="keyword" label="关键词" min-width="150" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.keyword || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="operator" label="操作人" width="110" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.operator || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="detail" label="说明" min-width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.detail || '—' }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="ks-pagination"
|
||||
layout="total, prev, pager, next"
|
||||
:total="logTotal"
|
||||
:page-size="LOG_PAGE_SIZE"
|
||||
:current-page="logPage"
|
||||
@current-change="onLogPageChange"
|
||||
/>
|
||||
</el-dialog>
|
||||
<AddKeywordsDialog
|
||||
v-model="addDialogVisible"
|
||||
:country-options="countries"
|
||||
:default-country="filterCountry"
|
||||
@added="reloadFromFirstPage"
|
||||
/>
|
||||
<KeywordStatsDialog v-model="statsDialogVisible" />
|
||||
<RandomKeywordsDialog v-model="randomDialogVisible" @marked="loadList" />
|
||||
<ShareLogsDialog v-model="logsDialogVisible" />
|
||||
</AmazonToolPageShell>
|
||||
</div>
|
||||
</template>
|
||||
@@ -256,25 +150,21 @@ import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue'
|
||||
import AddKeywordsDialog from '@/pages/common/keyword-share/AddKeywordsDialog.vue'
|
||||
import KeywordStatsDialog from '@/pages/common/keyword-share/KeywordStatsDialog.vue'
|
||||
import RandomKeywordsDialog from '@/pages/common/keyword-share/RandomKeywordsDialog.vue'
|
||||
import ShareLogsDialog from '@/pages/common/keyword-share/ShareLogsDialog.vue'
|
||||
import {
|
||||
addKeywordShareKeywords,
|
||||
deleteKeywordShareKeywords,
|
||||
fetchKeywordShareFilters,
|
||||
fetchKeywordShareKeywords,
|
||||
fetchKeywordShareLogs,
|
||||
fetchKeywordShareRandom,
|
||||
fetchKeywordShareStatsGrouped,
|
||||
markKeywordShareUsage,
|
||||
normalizeKeywordStatsGrouped,
|
||||
unmarkKeywordShareUsage,
|
||||
} from '@/shared/api/types/modules/keyword-share'
|
||||
import type {
|
||||
KeywordShareAddItem,
|
||||
KeywordShareCategory,
|
||||
KeywordShareFiltersVo,
|
||||
KeywordShareListVo,
|
||||
KeywordShareLogRow,
|
||||
KeywordShareLogType,
|
||||
KeywordShareRow,
|
||||
KeywordShareStatusFilter,
|
||||
KeywordShareUsedDays,
|
||||
@@ -282,8 +172,6 @@ import type {
|
||||
|
||||
/** 后端分页每页 200(契约固定) */
|
||||
const PAGE_SIZE = 200
|
||||
const STATS_PAGE_SIZE = 50
|
||||
const LOG_PAGE_SIZE = 20
|
||||
const SEARCH_DEBOUNCE_MS = 300
|
||||
|
||||
const USED_DAYS_OPTIONS: ReadonlyArray<{ label: string; value: KeywordShareUsedDays }> = [
|
||||
@@ -296,12 +184,6 @@ const USED_DAYS_OPTIONS: ReadonlyArray<{ label: string; value: KeywordShareUsedD
|
||||
{ label: '近360天', value: 360 },
|
||||
]
|
||||
|
||||
const LOG_TYPE_TABS: ReadonlyArray<{ label: string; value: KeywordShareLogType }> = [
|
||||
{ label: '使用', value: 'usage' },
|
||||
{ label: '添加', value: 'add' },
|
||||
{ label: '删除', value: 'delete' },
|
||||
]
|
||||
|
||||
// ---- 筛选状态 ----
|
||||
const filterCountry = ref('')
|
||||
const filterCategory = ref('')
|
||||
@@ -475,162 +357,11 @@ function removeKeyword(row: KeywordShareRow) {
|
||||
})
|
||||
}
|
||||
|
||||
// ---- 添加弹窗 ----
|
||||
// ---- 弹窗开关(内容、请求与分页状态由各弹窗组件自持)----
|
||||
const addDialogVisible = ref(false)
|
||||
const addRows = ref<KeywordShareAddItem[]>([])
|
||||
const addSubmitting = ref(false)
|
||||
const addResultText = ref('')
|
||||
|
||||
function openAddDialog() {
|
||||
addRows.value = [{ country: filterCountry.value, keyword: '', chinese: '' }]
|
||||
addResultText.value = ''
|
||||
addDialogVisible.value = true
|
||||
}
|
||||
|
||||
function addAddRow() {
|
||||
addRows.value.push({ country: filterCountry.value, keyword: '', chinese: '' })
|
||||
}
|
||||
|
||||
function removeAddRow(index: number) {
|
||||
if (addRows.value.length <= 1) return
|
||||
addRows.value.splice(index, 1)
|
||||
}
|
||||
|
||||
function submitAdd() {
|
||||
const items = addRows.value
|
||||
.map((row) => ({
|
||||
country: String(row.country ?? '').trim(),
|
||||
keyword: String(row.keyword ?? '').trim(),
|
||||
chinese: String(row.chinese ?? '').trim(),
|
||||
}))
|
||||
.filter((row) => row.country && row.keyword)
|
||||
if (!items.length) {
|
||||
ElMessage.warning('请至少填写一行完整的关键词(国家 + 关键词)')
|
||||
return
|
||||
}
|
||||
addSubmitting.value = true
|
||||
addKeywordShareKeywords(items)
|
||||
.then((data) => {
|
||||
addSubmitting.value = false
|
||||
addResultText.value = `新增 ${data.added} 条,跳过(重复)${data.skipped} 条`
|
||||
ElMessage.success(addResultText.value)
|
||||
reloadFromFirstPage()
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
addSubmitting.value = false
|
||||
ElMessage.error(error instanceof Error ? error.message : '添加失败')
|
||||
})
|
||||
}
|
||||
|
||||
// ---- 词库统计弹窗 ----
|
||||
const statsDialogVisible = ref(false)
|
||||
const statsGroupedRows = ref<Array<{ country: string; category: string; count: number }>>([])
|
||||
const statsPage = ref(1)
|
||||
|
||||
const pagedStatsGrouped = computed(() =>
|
||||
statsGroupedRows.value.slice((statsPage.value - 1) * STATS_PAGE_SIZE, statsPage.value * STATS_PAGE_SIZE),
|
||||
)
|
||||
|
||||
function openStatsDialog() {
|
||||
statsDialogVisible.value = true
|
||||
fetchKeywordShareStatsGrouped()
|
||||
.then((data) => {
|
||||
// /stats-grouped 的返回结构按后端实现演进,这里统一做兼容映射
|
||||
statsGroupedRows.value = normalizeKeywordStatsGrouped(data)
|
||||
statsPage.value = 1
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
statsGroupedRows.value = []
|
||||
ElMessage.error(error instanceof Error ? error.message : '词库统计加载失败')
|
||||
})
|
||||
}
|
||||
|
||||
// ---- 随机抽词弹窗 ----
|
||||
const randomDialogVisible = ref(false)
|
||||
const randomLoading = ref(false)
|
||||
const randomRows = ref<KeywordShareRow[]>([])
|
||||
const randomMarking = ref(false)
|
||||
|
||||
const randomMarkableRows = computed(() => randomRows.value.filter((row) => !row.used))
|
||||
|
||||
function openRandomDialog() {
|
||||
randomLoading.value = true
|
||||
fetchKeywordShareRandom(10)
|
||||
.then((data) => {
|
||||
randomLoading.value = false
|
||||
randomRows.value = Array.isArray(data) ? data : []
|
||||
randomDialogVisible.value = true
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
randomLoading.value = false
|
||||
ElMessage.error(error instanceof Error ? error.message : '随机抽词失败')
|
||||
})
|
||||
}
|
||||
|
||||
function markRandomRows() {
|
||||
const items = randomMarkableRows.value.map((row) => ({
|
||||
country: String(row.country ?? ''),
|
||||
keyword: String(row.keyword ?? ''),
|
||||
}))
|
||||
if (!items.length) return
|
||||
randomMarking.value = true
|
||||
markKeywordShareUsage(items)
|
||||
.then((data) => {
|
||||
randomMarking.value = false
|
||||
ElMessage.success(`已标记 ${data.marked} 条为已使用`)
|
||||
randomRows.value = randomRows.value.map((row) => ({ ...row, used: true }))
|
||||
void loadList()
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
randomMarking.value = false
|
||||
ElMessage.error(error instanceof Error ? error.message : '标记失败')
|
||||
})
|
||||
}
|
||||
|
||||
// ---- 团队共享记录弹窗 ----
|
||||
const logsDialogVisible = ref(false)
|
||||
const logType = ref<KeywordShareLogType>('usage')
|
||||
const logRows = ref<KeywordShareLogRow[]>([])
|
||||
const logTotal = ref(0)
|
||||
const logPage = ref(1)
|
||||
|
||||
function formatLogType(type: unknown): string {
|
||||
if (type === 'usage') return '使用'
|
||||
if (type === 'add') return '添加'
|
||||
if (type === 'delete') return '删除'
|
||||
return String(type ?? '—')
|
||||
}
|
||||
|
||||
function loadLogs() {
|
||||
fetchKeywordShareLogs({ type: logType.value, page: logPage.value, size: LOG_PAGE_SIZE })
|
||||
.then((data) => {
|
||||
logRows.value = Array.isArray(data?.rows) ? data.rows : []
|
||||
logTotal.value = Number(data?.total) || 0
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
logRows.value = []
|
||||
logTotal.value = 0
|
||||
ElMessage.error(error instanceof Error ? error.message : '共享记录加载失败')
|
||||
})
|
||||
}
|
||||
|
||||
function openLogsDialog() {
|
||||
logsDialogVisible.value = true
|
||||
logType.value = 'usage'
|
||||
logPage.value = 1
|
||||
void loadLogs()
|
||||
}
|
||||
|
||||
function switchLogType(type: KeywordShareLogType) {
|
||||
logType.value = type
|
||||
logPage.value = 1
|
||||
void loadLogs()
|
||||
}
|
||||
|
||||
function onLogPageChange(next: number) {
|
||||
logPage.value = next
|
||||
void loadLogs()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadFilters()
|
||||
@@ -830,75 +561,6 @@ onBeforeUnmount(() => {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.add-rows {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.add-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.add-country {
|
||||
width: 130px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.add-keyword {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.add-chinese {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.dialog-btn-row {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.dialog-result {
|
||||
margin: 10px 0 0;
|
||||
color: #86efac;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.dialog-empty {
|
||||
color: #a0acbe;
|
||||
font-size: 13px;
|
||||
padding: 20px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logs-tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.logs-tab {
|
||||
padding: 7px 18px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 6px;
|
||||
background: #2b3447;
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.logs-tab--active {
|
||||
border-color: #22c55e;
|
||||
background: #12301f;
|
||||
color: #86efac;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.filter-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
|
||||
Reference in New Issue
Block a user