导出字段调整
parent
d996a49a71
commit
53bf0b7fa9
|
|
@ -309,12 +309,46 @@ function formatExportProjectCell(project?: { opportunityCode?: string; opportuni
|
||||||
if (!project) {
|
if (!project) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const lines = [
|
const segments = [
|
||||||
normalizeExportText(project.opportunityCode) ? `编码:${normalizeExportText(project.opportunityCode)}` : "",
|
normalizeExportText(project.opportunityCode) ? `编码:${normalizeExportText(project.opportunityCode)}` : "",
|
||||||
normalizeExportText(project.opportunityName) ? `项目名称:${normalizeExportText(project.opportunityName)}` : "",
|
normalizeExportText(project.opportunityName) ? `项目名称:${normalizeExportText(project.opportunityName)}` : "",
|
||||||
project.amount === null || project.amount === undefined ? "" : `金额:${formatAmount(Number(project.amount))}`,
|
project.amount === null || project.amount === undefined ? "" : `金额:${formatAmount(Number(project.amount))}`,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
return lines.join("\n");
|
return segments.join("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatExportProjectListCell(projects?: Array<{ opportunityCode?: string; opportunityName?: string; amount?: number | null }>) {
|
||||||
|
if (!projects?.length) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return projects
|
||||||
|
.map((project, index) => {
|
||||||
|
const content = formatExportProjectCell(project);
|
||||||
|
return content ? `项目${index + 1} ${content}` : "";
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExcelDisplayWidth(value?: string | null) {
|
||||||
|
if (!value) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(value).reduce((total, char) => total + (/[\u4e00-\u9fff\u3400-\u4dbf\uff00-\uffef]/.test(char) ? 2 : 1), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExcelWrappedLineCount(value: string | null | undefined, columnWidth: number) {
|
||||||
|
if (!value) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const safeWidth = Math.max(1, Math.floor(columnWidth));
|
||||||
|
return value.split("\n").reduce((total, line) => {
|
||||||
|
const lineWidth = Math.max(1, getExcelDisplayWidth(line));
|
||||||
|
return total + Math.max(1, Math.ceil(lineWidth / safeWidth));
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatExportFilenameTime(date = new Date()) {
|
function formatExportFilenameTime(date = new Date()) {
|
||||||
|
|
@ -340,7 +374,6 @@ function downloadExcelFile(filename: string, content: BlobPart) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSalesExportHeaders(items: SalesExpansionItem[]) {
|
function buildSalesExportHeaders(items: SalesExpansionItem[]) {
|
||||||
const maxProjects = Math.max(0, ...items.map((item) => item.relatedProjects?.length ?? 0));
|
|
||||||
const headers = [
|
const headers = [
|
||||||
"工号",
|
"工号",
|
||||||
"姓名",
|
"姓名",
|
||||||
|
|
@ -353,20 +386,15 @@ function buildSalesExportHeaders(items: SalesExpansionItem[]) {
|
||||||
"销售是否在职",
|
"销售是否在职",
|
||||||
"销售以前是否做过云桌面项目",
|
"销售以前是否做过云桌面项目",
|
||||||
"跟进项目金额",
|
"跟进项目金额",
|
||||||
|
"项目信息",
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let index = 0; index < maxProjects; index += 1) {
|
|
||||||
headers.push(`项目${index + 1}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
headers.push("创建人", "更新修改时间");
|
headers.push("创建人", "更新修改时间");
|
||||||
headers.push("跟进记录");
|
headers.push("跟进记录");
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSalesExportData(items: SalesExpansionItem[]) {
|
function buildSalesExportData(items: SalesExpansionItem[]) {
|
||||||
const maxProjects = Math.max(0, ...items.map((item) => item.relatedProjects?.length ?? 0));
|
|
||||||
|
|
||||||
return items.map((item) => {
|
return items.map((item) => {
|
||||||
const row = [
|
const row = [
|
||||||
normalizeExportText(item.employeeNo),
|
normalizeExportText(item.employeeNo),
|
||||||
|
|
@ -380,13 +408,9 @@ function buildSalesExportData(items: SalesExpansionItem[]) {
|
||||||
item.active === null || item.active === undefined ? "" : item.active ? "是" : "否",
|
item.active === null || item.active === undefined ? "" : item.active ? "是" : "否",
|
||||||
formatExportBoolean(item.hasExp),
|
formatExportBoolean(item.hasExp),
|
||||||
normalizeExportText(formatRelatedProjectAmount(item.relatedProjects)),
|
normalizeExportText(formatRelatedProjectAmount(item.relatedProjects)),
|
||||||
|
formatExportProjectListCell(item.relatedProjects),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let index = 0; index < maxProjects; index += 1) {
|
|
||||||
const project = item.relatedProjects?.[index];
|
|
||||||
row.push(formatExportProjectCell(project));
|
|
||||||
}
|
|
||||||
|
|
||||||
row.push(
|
row.push(
|
||||||
normalizeExportText(item.owner),
|
normalizeExportText(item.owner),
|
||||||
normalizeExportText(item.updatedAt),
|
normalizeExportText(item.updatedAt),
|
||||||
|
|
@ -397,7 +421,6 @@ function buildSalesExportData(items: SalesExpansionItem[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildChannelExportHeaders(items: ChannelExpansionItem[]) {
|
function buildChannelExportHeaders(items: ChannelExpansionItem[]) {
|
||||||
const maxProjects = Math.max(0, ...items.map((item) => item.relatedProjects?.length ?? 0));
|
|
||||||
const maxContacts = Math.max(0, ...items.map((item) => item.contacts?.length ?? 0));
|
const maxContacts = Math.max(0, ...items.map((item) => item.contacts?.length ?? 0));
|
||||||
const headers = [
|
const headers = [
|
||||||
"编码",
|
"编码",
|
||||||
|
|
@ -415,12 +438,9 @@ function buildChannelExportHeaders(items: ChannelExpansionItem[]) {
|
||||||
"人员规模",
|
"人员规模",
|
||||||
"以前是否做过云桌面项目",
|
"以前是否做过云桌面项目",
|
||||||
"跟进项目金额",
|
"跟进项目金额",
|
||||||
|
"项目信息",
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let index = 0; index < maxProjects; index += 1) {
|
|
||||||
headers.push(`项目${index + 1}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let index = 0; index < maxContacts; index += 1) {
|
for (let index = 0; index < maxContacts; index += 1) {
|
||||||
headers.push(`人员${index + 1}姓名`, `人员${index + 1}联系电话`, `人员${index + 1}职位`);
|
headers.push(`人员${index + 1}姓名`, `人员${index + 1}联系电话`, `人员${index + 1}职位`);
|
||||||
}
|
}
|
||||||
|
|
@ -432,7 +452,6 @@ function buildChannelExportHeaders(items: ChannelExpansionItem[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildChannelExportData(items: ChannelExpansionItem[]) {
|
function buildChannelExportData(items: ChannelExpansionItem[]) {
|
||||||
const maxProjects = Math.max(0, ...items.map((item) => item.relatedProjects?.length ?? 0));
|
|
||||||
const maxContacts = Math.max(0, ...items.map((item) => item.contacts?.length ?? 0));
|
const maxContacts = Math.max(0, ...items.map((item) => item.contacts?.length ?? 0));
|
||||||
|
|
||||||
return items.map((item) => {
|
return items.map((item) => {
|
||||||
|
|
@ -452,13 +471,9 @@ function buildChannelExportData(items: ChannelExpansionItem[]) {
|
||||||
item.size ? `${item.size}人` : "",
|
item.size ? `${item.size}人` : "",
|
||||||
formatExportBoolean(item.hasDesktopExp),
|
formatExportBoolean(item.hasDesktopExp),
|
||||||
normalizeExportText(formatRelatedProjectAmount(item.relatedProjects)),
|
normalizeExportText(formatRelatedProjectAmount(item.relatedProjects)),
|
||||||
|
formatExportProjectListCell(item.relatedProjects),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let index = 0; index < maxProjects; index += 1) {
|
|
||||||
const project = item.relatedProjects?.[index];
|
|
||||||
row.push(formatExportProjectCell(project));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let index = 0; index < maxContacts; index += 1) {
|
for (let index = 0; index < maxContacts; index += 1) {
|
||||||
const contact = item.contacts?.[index];
|
const contact = item.contacts?.[index];
|
||||||
row.push(
|
row.push(
|
||||||
|
|
@ -1623,26 +1638,40 @@ export default function Expansion() {
|
||||||
|
|
||||||
worksheet.addRow(headers);
|
worksheet.addRow(headers);
|
||||||
rows.forEach((row) => {
|
rows.forEach((row) => {
|
||||||
worksheet.addRow(row);
|
worksheet.addRow(row);
|
||||||
});
|
});
|
||||||
|
|
||||||
worksheet.views = [{ state: "frozen", ySplit: 1 }];
|
worksheet.views = [{ state: "frozen", ySplit: 1 }];
|
||||||
const followUpColumnIndex = headers.indexOf("跟进记录") + 1;
|
const projectInfoColumnIndex = headers.indexOf("项目信息") + 1;
|
||||||
const projectColumnIndexes = headers
|
|
||||||
.map((header, index) => (header.startsWith("项目") ? index + 1 : -1))
|
|
||||||
.filter((index) => index > 0);
|
|
||||||
worksheet.getRow(1).height = 24;
|
worksheet.getRow(1).height = 24;
|
||||||
worksheet.getRow(1).font = { bold: true };
|
worksheet.getRow(1).font = { bold: true };
|
||||||
worksheet.getRow(1).alignment = { vertical: "middle", horizontal: "center" };
|
worksheet.getRow(1).alignment = { vertical: "middle", horizontal: "center" };
|
||||||
|
|
||||||
|
const projectInfoColumnWidth = projectInfoColumnIndex > 0
|
||||||
|
? Math.min(
|
||||||
|
80,
|
||||||
|
Math.max(
|
||||||
|
16,
|
||||||
|
getExcelDisplayWidth(headers[projectInfoColumnIndex - 1] || "") + 2,
|
||||||
|
rows.reduce((maxWidth, row) => {
|
||||||
|
const cellValue = row[projectInfoColumnIndex - 1];
|
||||||
|
const longestLineWidth = typeof cellValue === "string"
|
||||||
|
? cellValue.split("\n").reduce((lineMax, line) => Math.max(lineMax, getExcelDisplayWidth(line)), 0)
|
||||||
|
: 0;
|
||||||
|
return Math.max(maxWidth, longestLineWidth + 2);
|
||||||
|
}, 0),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: 30;
|
||||||
|
|
||||||
headers.forEach((header, index) => {
|
headers.forEach((header, index) => {
|
||||||
const column = worksheet.getColumn(index + 1);
|
const column = worksheet.getColumn(index + 1);
|
||||||
if (header === "跟进记录") {
|
if (header === "跟进记录") {
|
||||||
column.width = 42;
|
column.width = 42;
|
||||||
|
} else if (header === "项目信息") {
|
||||||
|
column.width = projectInfoColumnWidth;
|
||||||
} else if (header.includes("办公地址") || header.includes("备注")) {
|
} else if (header.includes("办公地址") || header.includes("备注")) {
|
||||||
column.width = 24;
|
column.width = 24;
|
||||||
} else if (header.startsWith("项目")) {
|
|
||||||
column.width = 26;
|
|
||||||
} else if (header.includes("渠道属性") || header.includes("内部属性") || header.includes("聚焦行业")) {
|
} else if (header.includes("渠道属性") || header.includes("内部属性") || header.includes("聚焦行业")) {
|
||||||
column.width = 18;
|
column.width = 18;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1661,18 +1690,16 @@ export default function Expansion() {
|
||||||
cell.alignment = {
|
cell.alignment = {
|
||||||
vertical: "top",
|
vertical: "top",
|
||||||
horizontal: rowNumber === 1 ? "center" : "left",
|
horizontal: rowNumber === 1 ? "center" : "left",
|
||||||
wrapText: headers[columnNumber - 1] === "跟进记录" || headers[columnNumber - 1].startsWith("项目"),
|
wrapText: headers[columnNumber - 1] === "跟进记录" || headers[columnNumber - 1] === "项目信息",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
if (rowNumber > 1 && followUpColumnIndex > 0) {
|
if (rowNumber > 1) {
|
||||||
const followUpText = row.getCell(followUpColumnIndex).value as string | null | undefined;
|
const projectText = projectInfoColumnIndex > 0 ? row.getCell(projectInfoColumnIndex).value as string | null | undefined : "";
|
||||||
const followUpLineCount = typeof followUpText === "string" && followUpText ? followUpText.split("\n").length : 1;
|
const projectLineCount = getExcelWrappedLineCount(
|
||||||
const projectLineCount = projectColumnIndexes.reduce((max, columnIndex) => {
|
typeof projectText === "string" ? projectText : "",
|
||||||
const projectText = row.getCell(columnIndex).value as string | null | undefined;
|
projectInfoColumnWidth,
|
||||||
const lineCount = typeof projectText === "string" && projectText ? projectText.split("\n").length : 1;
|
);
|
||||||
return Math.max(max, lineCount);
|
row.height = Math.max(22, projectLineCount * 16);
|
||||||
}, 1);
|
|
||||||
row.height = Math.max(22, Math.max(followUpLineCount, projectLineCount) * 16);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue