cloud-web-corejs 1.0.54-dev.284 → 1.0.54-dev.287
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/VabUpload/view.vue +135 -135
- package/src/components/xform/form-designer/setting-panel/form-setting.vue +40 -5
- package/src/components/xform/form-render/indexMixin.js +428 -1
- package/src/components/xform/mixins/defaultHandle.js +330 -1
- package/src/utils/pdfUtil.js +71 -0
- package/src/views/user/form/view/list.vue +12 -1
@@ -2538,6 +2538,115 @@ modules = {
|
|
2538
2538
|
async exportPdf() {
|
2539
2539
|
// statusEl.style.display = 'block';
|
2540
2540
|
// statusEl.textContent = '正在准备导出内容...';
|
2541
|
+
const loadingObj = this.$baseLoading();
|
2542
|
+
try {
|
2543
|
+
// 获取要导出的元素
|
2544
|
+
const element = this.$parent.$el;
|
2545
|
+
// 计算内容总高度
|
2546
|
+
|
2547
|
+
|
2548
|
+
// 克隆元素(不影响原始页面)
|
2549
|
+
// statusEl.textContent = '克隆内容...';
|
2550
|
+
|
2551
|
+
|
2552
|
+
const constainter = this.$parent.$parent.$el;
|
2553
|
+
|
2554
|
+
|
2555
|
+
const clonedElement = element.cloneNode(true);
|
2556
|
+
let wfTab = clonedElement.querySelector(".wf-tab");
|
2557
|
+
if(wfTab)wfTab.remove()
|
2558
|
+
|
2559
|
+
clonedElement.style.width = element.offsetWidth + 'px';
|
2560
|
+
|
2561
|
+
// 应用样式以展开内容
|
2562
|
+
clonedElement.style.height = 'auto';
|
2563
|
+
clonedElement.style.overflow = 'visible';
|
2564
|
+
clonedElement.style.position = 'absolute';
|
2565
|
+
clonedElement.style.left = '-9999px';
|
2566
|
+
// document.body.appendChild(clonedElement);
|
2567
|
+
// document.body.appendChild(constainter);
|
2568
|
+
|
2569
|
+
constainter.appendChild(clonedElement)
|
2570
|
+
|
2571
|
+
const contentHeight = clonedElement.scrollHeight;
|
2572
|
+
const contentWidth = clonedElement.offsetWidth;
|
2573
|
+
|
2574
|
+
// 设置PDF参数
|
2575
|
+
const pdf = new JsPDF('p', 'mm', 'a4');
|
2576
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
2577
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
2578
|
+
const padding = 10;
|
2579
|
+
|
2580
|
+
|
2581
|
+
|
2582
|
+
// 计算需要多少页
|
2583
|
+
const scale = pageWidth / contentWidth;
|
2584
|
+
const scaledHeight = contentHeight * scale;
|
2585
|
+
const pages = Math.ceil(scaledHeight / pageHeight);
|
2586
|
+
|
2587
|
+
// 分页捕获并添加到PDF
|
2588
|
+
// statusEl.textContent = '正在生成PDF (0/' + pages + ')';
|
2589
|
+
|
2590
|
+
for (let i = 0; i < pages; i++) {
|
2591
|
+
// 计算当前页的裁剪位置
|
2592
|
+
const position = i * pageHeight / scale;
|
2593
|
+
|
2594
|
+
// 使用html2canvas捕获当前页内容
|
2595
|
+
const canvas = await html2Canvas(clonedElement, {
|
2596
|
+
scale: 2,
|
2597
|
+
// useCORS: true,
|
2598
|
+
windowHeight: pageHeight / scale,
|
2599
|
+
y: position,
|
2600
|
+
height: pageHeight / scale,
|
2601
|
+
width: contentWidth,
|
2602
|
+
logging: false
|
2603
|
+
});
|
2604
|
+
|
2605
|
+
// 将canvas转换为图像
|
2606
|
+
const imgData = canvas.toDataURL('image/jpeg', 0.95);
|
2607
|
+
|
2608
|
+
// 添加新页面(第一页除外)
|
2609
|
+
if (i > 0) {
|
2610
|
+
pdf.addPage();
|
2611
|
+
}
|
2612
|
+
|
2613
|
+
// 将图像添加到PDF
|
2614
|
+
pdf.addImage(imgData, 'JPEG', padding, padding, pageWidth - 2*padding, pageHeight - 2*padding);
|
2615
|
+
|
2616
|
+
// statusEl.textContent = '正在生成PDF (' + (i+1) + '/' + pages + ')';
|
2617
|
+
}
|
2618
|
+
|
2619
|
+
// 移除克隆元素
|
2620
|
+
// document.body.removeChild(constainter);
|
2621
|
+
constainter.removeChild(clonedElement);
|
2622
|
+
|
2623
|
+
// 保存PDF
|
2624
|
+
// statusEl.textContent = '正在保存文件...';
|
2625
|
+
let fileName = this.reportTemplate.formName+".pdf";
|
2626
|
+
pdf.save(fileName);
|
2627
|
+
|
2628
|
+
// statusEl.textContent = 'PDF导出成功!';
|
2629
|
+
// statusEl.style.background = '#e8f5e9';
|
2630
|
+
// statusEl.style.color = '#2e7d32';
|
2631
|
+
|
2632
|
+
// 3秒后隐藏状态
|
2633
|
+
/* setTimeout(() => {
|
2634
|
+
statusEl.style.display = 'none';
|
2635
|
+
}, 3000); */
|
2636
|
+
|
2637
|
+
} catch (error) {
|
2638
|
+
console.error('导出失败:', error);
|
2639
|
+
// statusEl.textContent = '导出失败: ' + error.message;
|
2640
|
+
// statusEl.style.background = '#ffebee';
|
2641
|
+
// statusEl.style.color = '#c62828';
|
2642
|
+
}finally{
|
2643
|
+
loadingObj.close();
|
2644
|
+
}
|
2645
|
+
},
|
2646
|
+
|
2647
|
+
async exportPdf1() {
|
2648
|
+
// statusEl.style.display = 'block';
|
2649
|
+
// statusEl.textContent = '正在准备导出内容...';
|
2541
2650
|
|
2542
2651
|
try {
|
2543
2652
|
|
@@ -2557,6 +2666,18 @@ modules = {
|
|
2557
2666
|
let wfTab = clonedElement.querySelector(".wf-tab");
|
2558
2667
|
if(wfTab)wfTab.remove()
|
2559
2668
|
|
2669
|
+
|
2670
|
+
const scrollElements = clonedElement.querySelectorAll('.vxe-table--body-wrapper')
|
2671
|
+
|
2672
|
+
// 临时禁用虚拟滚动
|
2673
|
+
/* for(let scrollElement of scrollElements){
|
2674
|
+
const originalScrollTop = scrollElement.scrollTop
|
2675
|
+
// scrollElement.style = 'overflow:visible;max-height:inherit !important'
|
2676
|
+
scrollElement.style = scrollElement.style+ 'overflow:visible;max-height:inherit !important;'
|
2677
|
+
// scrollElement.style["max-height"] = 'inherit !important'
|
2678
|
+
scrollElement.scrollTop = 0
|
2679
|
+
} */
|
2680
|
+
|
2560
2681
|
clonedElement.style.width = element.offsetWidth + 'px';
|
2561
2682
|
|
2562
2683
|
// 应用样式以展开内容
|
@@ -2567,6 +2688,114 @@ modules = {
|
|
2567
2688
|
// document.body.appendChild(clonedElement);
|
2568
2689
|
// document.body.appendChild(constainter);
|
2569
2690
|
|
2691
|
+
|
2692
|
+
/* let dom1 = clonedElement.querySelector(".detail-wrap")
|
2693
|
+
debugger
|
2694
|
+
if(dom1){
|
2695
|
+
debugger
|
2696
|
+
let dom2 = dom1.children[1];
|
2697
|
+
dom2.style.height = "auto;"
|
2698
|
+
dom2.querySelector(".d-cont").style.height = "auto;"
|
2699
|
+
|
2700
|
+
} */
|
2701
|
+
|
2702
|
+
constainter.appendChild(clonedElement)
|
2703
|
+
|
2704
|
+
html2Canvas(clonedElement, {
|
2705
|
+
scrollY: 0,
|
2706
|
+
useCORS: true,
|
2707
|
+
allowTaint: true,
|
2708
|
+
scale: 2 // 提高分辨率
|
2709
|
+
}).then(canvas => {
|
2710
|
+
const pdf = new JsPDF('p', 'mm', 'a4')
|
2711
|
+
const imgData = canvas.toDataURL('image/png')
|
2712
|
+
const imgWidth = 210 // A4宽度
|
2713
|
+
const imgHeight = (canvas.height * imgWidth) / canvas.width
|
2714
|
+
|
2715
|
+
// 分页处理
|
2716
|
+
let heightLeft = imgHeight
|
2717
|
+
let position = 0
|
2718
|
+
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight)
|
2719
|
+
|
2720
|
+
while (heightLeft > 0) {
|
2721
|
+
position = heightLeft - imgHeight
|
2722
|
+
pdf.addPage()
|
2723
|
+
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight)
|
2724
|
+
heightLeft -= 297 // A4高度
|
2725
|
+
}
|
2726
|
+
|
2727
|
+
pdf.save(`导出.pdf`)
|
2728
|
+
|
2729
|
+
constainter.removeChild(clonedElement);
|
2730
|
+
})
|
2731
|
+
|
2732
|
+
} catch (error) {
|
2733
|
+
console.error('导出失败:', error);
|
2734
|
+
// statusEl.textContent = '导出失败: ' + error.message;
|
2735
|
+
// statusEl.style.background = '#ffebee';
|
2736
|
+
// statusEl.style.color = '#c62828';
|
2737
|
+
}
|
2738
|
+
},
|
2739
|
+
async exportPdf2() {
|
2740
|
+
// statusEl.style.display = 'block';
|
2741
|
+
// statusEl.textContent = '正在准备导出内容...';
|
2742
|
+
|
2743
|
+
try {
|
2744
|
+
|
2745
|
+
// 获取要导出的元素
|
2746
|
+
const element = this.$parent.$el;
|
2747
|
+
// 计算内容总高度
|
2748
|
+
|
2749
|
+
|
2750
|
+
// 克隆元素(不影响原始页面)
|
2751
|
+
// statusEl.textContent = '克隆内容...';
|
2752
|
+
|
2753
|
+
|
2754
|
+
const constainter = this.$parent.$parent.$el;
|
2755
|
+
|
2756
|
+
|
2757
|
+
const clonedElement = element.cloneNode(true);
|
2758
|
+
let wfTab = clonedElement.querySelector(".wf-tab");
|
2759
|
+
if(wfTab)wfTab.remove()
|
2760
|
+
|
2761
|
+
|
2762
|
+
const scrollElements = clonedElement.querySelectorAll('.vxe-table--body-wrapper')
|
2763
|
+
|
2764
|
+
// 临时禁用虚拟滚动
|
2765
|
+
/* for(let scrollElement of scrollElements){
|
2766
|
+
const originalScrollTop = scrollElement.scrollTop
|
2767
|
+
// scrollElement.style = 'overflow:visible;max-height:inherit !important'
|
2768
|
+
// scrollElement.style = scrollElement.style+ 'overflow:visible;max-height:inherit !important;'
|
2769
|
+
scrollElement.style["overflow"] = 'visible'
|
2770
|
+
scrollElement.style["max-height"] = 'inherit !important'
|
2771
|
+
scrollElement.scrollTop = 0
|
2772
|
+
} */
|
2773
|
+
|
2774
|
+
|
2775
|
+
let dom4 = clonedElement.querySelector(".designer-view")
|
2776
|
+
// dom4.style.height = "auto;"
|
2777
|
+
let dom1 = clonedElement.querySelector(".detail-wrap")
|
2778
|
+
debugger
|
2779
|
+
if(dom1){
|
2780
|
+
debugger
|
2781
|
+
// designer-view
|
2782
|
+
let dom2 = dom1.children[1];
|
2783
|
+
dom2.style.height = "auto;"
|
2784
|
+
dom2.querySelector(".d-cont").style.height = "auto;"
|
2785
|
+
|
2786
|
+
}
|
2787
|
+
|
2788
|
+
clonedElement.style.width = element.offsetWidth + 'px';
|
2789
|
+
|
2790
|
+
// 应用样式以展开内容
|
2791
|
+
clonedElement.style.height = 'auto';
|
2792
|
+
clonedElement.style.overflow = 'visible';
|
2793
|
+
clonedElement.style.position = 'absolute';
|
2794
|
+
// clonedElement.style.left = '-9999px';
|
2795
|
+
clonedElement.style.left = '100px';
|
2796
|
+
// document.body.appendChild(clonedElement);
|
2797
|
+
// document.body.appendChild(constainter);
|
2798
|
+
|
2570
2799
|
constainter.appendChild(clonedElement)
|
2571
2800
|
|
2572
2801
|
const contentHeight = clonedElement.scrollHeight;
|
@@ -2585,9 +2814,9 @@ modules = {
|
|
2585
2814
|
const scaledHeight = contentHeight * scale;
|
2586
2815
|
const pages = Math.ceil(scaledHeight / pageHeight);
|
2587
2816
|
|
2817
|
+
debugger
|
2588
2818
|
// 分页捕获并添加到PDF
|
2589
2819
|
// statusEl.textContent = '正在生成PDF (0/' + pages + ')';
|
2590
|
-
|
2591
2820
|
for (let i = 0; i < pages; i++) {
|
2592
2821
|
// 计算当前页的裁剪位置
|
2593
2822
|
const position = i * pageHeight / scale;
|
@@ -2640,6 +2869,204 @@ modules = {
|
|
2640
2869
|
// statusEl.style.background = '#ffebee';
|
2641
2870
|
// statusEl.style.color = '#c62828';
|
2642
2871
|
}
|
2872
|
+
},
|
2873
|
+
async exportPdf4() {
|
2874
|
+
// statusEl.style.display = 'block';
|
2875
|
+
// statusEl.textContent = '正在准备导出内容...';
|
2876
|
+
|
2877
|
+
try {
|
2878
|
+
|
2879
|
+
// 获取要导出的元素
|
2880
|
+
const element = this.$parent.$el;
|
2881
|
+
// 计算内容总高度
|
2882
|
+
|
2883
|
+
|
2884
|
+
// 克隆元素(不影响原始页面)
|
2885
|
+
// statusEl.textContent = '克隆内容...';
|
2886
|
+
|
2887
|
+
|
2888
|
+
const constainter = this.$parent.$parent.$el;
|
2889
|
+
|
2890
|
+
|
2891
|
+
const clonedElement = element.cloneNode(true);
|
2892
|
+
let wfTab = clonedElement.querySelector(".wf-tab");
|
2893
|
+
if(wfTab)wfTab.remove()
|
2894
|
+
|
2895
|
+
|
2896
|
+
const scrollElements = clonedElement.querySelectorAll('.vxe-table--body-wrapper')
|
2897
|
+
|
2898
|
+
// 临时禁用虚拟滚动
|
2899
|
+
for(let scrollElement of scrollElements){
|
2900
|
+
const originalScrollTop = scrollElement.scrollTop
|
2901
|
+
// scrollElement.style = 'overflow:visible;max-height:inherit !important'
|
2902
|
+
// scrollElement.style = scrollElement.style+ 'overflow:visible;max-height:inherit !important;'
|
2903
|
+
scrollElement.style["overflow"] = 'visible'
|
2904
|
+
scrollElement.style["max-height"] = 'inherit !important'
|
2905
|
+
scrollElement.scrollTop = 0
|
2906
|
+
}
|
2907
|
+
|
2908
|
+
|
2909
|
+
let dom4 = clonedElement.querySelector(".designer-view")
|
2910
|
+
// dom4.style.height = "auto;"
|
2911
|
+
let dom1 = clonedElement.querySelector(".detail-wrap")
|
2912
|
+
debugger
|
2913
|
+
if(dom1){
|
2914
|
+
debugger
|
2915
|
+
// designer-view
|
2916
|
+
let dom2 = dom1.children[1];
|
2917
|
+
dom2.style.height = "auto;"
|
2918
|
+
dom2.querySelector(".d-cont").style.height = "auto;"
|
2919
|
+
|
2920
|
+
}
|
2921
|
+
|
2922
|
+
clonedElement.style.width = element.offsetWidth + 'px';
|
2923
|
+
|
2924
|
+
// 应用样式以展开内容
|
2925
|
+
clonedElement.style.height = 'auto';
|
2926
|
+
clonedElement.style.overflow = 'visible';
|
2927
|
+
clonedElement.style.position = 'absolute';
|
2928
|
+
// clonedElement.style.left = '-9999px';
|
2929
|
+
clonedElement.style.left = '100px';
|
2930
|
+
// document.body.appendChild(clonedElement);
|
2931
|
+
// document.body.appendChild(constainter);
|
2932
|
+
|
2933
|
+
constainter.appendChild(clonedElement)
|
2934
|
+
|
2935
|
+
|
2936
|
+
const canvas = await html2Canvas(clonedElement, {
|
2937
|
+
scale: 2,
|
2938
|
+
useCORS: true,
|
2939
|
+
logging: false,
|
2940
|
+
onclone: (clonedDoc) => {
|
2941
|
+
|
2942
|
+
}
|
2943
|
+
});
|
2944
|
+
|
2945
|
+
|
2946
|
+
// 移除克隆元素
|
2947
|
+
// document.body.removeChild(constainter);
|
2948
|
+
constainter.removeChild(clonedElement);
|
2949
|
+
|
2950
|
+
// 5. 生成PDF
|
2951
|
+
this.currentStep = '创建PDF文档...';
|
2952
|
+
this.progress = 70;
|
2953
|
+
|
2954
|
+
const imgData = canvas.toDataURL('image/jpeg', 0.95);
|
2955
|
+
const pdf = new JsPDF('p', 'mm', 'a4');
|
2956
|
+
|
2957
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
2958
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
2959
|
+
|
2960
|
+
// const imgWidth = canvas.width;
|
2961
|
+
const imgWidth = element.offsetWidth;
|
2962
|
+
const imgHeight = canvas.height;
|
2963
|
+
|
2964
|
+
const ratio = pageWidth / imgWidth;
|
2965
|
+
const imgHeightOnPDF = imgHeight * ratio;
|
2966
|
+
|
2967
|
+
// 计算需要多少页
|
2968
|
+
let totalPages = Math.ceil(imgHeightOnPDF / pageHeight);
|
2969
|
+
let position = 0;
|
2970
|
+
|
2971
|
+
// 添加第一页
|
2972
|
+
pdf.addImage(imgData, 'JPEG', 0, position, pageWidth, imgHeightOnPDF);
|
2973
|
+
|
2974
|
+
// 添加额外页面(如果需要)
|
2975
|
+
for (let i = 1; i < totalPages; i++) {
|
2976
|
+
position -= pageHeight;
|
2977
|
+
pdf.addPage();
|
2978
|
+
pdf.addImage(imgData, 'JPEG', 0, position, pageWidth, imgHeightOnPDF);
|
2979
|
+
}
|
2980
|
+
|
2981
|
+
this.pdfPages = totalPages;
|
2982
|
+
|
2983
|
+
// 6. 生成预览
|
2984
|
+
this.currentStep = '生成预览...';
|
2985
|
+
this.progress = 90;
|
2986
|
+
|
2987
|
+
const pdfBlob = pdf.output('blob');
|
2988
|
+
this.pdfPreviewUrl = URL.createObjectURL(pdfBlob);
|
2989
|
+
|
2990
|
+
// 7. 自动下载
|
2991
|
+
pdf.save('exported-content.pdf');
|
2992
|
+
|
2993
|
+
this.progress = 100;
|
2994
|
+
setTimeout(() => {
|
2995
|
+
this.isExporting = false;
|
2996
|
+
}, 500);
|
2997
|
+
|
2998
|
+
} catch (error) {
|
2999
|
+
console.error('导出失败:', error);
|
3000
|
+
// statusEl.textContent = '导出失败: ' + error.message;
|
3001
|
+
// statusEl.style.background = '#ffebee';
|
3002
|
+
// statusEl.style.color = '#c62828';
|
3003
|
+
}
|
3004
|
+
},
|
3005
|
+
async exportPdf5() {
|
3006
|
+
try {
|
3007
|
+
// 获取要导出的元素
|
3008
|
+
const element = this.$parent.$el;
|
3009
|
+
// 计算内容总高度
|
3010
|
+
|
3011
|
+
|
3012
|
+
// 克隆元素(不影响原始页面)
|
3013
|
+
// statusEl.textContent = '克隆内容...';
|
3014
|
+
|
3015
|
+
|
3016
|
+
const constainter = this.$parent.$parent.$el;
|
3017
|
+
// 获取dom元素
|
3018
|
+
// const dom = document.querySelector('#id名称')
|
3019
|
+
if (element) {
|
3020
|
+
html2Canvas(element).then(async canvas => {
|
3021
|
+
// A4纸,纵向
|
3022
|
+
let pdf = new JsPDF('p', 'mm', 'a4')
|
3023
|
+
let ctx = canvas.getContext('2d')
|
3024
|
+
let a4w = 190
|
3025
|
+
// A4大小,210mm x 297mm,四边各保留10mm的边距,显示区域190x277
|
3026
|
+
let a4h = 277
|
3027
|
+
// 按A4显示比例换算一页图像的像素高度
|
3028
|
+
let imgHeight = Math.floor((a4h * canvas.width) / a4w)
|
3029
|
+
let renderedHeight = 0
|
3030
|
+
while (renderedHeight < canvas.height) {
|
3031
|
+
let page = document.createElement('canvas')
|
3032
|
+
page.width = canvas.width
|
3033
|
+
// 可能内容不足一页
|
3034
|
+
page.height = Math.min(imgHeight, canvas.height - renderedHeight)
|
3035
|
+
// 用getImageData剪裁指定区域,并画到前面创建的canvas对象中
|
3036
|
+
page.getContext('2d').putImageData(
|
3037
|
+
ctx.getImageData(
|
3038
|
+
0,
|
3039
|
+
renderedHeight,
|
3040
|
+
canvas.width,
|
3041
|
+
Math.min(imgHeight, canvas.height - renderedHeight)
|
3042
|
+
),
|
3043
|
+
0,
|
3044
|
+
0
|
3045
|
+
)
|
3046
|
+
// 添加图像到页面,保留10mm边距
|
3047
|
+
pdf.addImage(
|
3048
|
+
page.toDataURL('image/jpeg', 1.0),
|
3049
|
+
'JPEG',
|
3050
|
+
10,
|
3051
|
+
10,
|
3052
|
+
a4w,
|
3053
|
+
Math.min(a4h, (a4w * page.height) / page.width)
|
3054
|
+
)
|
3055
|
+
|
3056
|
+
renderedHeight += imgHeight
|
3057
|
+
if (renderedHeight < canvas.height) {
|
3058
|
+
// 如果后面还有内容,添加一个空页
|
3059
|
+
pdf.addPage()
|
3060
|
+
}
|
3061
|
+
// delete page;
|
3062
|
+
}
|
3063
|
+
// 保存文件
|
3064
|
+
pdf.save('文档名称.pdf')
|
3065
|
+
})
|
3066
|
+
}
|
3067
|
+
} catch (err) {
|
3068
|
+
console.log(err)
|
3069
|
+
}
|
2643
3070
|
}
|
2644
3071
|
}
|
2645
3072
|
};
|