|
@@ -87,8 +87,8 @@
|
|
|
<div class="left_scheme" v-if="type !== 'module'">
|
|
|
<div class="scheme-header">
|
|
|
<div class="title">
|
|
|
- 请选择可用的方案
|
|
|
- <span class="count">[方案数量:47]</span>
|
|
|
+ 请选择文档
|
|
|
+ <!-- <span class="count">[方案数量:47]</span> -->
|
|
|
<i class="el-icon-menu"></i>
|
|
|
</div>
|
|
|
<div class="search">
|
|
@@ -97,19 +97,21 @@
|
|
|
placeholder="请输入搜索"
|
|
|
prefix-icon="el-icon-search"
|
|
|
clearable
|
|
|
+ @keyup.enter.native="handleSearch"
|
|
|
+ @clear="handleClear"
|
|
|
>
|
|
|
</el-input>
|
|
|
</div>
|
|
|
- <div class="action-btns">
|
|
|
+ <!-- <div class="action-btns">
|
|
|
<el-button type="primary" size="small" @click="createScheme"
|
|
|
>新建方案</el-button
|
|
|
>
|
|
|
<el-button type="primary" size="small" @click="createCategory"
|
|
|
>新建分类</el-button
|
|
|
>
|
|
|
- </div>
|
|
|
+ </div> -->
|
|
|
<div class="current-scheme">
|
|
|
- 当前方案: {{ currentScheme || "已选择方案三" }}
|
|
|
+ 当前文档: {{ currentScheme || "已选择方案三" }}
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -119,9 +121,11 @@
|
|
|
:props="defaultProps"
|
|
|
@node-click="handleNodeClick"
|
|
|
:default-expanded-keys="expandedKeys"
|
|
|
+ node-key="id"
|
|
|
+ ref="documentTree"
|
|
|
>
|
|
|
<span class="custom-tree-node" slot-scope="{ node, data }">
|
|
|
- <span>
|
|
|
+ <span @click="onLoadArticle(data.id)">
|
|
|
<i class="el-icon-folder" v-if="data.children"></i>
|
|
|
<i class="el-icon-document" v-else></i>
|
|
|
{{ node.label }}
|
|
@@ -135,21 +139,23 @@
|
|
|
<div class="natural">
|
|
|
<div class="resource-header-title">
|
|
|
<div class="title-left">
|
|
|
- <span>请选择可用的模块</span>
|
|
|
- <!-- <span class="resource-count">[资源明细] 资源数量:474</span> -->
|
|
|
+ <span>请选择模块</span>
|
|
|
+ <!-- <span class="resource-count">[资源明细] 资源数量:474</span> -->
|
|
|
</div>
|
|
|
<i class="el-icon-menu"></i>
|
|
|
</div>
|
|
|
<div class="resource-container">
|
|
|
<div class="resource-header">
|
|
|
<el-input
|
|
|
- v-model="resourceSearchKey"
|
|
|
+ v-model="templateSearchKey"
|
|
|
placeholder="请输入选择"
|
|
|
prefix-icon="el-icon-search"
|
|
|
clearable
|
|
|
+ @keyup.enter.native="handleTemplateSearch"
|
|
|
+ @clear="handleResourceClear"
|
|
|
>
|
|
|
</el-input>
|
|
|
- <!-- <div class="action-btns">
|
|
|
+ <!-- <div class="action-btns">
|
|
|
<el-button type="primary" @click="createResource"
|
|
|
>新建资源</el-button
|
|
|
>
|
|
@@ -185,12 +191,14 @@
|
|
|
sort: true,
|
|
|
}"
|
|
|
:disabled="type == 'module'"
|
|
|
+ @end="handleDragEnd"
|
|
|
>
|
|
|
<transition-group>
|
|
|
<div
|
|
|
v-for="template in category.templates"
|
|
|
- :key="template.id"
|
|
|
+ :key="template.dcb_id || template.name"
|
|
|
class="resource-item"
|
|
|
+ :data-template-id="template.dcb_id"
|
|
|
>
|
|
|
<el-checkbox
|
|
|
v-model="template.selected"
|
|
@@ -198,42 +206,13 @@
|
|
|
(val) =>
|
|
|
handleTemplateSelect(category, template, val)
|
|
|
"
|
|
|
+ :disabled="isTemplateUsed(template)"
|
|
|
>
|
|
|
- {{ template.name }}
|
|
|
+ {{ template.dcb_name }}
|
|
|
</el-checkbox>
|
|
|
</div>
|
|
|
- <!-- <div
|
|
|
- class="sub-menus min-width-content"
|
|
|
- v-for="(it, index) in category.templates"
|
|
|
- :key="index"
|
|
|
- >
|
|
|
- <div
|
|
|
- :title="it.name"
|
|
|
- style="
|
|
|
- cursor: move;
|
|
|
- white-space: nowrap;
|
|
|
- overflow: hidden; /* 隐藏超出部分 */
|
|
|
- text-overflow: ellipsis; /* 显示省略号 */
|
|
|
- width: 100%;
|
|
|
- "
|
|
|
- >
|
|
|
- {{ it.name }}
|
|
|
- </div>
|
|
|
- </div> -->
|
|
|
</transition-group>
|
|
|
</draggable>
|
|
|
- <!-- <div
|
|
|
- v-for="template in category.templates"
|
|
|
- :key="template.id"
|
|
|
- class="resource-item"
|
|
|
- >
|
|
|
- <el-checkbox
|
|
|
- v-model="template.selected"
|
|
|
- @change="(val) => handleTemplateSelect(category, template, val)"
|
|
|
- >
|
|
|
- {{ template.name }}
|
|
|
- </el-checkbox>
|
|
|
- </div> -->
|
|
|
</div>
|
|
|
</el-collapse-item>
|
|
|
</el-collapse>
|
|
@@ -522,6 +501,19 @@
|
|
|
</el-tab-pane>
|
|
|
<el-tab-pane label="模板内容" name="template">
|
|
|
<div class="template-content">
|
|
|
+
|
|
|
+ <!-- <div class="search-box">
|
|
|
+ <el-input
|
|
|
+ v-model="templateSearchKey"
|
|
|
+ placeholder="搜索模板"
|
|
|
+ @keyup.enter="handleTemplateSearch"
|
|
|
+ clearable
|
|
|
+ @clear="handleTemplateClear"
|
|
|
+ >
|
|
|
+ <i slot="prefix" class="el-input__icon el-icon-search"></i>
|
|
|
+ </el-input>
|
|
|
+ </div> -->
|
|
|
+
|
|
|
<!-- 原有的menus和editor内容 -->
|
|
|
<div class="menus-box">
|
|
|
<menus
|
|
@@ -716,8 +708,7 @@
|
|
|
:model="docForm"
|
|
|
:rules="docRules"
|
|
|
ref="docRef"
|
|
|
- label-position="right"
|
|
|
- label-width="100"
|
|
|
+ label-width="120px"
|
|
|
>
|
|
|
<el-form-item label="文档标题:" prop="dcm_title">
|
|
|
<el-input
|
|
@@ -747,9 +738,21 @@
|
|
|
<el-option label="共享模板" :value="3" />
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
- <!-- <el-form-item label="创建人:">
|
|
|
- {{ userInfo && userInfo.username }}
|
|
|
- </el-form-item> -->
|
|
|
+ <el-form-item label="文档分类:">
|
|
|
+ <el-select
|
|
|
+ v-model="docForm.dcm_category_id"
|
|
|
+ style="width: 60%"
|
|
|
+ placeholder="请选择文档模板类别"
|
|
|
+ :disabled="docAttr.id > 0"
|
|
|
+ ><el-option
|
|
|
+ v-for="(item, index) in articleCategoryList"
|
|
|
+ :key="index"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.id"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ <!-- {{ userInfo && userInfo.username }} -->
|
|
|
+ </el-form-item>
|
|
|
</el-form>
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
<el-button @click="closeDoc">取 消</el-button>
|
|
@@ -826,7 +829,7 @@ export default {
|
|
|
//文档属性
|
|
|
docAttr: {
|
|
|
id: 0,
|
|
|
- category_id: "",
|
|
|
+ dcm_category_id: "",
|
|
|
title: "",
|
|
|
content: "",
|
|
|
status: 5,
|
|
@@ -857,12 +860,16 @@ export default {
|
|
|
docForm: {
|
|
|
dcm_title: "",
|
|
|
dcm_type: "",
|
|
|
+ dcm_category_id: "",
|
|
|
},
|
|
|
docRules: {
|
|
|
dcm_title: [
|
|
|
{ required: true, message: "请输文档名称", trigger: "blur" },
|
|
|
],
|
|
|
dcm_type: [
|
|
|
+ { required: true, message: "请选择文档模板分类", trigger: "change" },
|
|
|
+ ],
|
|
|
+ dcm_category_id: [
|
|
|
{ required: true, message: "请选择文档分类", trigger: "change" },
|
|
|
],
|
|
|
},
|
|
@@ -872,30 +879,7 @@ export default {
|
|
|
searchKey: "",
|
|
|
currentScheme: "",
|
|
|
expandedKeys: [], // 默认展开的节点
|
|
|
- schemeData: [
|
|
|
- {
|
|
|
- label: "LED项目",
|
|
|
- children: [],
|
|
|
- },
|
|
|
- {
|
|
|
- label: "LCD项目",
|
|
|
- children: [],
|
|
|
- },
|
|
|
- {
|
|
|
- label: "集成项目",
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: "方案一",
|
|
|
- },
|
|
|
- {
|
|
|
- label: "方案二",
|
|
|
- },
|
|
|
- {
|
|
|
- label: "方案三",
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
+ schemeData: [],
|
|
|
defaultProps: {
|
|
|
children: "children",
|
|
|
label: "label",
|
|
@@ -935,7 +919,7 @@ export default {
|
|
|
{
|
|
|
label: "1.1. 强大的显示功能",
|
|
|
children: [
|
|
|
- { label: "1.1.1. 计算机信号显示" },
|
|
|
+ { label: "1.1.1. 计算���信号显示" },
|
|
|
{ label: "1.1.2. 视频信号显示" },
|
|
|
{ label: "1.1.3. 海量流媒体信号接入" },
|
|
|
{ label: "1.1.4. 网络信号显示" },
|
|
@@ -960,6 +944,8 @@ export default {
|
|
|
children: "children",
|
|
|
label: "label",
|
|
|
},
|
|
|
+ templateSearchKey: "", // 添加模板搜索关键字
|
|
|
+ originalTemplateList: [], // 保存原始模板列表
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
@@ -1017,6 +1003,8 @@ export default {
|
|
|
arrow.style.margin = "0";
|
|
|
});
|
|
|
});
|
|
|
+ this.initTemplateSelection();
|
|
|
+ this.expandedKeys = []; // 初始化展开节点数组
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
@@ -1094,8 +1082,9 @@ export default {
|
|
|
},
|
|
|
/* 方案点击 */
|
|
|
handleNodeClick(data) {
|
|
|
+ console.log(data);
|
|
|
this.currentScheme = data.label;
|
|
|
- this.resourceDialogVisible = true; // 点击方案时打开资源选择弹框
|
|
|
+ this.resourceDialogVisible = true; // 点击方案时打开资���选择弹框
|
|
|
},
|
|
|
|
|
|
createScheme() {
|
|
@@ -1188,6 +1177,7 @@ export default {
|
|
|
this.docForm = {
|
|
|
dcm_title: "",
|
|
|
dcm_type: "",
|
|
|
+ dcm_category_id: "",
|
|
|
};
|
|
|
},
|
|
|
/* 确定新增模块*/
|
|
@@ -1196,6 +1186,7 @@ export default {
|
|
|
if (valid) {
|
|
|
this.docAttr.dcm_title = this.docForm.dcm_title;
|
|
|
this.docAttr.dcm_type = this.docForm.dcm_type;
|
|
|
+ this.docAttr.dcm_category_id = this.docForm.dcm_category_id;
|
|
|
this.onSave();
|
|
|
}
|
|
|
});
|
|
@@ -1211,9 +1202,9 @@ export default {
|
|
|
);
|
|
|
},
|
|
|
updateAttrs(newComs, oldComs) {
|
|
|
- console.log(newComs);
|
|
|
newComs.forEach((newCom, comIndex) => {
|
|
|
const oldCom = oldComs[comIndex];
|
|
|
+ console.log("oldCom:", oldCom, "newCom:", newCom);
|
|
|
if (oldCom) {
|
|
|
newCom.attrs.forEach((newAttr, attrIndex) => {
|
|
|
const oldAttr = oldCom.attrs[attrIndex];
|
|
@@ -1229,6 +1220,7 @@ export default {
|
|
|
updateGlobalAttr(attrId, newContent) {
|
|
|
// 遍历所有组件,更新匹配的属性
|
|
|
this.coms.forEach((com) => {
|
|
|
+ console.log(com);
|
|
|
com.attrs.forEach((attr) => {
|
|
|
// 只更新非 variableNull 类型的属性
|
|
|
if (attr.name === attrId && attr.type !== "variableNull") {
|
|
@@ -1237,7 +1229,7 @@ export default {
|
|
|
});
|
|
|
|
|
|
// 如果是文本区域,更新内容中的占位符
|
|
|
- if (com.type === "TextArea") {
|
|
|
+ if (com.dcb_type === "TextArea") {
|
|
|
com.content = com.content.replace(
|
|
|
new RegExp(`{{${attrId}}}`, "g"),
|
|
|
(match) => {
|
|
@@ -1466,7 +1458,7 @@ export default {
|
|
|
viewModule() {
|
|
|
this.showView = 1;
|
|
|
},
|
|
|
- /* 更新变量 */
|
|
|
+ /* 更新变��� */
|
|
|
/* uptadeVariable(value) {
|
|
|
for (const item of this.coms) {
|
|
|
for (const el of item.attrs) {
|
|
@@ -1557,14 +1549,14 @@ export default {
|
|
|
try {
|
|
|
// 获取模板信息
|
|
|
const { data } = await getTemplateInfo(id);
|
|
|
-
|
|
|
+ console.log(!data.dcb_attrs || !data.dcb_type);
|
|
|
// 设置默认值
|
|
|
- if (!data.attrs || !data.type) {
|
|
|
+ if (!data.dcb_attrs || !data.dcb_type) {
|
|
|
Object.assign(data, {
|
|
|
- attrs: "[]",
|
|
|
- content: "请填写内容",
|
|
|
+ dcb_attrs: "[]",
|
|
|
+ dcb_nr: "请填写内容",
|
|
|
lay_id: "textArea",
|
|
|
- type: "TextArea",
|
|
|
+ dcb_type: "TextArea",
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -1574,26 +1566,31 @@ export default {
|
|
|
: "新建模块-" + settings.title;
|
|
|
|
|
|
// 解析属性
|
|
|
- data.attrs = JSON.parse(data.attrs);
|
|
|
-
|
|
|
+ data.dcb_attrs = JSON.parse(data.dcb_attrs);
|
|
|
+ data.content = data.dcb_nr;
|
|
|
+ data.type = data.dcb_type;
|
|
|
+ data.name = data.dcb_name;
|
|
|
+ data.attrs = data.dcb_attrs;
|
|
|
// 获取公式并更新属性
|
|
|
const {
|
|
|
data: { dataList },
|
|
|
} = await searchFormula({ page: 1, pageSize: 999 });
|
|
|
console.log(data);
|
|
|
- data.attrs = data.attrs.map((item) => {
|
|
|
+ data.dcb_attrs = data.dcb_attrs.map((item) => {
|
|
|
const formula = dataList.find((el) => el.id === item.id);
|
|
|
return formula
|
|
|
? { ...item, formula: formula.formula, data: formula }
|
|
|
: item;
|
|
|
});
|
|
|
// 从 content 中提取 {{}} 包裹的 ID
|
|
|
- const contentIds = (data.content.match(/{{([^}]+)}}/g) || []).map(
|
|
|
+ const contentIds = (data.dcb_nr.match(/{{([^}]+)}}/g) || []).map(
|
|
|
(match) => match.slice(2, -2).trim()
|
|
|
);
|
|
|
|
|
|
- // 过滤 attrs,只保留在 content 中出现的 ID
|
|
|
- data.attrs = data.attrs.filter((item) => contentIds.includes(item.id));
|
|
|
+ // 过滤 attrs,只保留在 content 中出��的 ID
|
|
|
+ data.dcb_attrs = data.dcb_attrs.filter((item) =>
|
|
|
+ contentIds.includes(item.id)
|
|
|
+ );
|
|
|
|
|
|
this.coms = [data];
|
|
|
} catch (error) {
|
|
@@ -1666,6 +1663,9 @@ export default {
|
|
|
async onLoadArticle(id) {
|
|
|
try {
|
|
|
this.loading = true;
|
|
|
+ // 在加载文档前重置所有模板状态
|
|
|
+ this.resetAllTemplateSelections();
|
|
|
+
|
|
|
const res = await getDocumentInfo(id);
|
|
|
|
|
|
if (res.status !== 200) {
|
|
@@ -1675,6 +1675,7 @@ export default {
|
|
|
this.docAttr = {
|
|
|
dcm_id: res.data.dcm_id,
|
|
|
dcm_type: Number(res.data.dcm_type),
|
|
|
+ dcm_category_id: res.data.dcm_category_id,
|
|
|
dcm_title: res.data.dcm_title,
|
|
|
content: "",
|
|
|
status: res.data.status,
|
|
@@ -1684,12 +1685,18 @@ export default {
|
|
|
linkProject: res.data.linkProject,
|
|
|
projects: res.data.projects,
|
|
|
};
|
|
|
+ // 同时更新 docForm
|
|
|
+ this.docForm = {
|
|
|
+ dcm_title: res.data.dcm_title,
|
|
|
+ dcm_type: Number(res.data.dcm_type),
|
|
|
+ dcm_category_id: res.data.dcm_category_id, // 确保这个字段也被设置
|
|
|
+ };
|
|
|
|
|
|
const templateData =
|
|
|
typeof res.data.dcm_data === "string"
|
|
|
? JSON.parse(res.data.dcm_data)
|
|
|
: res.data.dcm_data;
|
|
|
-
|
|
|
+
|
|
|
const updatedComs = await Promise.all(
|
|
|
templateData.map(async (el) => {
|
|
|
/* let templateInfo = { data: {} };
|
|
@@ -1727,6 +1734,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
this.uptadeSearch();
|
|
|
+ this.initTemplateSelection();
|
|
|
} catch (error) {
|
|
|
console.error("Error in onLoadArticle:", error);
|
|
|
} finally {
|
|
@@ -1737,6 +1745,9 @@ export default {
|
|
|
async onTemplateInfo(id) {
|
|
|
try {
|
|
|
this.loading = true;
|
|
|
+ // 在加载模板前重置所有模板状态
|
|
|
+ this.resetAllTemplateSelections();
|
|
|
+
|
|
|
// 获取文档信息
|
|
|
const res = await getDocumentInfo({ id });
|
|
|
|
|
@@ -1775,7 +1786,7 @@ export default {
|
|
|
|
|
|
// 使用模板的 content 作为基础
|
|
|
let content = templateInfo.data.content;
|
|
|
- // 使用模板的 attrs 作为基础,但排除 Directory 类型
|
|
|
+ // 使用模板的 attrs 作为基础,���排除 Directory 类型
|
|
|
let attrs = templateInfo.data.attrs
|
|
|
? JSON.parse(templateInfo.data.attrs).filter(
|
|
|
(attr) => attr.type !== "Directory"
|
|
@@ -1845,6 +1856,7 @@ export default {
|
|
|
document.title = `${this.docAttr.title}-${settings.title}`;
|
|
|
}
|
|
|
this.uptadeSearch();
|
|
|
+ this.initTemplateSelection();
|
|
|
} catch (error) {
|
|
|
console.error("加载模板信息时出错:", error);
|
|
|
this.$message.error("加载模板信息时出错,请稍后重试");
|
|
@@ -1853,7 +1865,20 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
onRemove(index) {
|
|
|
+ const removedComponent = this.coms[index];
|
|
|
+ // 移除组件
|
|
|
this.coms.splice(index, 1);
|
|
|
+
|
|
|
+ // 如果是从模板创建的组件,更新对应模板的选中状态
|
|
|
+ if (removedComponent.dcb_id) {
|
|
|
+ const template = this.categoryList
|
|
|
+ .flatMap((category) => category.templates || [])
|
|
|
+ .find((t) => t.dcb_id === removedComponent.dcb_id);
|
|
|
+
|
|
|
+ if (template) {
|
|
|
+ this.updateTemplateSelection(template, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
/* 目录信息 */
|
|
|
onCatalogIndex(e) {
|
|
@@ -1957,6 +1982,7 @@ export default {
|
|
|
_this.docForm = {
|
|
|
dcm_title: "",
|
|
|
dcm_type: "",
|
|
|
+ dcm_category_id: "",
|
|
|
};
|
|
|
_this.searchArticle();
|
|
|
});
|
|
@@ -1970,12 +1996,13 @@ export default {
|
|
|
_this.docForm = {
|
|
|
dcm_title: "",
|
|
|
dcm_type: "",
|
|
|
+ dcm_category_id: "",
|
|
|
};
|
|
|
_this.searchArticle();
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- /*更新 */
|
|
|
+ /*更�� */
|
|
|
onUpload() {
|
|
|
let _this = this;
|
|
|
if (_this.coms.length <= 0) {
|
|
@@ -2282,8 +2309,18 @@ export default {
|
|
|
|
|
|
//插入新记录
|
|
|
insertNew(e) {
|
|
|
- let _this = this;
|
|
|
- _this.coms.push(e);
|
|
|
+ this.coms.push(e);
|
|
|
+
|
|
|
+ // 如果是从模板拖拽的,更新模板选中状态
|
|
|
+ if (e.dcb_id) {
|
|
|
+ const template = this.categoryList
|
|
|
+ .flatMap((category) => category.templates || [])
|
|
|
+ .find((t) => t.dcb_id === e.dcb_id);
|
|
|
+
|
|
|
+ if (template) {
|
|
|
+ this.updateTemplateSelection(template, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
//插入分页
|
|
@@ -2374,7 +2411,7 @@ export default {
|
|
|
let _this = this;
|
|
|
// console.log("insertconstant");
|
|
|
if (_this.comIndex < 0) {
|
|
|
- _this.$alert("请选择插入图层");
|
|
|
+ _this.$alert("请选择��入图层");
|
|
|
return false;
|
|
|
}
|
|
|
let com = _this.coms[_this.comIndex];
|
|
@@ -2595,32 +2632,401 @@ export default {
|
|
|
},
|
|
|
|
|
|
//获取文档模板列表
|
|
|
- searchArticle() {
|
|
|
- let _this = this;
|
|
|
- pageDocument({
|
|
|
- page: 1,
|
|
|
- pageSize: 99,
|
|
|
- isContentShow: true,
|
|
|
- }).then((res) => {
|
|
|
- if (res.status != 200) return;
|
|
|
- this.articleList = res.data.dataList;
|
|
|
- /* _this.articleList = res.data.dataList.filter(
|
|
|
- (el) => el.is_template == 0
|
|
|
- );
|
|
|
- _this.templateList = res.data.dataList.filter(
|
|
|
- (el) => el.is_template == 1
|
|
|
- ); */
|
|
|
- });
|
|
|
+ async searchArticle() {
|
|
|
+ try {
|
|
|
+ // 获取文档分类
|
|
|
+ const categoryRes = await searchDocumentCategory({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 999,
|
|
|
+ });
|
|
|
+ if (categoryRes.status !== 200) return;
|
|
|
+
|
|
|
+ // 获取文档列表
|
|
|
+ const documentRes = await pageDocument({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 99,
|
|
|
+ isContentShow: true,
|
|
|
+ });
|
|
|
+ if (documentRes.status !== 200) return;
|
|
|
+
|
|
|
+ // 处理数据为树形结构
|
|
|
+ this.schemeData = categoryRes.data.dataList.map((category) => ({
|
|
|
+ label: category.name,
|
|
|
+ id: category.id,
|
|
|
+ children: documentRes.data.dataList
|
|
|
+ .filter((doc) => doc.dcm_category_id === category.id)
|
|
|
+ .map((doc) => ({
|
|
|
+ label: doc.dcm_title,
|
|
|
+ id: doc.dcm_id,
|
|
|
+ type: "document",
|
|
|
+ })),
|
|
|
+ }));
|
|
|
+
|
|
|
+ // 更新默认展开的节点 - 展开所有分类
|
|
|
+ this.expandedKeys = this.schemeData.map((category) => category.id);
|
|
|
+
|
|
|
+ console.log("Processed schemeData:", this.schemeData);
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error processing document data:", error);
|
|
|
+ this.$message.error("获取文档数据失败");
|
|
|
+ }
|
|
|
},
|
|
|
// 添加模板选择处理方法
|
|
|
- handleTemplateSelect(category, template, value) {
|
|
|
+ /* handleTemplateSelect(category, template, value) {
|
|
|
template.selected = value;
|
|
|
console.log("Selected template:", {
|
|
|
category: category.name,
|
|
|
- template: template.name,
|
|
|
+ template: template.dcb_name,
|
|
|
selected: value,
|
|
|
});
|
|
|
// 这里可以添加其他选择逻辑
|
|
|
+ }, */
|
|
|
+ // 检查模板是否已被使用
|
|
|
+ isTemplateUsed(template) {
|
|
|
+ const isUsed = this.coms.some((com) => com.dcb_id === template.dcb_id);
|
|
|
+ if (isUsed) {
|
|
|
+ // 如果模板被使用,设置 selected 为 true
|
|
|
+ template.selected = true;
|
|
|
+
|
|
|
+ // 同步其他分类中相同模板的选中状态
|
|
|
+ this.categoryList.forEach((category) => {
|
|
|
+ const sameTemplate = category.templates?.find(
|
|
|
+ (t) => t.dcb_id === template.dcb_id
|
|
|
+ );
|
|
|
+ if (sameTemplate) {
|
|
|
+ sameTemplate.selected = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /* return isUsed; */
|
|
|
+ },
|
|
|
+ // 处理模板选择
|
|
|
+ handleTemplateSelect(category, template, isSelected) {
|
|
|
+ // 更新模板选中状态
|
|
|
+ template.selected = isSelected;
|
|
|
+
|
|
|
+ if (isSelected) {
|
|
|
+ // 如果是选中,添加到组件列表
|
|
|
+ /* const newComponent = {
|
|
|
+ ...template,
|
|
|
+ type: template.dcb_type || "TextArea",
|
|
|
+ lay_id: template.lay_id || "textArea",
|
|
|
+ content: template.dcb_nr || "",
|
|
|
+ attrs:
|
|
|
+ typeof template.dcb_attrs === "string"
|
|
|
+ ? JSON.parse(template.dcb_attrs)
|
|
|
+ : template.dcb_attrs || [],
|
|
|
+ };
|
|
|
+ this.coms.push(newComponent); */
|
|
|
+ } else {
|
|
|
+ // 如果取消选中,从组件列表中移除
|
|
|
+ const index = this.coms.findIndex(
|
|
|
+ (com) => com.dcb_id === template.dcb_id
|
|
|
+ );
|
|
|
+ if (index !== -1) {
|
|
|
+ this.coms.splice(index, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步其他分类中相同模板的选中状态
|
|
|
+ this.categoryList.forEach((cat) => {
|
|
|
+ if (cat.id !== category.id) {
|
|
|
+ const sameTemplate = cat.templates?.find(
|
|
|
+ (t) => t.dcb_id === template.dcb_id
|
|
|
+ );
|
|
|
+ if (sameTemplate) {
|
|
|
+ sameTemplate.selected = isSelected;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 初始化模板选中状态
|
|
|
+ initTemplateSelection() {
|
|
|
+ // 先重置所有选中状态
|
|
|
+ this.resetAllTemplateSelections();
|
|
|
+
|
|
|
+ // 然后根据已渲染组件更新选中状态
|
|
|
+ this.coms.forEach((com) => {
|
|
|
+ this.categoryList.forEach((category) => {
|
|
|
+ const template = category.templates?.find(
|
|
|
+ (t) => t.dcb_id === com.dcb_id
|
|
|
+ );
|
|
|
+ if (template) {
|
|
|
+ template.selected = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 修改后的 handleDragEnd 方法
|
|
|
+ handleDragEnd(evt) {
|
|
|
+ // 检查是否是克隆操作
|
|
|
+ if (!evt || !evt.item || evt.pullMode !== "clone") {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取拖拽的数据
|
|
|
+ const draggedData = evt.item.dataset;
|
|
|
+ if (!draggedData) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从拖拽的DOM元素中获取模板ID
|
|
|
+ const templateId = evt.item.getAttribute("data-template-id");
|
|
|
+ if (!templateId) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找对应的模板
|
|
|
+ const draggedTemplate = this.categoryList
|
|
|
+ .flatMap((category) => category.templates || [])
|
|
|
+ .find((template) => template.dcb_id === templateId);
|
|
|
+
|
|
|
+ if (draggedTemplate) {
|
|
|
+ this.updateTemplateSelection(draggedTemplate, true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 更新模板选中状态的通用方法
|
|
|
+ updateTemplateSelection(template, isSelected) {
|
|
|
+ // 更新所有分类中相同模板的选中状态
|
|
|
+ this.categoryList.forEach((category) => {
|
|
|
+ const sameTemplate = category.templates?.find(
|
|
|
+ (t) => t.dcb_id === template.dcb_id
|
|
|
+ );
|
|
|
+ if (sameTemplate) {
|
|
|
+ sameTemplate.selected = isSelected;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 添加重置所有模板选中状态的方法
|
|
|
+ resetAllTemplateSelections() {
|
|
|
+ this.categoryList.forEach((category) => {
|
|
|
+ if (category.templates) {
|
|
|
+ category.templates.forEach((template) => {
|
|
|
+ template.selected = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 处理搜索
|
|
|
+ async handleSearch() {
|
|
|
+ if (!this.searchKey.trim()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ this.loading = true;
|
|
|
+ const res = await pageDocument({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 999,
|
|
|
+ dcm_title: this.searchKey.trim(),
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res.status === 200) {
|
|
|
+ // 更新树形数据
|
|
|
+ const searchResults = res.data.dataList.map((doc) => ({
|
|
|
+ id: doc.dcm_id,
|
|
|
+ label: doc.dcm_title,
|
|
|
+ children: null,
|
|
|
+ }));
|
|
|
+
|
|
|
+ const searchResultNode = {
|
|
|
+ id: "search-result", // 为搜索结果节点添加唯一ID
|
|
|
+ label: "搜索结果",
|
|
|
+ children: searchResults,
|
|
|
+ };
|
|
|
+
|
|
|
+ // 更新树形数据
|
|
|
+ this.schemeData = [
|
|
|
+ searchResultNode,
|
|
|
+ /* ...this.schemeData.filter(item => item.label !== "搜索结果") */
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 更新需要展开的节点keys
|
|
|
+ this.expandedKeys = [
|
|
|
+ "search-result", // 展开搜索结果分类
|
|
|
+ ...searchResults.map((item) => item.id), // 展开所有搜索结果项
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 强制更新树形组件
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.documentTree) {
|
|
|
+ this.$refs.documentTree.store.defaultExpandedKeys =
|
|
|
+ this.expandedKeys;
|
|
|
+ this.$refs.documentTree.updateKeyChildren();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果没有搜索结果,显示提示
|
|
|
+ if (searchResults.length === 0) {
|
|
|
+ this.$message.info("未找到匹配的文档");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("搜索文档失败:", error);
|
|
|
+ this.$message.error("搜索失败,请重试");
|
|
|
+ } finally {
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 修改清空处理方法
|
|
|
+ async handleClear() {
|
|
|
+ this.searchKey = "";
|
|
|
+ this.expandedKeys = []; // 清空展开的节点
|
|
|
+ await this.searchArticle();
|
|
|
+
|
|
|
+ // 重置树形组件的展开状态
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.documentTree) {
|
|
|
+ this.$refs.documentTree.store.defaultExpandedKeys = [];
|
|
|
+ this.$refs.documentTree.updateKeyChildren();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 添加搜索处理方法
|
|
|
+ async handleResourceSearch() {
|
|
|
+ /* const searchKey = this.resourceSearchKey.toLowerCase().trim();
|
|
|
+
|
|
|
+ // 遍历所有分类
|
|
|
+ this.categoryList.forEach(category => {
|
|
|
+ if (category.templates) {
|
|
|
+ // 过滤模板列表
|
|
|
+ const filteredTemplates = category.templates.filter(template =>
|
|
|
+ template.dcb_name.toLowerCase().includes(searchKey)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 使用 Vue.set 确保响应式更新
|
|
|
+ this.$set(category, 'templates', filteredTemplates);
|
|
|
+ }
|
|
|
+ }); */
|
|
|
+ if (!this.templateSearchKey.trim()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 调用搜索模板接口
|
|
|
+ const res = await searchTemplate({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 999,
|
|
|
+ dcb_name: this.templateSearchKey.trim(),
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res.status === 200) {
|
|
|
+ // 保存当前分类的原始模板
|
|
|
+ this.originalTemplateList = [...this.categoryList];
|
|
|
+
|
|
|
+ // 处理搜索结果
|
|
|
+ const searchResults = res.data.dataList.map((template) => {
|
|
|
+ // 确保模板数据格式正确
|
|
|
+ if (!template.attrs) {
|
|
|
+ template.attrs = "[]";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ template.attrs =
|
|
|
+ typeof template.attrs === "string"
|
|
|
+ ? JSON.parse(template.attrs)
|
|
|
+ : template.attrs;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error parsing template attrs:", error);
|
|
|
+ template.attrs = [];
|
|
|
+ }
|
|
|
+ return template;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新分类列表,将搜索结果放在一个特殊分类下
|
|
|
+ this.categoryList = [
|
|
|
+ {
|
|
|
+ id: "search-results",
|
|
|
+ name: "搜索结果",
|
|
|
+ templates: searchResults.map((template) => ({
|
|
|
+ ...template,
|
|
|
+ selected: this.coms.some(
|
|
|
+ (com) => com.dcb_id === template.dcb_id
|
|
|
+ ),
|
|
|
+ })),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("搜索模板失败:", error);
|
|
|
+ this.$message.error("搜索失败,请重试");
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 添加清除搜索处理方法
|
|
|
+ handleResourceClear() {
|
|
|
+ // 重置搜索并恢复原始列表
|
|
|
+ this.resourceSearchKey = "";
|
|
|
+ this.initCategoryList();
|
|
|
+ },
|
|
|
+ // 处理模板搜索
|
|
|
+ async handleTemplateSearch() {
|
|
|
+ /* if (!this.templateSearchKey.trim()) {
|
|
|
+ return;
|
|
|
+ } */
|
|
|
+ console.log(12);
|
|
|
+ try {
|
|
|
+ // 调用搜索模板接口
|
|
|
+ const res = await searchTemplate({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 999,
|
|
|
+ dcb_name: this.templateSearchKey.trim(),
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res.status === 200) {
|
|
|
+ // 保存当前分类的原始模板
|
|
|
+ this.originalTemplateList = [...this.categoryList];
|
|
|
+
|
|
|
+ // 处理搜索结果
|
|
|
+ const searchResults = res.data.dataList.map((template) => {
|
|
|
+ // 确保模板数据格式正确
|
|
|
+ if (!template.attrs) {
|
|
|
+ template.attrs = "[]";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ template.attrs =
|
|
|
+ typeof template.attrs === "string"
|
|
|
+ ? JSON.parse(template.attrs)
|
|
|
+ : template.attrs;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error parsing template attrs:", error);
|
|
|
+ template.attrs = [];
|
|
|
+ }
|
|
|
+ return template;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新分类列表,将搜索结果放在一个特殊分类下
|
|
|
+ this.categoryList = [
|
|
|
+ {
|
|
|
+ id: "search-results",
|
|
|
+ name: "搜索结果",
|
|
|
+ templates: searchResults.map((template) => ({
|
|
|
+ ...template,
|
|
|
+ selected: this.coms.some(
|
|
|
+ (com) => com.dcb_id === template.dcb_id
|
|
|
+ ),
|
|
|
+ })),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("搜索模板失败:", error);
|
|
|
+ this.$message.error("搜索失败,请重试");
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 清空搜索
|
|
|
+ async handleTemplateClear() {
|
|
|
+ this.templateSearchKey = "";
|
|
|
+ // 如果有保存的原始列表,恢复它
|
|
|
+ if (this.originalTemplateList.length > 0) {
|
|
|
+ this.categoryList = [...this.originalTemplateList];
|
|
|
+ } else {
|
|
|
+ // 否则重新初始化分类列表
|
|
|
+ await this.initCategoryList();
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
};
|
|
@@ -2708,4 +3114,15 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.template-content {
|
|
|
+ .search-box {
|
|
|
+ padding: 10px;
|
|
|
+ border-bottom: 1px solid #ebeef5;
|
|
|
+
|
|
|
+ .el-input {
|
|
|
+ width: 300px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|