feat(appearance-patent): 外观专利数据库主管列+导出+分组筛选——后管只读页补「所属主管」读侧现算列(owner 是主管取自己、普通账户取创建人,铁律 30 读不到不猜名)、GET /export 与分页共用同一过滤面与正门出 xlsx(SXSSF,上限 5 万行超限拒)、分组筛选 group_id 按 selectUserIdsByGroupId 解析「组长本人+名下子账户」整集 SQL 下推(铁律 20,选项复用既有 GET /shop-manages/groups 不下新端点);前端加主管列/分组下拉/导出按钮(blob 落盘+业务错误信封解包),wiring 护栏补导出发送口钉与 watch token(25 处发送口);棘轮 1073→1074 一枚记名,「无侵权」白名单登记导出上限文案

This commit is contained in:
2026-11-11 02:03:25 +08:00
parent 9b4404d027
commit 6f85f17c58
16 changed files with 1007 additions and 90 deletions
@@ -2,9 +2,16 @@
import { formatDateTime, orderedPair } from '@/utils/datetime'
/** 外观专利无侵权数据 · 只读分页列表(v1.3,展示形式参照「去重数据库」页:自绘 table +
* OldPagination,不做卡片宫格)。数据由出表成功点自动同步(后端 SyncService),本页零写操作:
* 无编辑/导入/导出,下载走既有结果直链/任务中心。 */
* 无编辑/导入,下载走既有结果直链/任务中心;导出(2026-11-11 客户需求)带当前过滤面 +
* 公司 tab 走后端 /export 全量出 xlsx(含所属主管列)。分组下拉(主管=组长)选项与去重页
* 共用 GET /shop-manages/groups,选中后以 group_id 走同一过滤面(列表与导出同源)。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { fetchAppearancePatentCleanList } from './appearance-patent-clean-api.ts'
import {
exportAppearancePatentCleanList,
fetchAppearancePatentCleanList,
fetchDedupeTotalGroups,
type DedupeGroupOption,
} 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'
@@ -23,8 +30,12 @@ const rows = ref<AppearancePatentCleanItem[]>([])
const total = ref(0)
const page = ref(1)
const pageSize = ref(10)
/** 导出在途锁:避免连点导出把同一份过滤面重复请求两遍。 */
const exporting = ref(false)
/** 同步台账是累计数据,日期初值故意留空(默认当天会让首屏只剩今天同步的行);见 date-filter-default-today 护栏的 EXEMPT。 */
const filter = reactive(createAppearancePatentCleanFilterState())
/** 分组(主管)下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
const groupOptions = ref<DedupeGroupOption[]>([])
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
function clampDatePair(): void {
const [s, e] = orderedPair(filter.startDate, filter.endDate)
@@ -34,6 +45,16 @@ function clampDatePair(): void {
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
/** 分组选项与去重页/店铺管理同源(GET /shop-manages/groups);失败静默回空——分组只是筛选项,
* 不该让它把首屏行集一起拖死(列表失败有自己的 LoadFailureBar)。 */
async function loadGroupOptions(): Promise<void> {
try {
groupOptions.value = await fetchDedupeTotalGroups(companyTab.requestCompanyId)
} catch {
groupOptions.value = []
}
}
async function load(): Promise<void> {
loading.value = true
loadFailure.value = ''
@@ -44,6 +65,7 @@ async function load(): Promise<void> {
taskId: filter.taskId,
asin: filter.asin,
country: filter.country,
groupId: filter.groupId,
startDate: filter.startDate,
endDate: filter.endDate,
companyId: companyTab.requestCompanyId,
@@ -59,6 +81,37 @@ async function load(): Promise<void> {
}
}
/** 导出与页签同一过滤面(含公司 tab 与分组),服务端全量出 xlsx;成功后浏览器落盘,失败弹可读文案。 */
async function exportAll(): Promise<void> {
if (exporting.value) return
exporting.value = true
try {
const result = await exportAppearancePatentCleanList({
taskId: filter.taskId,
asin: filter.asin,
country: filter.country,
groupId: filter.groupId,
startDate: filter.startDate,
endDate: filter.endDate,
companyId: companyTab.requestCompanyId,
})
const url = URL.createObjectURL(result.blob)
const anchor = document.createElement('a')
anchor.href = url
anchor.download = result.filename
document.body.appendChild(anchor)
anchor.click()
anchor.remove()
URL.revokeObjectURL(url)
showAdminFeedback(`已导出 ${result.filename}`, 'success')
} catch (error) {
const message = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
showAdminFeedback(message, 'error')
} finally {
exporting.value = false
}
}
function apply(): void {
page.value = 1
void load()
@@ -76,10 +129,12 @@ function changeSize(size: number) {
void load()
}
// 切公司 = 重新取数:任务号/ASIN 是上一家选中的值,在新一家的行集里筛不出东西,必须一起清。
watch(() => companyTab.activeId, () => { filter.taskId = ''; filter.asin = ''; page.value = 1; void load() })
// 切公司 = 重新取数:任务号/ASIN/分组是上一家选中的值,在新一家的行集里筛不出东西,必须一起清,
// 分组选项也按新公司重取(选项集是公司隔离的)。
watch(() => companyTab.activeId, () => { filter.taskId = ''; filter.asin = ''; filter.groupId = ''; page.value = 1; void loadGroupOptions(); void load() })
onMounted(() => {
void loadGroupOptions()
void load()
})
</script>
@@ -107,6 +162,13 @@ onMounted(() => {
<option v-for="code in ASIN_COUNTRY_CODES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
</select>
</div>
<div class="form-group">
<label>分组</label>
<select v-model="filter.groupId">
<option value="">全部分组</option>
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
</select>
</div>
<div class="form-group">
<label>同步开始日期</label>
<input v-model="filter.startDate" type="date" :max="filter.endDate" @change="clampDatePair" />
@@ -117,6 +179,9 @@ onMounted(() => {
</div>
<div class="clean-filter-actions">
<button class="btn" type="button" @click="apply">查询</button>
<button class="btn btn-export" type="button" :disabled="exporting" @click="exportAll">
{{ exporting ? '导出中...' : '导出' }}
</button>
</div>
</div>
@@ -126,6 +191,7 @@ onMounted(() => {
<thead>
<tr>
<th style="width: 90px">任务号</th>
<th style="width: 110px">所属主管</th>
<th>ASIN</th>
<th style="width: 64px">国家</th>
<th>SKU</th>
@@ -140,6 +206,7 @@ onMounted(() => {
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<td>{{ row.taskId ?? '-' }}</td>
<td :title="row.supervisorName || ''">{{ row.supervisorName || '-' }}</td>
<td class="mono-cell">{{ row.asin || '-' }}</td>
<td>{{ asinCountryLabel(row.country || '') }}</td>
<td class="mono-cell">{{ row.sku || '-' }}</td>
@@ -151,10 +218,10 @@ onMounted(() => {
</tr>
</template>
<tr v-else-if="loading">
<td colspan="9" class="empty-tip">加载中...</td>
<td colspan="10" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="9" class="empty-tip">暂无无侵权数据</td>
<td colspan="10" class="empty-tip">暂无无侵权数据</td>
</tr>
</tbody>
</table>
@@ -195,7 +262,7 @@ h3 {
}
.clean-filter-row {
display: grid;
grid-template-columns: repeat(5, minmax(150px, 1fr)) auto;
grid-template-columns: repeat(6, minmax(150px, 1fr)) auto;
gap: 12px;
align-items: end;
margin-bottom: 16px;
@@ -1,9 +1,13 @@
/** 外观专利无侵权数据列表查询适配(v1.3 AC-5):GET /api/admin/appearance-patent-clean-items。
* 只读页,无写/删/导出入口。公司 tab 的值由本发送口从原始入参自己下传(白名单构造不认识
* company_id),取值口形状由 company-tab-wiring 护栏钉住。 */
* 只读页+导出(2026-11-11 客户需求「数据得导出来」):公司 tab 的值由本发送口从原始入参自己下传
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。 */
import { http } from '@/api/http'
import { errorTextOf } from '../../api/envelope.ts'
import {
toAppearancePatentCleanExportParams,
toAppearancePatentCleanListParams,
type AppearancePatentCleanExportParams,
type AppearancePatentCleanExportQuery,
type AppearancePatentCleanListParams,
} from './appearance-patent-clean-filter.ts'
import {
@@ -21,6 +25,7 @@ export async function fetchAppearancePatentCleanList(
taskId: params.taskId ?? '',
asin: params.asin ?? '',
country: params.country ?? '',
groupId: params.groupId ?? '',
startDate: params.startDate ?? '',
endDate: params.endDate ?? '',
},
@@ -31,3 +36,66 @@ export async function fetchAppearancePatentCleanList(
const { data } = await http.get<unknown>(APPEARANCE_PATENT_CLEAN_ENDPOINT, { params: query })
return parseAppearancePatentCleanPage(data)
}
export interface AppearancePatentCleanExportResult {
blob: Blob
filename: string
}
/** 从 Content-Disposition 取 filename*(UTF-8 轨,后端 DownloadHeaderUtil 双轨口径),取不到回退常量名。 */
function exportFilenameOf(disposition: unknown): string {
const raw = typeof disposition === 'string' ? disposition : ''
const star = /filename\*=(?:UTF-8'')?([^;]+)/i.exec(raw)
if (star?.[1]) {
try {
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, '')) || '外观专利数据库.xlsx'
} catch {
// 编码坏的 filename* 当作没有,走 ASCII 轨或常量名
}
}
const plain = /filename="([^"]+)"/i.exec(raw)
return plain?.[1] || '外观专利数据库.xlsx'
}
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。 */
export async function exportAppearancePatentCleanList(
params: AppearancePatentCleanExportParams,
): Promise<AppearancePatentCleanExportResult> {
const query: AppearancePatentCleanExportQuery = toAppearancePatentCleanExportParams({
taskId: params.taskId ?? '',
asin: params.asin ?? '',
country: params.country ?? '',
groupId: params.groupId ?? '',
startDate: params.startDate ?? '',
endDate: params.endDate ?? '',
})
if (params.companyId != null) query.company_id = params.companyId
const response = await http.get<Blob>(`${APPEARANCE_PATENT_CLEAN_ENDPOINT}/export`, {
params: query,
responseType: 'blob',
timeout: 120_000,
})
const disposition = response.headers?.['content-disposition']
if (!disposition) {
// 没有附件头=服务端回了业务错误信封(HTTP 200 + JSON),把 blob 文本解回错误文案抛给页面
const blob = response.data
let payload: unknown = null
if (blob && typeof blob.text === 'function') {
const text = await blob.text()
try {
payload = JSON.parse(text)
} catch {
payload = text
}
}
throw new Error(errorTextOf(payload))
}
return { blob: response.data, filename: exportFilenameOf(disposition) }
}
/** 分组(主管)下拉选项:复用既有 GET /shop-manages/groups(与去重页/店铺管理共用同一分组集,
* 不下新端点)。2026-11-11 客户口径「主管就是组长,可以筛选组长来导出,就是分组」——
* 选项是分组管理里那一行(DedupeGroupOption {id, name, leaderUserId}),选中后以 group_id
* 走本文件 list/export 同一过滤面。 */
export { fetchDedupeTotalGroups } from '../asin/dedupe-total-api.ts'
export type { DedupeGroupOption } from '../asin/dedupe-total-api.ts'
@@ -1,10 +1,13 @@
/** 外观专利无侵权数据页筛选纯函数(v1.3 AC-5):任务号/ASIN/国家/起止时间 + snake 分页参数。
/** 外观专利无侵权数据页筛选纯函数(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;空白不下发)。
* `asin`、`country`、`group_id`、`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 护栏的发送行钉看守。 */
* 原始入参自己下传——取值口由 company-tab-wiring 护栏的发送行钉看守。
* 分组语义(2026-11-11 客户口径「主管就是组长,可以筛选组长来导出,就是分组」):下拉选项是
* 分组管理里那一行(biz_shop_manage_group),group_id 下发后服务端解析「组长本人+名下子账户」
* 整集 SQL 下推;行上「所属主管」列与它同源(组长行=自己,子账户行=创建人)。 */
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
/** 每页条数默认 10(蓝图 §3.2),上限 100。 */
@@ -20,6 +23,8 @@ export interface AppearancePatentCleanFilterState {
asin: string
/** 国家代码,空串=全部。 */
country: string
/** 分组 id 文本(分组管理里那一行,组长即该组主管),空串=全部分组。 */
groupId: string
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
startDate: string
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
@@ -27,7 +32,7 @@ export interface AppearancePatentCleanFilterState {
}
export function createAppearancePatentCleanFilterState(): AppearancePatentCleanFilterState {
return { taskId: '', asin: '', country: '', startDate: '', endDate: '' }
return { taskId: '', asin: '', country: '', groupId: '', startDate: '', endDate: '' }
}
/** 是否有任一激活筛选条件。 */
@@ -35,6 +40,7 @@ export function appearancePatentCleanFilterActive(state: AppearancePatentCleanFi
if ((state.taskId || '').trim()) return true
if ((state.asin || '').trim()) return true
if ((state.country || '').trim()) return true
if ((state.groupId || '').trim()) return true
if (validIsoDateOrUndefined(state.startDate) || validIsoDateOrUndefined(state.endDate)) return true
return false
}
@@ -46,12 +52,25 @@ export interface AppearancePatentCleanQuery {
task_id?: number
asin?: string
country?: string
group_id?: number
start_date?: string
end_date?: string
/** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */
company_id?: number
}
/** 导出查询参数:与列表同一过滤面、无分页(全量导出由服务侧 EXPORT_MAX_ROWS 上限兜住)。 */
export interface AppearancePatentCleanExportQuery {
task_id?: number
asin?: string
country?: string
group_id?: number
start_date?: string
end_date?: string
/** 公司 tab 同列表口径:白名单构造不点名,由 api 发送口下传。 */
company_id?: number
}
/** api 模块的入参:筛选态 + 分页 + 公司值(camel)。 */
export interface AppearancePatentCleanListParams {
page: number
@@ -59,11 +78,42 @@ export interface AppearancePatentCleanListParams {
taskId?: string
asin?: string
country?: string
groupId?: string
startDate?: string
endDate?: string
companyId?: number | null
}
/** api 导出入口的入参:筛选态 + 公司值(camel,无分页)。 */
export interface AppearancePatentCleanExportParams {
taskId?: string
asin?: string
country?: string
groupId?: string
startDate?: string
endDate?: string
companyId?: number | null
}
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段);列表与导出共用这一个取值口,
* 「导出的过滤面和页签看到的永远同源」由这条单出口保证,不出现两处各算各的。 */
function toAppearancePatentCleanFilterQuery(state: AppearancePatentCleanFilterState): AppearancePatentCleanExportQuery {
const query: AppearancePatentCleanExportQuery = {}
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 groupId = Number.parseInt((state.groupId || '').trim(), 10)
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
const startDate = validIsoDateOrUndefined(state.startDate)
if (startDate) query.start_date = startDate
const endDate = validIsoDateOrUndefined(state.endDate)
if (endDate) query.end_date = endDate
return query
}
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期不下发,分页钳制在此单出口(不含公司维)。 */
export function toAppearancePatentCleanListParams(
state: AppearancePatentCleanFilterState,
@@ -73,16 +123,16 @@ export function toAppearancePatentCleanListParams(
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
return {
page: safePage,
page_size: safeSize,
...toAppearancePatentCleanFilterQuery(state),
}
}
/** 过滤态 → 导出查询参数(无分页;归一规则与列表逐字同源)。 */
export function toAppearancePatentCleanExportParams(
state: AppearancePatentCleanFilterState,
): AppearancePatentCleanExportQuery {
return toAppearancePatentCleanFilterQuery(state)
}
@@ -7,6 +7,8 @@ export interface AppearancePatentCleanItem {
resultId: number | null
taskId: number | null
userId: number | null
/** 所属主管(后端读侧现算列:主管/公司超管=自己,普通账户=创建人;读不到为空 → 界面展示 -)。 */
supervisorName: string
companyId: number | null
rowNo: number | null
asin: string
@@ -58,6 +60,7 @@ export function toAppearancePatentCleanItem(raw: unknown): AppearancePatentClean
resultId: numberOrNull(record.resultId ?? record.result_id),
taskId: numberOrNull(record.taskId ?? record.task_id),
userId: numberOrNull(record.userId ?? record.user_id),
supervisorName: text(record.supervisorName ?? record.supervisor_name),
companyId: numberOrNull(record.companyId ?? record.company_id),
rowNo: numberOrNull(record.rowNo ?? record.row_no),
asin: text(record.asin),