|
|
@@ -220,18 +220,6 @@ const initPreview = async () => {
|
|
|
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;
|
|
|
@@ -253,12 +241,60 @@ const initPreview = async () => {
|
|
|
|
|
|
if (nodeEnv === 'dev' || nodeEnv === 'uat') {
|
|
|
try {
|
|
|
- await initCommonData();
|
|
|
-
|
|
|
+ // 1. 获取实例和字段数据(数据绑定留给前端处理,后端只做图片/高亮/续页处理)
|
|
|
+ const res = await initCommonData();
|
|
|
+
|
|
|
+ // 2. 调用后端接口获取处理好的 SJS
|
|
|
const apiMethod = nodeEnv === 'dev' ? ExcelApi.process : ExcelApi.excel;
|
|
|
const sjsBlob: any = await apiMethod({ templateId, refId });
|
|
|
-
|
|
|
- previewSpread.open(sjsBlob, handleAfterOpen, handleOpenError);
|
|
|
+
|
|
|
+ // 3. 打开 SJS 后在回调中绑定数据源
|
|
|
+ previewSpread.open(sjsBlob, () => {
|
|
|
+ console.log('后端处理完成,预览加载完成');
|
|
|
+ const sheets = previewSpread.sheets;
|
|
|
+
|
|
|
+ // 构建数据源并绑定(后端不 setDataSource,交由前端处理)
|
|
|
+ // 后端已将 .jpg/.png 路径处理为背景图片,此处设 null 避免覆盖
|
|
|
+ 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.endsWith('.jpg') || trimmed.endsWith('.png')) {
|
|
|
+ sheetData[i.colCode] = null;
|
|
|
+ } else if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
|
+ try { sheetData[i.colCode] = JSON.parse(val); } catch { sheetData[i.colCode] = val; }
|
|
|
+ } else {
|
|
|
+ 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));
|
|
|
+
|
|
|
+ // 表格行样式同步(数据绑定后前端处理)
|
|
|
+ handleTableRowsAfterDataBind(sheets);
|
|
|
+
|
|
|
+ // 续页处理
|
|
|
+ hiddenPage().then(() => {
|
|
|
+ if (opType === 1) {
|
|
|
+ showSpread.value = false;
|
|
|
+ pdfLoading.value = true;
|
|
|
+ openPdf();
|
|
|
+ } else {
|
|
|
+ showPdf.value = false;
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, handleOpenError);
|
|
|
handleCopyIfNeeded();
|
|
|
} catch (error) {
|
|
|
console.error('后端处理 Excel 失败:', error);
|
|
|
@@ -469,25 +505,31 @@ const selectWingdings = (item) => {
|
|
|
|
|
|
const handleSave = () => {
|
|
|
loading.value = true;
|
|
|
-
|
|
|
+ console.log(1)
|
|
|
let dataSource = {};
|
|
|
+ console.log(1)
|
|
|
previewSpread.sheets.forEach((sheet) => {
|
|
|
// 收集 sheet 的数据源(兼容 table 绑定字段)
|
|
|
+ console.log(1)
|
|
|
const sheetData = collectSheetDataSource(sheet);
|
|
|
+ console.log(sheetData)
|
|
|
for (const key in sheetData) {
|
|
|
+ console.log(1)
|
|
|
if (dataSource[key] && sheetData[key] == sheetData[key]) {
|
|
|
} else {
|
|
|
dataSource[key] = sheetData[key];
|
|
|
}
|
|
|
}
|
|
|
+ console.log(1)
|
|
|
// 收集形状(浮动图片)数据
|
|
|
collectShapesIntoDataSource(sheet, dataSource);
|
|
|
});
|
|
|
-
|
|
|
+ console.log(dataSource)
|
|
|
if (Object.keys(dataSource).length > 0) {
|
|
|
+ console.log(1)
|
|
|
// 序列化为后端存储格式(对象/数组 → JSON 字符串)
|
|
|
const serializedData = serializeDataSourceForStorage(dataSource);
|
|
|
-
|
|
|
+ console.log(1)
|
|
|
DynamicTbValApi.saveAllColValue(insId.value, serializedData).then(res => {
|
|
|
if (res) {
|
|
|
ElMessage.success('保存成功')
|