mirror of
https://github.com/primedigitaltech/azon_seeker.git
synced 2026-10-05 07:13:06 +08:00
Merge branch 'refactor/search' into feat/advertisement
This commit is contained in:
commit
2635095f3f
@ -286,13 +286,55 @@ const filteredData = computed(() => {
|
|||||||
return data;
|
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 handleExport = async (opt: 'local' | 'cloud') => {
|
||||||
const headers = getItemHeaders();
|
let headers = getItemHeaders();
|
||||||
const items = toRaw(filteredData.value);
|
let items: Record<string, unknown>[] | AmazonItem[] = toRaw(filteredData.value);
|
||||||
|
|
||||||
|
const prepared = prepareExportItemsWithAboutPoints(headers, items as AmazonItem[]);
|
||||||
|
headers = prepared.headers;
|
||||||
|
items = prepared.items;
|
||||||
|
|
||||||
const fragments = [
|
const fragments = [
|
||||||
{
|
{
|
||||||
data: items,
|
data: items,
|
||||||
headers: headers,
|
headers,
|
||||||
imageColumn: ['A+截图', '商品图片链接'],
|
imageColumn: ['A+截图', '商品图片链接'],
|
||||||
name: 'items',
|
name: 'items',
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user