采购管理和零售管理相关的详情查看和打印预览
This commit is contained in:
1 parent
fe3054d814
commit
2a21372bee
18 files changed
+823
-209
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { VxeUI } from "vxe-table"
|
||||
|
||||
// 数组分块分组
|
||||
function chunk<T>(array: T[], size: number): T[][] {
|
||||
if (size <= 0) {
|
||||
throw new Error("组的大小必须大于0")
|
||||
}
|
||||
|
||||
const result: T[][] = []
|
||||
for (let i = 0; i < array.length; i += size) {
|
||||
result.push(array.slice(i, i + size))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 表格分页 + 表单信息 打印
|
||||
export const tablePrint = (
|
||||
editableTableRef: any,
|
||||
baseDataInfoRef: any,
|
||||
editableTableData: any,
|
||||
tableChunkSize: number = 20,
|
||||
printTitle: string = "",
|
||||
) => {
|
||||
const $table = editableTableRef
|
||||
const formPrintHtml = baseDataInfoRef ? baseDataInfoRef.innerHTML : ""
|
||||
if ($table && formPrintHtml) {
|
||||
// 分割每页20条
|
||||
Promise.all(
|
||||
chunk(editableTableData, tableChunkSize).map((pageData: any, index: number) => {
|
||||
return $table
|
||||
.getPrintHtml({
|
||||
data: pageData,
|
||||
})
|
||||
.then(({ html }: any) => {
|
||||
return {
|
||||
bodyHtml: index === 0 ? formPrintHtml + html : html,
|
||||
}
|
||||
})
|
||||
}),
|
||||
).then((pageBreaks) => {
|
||||
VxeUI.print({
|
||||
title: printTitle,
|
||||
showPageNumber: true,
|
||||
pageBreaks,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user