refactor(common-tools): 关键词共享页四个弹窗拆成子组件,958→573 行
可读性棘轮用户端「新增超长文件」判红(新建页 958 行超 800 上限)——按只许减的口径 拆而不是点名放行:添加/词库统计/随机抽词/团队共享记录四个弹窗各自成组件 (keyword-share/*Dialog.vue,状态、请求、分页自持),页面只留筛选/统计卡/表格与 开关 ref。行为不变;随机抽词改为弹窗内 loading(原先是按钮文案态)。 vue-tsc 0 错;npm test 927 pass / mount 5 文件全过。
This commit is contained in:
@@ -0,0 +1,204 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:model-value="modelValue"
|
||||||
|
title="添加关键词"
|
||||||
|
width="640px"
|
||||||
|
append-to-body
|
||||||
|
@update:model-value="(visible: boolean) => emit('update:modelValue', visible)"
|
||||||
|
@open="resetRows"
|
||||||
|
>
|
||||||
|
<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 countryOptions" :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>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
import { addKeywordShareKeywords } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
import type { KeywordShareAddItem } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue: boolean
|
||||||
|
countryOptions: string[]
|
||||||
|
defaultCountry: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'update:modelValue', visible: boolean): void
|
||||||
|
(e: 'added'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const addRows = ref<KeywordShareAddItem[]>([])
|
||||||
|
const addSubmitting = ref(false)
|
||||||
|
const addResultText = ref('')
|
||||||
|
|
||||||
|
function emptyRow(): KeywordShareAddItem {
|
||||||
|
return { country: props.defaultCountry, keyword: '', chinese: '' }
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetRows() {
|
||||||
|
addRows.value = [emptyRow()]
|
||||||
|
addResultText.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAddRow() {
|
||||||
|
addRows.value.push(emptyRow())
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
emit('added')
|
||||||
|
})
|
||||||
|
.catch((error: unknown) => {
|
||||||
|
addSubmitting.value = false
|
||||||
|
ElMessage.error(error instanceof Error ? error.message : '添加失败')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.btn-run {
|
||||||
|
padding: 9px 22px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: linear-gradient(135deg, #22c55e, #16a34a);
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-run:hover:not(:disabled) {
|
||||||
|
filter: brightness(1.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-run:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-ghost {
|
||||||
|
padding: 8px 18px;
|
||||||
|
border: 1px solid #3e4a62;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #2b3447;
|
||||||
|
color: #c8d2e2;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-ghost:hover:not(:disabled) {
|
||||||
|
background: #323d52;
|
||||||
|
color: #f5f8fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-ghost:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-danger {
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: #f87171;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-danger:hover {
|
||||||
|
color: #fca5a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-danger:disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:model-value="modelValue"
|
||||||
|
title="词库统计"
|
||||||
|
width="620px"
|
||||||
|
append-to-body
|
||||||
|
@update:model-value="(visible: boolean) => emit('update:modelValue', visible)"
|
||||||
|
@open="loadStats"
|
||||||
|
>
|
||||||
|
<div class="stats-sections">
|
||||||
|
<section v-for="section in STATS_SECTIONS" :key="section.key" class="stats-section">
|
||||||
|
<h4 class="stats-title">{{ section.title }}</h4>
|
||||||
|
<div v-if="!statsSections[section.key].length" class="dialog-empty">暂无数据</div>
|
||||||
|
<ul v-else class="stats-list">
|
||||||
|
<li v-for="item in statsSections[section.key]" :key="`${item.group}-${item.label}`" class="stats-row">
|
||||||
|
<span class="stats-label"><em v-if="item.group">{{ item.group }} / </em>{{ item.label }}</span>
|
||||||
|
<span class="stats-count">{{ item.count.toLocaleString('zh-CN') }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
import {
|
||||||
|
buildKeywordStatsSections,
|
||||||
|
fetchKeywordShareStatsGrouped,
|
||||||
|
} from '@/shared/api/types/modules/keyword-share'
|
||||||
|
import type { KeywordStatsSections } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
|
||||||
|
defineProps<{ modelValue: boolean }>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'update:modelValue', visible: boolean): void }>()
|
||||||
|
|
||||||
|
/** 词库统计四段(与桌面版弹窗同序) */
|
||||||
|
const STATS_SECTIONS: ReadonlyArray<{ key: keyof KeywordStatsSections; title: string }> = [
|
||||||
|
{ key: 'byCountry', title: '按国家分布' },
|
||||||
|
{ key: 'byCategory', title: '按一级类目分布' },
|
||||||
|
{ key: 'bySubCategory', title: '按二级类目分布' },
|
||||||
|
{ key: 'byCategoryL3', title: '按三级类目分布' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const EMPTY_STATS: KeywordStatsSections = { byCountry: [], byCategory: [], bySubCategory: [], byCategoryL3: [] }
|
||||||
|
const statsSections = ref<KeywordStatsSections>({ ...EMPTY_STATS })
|
||||||
|
|
||||||
|
function loadStats() {
|
||||||
|
fetchKeywordShareStatsGrouped()
|
||||||
|
.then((data) => {
|
||||||
|
statsSections.value = buildKeywordStatsSections(data)
|
||||||
|
})
|
||||||
|
.catch((error: unknown) => {
|
||||||
|
statsSections.value = { ...EMPTY_STATS }
|
||||||
|
ElMessage.error(error instanceof Error ? error.message : '词库统计加载失败')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dialog-empty {
|
||||||
|
color: #a0acbe;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-sections {
|
||||||
|
max-height: 460px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-section + .stats-section {
|
||||||
|
border-top: 1px solid #2c3854;
|
||||||
|
margin-top: 12px;
|
||||||
|
padding-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-title {
|
||||||
|
color: #4da3ff;
|
||||||
|
font-size: 13px;
|
||||||
|
margin: 0 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-row {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
font-size: 13px;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 3px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-label {
|
||||||
|
color: #e8ecf4;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-label em {
|
||||||
|
color: #8b95ad;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-count {
|
||||||
|
color: #ff9a3c;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-left: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:model-value="modelValue"
|
||||||
|
title="随机抽词(10 条)"
|
||||||
|
width="760px"
|
||||||
|
append-to-body
|
||||||
|
@update:model-value="(visible: boolean) => emit('update:modelValue', visible)"
|
||||||
|
@open="loadRandom"
|
||||||
|
>
|
||||||
|
<div v-if="loading" class="dialog-empty">抽词中...</div>
|
||||||
|
<div v-else-if="!rows.length" class="dialog-empty">暂无可抽取的关键词</div>
|
||||||
|
<el-table v-else :data="rows" 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="!markableRows.length || marking"
|
||||||
|
@click="markRows"
|
||||||
|
>
|
||||||
|
{{ marking ? '标记中...' : `一键标记已使用(${markableRows.length})` }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
import { fetchKeywordShareRandom, markKeywordShareUsage } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
import type { KeywordShareRow } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
|
||||||
|
defineProps<{ modelValue: boolean }>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'update:modelValue', visible: boolean): void
|
||||||
|
(e: 'marked'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const rows = ref<KeywordShareRow[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
const marking = ref(false)
|
||||||
|
|
||||||
|
const markableRows = computed(() => rows.value.filter((row) => !row.used))
|
||||||
|
|
||||||
|
function loadRandom() {
|
||||||
|
loading.value = true
|
||||||
|
fetchKeywordShareRandom(10)
|
||||||
|
.then((data) => {
|
||||||
|
loading.value = false
|
||||||
|
rows.value = Array.isArray(data) ? data : []
|
||||||
|
})
|
||||||
|
.catch((error: unknown) => {
|
||||||
|
loading.value = false
|
||||||
|
rows.value = []
|
||||||
|
ElMessage.error(error instanceof Error ? error.message : '随机抽词失败')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function markRows() {
|
||||||
|
const items = markableRows.value.map((row) => ({
|
||||||
|
country: String(row.country ?? ''),
|
||||||
|
keyword: String(row.keyword ?? ''),
|
||||||
|
}))
|
||||||
|
if (!items.length) return
|
||||||
|
marking.value = true
|
||||||
|
markKeywordShareUsage(items)
|
||||||
|
.then((data) => {
|
||||||
|
marking.value = false
|
||||||
|
ElMessage.success(`已标记 ${data.marked} 条为已使用`)
|
||||||
|
rows.value = rows.value.map((row) => ({ ...row, used: true }))
|
||||||
|
emit('marked')
|
||||||
|
})
|
||||||
|
.catch((error: unknown) => {
|
||||||
|
marking.value = false
|
||||||
|
ElMessage.error(error instanceof Error ? error.message : '标记失败')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.btn-run {
|
||||||
|
padding: 9px 22px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: linear-gradient(135deg, #22c55e, #16a34a);
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
font-family: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-run:hover:not(:disabled) {
|
||||||
|
filter: brightness(1.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-run:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-btn-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-empty {
|
||||||
|
color: #a0acbe;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ks-table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.used {
|
||||||
|
color: #86efac;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unused {
|
||||||
|
color: #93c5fd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:model-value="modelValue"
|
||||||
|
title="团队共享记录"
|
||||||
|
width="720px"
|
||||||
|
append-to-body
|
||||||
|
@update:model-value="(visible: boolean) => emit('update:modelValue', visible)"
|
||||||
|
@open="openFirstTab"
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
import { fetchKeywordShareLogs } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
import type { KeywordShareLogRow, KeywordShareLogType } from '@/shared/api/types/modules/keyword-share'
|
||||||
|
|
||||||
|
defineProps<{ modelValue: boolean }>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'update:modelValue', visible: boolean): void }>()
|
||||||
|
|
||||||
|
const LOG_PAGE_SIZE = 20
|
||||||
|
const LOG_TYPE_TABS: ReadonlyArray<{ label: string; value: KeywordShareLogType }> = [
|
||||||
|
{ label: '使用', value: 'usage' },
|
||||||
|
{ label: '添加', value: 'add' },
|
||||||
|
{ label: '删除', value: 'delete' },
|
||||||
|
]
|
||||||
|
|
||||||
|
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 openFirstTab() {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.ks-table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ks-pagination {
|
||||||
|
margin-top: 12px;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user