|
|
|
|
@ -57,19 +57,36 @@ const options = ref({
|
|
|
|
|
},
|
|
|
|
|
onSave: async (e) => {
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
onFileUpload: async (e) => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 常量赋值
|
|
|
|
|
const renderTemplate = (str, data) => {
|
|
|
|
|
return str.replace(/#\{(.*?)\}/g, (_, path) => {
|
|
|
|
|
return path.split('.').reduce((o, k) => o?.[k], data) ?? ' ';
|
|
|
|
|
let arr = path.split('.');
|
|
|
|
|
if (arr.length > 0) {
|
|
|
|
|
arr[0] = `#{${arr[0]}}`;
|
|
|
|
|
}
|
|
|
|
|
return arr.reduce((o, k) => o?.[k], data) ?? ' ';
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
// 数组赋值
|
|
|
|
|
const rowRenderTemplate = (str, index) => {
|
|
|
|
|
return str.replace(/\^\{(.*?)\}/g, (_, path) => {
|
|
|
|
|
return templateData[path][index] || ' ';
|
|
|
|
|
let res = str;
|
|
|
|
|
res = res.replace(/\^\{(.*?)\}/g, (_, path) => {
|
|
|
|
|
return templateData[`^{${path}}`][index] || ' ';
|
|
|
|
|
});
|
|
|
|
|
res = res.replace(/#\{(.*?)\}/g, (_, path) => {
|
|
|
|
|
let arr = path.split('.');
|
|
|
|
|
if (arr.length > 0) {
|
|
|
|
|
arr[0] = `#{${arr[0]}}`;
|
|
|
|
|
}
|
|
|
|
|
return arr.reduce((o, k) => o?.[k], templateData) ?? ' ';
|
|
|
|
|
});
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
// 是否进行数组赋值
|
|
|
|
|
const hasCaretPattern = (arr) => {
|
|
|
|
|
@ -81,7 +98,8 @@ const hasCaretPattern = (arr) => {
|
|
|
|
|
function traverse(items) {
|
|
|
|
|
for (const item of items) {
|
|
|
|
|
if (item.text && regex.test(item.text)) {
|
|
|
|
|
length = Math.max(length, templateData[extractPlaceholders(item.text)].length || 0);
|
|
|
|
|
// length = Math.max(length, templateData[extractPlaceholders(item.text)].length || 0);
|
|
|
|
|
length = Math.max(length, templateData[item.text].length || 0);
|
|
|
|
|
res = true; // 找到匹配
|
|
|
|
|
}
|
|
|
|
|
if (item.content && Array.isArray(item.content)) {
|
|
|
|
|
@ -104,7 +122,6 @@ const fillRowData = (e, index) => {
|
|
|
|
|
} else {
|
|
|
|
|
e.text = rowRenderTemplate(e.text || '', index);
|
|
|
|
|
}
|
|
|
|
|
console.log(e);
|
|
|
|
|
return e;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -159,7 +176,7 @@ const insertText = (e) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function extractPlaceholders(str) {
|
|
|
|
|
const regex = /[#\^]\{([^}]+)\}/g; // 匹配 #{...} 或 ^{...}
|
|
|
|
|
const regex = /[#\^]\{([^}]+)\}/g;
|
|
|
|
|
const result = [];
|
|
|
|
|
let match;
|
|
|
|
|
while ((match = regex.exec(str)) !== null) {
|
|
|
|
|
@ -172,7 +189,8 @@ onMounted(async () => {
|
|
|
|
|
const { data: assignData } = await templateAssign({ templateType: 1, contractId: route.query.contractId });
|
|
|
|
|
templateData = {};
|
|
|
|
|
assignData.forEach((item) => {
|
|
|
|
|
templateData[extractPlaceholders(item.varName)] = item.varValue;
|
|
|
|
|
// templateData[extractPlaceholders(item.varName)] = item.varValue;
|
|
|
|
|
templateData[item.varName] = item.varValue;
|
|
|
|
|
});
|
|
|
|
|
// console.log(templateData);
|
|
|
|
|
getPrintTemplate(route.query.templateId).then((e) => {
|
|
|
|
|
|