feat(phase-3): 后管无侵权只读页——私有鉴权闸+readCompanyIdOrOwn 公司隔离+分页钳制;前端自绘表格页与路由/操作提示/五护栏同轮记账

后端:AdminAppearancePatentCleanItemsController(GET /api/admin/appearance-patent-clean-items,requireCleanItemsAccess 照去重页形状)+ AppearancePatentCleanItemQueryService(page≤10000/size≤100 钳制防 (page-1)*page_size 溢出)+两 VO;PageDefaults 第五种 page_size=10 显式登记。前端:AppearancePatentCleanItemsPage(自绘 table+OldPagination,companyScoped)+api/filter/model 拆件;routes/company-scope/operation-guides 收口。护栏:company-tab-wiring 24 处发送口、date-range-order 分母 21 实例/9 对、date-guard EXEMPT、ChunkRow 无侵权白名单四件(LlmClient 仍是唯一结论值来源)、SourceScan 52 支、G2 WIRED_PAGE_KEYS 第七支。判据修正:columnKey→getColumnKey 对齐代码库命名。
This commit is contained in:
2026-11-10 02:27:50 +08:00
parent 0512359b21
commit 83f1ecf952
22 changed files with 1375 additions and 76 deletions
@@ -60,4 +60,7 @@ export const COMPANY_SCOPED_PAGES: readonly CompanyScopedPage[] = [
// 「无效的菜单权限项」。写侧(编辑/删除/重排)不带参数——归属由那一行的 id 与操作者公司共同判定,
// 跨公司写后端 403(见 docs/ops/menu-company-tree-design-2026-10-06.md §5)。
{ menuKey: 'admin_columns', apiFiles: ['src/pages/account/menu-manage-api.ts'], pageFiles: ['src/pages/account/MenusPage.vue'] },
// 外观专利无侵权数据(2026-11-10 v1.3):出表成功自动同步的只读明细,归属物化在行 company_id 列
// (V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
{ menuKey: 'admin_appearance_patent_clean_items', apiFiles: ['src/pages/patent/appearance-patent-clean-api.ts'], pageFiles: ['src/pages/patent/AppearancePatentCleanItemsPage.vue'] },
]
@@ -121,6 +121,10 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
text: '按账号、业务、状态、店铺和创建时间筛出客户端任务,点任务查看明细与分组结果;顶部汇总卡给当前在跑与疑似卡住的总量。',
steps: ['按条件筛任务', '查看任务明细', '核对汇总卡'],
},
admin_appearance_patent_clean_items: {
text: '本页只读:出表成功后「结论=无侵权」的明细自动同步到这里,按分公司隔离分页展示;支持任务号/ASIN/国家/同步日期筛选,下载原表请到任务中心取结果文件。',
steps: ['筛选记录', '核对结论明细', '到任务中心下载原表'],
},
}
/** 全部有独立/兜底提示的后台业务菜单 key。 */
@@ -0,0 +1,334 @@
<script setup lang="ts">
import { formatDateTime, orderedPair } from '@/utils/datetime'
/** 外观专利无侵权数据 · 只读分页列表(v1.3,展示形式参照「去重数据库」页:自绘 table +
* OldPagination,不做卡片宫格)。数据由出表成功点自动同步(后端 SyncService),本页零写操作:
* 无编辑/导入/导出,下载走既有结果直链/任务中心。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { fetchAppearancePatentCleanList } from './appearance-patent-clean-api.ts'
import type { AppearancePatentCleanItem } from './appearance-patent-clean-model.ts'
import { cleanItemReasonTooltip } from './appearance-patent-clean-model.ts'
import { createAppearancePatentCleanFilterState } from './appearance-patent-clean-filter.ts'
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
import OldPagination from '@/components/OldPagination.vue'
import { useCompanyTabStore } from '@/stores/company-tab'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { loadFailureMessage } from '@/components/load-failure-model'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
const companyTab = useCompanyTabStore()
const loading = ref(false)
const loadFailure = ref('')
const rows = ref<AppearancePatentCleanItem[]>([])
const total = ref(0)
const page = ref(1)
const pageSize = ref(10)
/** 同步台账是累计数据,日期初值故意留空(默认当天会让首屏只剩今天同步的行);见 date-filter-default-today 护栏的 EXEMPT。 */
const filter = reactive(createAppearancePatentCleanFilterState())
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
function clampDatePair(): void {
const [s, e] = orderedPair(filter.startDate, filter.endDate)
filter.startDate = s
filter.endDate = e
}
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
async function load(): Promise<void> {
loading.value = true
loadFailure.value = ''
try {
const result = await fetchAppearancePatentCleanList({
page: page.value,
pageSize: pageSize.value,
taskId: filter.taskId,
asin: filter.asin,
country: filter.country,
startDate: filter.startDate,
endDate: filter.endDate,
companyId: companyTab.requestCompanyId,
})
rows.value = result.items
total.value = result.total
if (result.page >= 1) page.value = result.page
} catch (error) {
loadFailure.value = loadFailureMessage(error, '无侵权数据加载失败')
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
}
}
function apply(): void {
page.value = 1
void load()
}
function changePage(next: number): void {
if (next < 1 || next > totalPages.value) return
page.value = next
void load()
}
function changeSize(size: number) {
pageSize.value = size
page.value = 1
void load()
}
// 切公司 = 重新取数:任务号/ASIN 是上一家选中的值,在新一家的行集里筛不出东西,必须一起清。
watch(() => companyTab.activeId, () => { filter.taskId = ''; filter.asin = ''; page.value = 1; void load() })
onMounted(() => {
void load()
})
</script>
<template>
<div class="clean-items-view">
<section class="panel-box">
<div class="clean-panel-head">
<h3>外观专利无侵权数据</h3>
</div>
<div class="clean-filter-row">
<div class="form-group">
<label>任务号</label>
<input v-model="filter.taskId" type="text" placeholder="输入任务号" @keyup.enter="apply" />
</div>
<div class="form-group">
<label>ASIN</label>
<input v-model="filter.asin" 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="code in ASIN_COUNTRY_CODES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
</select>
</div>
<div class="form-group">
<label>同步开始日期</label>
<input v-model="filter.startDate" type="date" :max="filter.endDate" @change="clampDatePair" />
</div>
<div class="form-group">
<label>同步结束日期</label>
<input v-model="filter.endDate" type="date" :min="filter.startDate" @change="clampDatePair" />
</div>
<div class="clean-filter-actions">
<button class="btn" type="button" @click="apply">查询</button>
</div>
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<div class="table-scroll clean-table-scroll">
<table>
<thead>
<tr>
<th style="width: 90px">任务号</th>
<th>ASIN</th>
<th style="width: 64px">国家</th>
<th>SKU</th>
<th>品牌</th>
<th style="width: 90px">价格</th>
<th>标题</th>
<th style="width: 130px">结论</th>
<th style="width: 150px">同步时间</th>
</tr>
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<td>{{ row.taskId ?? '-' }}</td>
<td class="mono-cell">{{ row.asin || '-' }}</td>
<td>{{ asinCountryLabel(row.country || '') }}</td>
<td class="mono-cell">{{ row.sku || '-' }}</td>
<td>{{ row.brand || '-' }}</td>
<td>{{ row.price || '-' }}</td>
<td class="title-cell" :title="row.title">{{ row.title || '-' }}</td>
<td class="conclusion-cell" :title="cleanItemReasonTooltip(row)">{{ row.conclusion || '-' }}</td>
<td>{{ formatDateTime(row.syncedAt || '') }}</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="9" class="empty-tip">暂无无侵权数据</td>
</tr>
</tbody>
</table>
</div>
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
</section>
</div>
</template>
<style scoped>
/* 像素复刻参照「去重数据库」页(panel-box + 自绘表格 + 旧式分页),只读无操作列。 */
.clean-items-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;
}
.clean-panel-head h3 {
margin: 0 0 16px;
}
.clean-filter-row {
display: grid;
grid-template-columns: repeat(5, minmax(150px, 1fr)) auto;
gap: 12px;
align-items: end;
margin-bottom: 16px;
}
.clean-filter-row .form-group {
min-width: 0;
}
.clean-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 {
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 input:hover,
.form-group select:hover {
border-color: #9fb7cd;
}
.form-group input:focus,
.form-group select:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.form-group input[type="date"] {
color-scheme: light;
}
.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;
}
.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;
}
.clean-table-scroll > table {
min-width: 1040px;
}
.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;
}
.mono-cell {
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
font-size: 12.5px;
}
.title-cell {
max-width: 260px;
}
.conclusion-cell {
max-width: 130px;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
</style>
@@ -0,0 +1,33 @@
/** 外观专利无侵权数据列表查询适配(v1.3 AC-5):GET /api/admin/appearance-patent-clean-items。
* 只读页,无写/删/导出入口。公司 tab 的值由本发送口从原始入参自己下传(白名单构造不认识
* company_id),取值口形状由 company-tab-wiring 护栏钉住。 */
import { http } from '@/api/http'
import {
toAppearancePatentCleanListParams,
type AppearancePatentCleanListParams,
} from './appearance-patent-clean-filter.ts'
import {
parseAppearancePatentCleanPage,
type AppearancePatentCleanPageResult,
} from './appearance-patent-clean-model.ts'
export const APPEARANCE_PATENT_CLEAN_ENDPOINT = '/api/admin/appearance-patent-clean-items'
export async function fetchAppearancePatentCleanList(
params: AppearancePatentCleanListParams,
): Promise<AppearancePatentCleanPageResult> {
const query = toAppearancePatentCleanListParams(
{
taskId: params.taskId ?? '',
asin: params.asin ?? '',
country: params.country ?? '',
startDate: params.startDate ?? '',
endDate: params.endDate ?? '',
},
params.page,
params.pageSize,
)
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get<unknown>(APPEARANCE_PATENT_CLEAN_ENDPOINT, { params: query })
return parseAppearancePatentCleanPage(data)
}
@@ -0,0 +1,88 @@
/** 外观专利无侵权数据页筛选纯函数(v1.3 AC-5):任务号/ASIN/国家/起止时间 + snake 分页参数。
* 产出与后端 §3.2 参数归一逐字对撞:`page`/`page_size`(默认 10、上限 100)、`task_id`、
* `asin`、`country`、`start_date`/`end_date`(ISO yyyy-MM-dd;空白不下发)。
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
* 最大 999_900,Number.MAX_SAFE_INTEGER 也不会把乘积顶出安全整数。纯逻辑,node --test 直测。
* 公司维不在这里:归一化构造器不认识 company_id(同 asin-filter 惯例),由 api 发送口从
* 原始入参自己下传——取值口由 company-tab-wiring 护栏的发送行钉看守。 */
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
/** 每页条数默认 10(蓝图 §3.2),上限 100。 */
export const APPEARANCE_PATENT_CLEAN_PAGE_SIZE = 10
export const APPEARANCE_PATENT_CLEAN_MAX_PAGE_SIZE = 100
/** 页码上限:与后端 AppearancePatentCleanItemQueryService.MAX_PAGE(CR-18 先例)同值,两侧不漂。 */
export const APPEARANCE_PATENT_CLEAN_MAX_PAGE = 10_000
export interface AppearancePatentCleanFilterState {
/** 任务号(纯数字文本,空串不限)。 */
taskId: string
/** ASIN 前缀。 */
asin: string
/** 国家代码,空串=全部。 */
country: string
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
startDate: string
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
endDate: string
}
export function createAppearancePatentCleanFilterState(): AppearancePatentCleanFilterState {
return { taskId: '', asin: '', country: '', startDate: '', endDate: '' }
}
/** 是否有任一激活筛选条件。 */
export function appearancePatentCleanFilterActive(state: AppearancePatentCleanFilterState): boolean {
if ((state.taskId || '').trim()) return true
if ((state.asin || '').trim()) return true
if ((state.country || '').trim()) return true
if (validIsoDateOrUndefined(state.startDate) || validIsoDateOrUndefined(state.endDate)) return true
return false
}
/** 序列化到后端的查询参数(snake_case,仅下发非空字段)。 */
export interface AppearancePatentCleanQuery {
page: number
page_size: number
task_id?: number
asin?: string
country?: string
start_date?: string
end_date?: string
/** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */
company_id?: number
}
/** api 模块的入参:筛选态 + 分页 + 公司值(camel)。 */
export interface AppearancePatentCleanListParams {
page: number
pageSize: number
taskId?: string
asin?: string
country?: string
startDate?: string
endDate?: string
companyId?: number | null
}
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期不下发,分页钳制在此单出口(不含公司维)。 */
export function toAppearancePatentCleanListParams(
state: AppearancePatentCleanFilterState,
page: number,
pageSize: number,
): AppearancePatentCleanQuery {
const safePage = Math.min(Math.max(Math.floor(page) || 1, 1), APPEARANCE_PATENT_CLEAN_MAX_PAGE)
const rawSize = Math.floor(pageSize) || APPEARANCE_PATENT_CLEAN_PAGE_SIZE
const safeSize = Math.min(Math.max(rawSize, 1), APPEARANCE_PATENT_CLEAN_MAX_PAGE_SIZE)
const query: AppearancePatentCleanQuery = { page: safePage, page_size: safeSize }
const taskId = Number.parseInt((state.taskId || '').trim(), 10)
if (Number.isFinite(taskId) && taskId > 0) query.task_id = taskId
const asin = (state.asin || '').trim()
if (asin) query.asin = asin
const country = (state.country || '').trim()
if (country) query.country = country
const startDate = validIsoDateOrUndefined(state.startDate)
if (startDate) query.start_date = startDate
const endDate = validIsoDateOrUndefined(state.endDate)
if (endDate) query.end_date = endDate
return query
}
@@ -0,0 +1,105 @@
/** 外观专利无侵权数据列表查询模型(v1.3 AC-5):解析 AppearancePatentCleanItemPageVo(camel),纯逻辑。
* 行值是同步服务从 chunk payload 原样落的,读侧只搬运不加工(与后端 toVo 同一口径)。 */
import { unwrap } from '../../api/envelope.ts'
export interface AppearancePatentCleanItem {
id: number
resultId: number | null
taskId: number | null
userId: number | null
companyId: number | null
rowNo: number | null
asin: string
country: string
sku: string
brand: string
price: string
title: string
imageUrl: string
itemUrl: string
conclusion: string
titleReason: string
appearanceReason: string
patentReason: string
sourceFilename: string
syncedAt?: string
}
export interface AppearancePatentCleanPageResult {
items: AppearancePatentCleanItem[]
total: number
page: number
pageSize: number
}
/** 前端首屏默认容量:与后端 PageDefaults.CLEAN_ITEMS_PAGE_SIZE(蓝图 §3.2 默认 10)同值。 */
export const APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE = 10
export function emptyAppearancePatentCleanPage(): AppearancePatentCleanPageResult {
return { items: [], total: 0, page: 1, pageSize: APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE }
}
function text(value: unknown): string {
return typeof value === 'string' ? value.trim() : ''
}
function numberOrNull(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
}
/** 解析单行明细;缺 id 视为无效。camel 为正、snake 容错(与去重页模型同形)。 */
export function toAppearancePatentCleanItem(raw: unknown): AppearancePatentCleanItem | null {
if (!raw || typeof raw !== 'object') return null
const record = raw as Record<string, unknown>
const id = numberOrNull(record.id)
if (id === null) return null
return {
id,
resultId: numberOrNull(record.resultId ?? record.result_id),
taskId: numberOrNull(record.taskId ?? record.task_id),
userId: numberOrNull(record.userId ?? record.user_id),
companyId: numberOrNull(record.companyId ?? record.company_id),
rowNo: numberOrNull(record.rowNo ?? record.row_no),
asin: text(record.asin),
country: text(record.country),
sku: text(record.sku),
brand: text(record.brand),
price: text(record.price),
title: text(record.title),
imageUrl: text(record.imageUrl ?? record.image_url),
itemUrl: text(record.itemUrl ?? record.item_url),
conclusion: text(record.conclusion),
titleReason: text(record.titleReason ?? record.title_reason),
appearanceReason: text(record.appearanceReason ?? record.appearance_reason),
patentReason: text(record.patentReason ?? record.patent_reason),
sourceFilename: text(record.sourceFilename ?? record.source_filename),
syncedAt: text(record.syncedAt ?? record.synced_at) || undefined,
}
}
/** 归一化分页负载(信封或已解包 VO)为前端结果;缺省字段回默认。无 keyset 游标(蓝图 Out of Scope)。 */
export function parseAppearancePatentCleanPage(payload: unknown): AppearancePatentCleanPageResult {
const out = emptyAppearancePatentCleanPage()
const core = unwrap<unknown>(payload)
if (!core || typeof core !== 'object') return out
const record = core as Record<string, unknown>
if (Array.isArray(record.items)) {
out.items = record.items
.map((raw) => toAppearancePatentCleanItem(raw))
.filter((item): item is AppearancePatentCleanItem => item !== null)
}
if (typeof record.total === 'number') out.total = Math.floor(record.total)
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
const rawSize = record.pageSize ?? record.page_size
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
return out
}
/** 结论单元格的悬停全文:三因齐给,空因不下发(读侧不加工的展示面出口)。 */
export function cleanItemReasonTooltip(item: AppearancePatentCleanItem): string {
const parts: string[] = []
if (item.titleReason) parts.push(`标题:${item.titleReason}`)
if (item.appearanceReason) parts.push(`外观:${item.appearanceReason}`)
if (item.patentReason) parts.push(`专利:${item.patentReason}`)
return parts.join('\n')
}
+1
View File
@@ -44,6 +44,7 @@ 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') },
{ path: 'patent-center/clean-items', menuKey: 'admin_appearance_patent_clean_items', title: '外观专利无侵权数据', companyScoped: true, load: () => import('@/pages/patent/AppearancePatentCleanItemsPage.vue') },
]
export function routeOf(page: AdminPageDef): RouteRecordRaw {
@@ -1,9 +1,5 @@
/**
* 外观专利无侵权数据页筛选纯函数(v1.3 AC-5)—— Pending Phase 3。
*
* Phase 3 组 B 落 `src/pages/patent/appearance-patent-clean-filter.ts`(照 dedupe-total-filter.ts
* 拆分:createAppearancePatentCleanFilterState / appearancePatentCleanFilterActive /
* toAppearancePatentCleanListParams)后,把下面两条 todo 转成真用例并移除 todo 标记:
* 外观专利无侵权数据页筛选纯函数(v1.3 AC-5)—— Phase 3 激活。
*
* 1. **snake 参数形状**:toAppearancePatentCleanListParams({...}) 产出
* `page`/`page_size`(默认 10、上限 100)、`task_id`、`asin`、`country`、
@@ -15,6 +11,57 @@
* `tests/*.test.ts`,不递归;纯函数零依赖可直测)
*/
import { test } from 'node:test'
import assert from 'node:assert/strict'
test.todo('Pending Phase 3: AC-5 筛选参数——snake page/page_size/task_id/asin/country/start_date/end_date 形状')
test.todo('Pending Phase 3: AC-5 筛选参数——page 钳制防 (page-1)*page_size 溢出(铁律 15)')
import {
APPEARANCE_PATENT_CLEAN_MAX_PAGE,
createAppearancePatentCleanFilterState,
toAppearancePatentCleanListParams,
} from '../src/pages/patent/appearance-patent-clean-filter.ts'
test('AC-5 筛选参数——snake page/page_size/task_id/asin/country/start_date/end_date 形状', () => {
const full = toAppearancePatentCleanListParams(
{ taskId: '33179', asin: ' B0AB8CDEF9 ', country: 'DE', startDate: '2026-11-01', endDate: '2026-11-09' },
2,
20,
)
// snake 逐字对撞后端 §3.2;ASIN 前后空白被构造器剥掉(后端服务侧再 trim 一次是双保险)。
assert.deepEqual(full, {
page: 2,
page_size: 20,
task_id: 33179,
asin: 'B0AB8CDEF9',
country: 'DE',
start_date: '2026-11-01',
end_date: '2026-11-09',
})
// 空白/非法值不下发:全空态只有分页两项;非法日期与空串同罪。
const blank = toAppearancePatentCleanListParams(createAppearancePatentCleanFilterState(), 1, 10)
assert.deepEqual(blank, { page: 1, page_size: 10 })
const dirty = toAppearancePatentCleanListParams(
{ taskId: 'abc', asin: ' ', country: '', startDate: '2026/11/01', endDate: 'not-a-date' },
1,
10,
)
assert.deepEqual(dirty, { page: 1, page_size: 10 })
assert.equal('task_id' in dirty, false, '非数字任务号不下发')
assert.equal('start_date' in dirty, false, '非法日期不下发')
})
test('AC-5 筛选参数——page 钳制防 (page-1)*page_size 溢出(铁律 15)', () => {
// page < 1 归 1;page_size 下限 1、默认 10、上限 100。
const low = toAppearancePatentCleanListParams(createAppearancePatentCleanFilterState(), 0, 0)
assert.equal(low.page, 1, 'page<1 归 1')
assert.equal(low.page_size, 10, 'page_size 非法回默认 10')
const big = toAppearancePatentCleanListParams(createAppearancePatentCleanFilterState(), 3, 500)
assert.equal(big.page_size, 100, 'page_size 上限 100')
// 溢出边界:page 极大值钳到 10_000(与后端 MAX_PAGE 同值),乘积 999_900 必须还是安全整数——
// 不钳的话 (Number.MAX_SAFE_INTEGER-1)*100 直接顶出安全整数域,翻页偏移就不再可靠。
const extreme = toAppearancePatentCleanListParams(createAppearancePatentCleanFilterState(), Number.MAX_SAFE_INTEGER, 100)
assert.equal(extreme.page, APPEARANCE_PATENT_CLEAN_MAX_PAGE)
const offset = (extreme.page - 1) * extreme.page_size
assert.equal(Number.isSafeInteger(offset), true, `(page-1)*page_size=${offset} 必须留在安全整数域`)
assert.equal(offset, 999_900)
})
@@ -70,11 +70,12 @@ function escapeRegExp(text: string): string {
}
/**
* 全部 21 个字面发送口:批次 1 的任务看板 5 处 + 批次 2(控制方 2026-10-05 点名「切 tab 数据还一样」那五页)7 处
* 全部 24 个字面发送口:批次 1 的任务看板 5 处 + 批次 2(控制方 2026-10-05 点名「切 tab 数据还一样」那五页)7 处
* + 批次 3(控制方 2026-10-05 点名「店铺撞款监控 店铺数据也要做隔离」那两页)4 处
* + 批次 4(控制方 2026-10-05 点名「菜单权限和用户管理也要区分公司 tab 的数据」里的用户管理)1 处
* + 批次 5(控制方 2026-10-06 点名「店铺密钥管理的数据按照公司区分」)1 处
* + 批次 6(控制方 2026-10-06 点名「菜单权限也加字段来区分」)3 处:菜单目录 / 新建菜单 / 用户管理里的授权树。
* + 批次 6(控制方 2026-10-06 点名「菜单权限也加字段来区分」)3 处:菜单目录 / 新建菜单 / 用户管理里的授权树
* + 批次 7(2026-11-10 v1.3 外观专利无侵权数据)1 处:只读列表。
* 批次 2 原 12 处里的品牌库 1 处 + 商品类目 4 处,随 2026-10-06「这两页退回全平台共享」一并摘掉。
*
* <p>`window` 的取法:本轮实扫的 own(到自己那行的距离)+ ≥150 余量,且当同文件还有下一个同名发送口时必须
@@ -122,6 +123,9 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
{ menuKey: 'admin_columns', file: 'src/pages/account/menu-manage-api.ts', fn: 'fetchMenuManageNodes', line: TASK_CENTER_SEND_LINE, window: 300, title: 'GET /permission-menus 目录(超管不带就把两家的同名行混成一排下发)' },
{ menuKey: 'admin_columns', file: 'src/pages/account/menu-manage-api.ts', fn: 'createMenu', line: TASK_CENTER_SEND_LINE, window: 300, title: 'POST /permission-menus 新建:归属由端点参数决定,前端不从树里猜' },
{ menuKey: 'admin_users', file: 'src/pages/account/user-menu-auth-api.ts', fn: 'fetchGrantableMenus', line: TASK_CENTER_SEND_LINE, window: 300, title: 'GET /permission-menus?grantableOnly 授权树:一家一套树后取错公司=已授权勾不上、提交必判无效' },
// ↓ 批次 7(2026-11-10 v1.3 外观专利无侵权数据):出表成功自动同步的只读明细,归属物化在行
// company_id 列(V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn;这一页只有一个发送口。
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 400, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
]
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
@@ -243,6 +247,8 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
// 编辑/删除/重排三支**故意不带**参数——归属由那一行的 id 与操作者公司共同判定,跨公司写后端 403
// (见 docs/ops/menu-company-tree-design-2026-10-06.md §5),给它们发 company_id 反而是第三处口径。
admin_columns: pinsFor('admin_columns'),
// 批次 7(v1.3 无侵权只读页):同样由 SEND_POINTS 现算——只有一个发送口(列表)。
admin_appearance_patent_clean_items: pinsFor('admin_appearance_patent_clean_items'),
}
/** 严格判据的分母由本轮实扫得出(修完不许恒绿也不许恒红):求值了几条 shape、其中几条通过。 */
@@ -342,7 +348,7 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
// 批次 2 原 12 条里的品牌库 1 条 + 商品类目 4 条随 2026-10-06「这两页退回全平台共享」摘掉)。
// 这条只防"整表被摘空/被改窄",逐处脱管由下面两条(对平闸门 + 窗口对平)负责。
assert.ok(SEND_POINTS.length >= 21,
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权只读页 1 条 = 24 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
for (const p of SEND_POINTS) {
const shape = pointShape(p)
const compliant = pointCompliant(p)
@@ -374,8 +380,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
if (hit) hit.pinned += 1
else grouped.set(key, { file: p.file, line: p.line, pinned: 1 })
}
assert.equal(grouped.size, 18,
`发送口表按 (文件, 整行) 应聚成 18 组(22 处发送口),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
assert.equal(grouped.size, 19,
`发送口表按 (文件, 整行) 应聚成 19 组(24 处发送口,批次 7 再落 1 处),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
for (const g of grouped.values()) {
const actual = occurrences(stripComments(read(g.file)), g.line)
assert.equal(g.pinned, actual,
@@ -717,6 +723,17 @@ const WATCH_BODY_PINS: ReadonlyArray<{
{ file: 'src/pages/account/menu-manage-api.ts', shapes: [/company_id\s*=\s*companyId\b/] },
],
},
// ↓ 批次 7(2026-11-10 v1.3 无侵权只读页):任务号/ASIN 是自由文本筛选,上一家填的值在新一家的
// 行集里筛不出东西 ⇒ 首屏「暂无无侵权数据」而输入框里还显示着那个值;页码回 1 同理。
{
file: 'src/pages/patent/AppearancePatentCleanItemsPage.vue',
token: "filter.taskId = ''; filter.asin = ''; page.value = 1; void load()",
why: '任务号/ASIN 是按行集筛的自由文本,上一家的值在新一家的行里不存在 ⇒ 切 tab 后首屏被筛成「暂无无侵权数据」,'
+ '而输入框还显示着上一家填的值;页码回 1 是因为新一家的行数更少,末尾的 void load() 才让切 tab 真的换数据',
premise: [
{ file: 'src/pages/patent/appearance-patent-clean-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
],
},
]
/** 取「`watch(() => companyTab.activeId, () => { … })`」这一条语句的原文;匹配不出返回 null(由调用方判探针失效)。 */
@@ -725,9 +742,9 @@ function watchStatement(source: string): string | null {
return m ? m[0] : null
}
test('切公司的 watch 体:每对 (file, token) 都要在该页 watch 体内出现(批次 1 两页 + 批次 2 三页 + 批次 3 两页 + 批次 4 一页 + 批次 5 一页 + 批次 6 一页)', () => {
test('切公司的 watch 体:每对 (file, token) 都要在该页 watch 体内出现(批次 1 两页 + 批次 2 三页 + 批次 3 两页 + 批次 4 一页 + 批次 5 一页 + 批次 6 一页 + 批次 7 一页)', () => {
assert.ok(WATCH_BODY_PINS.length >= 10,
`watch 体看守只剩 ${WATCH_BODY_PINS.length} 对(批次 1 的店铺管理/任务看板 + 批次 2 的去重库/查询ASIN/最低价ASIN + 批次 3 的撞款监控/店铺数据记录 + 批次 4 的用户管理 + 批次 5 的店铺密钥 + 批次 6 的菜单管理共 10 对)`
`watch 体看守只剩 ${WATCH_BODY_PINS.length} 对(批次 1 的店铺管理/任务看板 + 批次 2 的去重库/查询ASIN/最低价ASIN + 批次 3 的撞款监控/店铺数据记录 + 批次 4 的用户管理 + 批次 5 的店铺密钥 + 批次 6 的菜单管理 + 批次 7 v1.3 无侵权只读页共 11 对)`
+ '⇒ 这一族又退回"只钉少数几页",被摘掉那一页的"切公司不清筛选项"再次没人看守')
const pinnedFiles = new Set(WATCH_BODY_PINS.map((pin) => pin.file))
for (const pin of WATCH_BODY_PINS) {
@@ -34,6 +34,9 @@ const EXEMPT = new Set([
'src/pages/tasks/ShopDataTasksPage.vue',
'src/pages/tasks/ImageVideoTasksPage.vue',
'src/pages/records/RecordsHistoryPage.vue',
// 2026-11-10(v1.3):外观专利无侵权数据页与去重库同形状——出表成功自动同步的累计台账,
// 默认当天会让首屏只剩今天同步的行,历史同步行整批"消失"。
'src/pages/patent/AppearancePatentCleanItemsPage.vue',
// 2026-10-05(V146):两处是「到期时间」表单字段而非列表筛选——留空 = 永不过期,
// 是有业务语义的默认值,绝不能默认当天(默认当天等于建号即过期)。
'src/pages/account/CreateUserDialog.vue',
@@ -231,11 +231,11 @@ test('orderedPair 只在两端都有值且倒挂时交换', () => {
})
test('分母硬钉:四面控件实例数与成对数(扫描失明即红)', () => {
assert.equal(adminCtrls.length, 19, '后管实例数变了,先复算普查再改这里')
assert.equal(adminCtrls.length, 21, '后管实例数变了,先复算普查再改这里(v1.3 外观专利无侵权数据页再落一对起止=2 实例)')
assert.equal(userCtrls.length, 2, '用户端实例数变了')
assert.equal(finCtrls.length, 30, '财务系统实例数变了')
assert.equal(mxCtrls.length, 4, '麦象实例数变了')
assert.equal(pairCount(adminCtrls), 8, '后管成对区间应为 8')
assert.equal(pairCount(adminCtrls), 9, '后管成对区间应为 9(v1.3 外观专利无侵权数据页再落一对)')
assert.equal(pairCount(finCtrls), 11, '财务系统成对区间应为 11')
assert.equal(pairCount(mxCtrls), 2, '麦象成对区间应为 2')
assert.equal(pairCount(userCtrls), 0, '用户端出现成对区间说明新加了两个单只控件')
@@ -1,5 +1,5 @@
/**
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约 —— Pending Phase 3。
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约 —— Phase 3 激活。
*
* 用户拍板(2026-11-10):展示形式参照「去重数据库」页(DedupeRegistryPage 形态:自绘
* `<table>` 行列表 + `OldPagination.vue` 分页,**不做卡片宫格**);`companyScoped: true`
@@ -7,29 +7,78 @@
* `{items, total, page, pageSize}`。默认仅 super_admin 可见(菜单不预授权,判据在后端
* AdminAppearancePatentCleanItemsControllerTest 的菜单迁移支,这里只管前端接线)。
*
* Phase 0 预置的判据(接缝名是判据的一部分,Phase 3 微调必须同步改本文件并登记蓝图 §5):
* ① 页面组件落位 `src/pages/patent/AppearancePatentCleanItemsPage.vue`,且确实是
* 自绘 table + OldPagination 的分页列表(不是卡片宫格);
* ② routes.ts 注册 `patent-center/clean-items`(menuKey `admin_appearance_patent_clean_items`,
* companyScoped: true),COMPANY_SCOPED_PAGES 同步登记(company-tab-wiring 护栏随注册自动覆盖);
* ③ 挂载行为样本(激活时补齐):mock api 模块 → mount → 翻页/改每页条数、切公司 Tab 重取、
* 任务号/ASIN/国家/起止时间筛选生效、空态与加载失败条。
*
* 跑法:`npx vitest run tests/mount/appearance-patent-clean-page.test.ts`
*/
import { readFileSync } from 'node:fs'
import { fileURLToPath, URL } from 'node:url'
import { describe, expect, it } from 'vitest'
import { resolve } from 'node:path'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import AppearancePatentCleanItemsPage from '@/pages/patent/AppearancePatentCleanItemsPage.vue'
import { adminPages } from '@/router/routes'
import { COMPANY_SCOPED_PAGES } from '@/config/company-scope'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
const PAGE_PATH = 'src/pages/patent/AppearancePatentCleanItemsPage.vue'
const MENU_KEY = 'admin_appearance_patent_clean_items'
describe.skip('Pending Phase 3: AC-5 外观专利无侵权数据页(分页列表,参照去重数据库页)', () => {
const cleanApi = vi.hoisted(() => ({
fetchAppearancePatentCleanList: vi.fn(),
}))
vi.mock('@/pages/patent/appearance-patent-clean-api.ts', () => cleanApi)
function row(id: number, over: Record<string, unknown> = {}) {
return {
id,
resultId: 900 + id,
taskId: 33179,
userId: 7,
companyId: 1,
rowNo: id,
asin: `B0AB8CDEF${id}`,
country: 'DE',
sku: `SKU-${id}`,
brand: 'Anker',
price: '29.99',
title: `无侵权商品 ${id}`,
imageUrl: '',
itemUrl: '',
conclusion: '无侵权',
titleReason: '',
appearanceReason: '',
patentReason: '',
sourceFilename: 'list.xlsx',
syncedAt: '2026-11-10T10:30:00',
...over,
}
}
let pinia: Pinia
beforeEach(() => {
vi.clearAllMocks()
pinia = createPinia()
setActivePinia(pinia)
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
useCompanyTabStore().setActiveId(1)
})
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
cleanApi.fetchAppearancePatentCleanList.mockImplementation(() => Promise.resolve(payload))
const wrapper = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
await flushPromises()
await flushPromises()
return wrapper
}
describe('AC-5 外观专利无侵权数据页(分页列表,参照去重数据库页)', () => {
it('页面组件落位且是自绘 table + OldPagination 的分页列表', () => {
const src = readFileSync(fileURLToPath(new URL(`../../${PAGE_PATH}`, import.meta.url)), 'utf-8')
// vitest 的 cwd = admin-frontend-vue 根(Phase 0 预置用 new URL 模板串,被 vite 静态分析成
// undefined——skip 期间从未执行所以没暴露,激活时改走 cwd 解析)。
const src = readFileSync(resolve(process.cwd(), PAGE_PATH), 'utf-8')
expect(src).toContain('OldPagination')
expect(src).toContain('<table')
expect(src).not.toContain('el-card')
@@ -46,16 +95,90 @@ describe.skip('Pending Phase 3: AC-5 外观专利无侵权数据页(分页列
expect(scoped?.pageFiles).toContain(PAGE_PATH)
})
it('挂载后走 snake 分页参数且切公司 Tab 重取(激活时用真组件挂载补齐)', async () => {
// 页面组件 Phase 3 才落盘,vite 的 import-analysis 会在收集期解析动态导入 ⇒
// 这里必须用运行期字符串 + @vite-ignore 推迟解析;skip 期间永不执行。
const pageModule = '@/pages/patent/AppearancePatentCleanItemsPage.vue'
// 激活时补齐:vi.mock('@/pages/patent/appearance-patent-clean-api.ts') →
// const { default: Page } = await import(pageModule)
// mount(Page, { global: { plugins: [createPinia()] } }) →
// 断言首次请求 query 的 page/page_size(snake)与 {items,total,page,pageSize} 解包;
// 改每页条数/翻页重发;companyTab.activeId 变化触发重取(护栏 company-tab-wiring 同口径)。
const { default: Page } = await import(/* @vite-ignore */ pageModule)
expect(Page).toBeTruthy()
it('挂载后按首屏 snake 分页参数取数并解包 {items,total,page,pageSize}', async () => {
const wrapper = await mountWith({ items: [row(1), row(2)], total: 42, page: 1, pageSize: 10 })
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(1)
const firstCall = cleanApi.fetchAppearancePatentCleanList.mock.calls[0][0]
expect(firstCall.page).toBe(1)
expect(firstCall.pageSize).toBe(10)
expect(firstCall.companyId).toBe(1)
expect(wrapper.findAll('tbody tr')).toHaveLength(2)
expect(wrapper.text()).toContain('共 42 条')
expect(wrapper.text()).toContain('B0AB8CDEF1')
expect(wrapper.text()).toContain('无侵权')
})
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
const wrapper = await mountWith({ items: [row(11)], total: 42, page: 2, pageSize: 10 })
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
await flushPromises()
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(2)
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls[1][0].page).toBe(3)
const sizeSelect = wrapper.find('.page-size-select')
await sizeSelect.setValue('50')
await flushPromises()
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
expect(last.pageSize).toBe(50)
expect(last.page).toBe(1, '改每页条数后回第一页')
})
it('任务号/ASIN/国家/起止时间筛选生效', async () => {
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
const textInputs = wrapper.findAll('input[type="text"]')
await textInputs[0].setValue('33179')
await textInputs[1].setValue('B0AB8CDEF1')
await wrapper.find('select').setValue('DE')
const dateInputs = wrapper.findAll('input[type="date"]')
await dateInputs[0].setValue('2026-11-01')
await dateInputs[1].setValue('2026-11-09')
await wrapper.findAll('button').find((b) => b.text() === '查询')!.trigger('click')
await flushPromises()
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
expect(last).toMatchObject({
taskId: '33179',
asin: 'B0AB8CDEF1',
country: 'DE',
startDate: '2026-11-01',
endDate: '2026-11-09',
page: 1,
})
})
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
const thCount = empty.findAll('thead th').length
const emptyRow = empty.find('tbody tr')
expect(emptyRow.text()).toContain('暂无无侵权数据')
expect(Number(emptyRow.find('td').attributes('colspan'))).toBe(thCount, '空态 colspan 跟着列数走')
empty.unmount()
cleanApi.fetchAppearancePatentCleanList.mockRejectedValue(new Error('上游 502'))
const failed = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
await flushPromises()
await flushPromises()
expect(failed.find('.load-failure-bar').exists()).toBe(true)
expect(failed.find('.load-failure-bar').text()).toContain('无侵权数据加载失败')
})
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径)', async () => {
const wrapper = await mountWith({ items: [row(1)], total: 1, page: 1, pageSize: 10 })
const textInputs = wrapper.findAll('input[type="text"]')
await textInputs[0].setValue('33179')
const callsAfterMount = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
useCompanyTabStore().setActiveId(2)
await flushPromises()
await flushPromises()
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBeGreaterThan(callsAfterMount)
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
expect(last.companyId).toBe(2)
expect(last.taskId).toBe('', '切公司必须清掉上一家填的任务号')
expect(last.page).toBe(1)
})
})