feat(brandgating): 品牌Gating库并入店铺数据重复检查页

- 「店铺数据重复检查」新增「品牌Gating库」页签,承接原独立 Gating 网页后台的列表/筛选/统计、单条新增、批量导入、启停与删除。
- 复用既有 /api/admin/brand-gating 模块;接口权限键跟随宿主页 admin_shop_data_duplicate_check(V164 菜单已由 V166 删除)。
- 前端新增 brand-gating 模型/API 适配、BrandGatingPanel 与纯逻辑单测。
This commit is contained in:
2026-10-25 02:09:07 +08:00
parent 813bed66a3
commit 112c61afa8
7 changed files with 1169 additions and 21 deletions
@@ -0,0 +1,787 @@
<script setup lang="ts">
/**
* 品牌Gating库管理面板:以第三个页签嵌在「店铺数据重复检查」页里。
* 数据源 /api/admin/brand-gating(biz_brand_gating,全平台共享,不随公司 Tab 收窄)。
*/
import { computed, onMounted, reactive, ref } from 'vue'
import { formatDateTime } from '@/utils/datetime'
import { actionableErrorText, type AdminFeedbackKind } from '@/components/admin-feedback'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { openAdminConfirm } from '@/components/admin-confirm'
import OldPagination from '@/components/OldPagination.vue'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
import {
GATING_COUNTRIES,
GATING_SOURCES,
GATING_TYPES,
createBrandGatingFilter,
createBrandGatingForm,
validateBrandGatingForm,
type BrandGatingFilter,
type BrandGatingForm,
type BrandGatingRow,
type BrandGatingStats,
} from './brand-gating-model.ts'
import {
deleteBrandGating,
fetchBrandGatingPage,
fetchBrandGatingStats,
importBrandGatingText,
submitBrandGating,
updateBrandGatingStatus,
} from './brand-gating-api.ts'
const filter = reactive<BrandGatingFilter>(createBrandGatingFilter())
const page = ref(1)
const pageSize = ref(10)
const rows = ref<BrandGatingRow[]>([])
const total = ref(0)
const pageLoading = ref(false)
const loadError = ref('')
const loaded = ref(false)
const stats = ref<BrandGatingStats | null>(null)
const statsLoading = ref(false)
const statsError = ref('')
const form = reactive<BrandGatingForm>(createBrandGatingForm())
const addBusy = ref(false)
const batchText = ref('')
const importBusy = ref(false)
const busyRowId = ref(0)
const tipVisible = ref(true)
const countryOptions = GATING_COUNTRIES.filter((country) => country !== '全部')
const typeOptions = GATING_TYPES
const statsCards = computed(() => {
const current = stats.value
const byType = new Map((current?.byType ?? []).map((item) => [item.name, item.count]))
return [
{ label: 'Gating总记录', value: current?.total ?? 0, tone: '' },
{ label: '生效中', value: current?.active ?? 0, tone: 'ok' },
{ label: '已解除', value: current?.disabled ?? 0, tone: 'muted' },
{ label: '去重品牌数', value: current?.brands ?? 0, tone: '' },
{ label: '品牌gating', value: byType.get('品牌gating') ?? 0, tone: 'primary' },
{ label: '类目gating', value: byType.get('类目gating') ?? 0, tone: 'warn' },
{ label: '账户不符合', value: byType.get('账户不符合') ?? 0, tone: 'danger' },
]
})
function feedback(message: string, kind: AdminFeedbackKind): void {
showAdminFeedback(message, kind)
}
async function loadStats(): Promise<void> {
statsLoading.value = true
statsError.value = ''
try {
stats.value = await fetchBrandGatingStats()
} catch (error) {
statsError.value = actionableErrorText(error)
} finally {
statsLoading.value = false
}
}
async function loadPage(nextPage = page.value): Promise<void> {
pageLoading.value = true
loadError.value = ''
try {
const result = await fetchBrandGatingPage(filter, nextPage, pageSize.value)
rows.value = result.rows
total.value = result.total
page.value = nextPage
loaded.value = true
} catch (error) {
loadError.value = actionableErrorText(error)
} finally {
pageLoading.value = false
}
}
function query(): void {
loadPage(1)
}
function resetFilter(): void {
Object.assign(filter, createBrandGatingFilter())
loadPage(1)
}
function changePageSize(size: number): void {
pageSize.value = size
loadPage(1)
}
async function addOne(): Promise<void> {
const error = validateBrandGatingForm(form)
if (error) {
feedback(error, 'warning')
return
}
addBusy.value = true
try {
const added = await submitBrandGating(form)
if (added) {
feedback('新增成功', 'success')
form.brand = ''
form.asin = ''
form.remark = ''
} else {
feedback('该品牌 + 国家已存在,未重复添加', 'warning')
}
await Promise.all([loadPage(added ? 1 : page.value), loadStats()])
} catch (error) {
feedback(actionableErrorText(error), 'error')
} finally {
addBusy.value = false
}
}
async function batchAdd(): Promise<void> {
const text = batchText.value.trim()
if (!text) {
feedback('请粘贴批量数据', 'warning')
return
}
importBusy.value = true
try {
const result = await importBrandGatingText(text)
feedback(`批量导入完成:新增 ${result.added} 条,跳过重复 ${result.skipped} 条`, 'success')
batchText.value = ''
await Promise.all([loadPage(1), loadStats()])
} catch (error) {
feedback(actionableErrorText(error), 'error')
} finally {
importBusy.value = false
}
}
async function toggleStatus(row: BrandGatingRow): Promise<void> {
const enabling = row.status !== 1
if (!enabling) {
const confirmed = await openAdminConfirm({ danger: false,
title: '解除Gating',
message: `确认解除「${row.brand}」的Gating记录?解除后排查会跳过该品牌。`,
confirmText: '确认解除',
})
if (!confirmed) return
}
busyRowId.value = row.id
try {
await updateBrandGatingStatus(row.id, enabling ? 1 : 0)
feedback(enabling ? '已恢复生效' : '已解除,排查不再拦截', 'success')
await Promise.all([loadPage(), loadStats()])
} catch (error) {
feedback(actionableErrorText(error), 'error')
} finally {
busyRowId.value = 0
}
}
async function removeRow(row: BrandGatingRow): Promise<void> {
const confirmed = await openAdminConfirm({ danger: true,
targetName: row.brand,
message: `确认删除 ID=${row.id} 的「${row.brand}」Gating记录?此操作可能影响已有数据。`,
})
if (!confirmed) return
busyRowId.value = row.id
try {
await deleteBrandGating(row.id)
feedback('已删除', 'success')
const nextPage = rows.value.length === 1 && page.value > 1 ? page.value - 1 : page.value
await Promise.all([loadPage(nextPage), loadStats()])
} catch (error) {
feedback(actionableErrorText(error), 'error')
} finally {
busyRowId.value = 0
}
}
function typeClass(type: string): string {
if (type.includes('账户')) return 'g-tag-acc'
if (type.includes('类目')) return 'g-tag-cat'
return 'g-tag-brand'
}
function sourceText(source: string): string {
if (source === 'AUTO') return '自动同步'
if (source === 'MANUAL') return '手动'
return source || '—'
}
onMounted(() => {
loadStats()
loadPage(1)
})
</script>
<template>
<div class="gating-panel">
<div v-if="tipVisible" class="g-tip">
<span class="g-tip-title">当前页面操作提示</span>
<span>
维护不符合规则的品牌(品牌Gating / 类目Gating)。新增后可用下方筛选快速回查;云端 Gating 库与前端排查软件同步同一份数据,命中后会自动拦截。
<b>Gating 库为全平台共享数据,不随上方公司页签切换。</b>
</span>
<button class="g-tip-x" type="button" @click="tipVisible = false">收起 ✕</button>
</div>
<div v-if="statsError" class="g-stats-error">
<span>统计加载失败:{{ statsError }}</span>
<button type="button" @click="loadStats">重试</button>
</div>
<section class="g-cards" v-loading="statsLoading">
<div v-for="card in statsCards" :key="card.label" class="g-card" :class="card.tone">
<div class="g-n">{{ card.value.toLocaleString() }}</div>
<div class="g-t">{{ card.label }}</div>
</div>
</section>
<div class="g-forms">
<section class="g-panel">
<div class="g-panel-head">新增 Gating 品牌</div>
<div class="g-panel-body">
<div class="g-fields">
<label class="g-field">
<span>品牌 *</span>
<input v-model="form.brand" placeholder="品牌(必填)" @keyup.enter="addOne" />
</label>
<label class="g-field">
<span>国家</span>
<select v-model="form.country">
<option v-for="country in GATING_COUNTRIES" :key="country" :value="country">{{ country }}</option>
</select>
</label>
<label class="g-field">
<span>类型</span>
<select v-model="form.gatingType">
<option v-for="type in typeOptions" :key="type" :value="type">{{ type }}</option>
</select>
</label>
<label class="g-field">
<span>ASIN</span>
<input v-model="form.asin" placeholder="ASIN(可选)" @keyup.enter="addOne" />
</label>
<label class="g-field g-field-wide">
<span>备注</span>
<input v-model="form.remark" placeholder="备注(可选)" @keyup.enter="addOne" />
</label>
</div>
<div class="g-form-actions">
<button class="g-btn g-btn-primary" type="button" :disabled="addBusy" @click="addOne">
{{ addBusy ? '新增中…' : '新增' }}
</button>
</div>
</div>
</section>
<section class="g-panel">
<div class="g-panel-head">批量导入 Gating 品牌</div>
<div class="g-panel-body">
<textarea
v-model="batchText"
class="g-textarea"
placeholder="每行一个,格式:品牌,国家,类型,ASIN,备注(后四列可省略)&#10;示例:&#10;tory burch,英国,品牌gating&#10;jellycat,全部,品牌gating&#10;crocs,德国,类目gating"
></textarea>
<div class="g-form-actions">
<button class="g-btn g-btn-violet" type="button" :disabled="importBusy" @click="batchAdd">
{{ importBusy ? '导入中…' : '批量导入' }}
</button>
</div>
</div>
</section>
</div>
<section class="g-panel">
<div class="g-panel-head">Gating 品牌列表</div>
<div class="g-panel-body">
<div class="g-filters">
<input v-model="filter.keyword" placeholder="搜索品牌 / ASIN" @keyup.enter="query" />
<select v-model="filter.country">
<option value="">全部国家</option>
<option v-for="country in countryOptions" :key="country" :value="country">{{ country }}</option>
</select>
<select v-model="filter.gatingType">
<option value="">全部类型</option>
<option v-for="type in typeOptions" :key="type" :value="type">{{ type }}</option>
</select>
<select v-model="filter.status">
<option value="">全部状态</option>
<option value="1">生效</option>
<option value="0">已解除</option>
</select>
<select v-model="filter.source">
<option value="">全部来源</option>
<option v-for="source in GATING_SOURCES" :key="source" :value="source">{{ sourceText(source) }}</option>
</select>
<button class="g-btn g-btn-primary" type="button" @click="query">查询</button>
<button class="g-btn g-btn-ghost" type="button" @click="resetFilter">重置</button>
</div>
<LoadFailureBar v-if="loadError" :message="loadError" @retry="loadPage()" />
<div class="g-table-wrap" v-loading="pageLoading">
<table v-if="rows.length" class="g-table">
<thead>
<tr>
<th style="width: 64px">ID</th>
<th>品牌</th>
<th>ASIN</th>
<th style="width: 82px">国家</th>
<th style="width: 112px">类型</th>
<th style="width: 82px">状态</th>
<th style="width: 100px">来源</th>
<th>店铺</th>
<th>备注</th>
<th style="width: 156px">创建时间</th>
<th style="width: 118px">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="row in rows" :key="row.id">
<td class="g-dim">{{ row.id }}</td>
<td class="g-strong">{{ row.brand }}</td>
<td class="g-mono">{{ row.asin || '—' }}</td>
<td>{{ row.country || '—' }}</td>
<td><span class="g-tag" :class="typeClass(row.gatingType)">{{ row.gatingType || '—' }}</span></td>
<td>
<span class="g-tag" :class="row.status === 1 ? 'g-tag-on' : 'g-tag-off'">
{{ row.status === 1 ? '生效' : '已解除' }}
</span>
</td>
<td :class="row.source === 'AUTO' ? 'g-source-auto' : 'g-source-manual'">{{ sourceText(row.source) }}</td>
<td>{{ row.shopName || '—' }}</td>
<td class="g-remark" :title="row.remark">{{ row.remark || '—' }}</td>
<td class="g-time">{{ formatDateTime(row.createdAt) }}</td>
<td>
<div class="g-ops">
<button
class="g-btn g-btn-sm"
:class="row.status === 1 ? 'g-btn-ghost' : 'g-btn-green'"
type="button"
:disabled="busyRowId === row.id"
@click="toggleStatus(row)"
>
{{ row.status === 1 ? '解除' : '恢复' }}
</button>
<button
class="g-btn g-btn-sm g-btn-danger"
type="button"
:disabled="busyRowId === row.id"
@click="removeRow(row)"
>
删除
</button>
</div>
</td>
</tr>
</tbody>
</table>
<div v-else-if="!pageLoading && loaded" class="g-empty">暂无数据,请先在上方新增或使用前端排查软件同步</div>
</div>
<OldPagination
v-if="total"
:total="total"
:page="page"
:page-size="pageSize"
@change="loadPage"
@size-change="changePageSize"
/>
</div>
</section>
</div>
</template>
<style scoped>
.gating-panel {
--g-border: #e5e9f0;
--g-text: #1c2230;
--g-text2: #5a6474;
--g-text3: #98a1b1;
--g-primary: #2e5be6;
--g-danger: #d63a4a;
--g-green: #1f9d62;
--g-amber: #d9912b;
--g-violet: #7c5cd6;
--g-surface: #ffffff;
--g-mono: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
--g-shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 4px 18px rgba(20, 30, 60, 0.06);
display: flex;
flex-direction: column;
gap: 14px;
}
.g-tip {
display: flex;
align-items: flex-start;
gap: 10px;
background: #f5f9ff;
border: 1px solid #cfe0fb;
border-left: 4px solid var(--g-primary);
border-radius: 10px;
padding: 10px 14px;
font-size: 12px;
color: #1e40af;
line-height: 1.7;
}
.g-tip-title {
flex: none;
font-weight: 700;
color: #1d4ed8;
}
.g-tip b {
color: #1d4ed8;
}
.g-tip-x {
flex: none;
margin-left: auto;
border: none;
background: none;
color: #6b9ef0;
font-family: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
.g-stats-error {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 14px;
border-radius: 9px;
border: 1px solid #f3c6cc;
background: #fdebed;
color: var(--g-danger);
font-size: 12px;
}
.g-stats-error button {
border: none;
background: none;
color: var(--g-danger);
font-family: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
.g-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
gap: 10px;
}
.g-card {
background: var(--g-surface);
border: 1px solid var(--g-border);
border-top: 3px solid #9ca3af;
border-radius: 10px;
box-shadow: var(--g-shadow);
padding: 12px 14px;
}
.g-card.ok { border-top-color: var(--g-green); }
.g-card.muted { border-top-color: #b8c0ce; }
.g-card.primary { border-top-color: var(--g-primary); }
.g-card.warn { border-top-color: var(--g-amber); }
.g-card.danger { border-top-color: var(--g-danger); }
.g-card .g-n {
font-size: 24px;
font-weight: 700;
color: var(--g-text);
font-variant-numeric: tabular-nums;
line-height: 1.2;
}
.g-card .g-t {
margin-top: 3px;
font-size: 11.5px;
color: var(--g-text3);
}
.g-forms {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
gap: 14px;
}
.g-panel {
background: var(--g-surface);
border: 1px solid var(--g-border);
border-radius: 10px;
box-shadow: var(--g-shadow);
overflow: hidden;
}
.g-panel-head {
padding: 11px 15px;
background: #fafbfd;
border-bottom: 1px solid #e9edf3;
font-size: 13px;
font-weight: 700;
color: var(--g-text);
}
.g-panel-head::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
border-radius: 2px;
background: #2dd4bf;
margin-right: 8px;
vertical-align: 1px;
}
.g-panel-body {
padding: 14px 15px;
}
.g-fields {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px 12px;
}
.g-field {
display: flex;
flex-direction: column;
gap: 5px;
min-width: 0;
}
.g-field > span {
font-size: 12px;
color: var(--g-text2);
}
.g-field-wide {
grid-column: span 2;
}
.g-field input,
.g-field select,
.g-filters input,
.g-filters select {
width: 100%;
height: 34px;
padding: 0 10px;
border: 1px solid #d7dce5;
border-radius: 7px;
background: #fbfcfe;
color: var(--g-text);
font-family: inherit;
font-size: 13px;
outline: none;
}
.g-field input:focus,
.g-field select:focus,
.g-filters input:focus,
.g-filters select:focus {
border-color: var(--g-primary);
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
background: #fff;
}
.g-form-actions {
display: flex;
justify-content: flex-end;
margin-top: 12px;
}
.g-textarea {
width: 100%;
height: 126px;
padding: 9px 10px;
border: 1px solid #d7dce5;
border-radius: 7px;
background: #fbfcfe;
color: var(--g-text);
font-family: inherit;
font-size: 12.5px;
line-height: 1.6;
resize: vertical;
outline: none;
}
.g-textarea:focus {
border-color: var(--g-primary);
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
background: #fff;
}
.g-filters {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-bottom: 12px;
}
.g-filters input {
width: 190px;
}
.g-filters select {
width: 132px;
}
.g-btn {
height: 34px;
padding: 0 15px;
border: 1px solid transparent;
border-radius: 7px;
font-family: inherit;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.g-btn:disabled {
opacity: 0.55;
cursor: not-allowed;
}
.g-btn-sm {
height: 28px;
padding: 0 10px;
font-size: 12px;
border-radius: 6px;
}
.g-btn-primary {
background: var(--g-primary);
border-color: var(--g-primary);
color: #fff;
}
.g-btn-primary:hover:not(:disabled) {
background: #1e4bd8;
border-color: #1e4bd8;
}
.g-btn-violet {
background: var(--g-violet);
border-color: var(--g-violet);
color: #fff;
}
.g-btn-violet:hover:not(:disabled) {
background: #6b4bc4;
border-color: #6b4bc4;
}
.g-btn-green {
background: #e7f7ef;
border-color: #bce7d2;
color: var(--g-green);
}
.g-btn-green:hover:not(:disabled) {
background: #d9f2e5;
}
.g-btn-danger {
background: #fdebed;
border-color: #f3c6cc;
color: var(--g-danger);
}
.g-btn-danger:hover:not(:disabled) {
background: #fbdde1;
}
.g-btn-ghost {
background: #fff;
border-color: #d7dce5;
color: var(--g-text2);
}
.g-btn-ghost:hover:not(:disabled) {
border-color: var(--g-primary);
color: var(--g-primary);
}
.g-table-wrap {
overflow-x: auto;
border: 1px solid var(--g-border);
border-radius: 9px;
min-height: 90px;
}
.g-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
font-size: 12.5px;
}
.g-table th {
position: sticky;
top: 0;
z-index: 1;
padding: 10px;
background: #f7f9fc;
border-bottom: 1px solid var(--g-border);
color: var(--g-text2);
font-size: 12px;
font-weight: 600;
text-align: left;
white-space: nowrap;
}
.g-table td {
padding: 9px 10px;
border-bottom: 1px solid #eff2f7;
color: var(--g-text);
white-space: nowrap;
}
.g-table tbody tr:hover td {
background: #f7faff;
}
.g-table tbody tr:last-child td {
border-bottom: none;
}
.g-strong {
font-weight: 600;
}
.g-dim {
color: var(--g-text3);
}
.g-mono {
font-family: var(--g-mono);
}
.g-time {
color: var(--g-text2);
font-size: 11.5px;
}
.g-remark {
max-width: 190px;
overflow: hidden;
text-overflow: ellipsis;
color: var(--g-text2);
}
.g-source-auto {
color: var(--g-violet);
}
.g-source-manual {
color: #0d9488;
}
.g-tag {
display: inline-block;
padding: 2px 8px;
border-radius: 6px;
font-size: 11px;
font-weight: 600;
white-space: nowrap;
}
.g-tag-brand {
background: #eff6ff;
color: #2563eb;
}
.g-tag-cat {
background: #fef3c7;
color: #b45309;
}
.g-tag-acc {
background: #fee2e2;
color: #dc2626;
}
.g-tag-on {
background: #d1fae5;
color: #10b981;
}
.g-tag-off {
background: #e5e7eb;
color: #9ca3af;
}
.g-ops {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.g-empty {
padding: 42px 16px;
text-align: center;
color: var(--g-text3);
font-size: 13px;
}
</style>
@@ -13,8 +13,9 @@ import { aggregateDrawerRows, drawerSummaryOf, dupWithinGroup, indexShopGroups,
import type { DuplicateConsole, LedgerRow } from './duplicate-console-model.ts'
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
import { orderedPair } from '@/utils/datetime'
import BrandGatingPanel from './BrandGatingPanel.vue'
type Tab = 'dup' | 'ledger'
type Tab = 'dup' | 'ledger' | 'gating'
type Scope = 'global' | 'group'
const consoleData = ref<DuplicateConsole | null>(null)
@@ -431,18 +432,18 @@ onMounted(() => {
<div class="dup-head">
<div>
<h2>店铺数据撞款监控</h2>
<p>按 ASIN×店铺×站点分析同一 ASIN 在多家自营店铺/分组内的重复上架;分组归属来自店铺管理,只读展示。</p>
<p>按 ASIN×店铺×站点分析同一 ASIN 在多家自营店铺/分组内的重复上架;分组归属来自店铺管理,只读展示。品牌Gating库在同一页的第三个页签维护。</p>
</div>
</div>
<div v-if="loadError" class="load-banner">
<div v-if="loadError && activeTab !== 'gating'" class="load-banner">
<span>{{ loadError }}</span>
<button class="btn btn-ghost btn-sm" type="button" @click="loadConsole">重试</button>
<button class="btn btn-ghost btn-sm" type="button" @click="loadError = ''">知道了</button>
</div>
<!-- 筛选条件 -->
<section class="card filter">
<!-- 筛选条件(撞款/台账专用,Gating 页签隐藏) -->
<section v-if="activeTab !== 'gating'" class="card filter">
<div class="filter-title">筛选条件</div>
<div class="filter-row">
<div class="f-group">
@@ -492,10 +493,9 @@ onMounted(() => {
</div>
</section>
<div v-loading="loading" class="dup-body-wrap">
<template v-if="consoleData">
<div v-loading="loading && activeTab !== 'gating'" class="dup-body-wrap">
<!-- KPI 统计 -->
<section class="kpis">
<section v-if="consoleData && activeTab !== 'gating'" class="kpis">
<div v-for="kpi in kpis" :key="kpi.label" class="kpi" :class="kpi.tone">
<div class="k-label"><span class="k-dot"></span>{{ kpi.label }}</div>
<div class="k-value">{{ kpi.value }}</div>
@@ -504,7 +504,7 @@ onMounted(() => {
</section>
<!-- 店铺上架分布 -->
<section class="card store-strip">
<section v-if="consoleData && activeTab !== 'gating'" class="card store-strip">
<div class="strip-head">
<span class="strip-title">店铺上架分布</span>
<span class="strip-note">各店铺在本批站点中的上架记录量(含重复扫描)</span>
@@ -527,8 +527,9 @@ onMounted(() => {
<div class="tabs">
<button class="tab" :class="{ active: activeTab === 'dup' }" type="button" @click="switchTab('dup')">撞款监控 <span class="t-count">{{ totalDupCount }}</span></button>
<button class="tab" :class="{ active: activeTab === 'ledger' }" type="button" @click="switchTab('ledger')">全部ASIN台账 <span class="t-count">{{ ledgerTotal }}</span></button>
<button class="tab" :class="{ active: activeTab === 'gating' }" type="button" @click="switchTab('gating')">品牌Gating库</button>
</div>
<div class="actions">
<div v-if="activeTab !== 'gating'" class="actions">
<span v-if="overview" class="updated">数据更新时间 {{ overview.scannedAt || '—' }}</span>
<button v-if="isSuper" class="btn btn-ghost btn-sm" type="button" @click="groupInfoVisible = true">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" /><circle cx="9" cy="7" r="4" /><path d="M23 21v-2a4 4 0 0 0-3-3.87" /><path d="M16 3.13a4 4 0 0 1 0 7.75" /></svg>
@@ -545,8 +546,13 @@ onMounted(() => {
</div>
</div>
<!-- ============ 品牌Gating库(全平台共享数据) ============ -->
<template v-if="activeTab === 'gating'">
<BrandGatingPanel />
</template>
<!-- ============ 撞款监控 ============ -->
<template v-if="activeTab === 'dup'">
<template v-else-if="consoleData && activeTab === 'dup'">
<div v-if="isSuper" class="scope-bar">
<div class="seg">
<button class="seg-btn" :class="{ active: scope === 'global' }" type="button" @click="switchScope('global')">全店撞款</button>
@@ -626,7 +632,7 @@ onMounted(() => {
</template>
<!-- ============ 全部ASIN台账 ============ -->
<template v-else>
<template v-else-if="consoleData">
<div class="table-wrap" v-loading="ledgerLoading">
<table v-if="ledgerItems.length" class="ledger">
<thead>
@@ -661,9 +667,8 @@ onMounted(() => {
</div>
<OldPagination v-if="ledgerTotal" :total="ledgerTotal" :page="ledgerPage" :page-size="ledgerPageSize" @change="goPage" @size-change="changeLedgerSize" />
</template>
</template>
<div v-else-if="!loadError" class="card empty-state">
<div v-if="!consoleData && activeTab !== 'gating' && !loadError" class="card empty-state">
<div class="e-title">暂无扫描结果</div>
请点击右上角「重新分析」触发撞款扫描
</div>
@@ -0,0 +1,60 @@
/** 品牌Gating库接口适配:/api/admin/brand-gating 的列表/统计/新增/启停/删除/批量导入。 */
import { http } from '@/api/http'
import { unwrap } from '@/api/envelope'
import {
parseBrandGatingAddResult,
parseBrandGatingImportResult,
parseBrandGatingPage,
parseBrandGatingStats,
toBrandGatingQuery,
type BrandGatingFilter,
type BrandGatingForm,
type BrandGatingImportResult,
type BrandGatingPage,
type BrandGatingStats,
} from './brand-gating-model.ts'
export const BRAND_GATING_ENDPOINT = '/api/admin/brand-gating'
export async function fetchBrandGatingPage(
filter: BrandGatingFilter,
page: number,
pageSize: number,
): Promise<BrandGatingPage> {
const { data } = await http.get<unknown>(BRAND_GATING_ENDPOINT, {
params: toBrandGatingQuery(filter, page, pageSize),
})
return parseBrandGatingPage(unwrap<unknown>(data))
}
export async function fetchBrandGatingStats(): Promise<BrandGatingStats> {
const { data } = await http.get<unknown>(`${BRAND_GATING_ENDPOINT}/stats`)
return parseBrandGatingStats(unwrap<unknown>(data))
}
/** 单条新增:true=新增成功,false=品牌+国家已存在(后端撞唯一键返回 added=0)。 */
export async function submitBrandGating(form: BrandGatingForm): Promise<boolean> {
const { data } = await http.post<unknown>(BRAND_GATING_ENDPOINT, {
brand: form.brand.trim(),
country: form.country,
gatingType: form.gatingType,
asin: form.asin.trim(),
remark: form.remark.trim(),
})
return parseBrandGatingAddResult(unwrap<unknown>(data))
}
export async function updateBrandGatingStatus(id: number, status: 0 | 1): Promise<void> {
const { data } = await http.post<unknown>(`${BRAND_GATING_ENDPOINT}/${id}/status`, { status })
unwrap<unknown>(data)
}
export async function deleteBrandGating(id: number): Promise<void> {
const { data } = await http.delete<unknown>(`${BRAND_GATING_ENDPOINT}/${id}`)
unwrap<unknown>(data)
}
export async function importBrandGatingText(text: string): Promise<BrandGatingImportResult> {
const { data } = await http.post<unknown>(`${BRAND_GATING_ENDPOINT}/import`, { text })
return parseBrandGatingImportResult(unwrap<unknown>(data))
}
@@ -0,0 +1,177 @@
/** 品牌Gating库模型(任务:并入「店铺数据重复检查」页签):与 /api/admin/brand-gating 的 camel 契约对齐,纯逻辑。 */
export const GATING_COUNTRIES = ['全部', '英国', '德国', '法国', '西班牙', '意大利'] as const
export const GATING_TYPES = ['品牌gating', '类目gating', '账户不符合'] as const
export const GATING_SOURCES = ['AUTO', 'MANUAL'] as const
export type GatingStatusFilter = '' | '1' | '0'
export interface BrandGatingFilter {
keyword: string
country: string
gatingType: string
status: GatingStatusFilter
source: string
}
export interface BrandGatingForm {
brand: string
country: string
gatingType: string
asin: string
remark: string
}
export interface BrandGatingRow {
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 BrandGatingNameCount {
name: string
count: number
}
export interface BrandGatingStats {
total: number
active: number
disabled: number
brands: number
byType: BrandGatingNameCount[]
byCountry: BrandGatingNameCount[]
bySource: BrandGatingNameCount[]
}
export interface BrandGatingPage {
total: number
rows: BrandGatingRow[]
}
export interface BrandGatingImportResult {
added: number
skipped: number
}
export function createBrandGatingFilter(): BrandGatingFilter {
return { keyword: '', country: '', gatingType: '', status: '', source: '' }
}
export function createBrandGatingForm(): BrandGatingForm {
return { brand: '', country: '全部', gatingType: '品牌gating', asin: '', remark: '' }
}
/** 列表查询参数:空值与「全部」哨兵不下发,其余原样交给后端(与桌面版 list_gating 同口径)。 */
export function toBrandGatingQuery(
filter: BrandGatingFilter,
page: number,
pageSize: number,
): Record<string, string | number> {
const query: Record<string, string | number> = {
page: Math.max(1, Math.trunc(page) || 1),
size: Math.max(1, Math.trunc(pageSize) || 10),
}
const keyword = filter.keyword.trim()
if (keyword) query.keyword = keyword
if (filter.country && filter.country !== '全部') query.country = filter.country
if (filter.gatingType && filter.gatingType !== '全部') query.gatingType = filter.gatingType
if (filter.status === '1' || filter.status === '0') query.status = filter.status
if (filter.source && filter.source !== '全部') query.source = filter.source
return query
}
/** 单条新增前置校验:只拦空品牌,其余字段由后端落桌面版同款默认值。 */
export function validateBrandGatingForm(form: BrandGatingForm): string {
if (!form.brand.trim()) return '请填写品牌'
return ''
}
function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === 'object' ? (value as Record<string, unknown>) : null
}
function textOf(value: unknown): string {
return value == null ? '' : String(value).trim()
}
function countOf(value: unknown): number {
const count = Number(value)
return Number.isFinite(count) ? Math.max(0, Math.trunc(count)) : 0
}
function nameCountsOf(value: unknown): BrandGatingNameCount[] {
if (!Array.isArray(value)) return []
return value
.map((item) => {
const record = asRecord(item)
if (!record) return null
const name = textOf(record.name)
return name ? { name, count: countOf(record.count) } : null
})
.filter((item): item is BrandGatingNameCount => item !== null)
}
export function parseBrandGatingRow(raw: unknown): BrandGatingRow | null {
const record = asRecord(raw)
if (!record) return null
const id = Number(record.id)
if (!Number.isFinite(id)) return null
return {
id,
brand: textOf(record.brand),
asin: textOf(record.asin),
country: textOf(record.country),
gatingType: textOf(record.gatingType),
status: countOf(record.status) === 1 ? 1 : 0,
source: textOf(record.source),
shopName: textOf(record.shopName),
remark: textOf(record.remark),
createdAt: textOf(record.createdAt),
updatedAt: textOf(record.updatedAt),
disabledAt: textOf(record.disabledAt),
}
}
export function parseBrandGatingPage(raw: unknown): BrandGatingPage {
const record = asRecord(raw)
if (!record) return { total: 0, rows: [] }
const rows = Array.isArray(record.rows)
? record.rows
.map(parseBrandGatingRow)
.filter((row): row is BrandGatingRow => row !== null)
: []
return { total: countOf(record.total), rows }
}
export function parseBrandGatingStats(raw: unknown): BrandGatingStats {
const record = asRecord(raw)
return {
total: countOf(record?.total),
active: countOf(record?.active),
disabled: countOf(record?.disabled),
brands: countOf(record?.brands),
byType: nameCountsOf(record?.byType),
byCountry: nameCountsOf(record?.byCountry),
bySource: nameCountsOf(record?.bySource),
}
}
/** 单条新增回包:added=1 新增成功,0 表示撞唯一键(品牌+国家已存在)。 */
export function parseBrandGatingAddResult(raw: unknown): boolean {
return countOf(asRecord(raw)?.added) > 0
}
export function parseBrandGatingImportResult(raw: unknown): BrandGatingImportResult {
const record = asRecord(raw)
return { added: countOf(record?.added), skipped: countOf(record?.skipped) }
}
@@ -0,0 +1,117 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
createBrandGatingFilter,
createBrandGatingForm,
parseBrandGatingAddResult,
parseBrandGatingImportResult,
parseBrandGatingPage,
parseBrandGatingStats,
toBrandGatingQuery,
validateBrandGatingForm,
} from '../src/pages/tasks/brand-gating-model.ts'
test('brand_gating_form_defaults_match_desktop', () => {
const form = createBrandGatingForm()
assert.equal(form.country, '全部')
assert.equal(form.gatingType, '品牌gating')
assert.equal(form.brand, '')
assert.equal(validateBrandGatingForm(form), '请填写品牌')
assert.equal(validateBrandGatingForm({ ...form, brand: ' tory burch ' }), '')
})
test('brand_gating_query_omits_empty_and_all_sentinel', () => {
const filter = createBrandGatingFilter()
assert.deepEqual(toBrandGatingQuery(filter, 1, 10), { page: 1, size: 10 })
filter.country = '全部'
filter.gatingType = '全部'
filter.source = '全部'
assert.deepEqual(toBrandGatingQuery(filter, 2, 20), { page: 2, size: 20 })
filter.keyword = ' tory '
filter.country = '英国'
filter.gatingType = '类目gating'
filter.status = '1'
filter.source = 'AUTO'
assert.deepEqual(toBrandGatingQuery(filter, 3, 50), {
page: 3,
size: 50,
keyword: 'tory',
country: '英国',
gatingType: '类目gating',
status: '1',
source: 'AUTO',
})
})
test('brand_gating_page_parses_camel_rows_and_skips_invalid', () => {
const page = parseBrandGatingPage({
total: 2,
rows: [
{
id: 7,
brand: 'tory burch',
asin: 'B000000001',
country: '英国',
gatingType: '品牌gating',
status: 1,
source: 'MANUAL',
shopName: 'ShopA',
remark: '排查同步',
createdAt: '2026-10-24 10:00:00',
updatedAt: '2026-10-24 10:00:00',
disabledAt: null,
},
{ brand: '缺 id' },
],
})
assert.equal(page.total, 2)
assert.equal(page.rows.length, 1)
const row = page.rows[0]
assert.equal(row.id, 7)
assert.equal(row.gatingType, '品牌gating')
assert.equal(row.status, 1)
assert.equal(row.disabledAt, '')
assert.equal(row.createdAt, '2026-10-24 10:00:00')
})
test('brand_gating_stats_parses_groups_and_missing_fields', () => {
const stats = parseBrandGatingStats({
total: 9,
active: 6,
disabled: 3,
brands: 5,
byType: [
{ name: '品牌gating', count: 4 },
{ name: '', count: 99 },
{ count: 1 },
],
byCountry: [{ name: '英国', count: 3 }],
})
assert.equal(stats.total, 9)
assert.equal(stats.active, 6)
assert.equal(stats.brands, 5)
assert.deepEqual(stats.byType, [{ name: '品牌gating', count: 4 }])
assert.deepEqual(stats.byCountry, [{ name: '英国', count: 3 }])
assert.deepEqual(stats.bySource, [])
const empty = parseBrandGatingStats(null)
assert.deepEqual(empty, {
total: 0,
active: 0,
disabled: 0,
brands: 0,
byType: [],
byCountry: [],
bySource: [],
})
})
test('brand_gating_add_and_import_results', () => {
assert.equal(parseBrandGatingAddResult({ added: 1 }), true)
assert.equal(parseBrandGatingAddResult({ added: 0 }), false)
assert.equal(parseBrandGatingAddResult(null), false)
assert.deepEqual(parseBrandGatingImportResult({ added: 3, skipped: 2 }), { added: 3, skipped: 2 })
assert.deepEqual(parseBrandGatingImportResult(null), { added: 0, skipped: 0 })
})
@@ -33,8 +33,10 @@ import org.springframework.web.bind.annotation.RestController;
* 品牌Gating库(管理后台):独立小网页后台(gating_web_admin.py)并入数富管理后台,
* 共用主库同一张 biz_brand_gating 表。
*
* <p>页面权限键 {@code admin_brand_gating}(后台菜单 column_key,经
* {@link PermissionMenuService#requireConsolePageAccess} 把门);鉴权第一道门由
* <p>本模块以「品牌Gating库」页签嵌在「店铺数据重复检查」页(DuplicateCheckPage.vue)里,
* 不再占用独立菜单行(V164 菜单已由 V166 删除)。因此页面权限键跟随宿主页
* {@code admin_shop_data_duplicate_check},经
* {@link PermissionMenuService#requireConsolePageAccess} 把门;鉴权第一道门由
* AdminApiGuardFilter 的 /api/admin 前缀兜底(见 ApiGuardCoverageAuditor 口径)。</p>
*/
@RestController
@@ -43,8 +45,8 @@ import org.springframework.web.bind.annotation.RestController;
@Tag(name = "品牌Gating库(后台)", description = "品牌Gating库的列表/筛选/统计、单条新增、启停、删除与批量导入。")
public class BrandGatingController {
/** 后台菜单权限键(columns.column_key,与 V164 菜单行同键)。 */
private static final String PERMISSION_KEY = "admin_brand_gating";
/** 宿主页「店铺数据重复检查」的后台菜单权限键(columns.column_key)。 */
private static final String PERMISSION_KEY = "admin_shop_data_duplicate_check";
private static final String DENIAL_MESSAGE = "无权访问品牌Gating库";
private final BrandGatingService brandGatingService;
@@ -110,7 +112,7 @@ public class BrandGatingController {
return ApiResponse.success(brandGatingService.importRows(body));
}
/** 逐端点把门:登录态 + 后台菜单权限(admin_brand_gating)。 */
/** 逐端点把门:登录态 + 宿主页后台菜单权限(admin_shop_data_duplicate_check)。 */
private void requireBrandGatingAccess(HttpServletRequest request) {
AdminUserEntity operator = adminAuthSupport.requireUser(request);
permissionMenuService.requireConsolePageAccess(operator, DENIAL_MESSAGE, PERMISSION_KEY);
@@ -464,12 +464,12 @@ class BrandGatingServiceTest {
}
@Test
@DisplayName("控制器契约:权限键 admin_brand_gating、逐端点 requireUser + requireConsolePageAccess 把门")
@DisplayName("控制器契约:随宿主页用 admin_shop_data_duplicate_check 权限键、逐端点 requireUser + requireConsolePageAccess 把门")
void controllerGatesEveryEndpointWithPermissionKey() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/com/nanri/aiimage/modules/brandgating/controller/BrandGatingController.java"),
StandardCharsets.UTF_8);
assertThat(source).contains("PERMISSION_KEY = \"admin_brand_gating\"");
assertThat(source).contains("PERMISSION_KEY = \"admin_shop_data_duplicate_check\"");
assertThat(source).contains("adminAuthSupport.requireUser(request)");
assertThat(source).contains("requireConsolePageAccess(operator, DENIAL_MESSAGE, PERMISSION_KEY)");
// 6 个端点方法都必须先过把门助手