|
|
@@ -107,6 +107,7 @@ import { buildFileUrl } from '@/utils'
|
|
|
import axios from 'axios'
|
|
|
import { DynamicTbApi } from '@/api/pressure2/dynamictb'
|
|
|
import {DynamicTbColApi} from "@/api/pressure2/dynamictbcol";
|
|
|
+import { ExcelApi } from '@/api/pressure2/excel'
|
|
|
import { DynamicTbValApi } from '@/api/pressure2/dynamictbval'
|
|
|
import BatchUploadFile from "./BatchUploadFile.vue";
|
|
|
import {editReport, handleCopy, collectSheetDataSource, collectShapesIntoDataSource, serializeDataSourceForStorage} from "@/utils/reportUtil";
|
|
|
@@ -202,109 +203,145 @@ const fetchTemplateData = async () => {
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
-let dynamicTbColRespVOList
|
|
|
const initPreview = async () => {
|
|
|
- if(!props.initData.refId){
|
|
|
+ const { refId, opType, templateId } = props.initData;
|
|
|
+
|
|
|
+ if (!refId) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
loading.value = true;
|
|
|
- // showSpread.value=true;
|
|
|
- // showPdf.value=false;
|
|
|
- if (props.initData.opType == 0) {
|
|
|
+
|
|
|
+ if (opType === 0) {
|
|
|
showSpread.value = true;
|
|
|
pdfLoading.value = false;
|
|
|
}
|
|
|
|
|
|
previewSpread?.destroy();
|
|
|
+ previewSpread = new GC.Spread.Sheets.Workbook(previewContainer.value);
|
|
|
+
|
|
|
+ const handleAfterOpen = async () => {
|
|
|
+ console.log('后端处理完成,预览加载完成');
|
|
|
+ if (opType === 1) {
|
|
|
+ showSpread.value = false;
|
|
|
+ pdfLoading.value = true;
|
|
|
+ await openPdf();
|
|
|
+ } else {
|
|
|
+ showPdf.value = false;
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleOpenError = (error: any) => {
|
|
|
+ console.error('文件打开失败:', error);
|
|
|
+ loading.value = false;
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleCopyIfNeeded = () => {
|
|
|
+ if (opType === 0) {
|
|
|
+ handleCopy(previewSpread);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const initCommonData = async () => {
|
|
|
+ const res = await DynamicTbValApi.getDynamicTbInsAndValByRefId(props.initData);
|
|
|
+ insId.value = res.dynamicTbInsRespVO.id;
|
|
|
+ dynamicTbColRespVOList = res.dynamicTbColRespVOList;
|
|
|
+ colListData.value = res.dynamicTbColRespVOList.filter(i => i.colValType === 4);
|
|
|
+ return res;
|
|
|
+ };
|
|
|
+
|
|
|
+ if (nodeEnv === 'dev' || nodeEnv === 'uat') {
|
|
|
+ try {
|
|
|
+ await initCommonData();
|
|
|
+
|
|
|
+ const apiMethod = nodeEnv === 'dev' ? ExcelApi.process : ExcelApi.excel;
|
|
|
+ const sjsBlob: any = await apiMethod({ templateId, refId });
|
|
|
+
|
|
|
+ previewSpread.open(sjsBlob, handleAfterOpen, handleOpenError);
|
|
|
+ handleCopyIfNeeded();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('后端处理 Excel 失败:', error);
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- previewSpread = new GC.Spread.Sheets.Workbook(previewContainer.value)
|
|
|
try {
|
|
|
- let blob = await fetchTemplateData();
|
|
|
+ const blob = await fetchTemplateData();
|
|
|
if (!blob) return;
|
|
|
|
|
|
previewSpread.open(blob, async () => {
|
|
|
console.log('预览加载完成');
|
|
|
- let sheets = previewSpread.sheets;
|
|
|
- //DynamicTbValApi.getDynamicTbValByIns(props.instanceId)
|
|
|
- await DynamicTbValApi.getDynamicTbInsAndValByRefId(props.initData)
|
|
|
- .then(async res => {
|
|
|
-
|
|
|
- insId.value = res.dynamicTbInsRespVO.id;
|
|
|
-
|
|
|
- if (res.dynamicTbValRespVOList && res.dynamicTbValRespVOList.length > 0) {
|
|
|
- // 设置数据
|
|
|
- sheetData = {};
|
|
|
- res.dynamicTbValRespVOList.forEach(i => {
|
|
|
- const val = i.valValue;
|
|
|
- // 解析 JSON 字符串值,避免 SpreadJS 绑定时报"数据源不支持"
|
|
|
- if (typeof val === 'string') {
|
|
|
- const trimmed = val.trim();
|
|
|
- if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
|
- try {
|
|
|
- sheetData[i.colCode] = JSON.parse(val);
|
|
|
- } catch (e) {
|
|
|
- sheetData[i.colCode] = val;
|
|
|
- }
|
|
|
- } else {
|
|
|
+ const sheets = previewSpread.sheets;
|
|
|
+
|
|
|
+ const res = await DynamicTbValApi.getDynamicTbInsAndValByRefId(props.initData);
|
|
|
+ insId.value = res.dynamicTbInsRespVO.id;
|
|
|
+
|
|
|
+ if (res.dynamicTbValRespVOList && res.dynamicTbValRespVOList.length > 0) {
|
|
|
+ sheetData = {};
|
|
|
+ res.dynamicTbValRespVOList.forEach(i => {
|
|
|
+ const val = i.valValue;
|
|
|
+ if (typeof val === 'string') {
|
|
|
+ const trimmed = val.trim();
|
|
|
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
|
+ try {
|
|
|
+ sheetData[i.colCode] = JSON.parse(val);
|
|
|
+ } catch {
|
|
|
sheetData[i.colCode] = val;
|
|
|
}
|
|
|
} else {
|
|
|
sheetData[i.colCode] = val;
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- let dataSource1 = new GC.Spread.Sheets.Bindings.CellBindingSource(sheetData);
|
|
|
- if (props.initData.dataSource){
|
|
|
- dataSource1 = new GC.Spread.Sheets.Bindings.CellBindingSource(props.initData.dataSource);
|
|
|
- }
|
|
|
- sheets.forEach((sheet) => {
|
|
|
- sheet.setDataSource(dataSource1);
|
|
|
+ } else {
|
|
|
+ sheetData[i.colCode] = val;
|
|
|
+ }
|
|
|
});
|
|
|
- dynamicTbColRespVOList = res.dynamicTbColRespVOList
|
|
|
- // 可编辑字段
|
|
|
- const editCols = res.dynamicTbColRespVOList.filter(i => i.isEdit).map(i => i.colCode);
|
|
|
- // 图片字段
|
|
|
- const imgCols = res.dynamicTbColRespVOList.filter(i => i.colValType === 4).map(i => i.colCode);
|
|
|
- colListData.value = res.dynamicTbColRespVOList.filter(i => i.colValType === 4)
|
|
|
- for (const sheet of sheets) {
|
|
|
- await editReport(sheet, editCols, imgCols,props.initData.opType )
|
|
|
- }
|
|
|
- // 数据源绑定后,表格行自动扩展,需要同步第一行的合并规则、样式、行高到所有新增行
|
|
|
- handleTableRowsAfterDataBind(sheets);
|
|
|
- // 是否隐藏续页
|
|
|
- await hiddenPage()
|
|
|
-
|
|
|
- if (props.initData.opType == 1) {
|
|
|
- showSpread.value = false;
|
|
|
- pdfLoading.value = true;
|
|
|
- await openPdf();
|
|
|
- } else {
|
|
|
- showPdf.value = false;
|
|
|
- loading.value = false;
|
|
|
- }
|
|
|
- console.log(getWingdingsList)
|
|
|
- })
|
|
|
+ }
|
|
|
|
|
|
- }, (error) => {
|
|
|
- console.error('文件打开失败:', error);
|
|
|
- });
|
|
|
- // 处理复制
|
|
|
- if (props.initData.opType == 0) {
|
|
|
- handleCopy(previewSpread)
|
|
|
- }
|
|
|
+ let dataSource1 = new GC.Spread.Sheets.Bindings.CellBindingSource(sheetData);
|
|
|
+ if (props.initData.dataSource) {
|
|
|
+ dataSource1 = new GC.Spread.Sheets.Bindings.CellBindingSource(props.initData.dataSource);
|
|
|
+ }
|
|
|
+ sheets.forEach(sheet => sheet.setDataSource(dataSource1));
|
|
|
+
|
|
|
+ dynamicTbColRespVOList = res.dynamicTbColRespVOList;
|
|
|
+ const editCols = res.dynamicTbColRespVOList.filter(i => i.isEdit).map(i => i.colCode);
|
|
|
+ const imgCols = res.dynamicTbColRespVOList.filter(i => i.colValType === 4).map(i => i.colCode);
|
|
|
+ colListData.value = res.dynamicTbColRespVOList.filter(i => i.colValType === 4);
|
|
|
+
|
|
|
+ for (const sheet of sheets) {
|
|
|
+ await editReport(sheet, editCols, imgCols, opType);
|
|
|
+ }
|
|
|
+
|
|
|
+ handleTableRowsAfterDataBind(sheets);
|
|
|
+ await hiddenPage();
|
|
|
+
|
|
|
+ if (opType === 1) {
|
|
|
+ showSpread.value = false;
|
|
|
+ pdfLoading.value = true;
|
|
|
+ await openPdf();
|
|
|
+ } else {
|
|
|
+ showPdf.value = false;
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
+ }, handleOpenError);
|
|
|
+
|
|
|
+ handleCopyIfNeeded();
|
|
|
} catch (error) {
|
|
|
console.error('预览加载失败:', error);
|
|
|
- } finally {
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+let dynamicTbColRespVOList;
|
|
|
+
|
|
|
const openPdf = async () => {
|
|
|
const formData = new FormData()
|
|
|
const rules = []
|
|
|
previewSpread.sheets.forEach((sheet) => {
|
|
|
sheet.conditionalFormats.getRules().forEach(rule => {
|
|
|
- if (rule.ruleType() === 2) {
|
|
|
+ console.log(rule.condition().formula())
|
|
|
+ if (rule.condition().formula() == 'TRUE') {
|
|
|
console.log(rule)
|
|
|
rules.push({
|
|
|
sheet,
|