Merge branch 'refactor/search' into feat/advertisement

This commit is contained in:
PetrichorFun 2026-09-10 18:01:26 +08:00 committed by GitHub
commit 2635095f3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -286,13 +286,55 @@ const filteredData = computed(() => {
return data;
});
/** 导出时将「关于」拆成「要点1…要点n」多列 */
function prepareExportItemsWithAboutPoints(
headers: Header[],
items: AmazonItem[],
): { headers: Header[]; items: Record<string, unknown>[] } {
const aboutLines = (item: AmazonItem) => {
const raw = item.abouts;
if (!raw?.length) return [];
return raw
.flatMap((line) => line.split(/\r?\n/))
.map((s) => s.trim())
.filter(Boolean);
};
const nextHeaders = headers.filter((h) => h.prop !== 'abouts');
const lineArrays = items.map(aboutLines);
const maxN = Math.max(1, ...lineArrays.map((l) => l.length));
for (let i = 0; i < maxN; i++) {
nextHeaders.push({
label: `要点${i + 1}`,
prop: `aboutPoint${i + 1}`,
});
}
const nextItems = items.map((item, idx) => {
const row: Record<string, unknown> = { ...item };
const lines = lineArrays[idx];
for (let i = 0; i < maxN; i++) {
row[`aboutPoint${i + 1}`] = lines[i] ?? '';
}
return row;
});
return { headers: nextHeaders, items: nextItems };
}
const handleExport = async (opt: 'local' | 'cloud') => {
const headers = getItemHeaders();
const items = toRaw(filteredData.value);
let headers = getItemHeaders();
let items: Record<string, unknown>[] | AmazonItem[] = toRaw(filteredData.value);
const prepared = prepareExportItemsWithAboutPoints(headers, items as AmazonItem[]);
headers = prepared.headers;
items = prepared.items;
const fragments = [
{
data: items,
headers: headers,
headers,
imageColumn: ['A+截图', '商品图片链接'],
name: 'items',
},