Files
crawler-plugin/admin-frontend-vue/src/pages/gating/gating-import.ts
T
huangzd1997 eb6dd9bf44 feat(gating): 后管新增品牌Gating库管理页
菜单权限键 admin_brand_gating(admin_group_data 组),路由 asin-center/gating;
统计卡+五字段筛选+13 列表格+新增/删除/启停用/批量导入(粘文本 { text }
整段交后端,前端同款 parse_batch 规则只做行数预览);companyScoped=false
(biz_brand_gating 全平台共享表口径)。补 ops-cell 操作列宽登记与操作提示条。
2026-10-23 21:57:05 +08:00

67 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 批量导入文本解析(照抄桌面版 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} 条`
}