|
@@ -625,6 +625,7 @@ import ViewForm from "./com/view";
|
|
import elDragDialog from "@/directive/el-drag-dialog";
|
|
import elDragDialog from "@/directive/el-drag-dialog";
|
|
import draggable from "vuedraggable";
|
|
import draggable from "vuedraggable";
|
|
import htmlDocx from "html-docx-js/dist/html-docx";
|
|
import htmlDocx from "html-docx-js/dist/html-docx";
|
|
|
|
+import { searchFormula } from "@/api/formula";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
// import htmlDocx from "htmlDocx";
|
|
// import htmlDocx from "htmlDocx";
|
|
export default {
|
|
export default {
|
|
@@ -1163,29 +1164,45 @@ export default {
|
|
this.loading = false; // 结束加载动画
|
|
this.loading = false; // 结束加载动画
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- loadTemplateInfo(e) {
|
|
|
|
- let _this = this;
|
|
|
|
- let par = {
|
|
|
|
- id: e,
|
|
|
|
- };
|
|
|
|
- getTemplateInfo(par)
|
|
|
|
- .then((res) => {
|
|
|
|
- if (res.status != 200) return;
|
|
|
|
- if (res.data.attrs == null || res.data.type == "") {
|
|
|
|
- res.data.attrs = "[]";
|
|
|
|
- res.data.content = "请填写内容";
|
|
|
|
- res.data.lay_id = "textArea";
|
|
|
|
- res.data.type = "TextArea";
|
|
|
|
- }
|
|
|
|
- document.title =
|
|
|
|
- res.data.name == ""
|
|
|
|
- ? "新建模块-轻良实业"
|
|
|
|
- : res.data.name + "-轻良实业";
|
|
|
|
- res.data.attrs = JSON.parse(res.data.attrs);
|
|
|
|
- _this.coms = [res.data];
|
|
|
|
- console.log("11", _this.coms);
|
|
|
|
- })
|
|
|
|
- .catch(() => {});
|
|
|
|
|
|
+ async loadTemplateInfo(id) {
|
|
|
|
+ try {
|
|
|
|
+ // 获取模板信息
|
|
|
|
+ const { data } = await getTemplateInfo({ id });
|
|
|
|
+
|
|
|
|
+ // 设置默认值
|
|
|
|
+ if (!data.attrs || !data.type) {
|
|
|
|
+ Object.assign(data, {
|
|
|
|
+ attrs: "[]",
|
|
|
|
+ content: "请填写内容",
|
|
|
|
+ lay_id: "textArea",
|
|
|
|
+ type: "TextArea",
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 设置文档标题
|
|
|
|
+ document.title = data.name
|
|
|
|
+ ? `${data.name}-轻良实业`
|
|
|
|
+ : "新建模块-轻良实业";
|
|
|
|
+
|
|
|
|
+ // 解析属性
|
|
|
|
+ data.attrs = JSON.parse(data.attrs);
|
|
|
|
+
|
|
|
|
+ // 获取公式并更新属性
|
|
|
|
+ const {
|
|
|
|
+ data: { dataList },
|
|
|
|
+ } = await searchFormula({ page: 1, pageSize: 999 });
|
|
|
|
+ data.attrs = data.attrs.map((item) => {
|
|
|
|
+ const formula = dataList.find((el) => el.id === item.data.id);
|
|
|
|
+ return formula
|
|
|
|
+ ? { ...item, formula: formula.formula, data: formula }
|
|
|
|
+ : item;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ this.coms = [data];
|
|
|
|
+ console.log("11", this.coms);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("加载模板信息失败:", error);
|
|
|
|
+ }
|
|
},
|
|
},
|
|
onExport(e) {
|
|
onExport(e) {
|
|
let _this = this;
|
|
let _this = this;
|
|
@@ -1249,100 +1266,130 @@ export default {
|
|
_this.userInfo = res.data;
|
|
_this.userInfo = res.data;
|
|
},
|
|
},
|
|
//加载文档信息
|
|
//加载文档信息
|
|
- onLoadArticle(e) {
|
|
|
|
- let _this = this;
|
|
|
|
- this.loading = true; // Set loading to true
|
|
|
|
- getDocumentInfo({ id: e })
|
|
|
|
- .then((res) => {
|
|
|
|
- this.loading = false; // Set loading to false after data is loaded
|
|
|
|
- if (res.status !== 200) return;
|
|
|
|
- _this.docAttr = {
|
|
|
|
- id: res.data.id,
|
|
|
|
- category_id: res.data.category_id * 1,
|
|
|
|
- title: res.data.title,
|
|
|
|
- content: "",
|
|
|
|
- status: res.data.status,
|
|
|
|
- is_template: res.data.is_template,
|
|
|
|
- linkProduct: res.data.linkProduct,
|
|
|
|
- links: res.data.links,
|
|
|
|
- linkProject: res.data.linkProject,
|
|
|
|
- projects: res.data.projects,
|
|
|
|
- };
|
|
|
|
- const templatePromises = JSON.parse(res.data.data).map((el) => {
|
|
|
|
- return getTemplateInfo({ id: el.id }).then((response) => {
|
|
|
|
- this.loading = true;
|
|
|
|
- response.data.attrs = JSON.parse(response.data.attrs);
|
|
|
|
- return { ...el, ...response.data };
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ async onLoadArticle(id) {
|
|
|
|
+ try {
|
|
|
|
+ this.loading = true;
|
|
|
|
+ const res = await getDocumentInfo({ id });
|
|
|
|
+
|
|
|
|
+ if (res.status !== 200) {
|
|
|
|
+ throw new Error("Invalid response status");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.docAttr = {
|
|
|
|
+ id: res.data.id,
|
|
|
|
+ category_id: Number(res.data.category_id),
|
|
|
|
+ title: res.data.title,
|
|
|
|
+ content: "",
|
|
|
|
+ status: res.data.status,
|
|
|
|
+ is_template: res.data.is_template,
|
|
|
|
+ linkProduct: res.data.linkProduct,
|
|
|
|
+ links: res.data.links,
|
|
|
|
+ linkProject: res.data.linkProject,
|
|
|
|
+ projects: res.data.projects,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const templateData =
|
|
|
|
+ typeof res.data.data === "string"
|
|
|
|
+ ? JSON.parse(res.data.data)
|
|
|
|
+ : res.data.data;
|
|
|
|
|
|
- Promise.all(templatePromises)
|
|
|
|
- .then((updatedComs) => {
|
|
|
|
- _this.coms = updatedComs;
|
|
|
|
- this.loading = false;
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- console.error("Error fetching template info:", error);
|
|
|
|
- this.loading = false;
|
|
|
|
|
|
+ const updatedComs = await Promise.all(
|
|
|
|
+ templateData.map(async (el) => {
|
|
|
|
+ const templateInfo = await getTemplateInfo({ id: el.id });
|
|
|
|
+ const formulaData = await searchFormula({ page: 1, pageSize: 999 });
|
|
|
|
+
|
|
|
|
+ const attrs =
|
|
|
|
+ typeof templateInfo.data.attrs === "string"
|
|
|
|
+ ? JSON.parse(templateInfo.data.attrs)
|
|
|
|
+ : templateInfo.data.attrs;
|
|
|
|
+
|
|
|
|
+ attrs.forEach((item) => {
|
|
|
|
+ const matchedFormula = formulaData.data.dataList.find(
|
|
|
|
+ (ite) => ite.id === item.data.id
|
|
|
|
+ );
|
|
|
|
+ if (matchedFormula) {
|
|
|
|
+ item.data = matchedFormula;
|
|
|
|
+ item.formula = matchedFormula.formula;
|
|
|
|
+ }
|
|
});
|
|
});
|
|
- if (_this.type == "document" && _this.articleId !== undefined) {
|
|
|
|
- document.title = _this.docAttr.title + "-轻良实业";
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- console.error("Error:", error);
|
|
|
|
- })
|
|
|
|
- .finally(() => {
|
|
|
|
- this.loading = false; // 所有操作完成后取消 loading
|
|
|
|
- });
|
|
|
|
|
|
|
|
- this.uptadeSearch();
|
|
|
|
|
|
+ return { ...el, ...templateInfo.data, attrs };
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ this.coms = updatedComs;
|
|
|
|
+ console.log("coms", updatedComs);
|
|
|
|
+
|
|
|
|
+ if (this.type === "document" && this.articleId !== undefined) {
|
|
|
|
+ document.title = `${this.docAttr.title}-轻良实业`;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.uptadeSearch();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error in onLoadArticle:", error);
|
|
|
|
+ } finally {
|
|
|
|
+ this.loading = false;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
/* 加载模版信息 */
|
|
/* 加载模版信息 */
|
|
- onTemplateInfo(e) {
|
|
|
|
- let _this = this;
|
|
|
|
- this.loading = true;
|
|
|
|
- getDocumentInfo({ id: e })
|
|
|
|
- .then((res) => {
|
|
|
|
- this.loading = false; // Set loading to false after data is loaded
|
|
|
|
- if (res.status !== 200) return;
|
|
|
|
- _this.docAttr = {
|
|
|
|
- id: res.data.id,
|
|
|
|
- category_id: res.data.category_id * 1,
|
|
|
|
- title: res.data.title,
|
|
|
|
- content: "",
|
|
|
|
- status: res.data.status,
|
|
|
|
- is_template: res.data.is_template,
|
|
|
|
- linkProduct: res.data.linkProduct,
|
|
|
|
- links: res.data.links,
|
|
|
|
- linkProject: res.data.linkProject,
|
|
|
|
- projects: res.data.projects,
|
|
|
|
- };
|
|
|
|
- const templatePromises = JSON.parse(res.data.data).map((el) => {
|
|
|
|
- return getTemplateInfo({ id: el.id }).then((response) => {
|
|
|
|
- this.loading = true;
|
|
|
|
- response.data.attrs = JSON.parse(response.data.attrs);
|
|
|
|
- return { ...el, ...response.data };
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ async onTemplateInfo(id) {
|
|
|
|
+ try {
|
|
|
|
+ this.loading = true;
|
|
|
|
+ const res = await getDocumentInfo({ id });
|
|
|
|
|
|
- Promise.all(templatePromises)
|
|
|
|
- .then((updatedComs) => {
|
|
|
|
- _this.coms = updatedComs;
|
|
|
|
- this.loading = false;
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- console.error("Error fetching template info:", error);
|
|
|
|
- this.loading = false;
|
|
|
|
|
|
+ if (res.status !== 200) {
|
|
|
|
+ throw new Error("Invalid response status");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.docAttr = {
|
|
|
|
+ id: res.data.id,
|
|
|
|
+ category_id: Number(res.data.category_id),
|
|
|
|
+ title: res.data.title,
|
|
|
|
+ content: "",
|
|
|
|
+ status: res.data.status,
|
|
|
|
+ is_template: res.data.is_template,
|
|
|
|
+ linkProduct: res.data.linkProduct,
|
|
|
|
+ links: res.data.links,
|
|
|
|
+ linkProject: res.data.linkProject,
|
|
|
|
+ projects: res.data.projects,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const templateData = JSON.parse(res.data.data);
|
|
|
|
+
|
|
|
|
+ const updatedComs = await Promise.all(
|
|
|
|
+ templateData.map(async (el) => {
|
|
|
|
+ const templateInfo = await getTemplateInfo({ id: el.id });
|
|
|
|
+ const formulaData = await searchFormula({ page: 1, pageSize: 999 });
|
|
|
|
+
|
|
|
|
+ let attrs = JSON.parse(templateInfo.data.attrs);
|
|
|
|
+
|
|
|
|
+ attrs = attrs.map((item) => {
|
|
|
|
+ const matchedFormula = formulaData.data.dataList.find(
|
|
|
|
+ (ite) => ite.id === item.data.id
|
|
|
|
+ );
|
|
|
|
+ if (matchedFormula) {
|
|
|
|
+ return {
|
|
|
|
+ ...item,
|
|
|
|
+ data: matchedFormula,
|
|
|
|
+ formula: matchedFormula.formula,
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ return item;
|
|
});
|
|
});
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- console.error("Error:", error);
|
|
|
|
- })
|
|
|
|
- .finally(() => {
|
|
|
|
- this.loading = false; // 所有操作完成后取消 loading
|
|
|
|
- });
|
|
|
|
- this.uptadeSearch();
|
|
|
|
|
|
+
|
|
|
|
+ return { ...el, ...templateInfo.data, attrs };
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ this.coms = updatedComs;
|
|
|
|
+ console.log("coms", updatedComs);
|
|
|
|
+
|
|
|
|
+ this.uptadeSearch();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error in onTemplateInfo:", error);
|
|
|
|
+ } finally {
|
|
|
|
+ this.loading = false;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
onRemove(index) {
|
|
onRemove(index) {
|
|
this.coms.splice(index, 1);
|
|
this.coms.splice(index, 1);
|