revert(gating): 后管 Gating 页与入口回滚

删除品牌Gating库页面、API/导入/模型与测试,摘掉静态路由、操作指引条目与
ops-cell 列宽登记;菜单行由 V166 移除,后端模块保留但无授权入口。
This commit is contained in:
2026-10-24 09:20:36 +08:00
parent 68ec48b573
commit 052f2bd4a5
10 changed files with 0 additions and 1385 deletions
@@ -68,10 +68,6 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
text: '店铺信息按分组管理。长商城名会自动缩略,悬停即可查看完整内容。',
steps: ['选择分组', '维护店铺信息', '筛选核对结果'],
},
admin_brand_gating: {
text: '维护不符合规则的品牌(品牌Gating/类目Gating)。添加后可用筛选快速回查;云端Gating库与前端排查软件同步同一份数据,排查软件命中后会自动在此入库。',
steps: ['新增或批量导入', '筛选回查', '停用或删除'],
},
admin_shop_data_crawl_tasks: {
text: '店铺数据任务按状态和时间筛选。批量操作前请核对已选任务。',
steps: ['筛选任务', '检查状态', '执行批量操作'],
@@ -1,759 +0,0 @@
<script setup lang="ts">
/** 品牌Gating库(biz_brand_gating 并入管理后台)· 自绘列表页,布局沿用 DedupeRegistryPage 的
* panel-box + 双行筛选 + 旧式表格 + OldPagination,另加统计卡与新增/批量导入弹窗。 */
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDateTime } from '@/utils/datetime'
import OldPagination from '@/components/OldPagination.vue'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { loadFailureMessage } from '@/components/load-failure-model'
import { openAdminConfirm } from '@/components/admin-confirm'
import {
createGating,
deleteGating,
fetchGatingPage,
fetchGatingStats,
importGatingText,
updateGatingStatus,
} from './gating-api.ts'
import {
GATING_COUNTRIES,
GATING_DEFAULT_PAGE_SIZE,
GATING_PAGE_SIZES,
GATING_SOURCES,
GATING_TYPES,
createGatingFilterState,
gatingStatusLabel,
toGatingListParams,
type GatingFilterState,
type GatingItem,
type GatingStats,
} from './gating-model.ts'
import { gatingImportOutcomeText, parseGatingImportText } from './gating-import.ts'
const loading = ref(false)
const loadFailure = ref('')
const rows = ref<GatingItem[]>([])
const total = ref(0)
const page = ref(1)
const pageSize = ref(GATING_DEFAULT_PAGE_SIZE)
const filter = reactive(createGatingFilterState())
const stats = ref<GatingStats | null>(null)
const addVisible = ref(false)
const addSaving = ref(false)
const addForm = reactive({
brand: '',
asin: '',
country: '全部',
gatingType: '品牌gating',
source: 'MANUAL',
shopName: '',
remark: '',
})
const importVisible = ref(false)
const importRunning = ref(false)
const importText = ref('')
/** 导入前行数预览:同一份解析规则桌面版/后端共用,前端只做提示,不做拦截。 */
const importPreviewCount = computed(() => parseGatingImportText(importText.value).items.length)
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
async function loadStats(): Promise<void> {
try {
stats.value = await fetchGatingStats()
} catch {
// 统计卡失败不拦列表:留空展示 0,列表自己的失败条会说话。
stats.value = null
}
}
async function load(): Promise<void> {
loading.value = true
loadFailure.value = ''
try {
const result = await fetchGatingPage(toGatingListParams(filter, page.value, pageSize.value))
rows.value = result.rows
total.value = result.total
} catch (error) {
loadFailure.value = loadFailureMessage(error, 'Gating列表加载失败')
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
}
}
function apply(): void {
page.value = 1
void load()
}
function resetFilter(): void {
Object.assign(filter, createGatingFilterState())
apply()
}
function changePage(next: number): void {
if (next < 1 || next > totalPages.value) return
page.value = next
void load()
}
function changeSize(size: number): void {
pageSize.value = size
page.value = 1
void load()
}
function openAdd(): void {
addForm.brand = ''
addForm.asin = ''
addForm.country = '全部'
addForm.gatingType = '品牌gating'
addForm.source = 'MANUAL'
addForm.shopName = ''
addForm.remark = ''
addVisible.value = true
}
async function submitAdd(): Promise<void> {
const brand = addForm.brand.trim()
if (!brand) {
ElMessage.warning('请填写品牌')
return
}
addSaving.value = true
try {
await createGating({
brand,
asin: addForm.asin.trim(),
country: addForm.country,
gatingType: addForm.gatingType,
source: addForm.source,
shopName: addForm.shopName.trim(),
remark: addForm.remark.trim(),
})
addVisible.value = false
ElMessage.success('新增成功')
await Promise.all([load(), loadStats()])
} catch (error) {
showAdminFeedback(loadFailureMessage(error, '新增失败'), 'error')
} finally {
addSaving.value = false
}
}
function openImport(): void {
importText.value = ''
importVisible.value = true
}
async function submitImport(): Promise<void> {
const text = importText.value.trim()
if (!text) {
ElMessage.warning('请粘贴批量数据')
return
}
importRunning.value = true
try {
const result = await importGatingText(text)
importVisible.value = false
ElMessage.success(gatingImportOutcomeText(result.added, result.skipped))
await Promise.all([load(), loadStats()])
} catch (error) {
showAdminFeedback(loadFailureMessage(error, '导入失败'), 'error')
} finally {
importRunning.value = false
}
}
/** 启用/停用切换:停用需二次确认(解除后排查不再拦截),恢复直接执行。 */
async function toggleStatus(row: GatingItem): Promise<void> {
const next: 0 | 1 = row.status === 1 ? 0 : 1
if (next === 0) {
const confirmed = await openAdminConfirm({ message: `确认停用品牌「${row.brand}」?停用后排查自动跳过该品牌,不再拦截`, danger: true })
if (!confirmed) return
}
try {
await updateGatingStatus(row.id, next)
ElMessage.success(next === 1 ? '已恢复生效' : '已停用,排查不再拦截')
await Promise.all([load(), loadStats()])
} catch (error) {
showAdminFeedback(loadFailureMessage(error, '状态更新失败'), 'error')
}
}
async function removeRow(row: GatingItem): Promise<void> {
const confirmed = await openAdminConfirm({ message: `确认删除 ID=${row.id} 的Gating记录(品牌:${row.brand})?`, danger: true })
if (!confirmed) return
try {
await deleteGating(row.id)
ElMessage.success('已删除')
await Promise.all([load(), loadStats()])
} catch (error) {
showAdminFeedback(loadFailureMessage(error, '删除失败'), 'error')
}
}
onMounted(() => {
void load()
void loadStats()
})
</script>
<template>
<div class="gating-view">
<section class="panel-box">
<div class="gating-panel-head">
<h3>品牌Gating库</h3>
<div class="gating-head-actions">
<button class="btn" type="button" @click="openAdd">新增</button>
<button class="btn" type="button" @click="openImport">批量导入</button>
</div>
</div>
<div class="gating-cards">
<div class="stat-card">
<div class="stat-n">{{ stats?.total ?? 0 }}</div>
<div class="stat-t">Gating总记录</div>
</div>
<div class="stat-card stat-active">
<div class="stat-n">{{ stats?.active ?? 0 }}</div>
<div class="stat-t">生效中</div>
</div>
<div class="stat-card stat-disabled">
<div class="stat-n">{{ stats?.disabled ?? 0 }}</div>
<div class="stat-t">停用</div>
</div>
<div class="stat-card stat-brands">
<div class="stat-n">{{ stats?.brands ?? 0 }}</div>
<div class="stat-t">去重品牌数</div>
</div>
<div v-for="group in [
{ title: '按Gating类型', data: stats?.byType ?? [] },
{ title: '按国家', data: stats?.byCountry ?? [] },
{ title: '按来源', data: stats?.bySource ?? [] },
]" :key="group.title" class="stat-group">
<div class="stat-group-title">{{ group.title }}</div>
<div class="stat-group-body">
<span v-for="entry in group.data" :key="entry.name" class="stat-chip">
{{ entry.name }} <b>{{ entry.count }}</b>
</span>
<span v-if="!group.data.length" class="stat-chip stat-chip-empty">暂无</span>
</div>
</div>
</div>
<div class="gating-filter-row">
<div class="form-group">
<label>关键词</label>
<input v-model="filter.keyword" type="text" placeholder="品牌 / ASIN / 备注" @keyup.enter="apply" />
</div>
<div class="form-group">
<label>国家</label>
<select v-model="filter.country">
<option value="">全部国家</option>
<option v-for="country in GATING_COUNTRIES" :key="country" :value="country">{{ country }}</option>
</select>
</div>
<div class="form-group">
<label>Gating类型</label>
<select v-model="filter.gatingType">
<option value="">全部类型</option>
<option v-for="gatingType in GATING_TYPES" :key="gatingType" :value="gatingType">{{ gatingType }}</option>
</select>
</div>
<div class="form-group">
<label>状态</label>
<select v-model="filter.status">
<option value="">全部状态</option>
<option value="1">生效</option>
<option value="0">停用</option>
</select>
</div>
<div class="form-group">
<label>来源</label>
<select v-model="filter.source">
<option value="">全部来源</option>
<option v-for="source in GATING_SOURCES" :key="source" :value="source">{{ source }}</option>
</select>
</div>
<div class="gating-filter-actions">
<button class="btn" type="button" @click="apply">查询</button>
<button class="btn btn-secondary" type="button" @click="resetFilter">重置</button>
</div>
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<div class="table-scroll gating-table-scroll">
<table>
<thead>
<tr>
<th style="width: 60px">ID</th>
<th>品牌</th>
<th>ASIN</th>
<th>国家</th>
<th>Gating类型</th>
<th style="width: 70px">状态</th>
<th style="width: 80px">来源</th>
<th>店铺</th>
<th>备注</th>
<th style="width: 150px">创建时间</th>
<th style="width: 150px">更新时间</th>
<th style="width: 150px">停用时间</th>
<th style="width: 140px">操作</th>
</tr>
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<td>{{ row.id }}</td>
<td class="brand-cell">{{ row.brand }}</td>
<td class="mono-cell">{{ row.asin || '-' }}</td>
<td>{{ row.country }}</td>
<td><span class="type-tag">{{ row.gatingType }}</span></td>
<td>
<span class="status-tag" :class="row.status === 1 ? 'status-on' : 'status-off'">
{{ gatingStatusLabel(row.status) }}
</span>
</td>
<td>{{ row.source === 'AUTO' ? '自动同步' : '手动' }}</td>
<td>{{ row.shopName || '-' }}</td>
<td :title="row.remark">{{ row.remark || '-' }}</td>
<td class="time-cell">{{ formatDateTime(row.createdAt) }}</td>
<td class="time-cell">{{ formatDateTime(row.updatedAt) }}</td>
<td class="time-cell">{{ formatDateTime(row.disabledAt) }}</td>
<td class="ops-cell">
<button class="btn btn-sm" type="button" @click="toggleStatus(row)">
{{ row.status === 1 ? '停用' : '恢复' }}
</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeRow(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="13" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="13" class="empty-tip">暂无Gating记录</td>
</tr>
</tbody>
</table>
</div>
<OldPagination
:total="total"
:page="page"
:page-size="pageSize"
:sizes="[10, 20, 50]"
@change="changePage"
@size-change="changeSize"
/>
</section>
<div v-if="addVisible" class="modal-mask" @click.self="addVisible = false">
<div class="modal">
<h3>新增Gating品牌</h3>
<div class="form-group">
<label>品牌(必填)</label>
<input v-model="addForm.brand" type="text" placeholder="请输入品牌" @keyup.enter="submitAdd" />
</div>
<div class="form-group">
<label>国家</label>
<select v-model="addForm.country">
<option v-for="country in GATING_COUNTRIES" :key="country" :value="country">{{ country }}</option>
</select>
</div>
<div class="form-group">
<label>Gating类型</label>
<select v-model="addForm.gatingType">
<option v-for="gatingType in GATING_TYPES" :key="gatingType" :value="gatingType">{{ gatingType }}</option>
</select>
</div>
<div class="form-group">
<label>来源</label>
<select v-model="addForm.source">
<option v-for="source in GATING_SOURCES" :key="source" :value="source">{{ source }}</option>
</select>
</div>
<div class="form-group">
<label>ASIN(可选)</label>
<input v-model="addForm.asin" type="text" placeholder="请输入 ASIN" />
</div>
<div class="form-group">
<label>店铺(可选)</label>
<input v-model="addForm.shopName" type="text" placeholder="请输入店铺名" />
</div>
<div class="form-group">
<label>备注(可选)</label>
<input v-model="addForm.remark" type="text" placeholder="请输入备注" />
</div>
<div class="modal-actions">
<button class="btn" type="button" :disabled="addSaving" @click="submitAdd">保存</button>
<button class="btn btn-secondary" type="button" :disabled="addSaving" @click="addVisible = false">取消</button>
</div>
</div>
</div>
<div v-if="importVisible" class="modal-mask" @click.self="importVisible = false">
<div class="modal">
<h3>批量导入</h3>
<div class="form-group">
<label>每行一条:品牌[,国家[,类型[,ASIN[,备注]]]],支持逗号/分号/Tab 分隔;# 开头为注释行</label>
<textarea
v-model="importText"
class="import-textarea"
rows="10"
placeholder="示例:
tory burch,英国,品牌gating
jellycat,全部,品牌gating
crocs,德国,类目gating"
></textarea>
</div>
<div class="import-preview">将导入 {{ importPreviewCount }} 行(空行与注释行自动跳过)</div>
<div class="modal-actions">
<button class="btn" type="button" :disabled="importRunning" @click="submitImport">导入</button>
<button class="btn btn-secondary" type="button" :disabled="importRunning" @click="importVisible = false">取消</button>
</div>
</div>
</div>
</div>
</template>
<style scoped>
/* 布局与配色沿用去重总数据页(panel-box 蓝白末层样式)。 */
.gating-view {
font-family: inherit;
color: var(--c-text, #24384d);
display: flex;
flex-direction: column;
gap: 18px;
}
.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 0 16px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.gating-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.gating-panel-head h3 {
margin: 0;
}
.gating-head-actions {
display: flex;
gap: 10px;
}
.gating-cards {
display: flex;
gap: 12px;
flex-wrap: wrap;
align-items: stretch;
margin-bottom: 16px;
}
.stat-card {
flex: 0 0 132px;
padding: 12px 14px;
border: 1px solid #d8e3ee;
border-top: 3px solid #2dd4bf;
border-radius: 10px;
background: #ffffff;
}
.stat-card.stat-active { border-top-color: #34d399; }
.stat-card.stat-disabled { border-top-color: #9ca3af; }
.stat-card.stat-brands { border-top-color: #a78bfa; }
.stat-n {
font-size: 24px;
font-weight: 700;
color: #24384d;
}
.stat-t {
margin-top: 2px;
font-size: 12px;
color: #7a8194;
}
.stat-group {
flex: 1 1 200px;
min-width: 0;
padding: 10px 14px;
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #ffffff;
}
.stat-group-title {
font-size: 12px;
font-weight: 600;
color: #5b6f83;
margin-bottom: 6px;
}
.stat-group-body {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.stat-chip {
padding: 2px 8px;
border-radius: 6px;
background: #edf4fa;
color: #4e6479;
font-size: 12px;
white-space: nowrap;
}
.stat-chip b {
color: #2f5d8b;
}
.stat-chip-empty {
color: #9baaba;
}
.gating-filter-row {
display: grid;
grid-template-columns: repeat(5, minmax(140px, 1fr)) auto;
gap: 12px;
align-items: end;
margin-bottom: 16px;
}
.gating-filter-row .form-group {
min-width: 0;
}
.gating-filter-actions {
display: flex;
gap: 10px;
align-items: center;
white-space: nowrap;
}
.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,
.form-group select,
.form-group textarea {
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 textarea {
min-height: 0;
resize: vertical;
line-height: 1.6;
}
.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
border-color: #9fb7cd;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.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);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.6;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.gating-table-scroll > table {
min-width: 1360px;
}
.table-scroll th,
.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;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.brand-cell {
font-weight: 650;
}
.mono-cell {
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
font-size: 12.5px;
}
.time-cell {
color: #6b7280;
font-size: 12.5px;
}
.type-tag {
display: inline-block;
padding: 2px 8px;
border-radius: 6px;
background: #fef3c7;
color: #b45309;
font-size: 12px;
}
.status-tag {
display: inline-block;
padding: 2px 8px;
border-radius: 6px;
font-size: 12px;
}
.status-on {
background: #d1fae5;
color: #10b981;
}
.status-off {
background: #e5e7eb;
color: #9ca3af;
}
.ops-cell {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
text-align: right;
flex-wrap: wrap;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.modal {
display: flex;
flex-direction: column;
width: min(560px, 100%);
max-height: 84vh;
padding: 22px 24px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow-y: auto;
}
.modal .form-group {
margin-bottom: 14px;
}
.modal-actions {
display: flex;
gap: 10px;
margin-top: 16px;
}
.import-textarea {
height: 180px;
}
.import-preview {
font-size: 12.5px;
color: #5b6f83;
}
</style>
@@ -1,75 +0,0 @@
/** 品牌Gating库 API 适配:GET/POST/DELETE /api/admin/brand-gating(契约路径与字段不得擅改)。 */
import { http } from '@/api/http'
import { unwrap } from '@/api/envelope'
import {
parseGatingPage,
parseGatingStats,
toGatingItem,
type GatingItem,
type GatingPageResult,
type GatingStats,
} from './gating-model.ts'
export const GATING_ENDPOINT = '/api/admin/brand-gating'
/** 列表:GET /api/admin/brand-gating?page&size&keyword&country&gatingType&status&source → { total, rows }。 */
export async function fetchGatingPage(params: Record<string, string | number>): Promise<GatingPageResult> {
const { data } = await http.get<unknown>(GATING_ENDPOINT, { params })
return parseGatingPage(data)
}
/** 统计:GET /api/admin/brand-gating/stats → { total, active, disabled, brands, byType, byCountry, bySource }。 */
export async function fetchGatingStats(): Promise<GatingStats> {
const { data } = await http.get<unknown>(`${GATING_ENDPOINT}/stats`)
return parseGatingStats(data)
}
/** 单条新增字段(驼峰);source/shopName 可缺省由后端落默认。 */
export interface GatingCreatePayload {
brand: string
asin: string
country: string
gatingType: string
source: string
shopName: string
remark: string
}
/** 新增:POST /api/admin/brand-gating → { added }。 */
export async function createGating(payload: GatingCreatePayload): Promise<number> {
const { data } = await http.post<unknown>(GATING_ENDPOINT, payload)
const core = unwrap<Record<string, unknown>>(data)
const added = core && typeof core === 'object' ? Number((core as Record<string, unknown>).added) : NaN
return Number.isFinite(added) ? added : 0
}
/** 删除:DELETE /api/admin/brand-gating/{id} → { deleted }。 */
export async function deleteGating(id: number): Promise<void> {
const { data } = await http.delete<unknown>(`${GATING_ENDPOINT}/${id}`)
unwrap<unknown>(data)
}
/**
* 启用/停用:POST /api/admin/brand-gating/{id}/status body { status } → { updated }。
* 停用(status=0)由后端记 disabled_at=NOW(),恢复(status=1)清空 disabled_at。
*/
export async function updateGatingStatus(id: number, status: 0 | 1): Promise<void> {
const { data } = await http.post<unknown>(`${GATING_ENDPOINT}/${id}/status`, { status })
unwrap<unknown>(data)
}
/** 批量导入:POST /api/admin/brand-gating/import body { text } → { added, skipped }。原始文本整段交后端解析。 */
export async function importGatingText(text: string): Promise<{ added: number; skipped: number }> {
const { data } = await http.post<unknown>(`${GATING_ENDPOINT}/import`, { text })
const core = unwrap<Record<string, unknown>>(data)
const record = (core && typeof core === 'object' ? core : {}) as Record<string, unknown>
const added = Number(record.added)
const skipped = Number(record.skipped)
return {
added: Number.isFinite(added) ? added : 0,
skipped: Number.isFinite(skipped) ? skipped : 0,
}
}
/** 单条解析出口(供需要单取的场景复用,例如挂载测试构造数据)。 */
export { toGatingItem, type GatingItem }
@@ -1,66 +0,0 @@
/** 批量导入文本解析(照抄桌面版 gating_web_admin.py parse_batch 的行格式与跳过规则)。
* 纯逻辑、零依赖(tests/gating-import.test.ts 用 node --test 直连本文件)。
*
* 口径(与桌面版 L208-223 逐条对齐):
* - 按行拆分;每行去首尾空白与 BOM(\uFEFF);
* - 空行与以 # 开头的注释行跳过;
* - 行内按中英文逗号/分号/制表符([,\t;,;])切分,各段去空白后丢掉空段;
* - 字段序:品牌(必留)、国家(缺省「全部」)、Gating类型(缺省「品牌gating」)、ASIN(缺省空)、备注(缺省空);
* 第 5 列之后的段照桌面版丢弃。
*
* 前端只用它做导入前的行数预览;真正提交仍把原始文本整段交给后端
* (POST /api/admin/brand-gating/import { text },去重与入库由后端按同一份规则解析)。 */
export interface GatingImportItem {
brand: string
country: string
gatingType: string
asin: string
remark: string
}
export interface GatingImportParseResult {
items: GatingImportItem[]
/** 因空行/注释行/纯分隔符行被跳过的行数。 */
skippedLines: number
}
export const GATING_IMPORT_DEFAULT_COUNTRY = '全部'
export const GATING_IMPORT_DEFAULT_TYPE = '品牌gating'
/** 与桌面版一致的列分隔符:中英文逗号、中英文分号、制表符。 */
const FIELD_SPLIT_RE = /[,\t;,;]/
/** 解析批量导入文本;永不抛错(坏行计入 skippedLines)。 */
export function parseGatingImportText(text: string): GatingImportParseResult {
const items: GatingImportItem[] = []
let skippedLines = 0
const lines = String(text ?? '').split(/\r?\n/)
for (const rawLine of lines) {
const line = rawLine.trim().replace(/^\uFEFF/, '').trim()
if (!line || line.startsWith('#')) {
if (rawLine.trim()) skippedLines += 1
continue
}
const parts = line
.split(FIELD_SPLIT_RE)
.map((part) => part.trim())
.filter((part) => part.length > 0)
if (!parts.length) {
skippedLines += 1
continue
}
items.push({
brand: parts[0],
country: parts[1] ?? GATING_IMPORT_DEFAULT_COUNTRY,
gatingType: parts[2] ?? GATING_IMPORT_DEFAULT_TYPE,
asin: parts[3] ?? '',
remark: parts[4] ?? '',
})
}
return { items, skippedLines }
}
/** 导入完成反馈文案:新增 X 条,跳过重复 Y 条。 */
export function gatingImportOutcomeText(added: number, skipped: number): string {
return `批量导入完成:新增 ${added} 条,跳过重复 ${skipped} 条`
}
@@ -1,183 +0,0 @@
/** 品牌Gating库页面模型(biz_brand_gating 并入管理后台):类型、字典、筛选态与响应解析。
* 纯逻辑、零依赖(tests/gating-model.test.ts 用 node --test 直连本文件,别 import 带 @ 别名/axios 的模块)。 */
export interface GatingItem {
id: number
brand: string
asin: string
country: string
gatingType: string
/** 1=生效 0=停用。 */
status: number
source: string
shopName: string
remark: string
createdAt?: string
updatedAt?: string
disabledAt?: string
}
export interface GatingPageResult {
rows: GatingItem[]
total: number
}
/** 分组统计单行(GET stats 的 byType/byCountry/bySource)。 */
export interface GatingNameCount {
name: string
count: number
}
export interface GatingStats {
total: number
active: number
disabled: number
brands: number
byType: GatingNameCount[]
byCountry: GatingNameCount[]
bySource: GatingNameCount[]
}
export interface GatingFilterState {
/** 品牌/ASIN/备注 LIKE 关键词。 */
keyword: string
country: string
gatingType: string
/** '' = 全部;'1' 生效;'0' 停用。 */
status: string
source: string
}
/** 国家字典:与桌面版 gating_web_admin 下拉一致;'全部' 是表内真实取值(不限国家时用空串)。 */
export const GATING_COUNTRIES = ['全部', '英国', '德国', '法国', '西班牙', '意大利'] as const
export const GATING_TYPES = ['品牌gating', '类目gating', '账户不符合'] as const
export const GATING_SOURCES = ['AUTO', 'MANUAL'] as const
/** 每页条数档位(默认 10,可选 20/50)。 */
export const GATING_PAGE_SIZES = [10, 20, 50] as const
export const GATING_DEFAULT_PAGE_SIZE = 10
export function createGatingFilterState(): GatingFilterState {
return { keyword: '', country: '', gatingType: '', status: '', source: '' }
}
function text(value: unknown): string {
return typeof value === 'string' ? value.trim() : ''
}
function intOr(value: unknown, fallback: number): number {
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback
}
/** 解析单条记录;缺 id 视为无效。兼容 camel 与 snake 字段名。 */
export function toGatingItem(raw: unknown): GatingItem | null {
if (!raw || typeof raw !== 'object') return null
const record = raw as Record<string, unknown>
const id = intOr(record.id, 0)
if (id <= 0) return null
const item: GatingItem = {
id,
brand: text(record.brand),
asin: text(record.asin),
country: text(record.country),
gatingType: text(record.gatingType ?? record.gating_type),
status: intOr(record.status, 0),
source: text(record.source),
shopName: text(record.shopName ?? record.shop_name),
remark: text(record.remark),
}
const createdAt = text(record.createdAt ?? record.created_at)
const updatedAt = text(record.updatedAt ?? record.updated_at)
const disabledAt = text(record.disabledAt ?? record.disabled_at)
if (createdAt) item.createdAt = createdAt
if (updatedAt) item.updatedAt = updatedAt
if (disabledAt) item.disabledAt = disabledAt
return item
}
/** 解析列表负载({ total, rows };rows 兼容 items 别名),空负载回空页。 */
export function parseGatingPage(payload: unknown): GatingPageResult {
const out: GatingPageResult = { rows: [], total: 0 }
if (!payload || typeof payload !== 'object') return out
const record = payload as Record<string, unknown>
const rawRows = Array.isArray(record.rows) ? record.rows : Array.isArray(record.items) ? record.items : []
out.rows = rawRows
.map((raw) => toGatingItem(raw))
.filter((item): item is GatingItem => item !== null)
out.total = intOr(record.total, out.rows.length)
return out
}
/** 分组统计单组:数组 [{name,count}] 或桌面版遗留 dict({品牌gating: 3})都收。 */
export function parseGatingNameCountList(raw: unknown): GatingNameCount[] {
if (Array.isArray(raw)) {
const out: GatingNameCount[] = []
for (const item of raw) {
if (!item || typeof item !== 'object') continue
const record = item as Record<string, unknown>
const name = text(record.name)
if (!name) continue
out.push({ name, count: intOr(record.count, 0) })
}
return out
}
if (raw && typeof raw === 'object') {
const out: GatingNameCount[] = []
for (const [name, count] of Object.entries(raw as Record<string, unknown>)) {
if (!name) continue
out.push({ name, count: intOr(count, 0) })
}
return out
}
return []
}
/** 解析统计负载;缺省字段回 0/空数组。 */
export function parseGatingStats(payload: unknown): GatingStats {
const out: GatingStats = {
total: 0,
active: 0,
disabled: 0,
brands: 0,
byType: [],
byCountry: [],
bySource: [],
}
if (!payload || typeof payload !== 'object') return out
const record = payload as Record<string, unknown>
out.total = intOr(record.total, 0)
out.active = intOr(record.active, 0)
out.disabled = intOr(record.disabled, 0)
out.brands = intOr(record.brands, 0)
out.byType = parseGatingNameCountList(record.byType ?? record.by_type)
out.byCountry = parseGatingNameCountList(record.byCountry ?? record.by_country)
out.bySource = parseGatingNameCountList(record.bySource ?? record.by_source)
return out
}
/** 筛选态 + 分页 → 列表查询参数(page/size/keyword/country/gatingType/status/source);空白值不下发。 */
export function toGatingListParams(
state: GatingFilterState,
page: number,
pageSize: number,
): Record<string, string | number> {
const params: Record<string, string | number> = {
page: page >= 1 ? Math.floor(page) : 1,
size: pageSize >= 1 ? Math.floor(pageSize) : GATING_DEFAULT_PAGE_SIZE,
}
const keyword = (state.keyword || '').trim()
const country = (state.country || '').trim()
const gatingType = (state.gatingType || '').trim()
const status = (state.status || '').trim()
const source = (state.source || '').trim()
if (keyword) params.keyword = keyword
if (country) params.country = country
if (gatingType) params.gatingType = gatingType
if (status === '1' || status === '0') params.status = status
if (source) params.source = source
return params
}
/** 状态 → 展示文案;非 1 一律按停用。 */
export function gatingStatusLabel(status: unknown): string {
return status === 1 ? '生效' : '停用'
}
-2
View File
@@ -40,8 +40,6 @@ export const adminPages: AdminPageDef[] = [
{ path: 'asin-center/query', menuKey: 'admin_query_asin', title: '查询ASIN', companyScoped: true, load: () => import('@/pages/asin/QueryAsinPage.vue') },
{ path: 'asin-center/categories', menuKey: 'admin_product_categories', title: '商品类目', companyScoped: false, load: () => import('@/pages/asin/ProductCategoryPage.vue') },
{ path: 'asin-center/skip-price', menuKey: 'admin_skip_price_asin', title: '最低价ASIN', companyScoped: true, load: () => import('@/pages/asin/SkipPricePage.vue') },
// 品牌Gating库(biz_brand_gating):全平台共享表(桌面版 gating_web_admin 同源数据),不参与公司 tab。
{ path: 'asin-center/gating', menuKey: 'admin_brand_gating', title: '品牌Gating库', companyScoped: false, load: () => import('@/pages/gating/GatingPage.vue') },
]
export function routeOf(page: AdminPageDef): RouteRecordRaw {
@@ -1,58 +0,0 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { gatingImportOutcomeText, parseGatingImportText } from '../src/pages/gating/gating-import.ts'
test('gating_import_single_field_defaults', () => {
// 桌面版口径:只给品牌 → 国家=全部、类型=品牌gating、ASIN/备注空。
const result = parseGatingImportText('jellycat')
assert.equal(result.items.length, 1)
assert.deepEqual(result.items[0], { brand: 'jellycat', country: '全部', gatingType: '品牌gating', asin: '', remark: '' })
assert.equal(result.skippedLines, 0)
})
test('gating_import_full_five_fields', () => {
const result = parseGatingImportText('tory burch,英国,品牌gating,B0ABC123,人为录入')
assert.deepEqual(result.items[0], { brand: 'tory burch', country: '英国', gatingType: '品牌gating', asin: 'B0ABC123', remark: '人为录入' })
})
test('gating_import_mixed_separators_and_extra_fields_dropped', () => {
// 桌面版分隔符集合 [,\t;,;];第 5 列之后的段丢弃。
const result = parseGatingImportText('crocs,德国;类目gating\tB0X\t备注\t多余段')
assert.deepEqual(result.items[0], { brand: 'crocs', country: '德国', gatingType: '类目gating', asin: 'B0X', remark: '备注' })
})
test('gating_import_skip_blank_comment_and_separator_only_lines', () => {
const text = [
'',
' ',
'# 这是注释行',
';;,', // 纯分隔符行 → 空段全被丢,整行跳过
'jellycat',
].join('\n')
const result = parseGatingImportText(text)
assert.equal(result.items.length, 1)
assert.equal(result.items[0]?.brand, 'jellycat')
assert.equal(result.skippedLines, 2) // 注释行 + 纯分隔符行;纯空白行不计数
})
test('gating_import_bom_and_crlf_and_empty_parts', () => {
const result = parseGatingImportText('\uFEFFcrocs,德国,,B0X\r\n,头部空段被丢')
assert.equal(result.items.length, 2)
assert.equal(result.items[0]?.brand, 'crocs')
assert.equal(result.items[0]?.country, '德国')
// 桌面版口径:空段在切分后就被丢弃,后续字段整体左移(B0X 落到类型位)——照抄不修正。
assert.equal(result.items[0]?.gatingType, 'B0X')
assert.equal(result.items[0]?.asin, '')
assert.equal(result.items[1]?.brand, '头部空段被丢')
assert.equal(result.items[1]?.country, '全部')
})
test('gating_import_empty_input_never_throws', () => {
assert.deepEqual(parseGatingImportText(''), { items: [], skippedLines: 0 })
// @ts-expect-error 纯函数要扛住脏输入(运行时防呆)。
assert.deepEqual(parseGatingImportText(null), { items: [], skippedLines: 0 })
})
test('gating_import_outcome_text', () => {
assert.equal(gatingImportOutcomeText(3, 2), '批量导入完成:新增 3 条,跳过重复 2 条')
})
@@ -1,99 +0,0 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
createGatingFilterState,
gatingStatusLabel,
parseGatingNameCountList,
parseGatingPage,
parseGatingStats,
toGatingItem,
toGatingListParams,
} from '../src/pages/gating/gating-model.ts'
test('gating_filter_normal_primary_path', () => {
// 完整筛选映射到契约查询参数(page/size/keyword/country/gatingType/status/source)。
const state = { ...createGatingFilterState(), keyword: 'jellycat', country: '英国', gatingType: '品牌gating', status: '1', source: 'MANUAL' }
const params = toGatingListParams(state, 3, 20)
assert.equal(params.page, 3)
assert.equal(params.size, 20)
assert.equal(params.keyword, 'jellycat')
assert.equal(params.country, '英国')
assert.equal(params.gatingType, '品牌gating')
assert.equal(params.status, '1')
assert.equal(params.source, 'MANUAL')
})
test('gating_filter_boundary_blank_dropped', () => {
// 空筛选只带分页;非法 status(非 '0'/'1')不下发。
const params = toGatingListParams({ ...createGatingFilterState(), status: 'all', keyword: ' ' }, 0, -5)
assert.deepEqual(params, { page: 1, size: 10 })
})
test('gating_item_parse_normal_and_snake_fallback', () => {
const camel = toGatingItem({
id: 7, brand: 'jellycat', asin: 'B0ABC123', country: '英国', gatingType: '品牌gating',
status: 1, source: 'AUTO', shopName: '店A', remark: 'r',
createdAt: '2026-01-02 03:04:05', updatedAt: '2026-01-03 03:04:05', disabledAt: null,
})
assert.ok(camel)
assert.equal(camel.gatingType, '品牌gating')
assert.equal(camel.shopName, '店A')
assert.equal(camel.createdAt, '2026-01-02 03:04:05')
assert.equal(camel.disabledAt, undefined)
const snake = toGatingItem({
id: 9, gating_type: '类目gating', shop_name: '店B',
created_at: '2026-02-01 00:00:00', updated_at: '2026-02-02 00:00:00', disabled_at: '2026-02-03 00:00:00',
})
assert.ok(snake)
assert.equal(snake.gatingType, '类目gating')
assert.equal(snake.shopName, '店B')
assert.equal(snake.disabledAt, '2026-02-03 00:00:00')
})
test('gating_item_parse_invalid_rows_dropped', () => {
assert.equal(toGatingItem(null), null)
assert.equal(toGatingItem({ brand: 'no-id' }), null)
const page = parseGatingPage({ total: 3, rows: [{ id: 1, brand: 'a' }, { brand: 'bad' }, 'junk', null] })
assert.equal(page.rows.length, 1)
assert.equal(page.rows[0]?.brand, 'a')
assert.equal(page.total, 3)
})
test('gating_page_parse_empty_and_items_alias', () => {
assert.deepEqual(parseGatingPage(null), { rows: [], total: 0 })
const page = parseGatingPage({ total: 1, items: [{ id: 2, brand: 'b' }] })
assert.equal(page.rows.length, 1)
assert.equal(page.rows[0]?.id, 2)
})
test('gating_stats_parse_array_and_dict_forms', () => {
// 契约数组形态。
const stats = parseGatingStats({
total: 10, active: 8, disabled: 2, brands: 5,
byType: [{ name: '品牌gating', count: 6 }, { name: '类目gating', count: 2 }],
byCountry: [{ name: '英国', count: 4 }],
bySource: [{ name: 'AUTO', count: 7 }],
})
assert.equal(stats.total, 10)
assert.equal(stats.brands, 5)
assert.equal(stats.byType[0]?.name, '品牌gating')
assert.equal(stats.bySource[0]?.count, 7)
// 桌面版遗留 dict 形态也要能收。
const legacy = parseGatingStats({ total: 1, by_type: { '品牌gating': 3 }, by_country: { '全部': 1 }, by_source: { MANUAL: 1 } })
assert.equal(legacy.byType[0]?.name, '品牌gating')
assert.equal(legacy.byType[0]?.count, 3)
assert.equal(legacy.byCountry[0]?.name, '全部')
})
test('gating_name_count_list_garbage_in_empty_out', () => {
assert.deepEqual(parseGatingNameCountList(null), [])
assert.deepEqual(parseGatingNameCountList('x'), [])
assert.deepEqual(parseGatingNameCountList([{ name: '', count: 1 }, { count: 2 }, 'junk']), [])
})
test('gating_status_label', () => {
assert.equal(gatingStatusLabel(1), '生效')
assert.equal(gatingStatusLabel(0), '停用')
assert.equal(gatingStatusLabel(undefined), '停用')
})
@@ -1,138 +0,0 @@
/**
* 品牌Gating库页面挂载测试:渲染(统计卡 + 行)与两次操作载荷断言(新增、恢复生效)。
* 跑法:`npm run test:mount`(vitest + jsdom,配置见 vitest.config.ts)。
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import GatingPage from '@/pages/gating/GatingPage.vue'
const gatingApi = vi.hoisted(() => ({
fetchGatingPage: vi.fn(),
fetchGatingStats: vi.fn(),
createGating: vi.fn(),
deleteGating: vi.fn(),
updateGatingStatus: vi.fn(),
importGatingText: vi.fn(),
}))
vi.mock('@/pages/gating/gating-api', () => gatingApi)
const listPayload = {
total: 2,
rows: [
{
id: 1,
brand: 'jellycat',
asin: 'B0ABC123',
country: '英国',
gatingType: '品牌gating',
status: 1,
source: 'AUTO',
shopName: '',
remark: '',
createdAt: '2026-01-02 03:04:05',
updatedAt: '2026-01-03 03:04:05',
},
{
id: 2,
brand: 'crocs',
asin: '',
country: '全部',
gatingType: '类目gating',
status: 0,
source: 'MANUAL',
shopName: '店A',
remark: '人为录入',
createdAt: '2026-02-01 00:00:00',
updatedAt: '2026-02-02 00:00:00',
disabledAt: '2026-02-03 00:00:00',
},
],
}
const statsPayload = {
total: 2,
active: 1,
disabled: 1,
brands: 2,
byType: [{ name: '品牌gating', count: 1 }],
byCountry: [{ name: '英国', count: 1 }],
bySource: [{ name: 'MANUAL', count: 1 }],
}
const findButton = (wrapper: VueWrapper, label: string) =>
wrapper.findAll('button').find((button) => button.text().trim() === label)
describe('GatingPage', () => {
beforeEach(() => {
vi.clearAllMocks()
gatingApi.fetchGatingPage.mockResolvedValue(listPayload)
gatingApi.fetchGatingStats.mockResolvedValue(statsPayload)
})
it('渲染统计卡、筛选区与表格行', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
const text = wrapper.text()
expect(text).toContain('Gating总记录')
expect(text).toContain('去重品牌数')
expect(text).toContain('jellycat')
expect(text).toContain('crocs')
expect(text).toContain('生效')
expect(text).toContain('停用')
expect(text).toContain('按Gating类型')
expect(wrapper.findAll('tbody tr').length).toBeGreaterThanOrEqual(2)
expect(gatingApi.fetchGatingPage).toHaveBeenCalledTimes(1)
expect(gatingApi.fetchGatingStats).toHaveBeenCalledTimes(1)
})
it('新增弹窗提交后按驼峰字段发载荷', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
gatingApi.createGating.mockResolvedValue(1)
await findButton(wrapper, '新增')!.trigger('click')
const modal = wrapper.get('.modal')
const inputs = modal.findAll('input[type="text"]')
await inputs[0]!.setValue('jellycat') // 品牌
await inputs[1]!.setValue('B0Z9X') // ASIN
await inputs[2]!.setValue('店A') // 店铺
await inputs[3]!.setValue('测试备注') // 备注
await findButton(modal, '保存')!.trigger('click')
await flushPromises()
expect(gatingApi.createGating).toHaveBeenCalledTimes(1)
expect(gatingApi.createGating).toHaveBeenCalledWith({
brand: 'jellycat',
asin: 'B0Z9X',
country: '全部',
gatingType: '品牌gating',
source: 'MANUAL',
shopName: '店A',
remark: '测试备注',
})
})
it('停用行点恢复 → POST status 载荷 status=1;品牌为空时新增被拦截', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
const crocsRow = wrapper
.findAll('tbody tr')
.find((row) => row.text().includes('crocs'))!
await findButton(crocsRow, '恢复')!.trigger('click')
await flushPromises()
expect(gatingApi.updateGatingStatus).toHaveBeenCalledTimes(1)
expect(gatingApi.updateGatingStatus).toHaveBeenCalledWith(2, 1)
// 品牌必填:空品牌提交不发请求
await findButton(wrapper, '新增')!.trigger('click')
await findButton(wrapper.get('.modal'), '保存')!.trigger('click')
await flushPromises()
expect(gatingApi.createGating).not.toHaveBeenCalled()
})
})
@@ -36,7 +36,6 @@ const OPS_MIN_COL_PX: Record<string, number> = {
'src/pages/asin/ProductCategoryPage.vue': 138,
'src/pages/asin/QueryAsinPage.vue': 138,
'src/pages/asin/SkipPricePage.vue': 138,
'src/pages/gating/GatingPage.vue': 138,
'src/pages/records/DeviceLogsPage.vue': 138,
'src/pages/records/RecordsDigitalHumanVersionPage.vue': 287,
'src/pages/records/RecordsSoftwareVersionPage.vue': 77,