Ver Fonte

修改问题

yangg há 5 meses atrás
pai
commit
1ec99ff742

+ 4 - 2
ui/src/views/system/document/com/editor.vue

@@ -198,7 +198,9 @@ export default {
               item.content !== currentCom.content ||
               item.dcb_nr !== currentCom.dcb_nr ||
               JSON.stringify(item.attrs) !== JSON.stringify(currentCom.attrs) ||
-              JSON.stringify(item.dcb_attrs) !== JSON.stringify(currentCom.dcb_attrs)
+              JSON.stringify(item.dcb_attrs) !== JSON.stringify(currentCom.dcb_attrs)||
+              item.isEdit!==currentCom.isEdit||
+              item!==currentCom
             );
           });
 
@@ -226,7 +228,7 @@ export default {
               name: item.dcb_name || item.name,
             };
           });
-
+          console.log("comList:",this.comList);
           // 使用 Vue.set 更新整个数组
           this.$set(this, 'comList', processedComs);
           // 仅在数据确实发生变化时才触发父组件更新

+ 1 - 1
ui/src/views/system/document/com/view.vue

@@ -16,7 +16,7 @@
     </div>
     <div class="export">
       <el-button
-        @click="onExport"
+        @click="onExports"
         type="primary"
         :loading="exporting"
         :disabled="exporting"

+ 188 - 156
ui/src/views/system/document/create.vue

@@ -521,7 +521,8 @@
                   :props="{ children: 'children', label: 'label' }"
                   node-key="id"
                   draggable
-                  @node-drag-end="handleDirectoryDragEnd">
+                  @node-drag-end="handleDirectoryDragEnd"
+                >
                   <span class="custom-tree-node" slot-scope="{ node, data }">
                     <template v-if="data.isEditing">
                       <el-input
@@ -533,12 +534,15 @@
                       />
                     </template>
                     <template v-else>
-                      <span @dblclick="handleDirectoryEdit(data)">{{ data.label }}</span>
+                      <span @dblclick="handleDirectoryEdit(data)">{{
+                        data.label
+                      }}</span>
                       <span class="directory-actions">
                         <el-button
                           type="text"
                           size="mini"
-                          @click="handleDirectoryEdit(data)">
+                          @click="handleDirectoryEdit(data)"
+                        >
                           编辑
                         </el-button>
                       </span>
@@ -635,34 +639,32 @@
                       <span class="label">模块名称:</span>
                       <span class="value">{{ it.dcb_name }}</span>
                     </div>
-                    <!-- 替换原有按钮组为下拉菜单 -->
                   </div>
                 </div>
                 <div class="module-actions">
-                  <el-dropdown trigger="click">
-                    <el-button circle icon="el-icon-more"></el-button>
-                    <el-dropdown-menu slot="dropdown">
-                      <el-dropdown-item
-                        v-if="type !== 'document'"
-                        @click.native="onSaveTemplate(it)"
-                      >
-                        <i class="el-icon-document-add"></i> 保存模块
-                      </el-dropdown-item>
-                      <el-dropdown-item
-                        @click.native="onEdit(index, it.isEdit !== 1 ? 1 : 2)"
-                      >
-                        <i
-                          :class="
-                            it.isEdit !== 1 ? 'el-icon-edit' : 'el-icon-view'
-                          "
-                        ></i>
-                        {{ it.isEdit !== 1 ? "编辑" : "预览" }}
-                      </el-dropdown-item>
-                      <el-dropdown-item @click.native="onRemove(index)">
-                        <i class="el-icon-delete"></i> 删除
-                      </el-dropdown-item>
-                    </el-dropdown-menu>
-                  </el-dropdown>
+                  <el-button
+                    v-if="type !== 'document'"
+                    type="text"
+                    size="mini"
+                    @click="onSaveTemplate(it)"
+                  >
+                    <i class="el-icon-document-add"></i> 保存
+                  </el-button>
+                  <el-button
+                    type="text"
+                    size="mini"
+                    @click="onEdit(index, it.isEdit !== 1 ? 1 : 2)"
+                  >
+                    <i :class="it.isEdit !== 1 ? 'el-icon-edit' : 'el-icon-view'"></i>
+                    {{ it.isEdit !== 1 ? "编辑" : "预览" }}
+                  </el-button>
+                  <el-button
+                    type="text"
+                    size="mini"
+                    @click="onRemove(index)"
+                  >
+                    <i class="el-icon-delete"></i> 删除
+                  </el-button>
                 </div>
               </div>
             </template>
@@ -1133,19 +1135,21 @@ export default {
     // 更新目录数据
     updateCatalog(modules) {
       let catalogData = [];
-      
+
       modules.forEach((module, moduleIndex) => {
         // 获取并排序目录类型的属性
         const directoryAttrs = module.attrs
-          .filter(attr => attr.type === "Directory")
+          .filter((attr) => attr.type === "Directory")
           .sort((a, b) => {
             // 首先按层级排序
             if (a.level !== b.level) return a.level - b.level;
             // 同层级按编号自然排序
-            return a.number.localeCompare(b.number, undefined, { numeric: true });
+            return a.number.localeCompare(b.number, undefined, {
+              numeric: true,
+            });
           });
 
-        directoryAttrs.forEach(attr => {
+        directoryAttrs.forEach((attr) => {
           const catalogItem = {
             id: attr.id,
             label: `${attr.number} ${attr.content}`,
@@ -1154,7 +1158,7 @@ export default {
             content: attr.content,
             number: attr.number,
             children: [],
-            isEditing: false
+            isEditing: false,
           };
 
           // 根据level确定目录层级
@@ -1176,11 +1180,11 @@ export default {
 
     // 添加 findParentDirectory 辅助方法
     findParentDirectory(catalogData, number) {
-      const parentNumber = number.split('.').slice(0, -1).join('.');
-      
+      const parentNumber = number.split(".").slice(0, -1).join(".");
+
       const findInChildren = (items) => {
         for (let item of items) {
-          if (item.label.startsWith(parentNumber + ' ')) {
+          if (item.label.startsWith(parentNumber + " ")) {
             return item;
           }
           if (item.children) {
@@ -1779,22 +1783,22 @@ export default {
       try {
         // 深拷贝以避免引用问题
         const newComList = JSON.parse(JSON.stringify(comList));
-        
+
         // 确保每个组件的属性都被正确处理
-        newComList.forEach(com => {
+        newComList.forEach((com) => {
           // 确保 dcb_attrs 是数组
           if (!Array.isArray(com.dcb_attrs)) {
             com.dcb_attrs = [];
           }
-          
+
           // 确保 attrs 是数组
           if (!Array.isArray(com.attrs)) {
             com.attrs = [];
           }
 
           // 处理其他必要的属性
-          com.content = com.content || com.dcb_nr || '';
-          com.dcb_nr = com.content || com.dcb_nr || '';
+          com.content = com.content || com.dcb_nr || "";
+          com.dcb_nr = com.content || com.dcb_nr || "";
           com.type = com.dcb_type || com.type;
           com.name = com.dcb_name || com.name;
         });
@@ -1805,17 +1809,17 @@ export default {
         // 保存到本地存储
         this.saveToLocalStorage();
       } catch (error) {
-        console.error('重建组件时出错:', error);
-        this.$message.error('重建组件失败:' + error.message);
+        console.error("重建组件时出错:", error);
+        this.$message.error("重建组件失败:" + error.message);
       }
     },
 
     // 添加一个保存到本地存储的方法
     saveToLocalStorage() {
       try {
-        localStorage.setItem('document_coms', JSON.stringify(this.coms));
+        localStorage.setItem("document_coms", JSON.stringify(this.coms));
       } catch (error) {
-        console.warn('保存到本地存储失败:', error);
+        console.warn("保存到本地存储失败:", error);
       }
     },
 
@@ -2411,10 +2415,13 @@ export default {
 
       const com = this.coms[this.comIndex];
       const currentLevel = e.content.level || 1;
-      
+
       try {
         // 生成目录编号和内容
-        const { number, content } = this.generateDirectoryItem(this.comIndex, currentLevel);
+        const { number, content } = this.generateDirectoryItem(
+          this.comIndex,
+          currentLevel
+        );
         console.log(number);
         const directoryItem = {
           type: "Directory",
@@ -2424,26 +2431,26 @@ export default {
           number,
           content: content || "新建目录项",
           level: currentLevel,
-          moduleIndex: this.comIndex
+          moduleIndex: this.comIndex,
         };
 
         com.attrs.push(directoryItem);
-        
+
         // 更新文本内容
         this.insertCmd = {
-          content: `{{${directoryItem.id}}}`
+          content: `{{${directoryItem.id}}}`,
         };
 
         // 更新目录树
         this.updateCatalog(this.coms);
-        
+
         // 强制更新视图
         this.$nextTick(() => {
           this.$forceUpdate();
         });
       } catch (error) {
-        console.error('Error inserting directory:', error);
-        this.$message.error('插入目录失败,请重试');
+        console.error("Error inserting directory:", error);
+        this.$message.error("插入目录失败,请重试");
       }
     },
 
@@ -2454,14 +2461,14 @@ export default {
       }
 
       const module = this.coms[moduleIndex];
-      if (!module || !module.attrs) return '';
+      if (!module || !module.attrs) return "";
 
       // 获取所有目录类型的属性并按编号排序
       const directories = module.attrs
-        .filter(attr => attr.type === 'Directory' && attr.level < level)
+        .filter((attr) => attr.type === "Directory" && attr.level < level)
         .sort((a, b) => {
-          const aNum = a.number.split('.').map(Number);
-          const bNum = b.number.split('.').map(Number);
+          const aNum = a.number.split(".").map(Number);
+          const bNum = b.number.split(".").map(Number);
           for (let i = 0; i < Math.min(aNum.length, bNum.length); i++) {
             if (aNum[i] !== bNum[i]) return aNum[i] - bNum[i];
           }
@@ -2476,13 +2483,13 @@ export default {
     // 修改 generateDirectoryItem 方法
     generateDirectoryItem(moduleIndex, level) {
       const module = this.coms[moduleIndex];
-      const existingDirs = module.attrs.filter(attr => 
-        attr.type === "Directory" && attr.level === level
+      const existingDirs = module.attrs.filter(
+        (attr) => attr.type === "Directory" && attr.level === level
       );
 
       const parentNumber = this.findParentNumber(moduleIndex, level);
       const siblingCount = existingDirs.length;
-      
+
       let number;
       if (level === 1) {
         number = (moduleIndex + 1).toString();
@@ -2490,9 +2497,9 @@ export default {
         number = `${parentNumber}.${siblingCount + 1}`;
       }
 
-      return { 
-        number, 
-        content: `第${number}章` // 默认内容
+      return {
+        number,
+        content: `第${number}章`, // 默认内容
       };
     },
 
@@ -3411,7 +3418,7 @@ export default {
     async onEdit(index, state) {
       try {
         if (this.isSaving) return;
-          this.isSaving = true;
+        this.isSaving = true;
 
         // 保存当前组件的完整数据
         const currentCom = JSON.parse(JSON.stringify(this.coms[index]));
@@ -3425,29 +3432,28 @@ export default {
         }
 
         // 更新编辑状态
-          this.coms = this.coms.map((it, idx) => {
+        this.coms = this.coms.map((it, idx) => {
           if (idx === index) {
             return {
               ...currentCom, // 保持原有属性
               isEdit: state,
               attrs: currentCom.attrs || [], // 确保attrs不会丢失
-              dcb_attrs: currentCom.dcb_attrs || [] // 确保dcb_attrs不会丢失
+              dcb_attrs: currentCom.dcb_attrs || [], // 确保dcb_attrs不会丢失
             };
           }
           return {
             ...it,
-            isEdit: 2
+            isEdit: 2,
           };
         });
 
         // 更新当前索引
-          this.comIndex = index;
+        this.comIndex = index;
 
-          // 触发重建
+        // 触发重建
         await this.onRebuild(this.coms);
-
       } catch (error) {
-       /*  console.error("切换模式失败:", error);
+        /*  console.error("切换模式失败:", error);
         this.$message.error("切换模式失败:" + error.message); */
       } finally {
         this.isSaving = false;
@@ -3456,6 +3462,7 @@ export default {
 
     // 删除模块
     onRemove(index) {
+      console.log(index);
       this.$confirm("此操作将删除该模块, 是否继续?", "提示", {
         confirmButtonText: "确定",
         cancelButtonText: "取消",
@@ -3482,26 +3489,27 @@ export default {
       const originalDcbAttrs = item.dcb_attrs || [];
 
       // 从内容中提取ID
-      const contentIds = ((item.content || item.dcb_nr).match(/{{([^}]+)}}/g) || [])
-        .map(match => match.slice(2, -2).trim());
+      const contentIds = (
+        (item.content || item.dcb_nr).match(/{{([^}]+)}}/g) || []
+      ).map((match) => match.slice(2, -2).trim());
 
       if (contentIds.length > 0) {
         // 只过滤掉确实不存在的ID
-        item.attrs = originalAttrs.filter(attr => 
-          attr && (
-            contentIds.includes(attr.id) || 
-            attr.type === "ProductAttr" || // 保留特殊类型属性
-            attr.type === "variableNull"
-          )
+        item.attrs = originalAttrs.filter(
+          (attr) =>
+            attr &&
+            (contentIds.includes(attr.id) ||
+              attr.type === "ProductAttr" || // 保留特殊类型属性
+              attr.type === "variableNull")
         );
-        
+
         if (item.dcb_attrs) {
-          item.dcb_attrs = originalDcbAttrs.filter(attr =>
-            attr && (
-              contentIds.includes(attr.id) ||
-              attr.type === "ProductAttr" ||
-              attr.type === "variableNull"
-            )
+          item.dcb_attrs = originalDcbAttrs.filter(
+            (attr) =>
+              attr &&
+              (contentIds.includes(attr.id) ||
+                attr.type === "ProductAttr" ||
+                attr.type === "variableNull")
           );
         }
       }
@@ -3793,44 +3801,50 @@ export default {
 
     // 生成目录编号
     generateDirectoryNumber(moduleIndex, level) {
-      let number = '';
-      
+      let number = "";
+
       if (level === 1) {
         // 一级标题使用模块序号
         number = (moduleIndex + 1).toString();
       } else {
         // 查找父级目录编号
         const parentNumber = this.findParentNumber(moduleIndex, level);
-        
+
         // 获取当前级别的计数
-        const siblings = this.getSiblingDirectories(moduleIndex, level, parentNumber);
+        const siblings = this.getSiblingDirectories(
+          moduleIndex,
+          level,
+          parentNumber
+        );
         const currentCount = siblings.length + 1;
-        
+
         // 组合编号
         number = `${parentNumber}.${currentCount}`;
       }
-      
+
       return number;
     },
 
     // 获取同级目录项
     getSiblingDirectories(moduleIndex, level, parentNumber) {
       const siblings = [];
-      
+
       // 遍历所有模块查找同级目录
       for (let i = 0; i < moduleIndex; i++) {
         const module = this.coms[i];
         if (module.attrs) {
-          module.attrs.forEach(attr => {
-            if (attr.type === 'Directory' && 
-                attr.level === level &&
-                attr.number.startsWith(parentNumber)) {
+          module.attrs.forEach((attr) => {
+            if (
+              attr.type === "Directory" &&
+              attr.level === level &&
+              attr.number.startsWith(parentNumber)
+            ) {
               siblings.push(attr);
             }
           });
         }
       }
-      
+
       return siblings;
     },
 
@@ -4147,7 +4161,7 @@ export default {
 
       // 生成唯一ID
       const attrId = `ProductAttr_${Date.now()}`;
-      
+
       const data = {
         type: "ProductAttr",
         id: attrId,
@@ -4162,7 +4176,7 @@ export default {
 
       // 更新文本内容
       this.insertCmd = {
-        content: `{{${attrId}}}`
+        content: `{{${attrId}}}`,
       };
 
       // 如果有产品信息,添加到文档关联商品
@@ -4171,7 +4185,11 @@ export default {
           this.docAttr.linkProduct = [];
         }
         // 避免重复添加
-        if (!this.docAttr.linkProduct.some(p => p.dcp_p_no === e.productInfo.dcp_p_no)) {
+        if (
+          !this.docAttr.linkProduct.some(
+            (p) => p.dcp_p_no === e.productInfo.dcp_p_no
+          )
+        ) {
           this.docAttr.linkProduct.push(e.productInfo);
         }
       }
@@ -4189,18 +4207,18 @@ export default {
 
     // 添加一个解析目录内容的方法
     parseDirectoryContent(content) {
-      if (!content) return '';
-      
+      if (!content) return "";
+
       // 匹配 {{Directory_x_x_xxxxxxxxxx}} 格式的内容
       const directoryPattern = /{{(Directory_\d+_\d+_\d+)}}/g;
-      
+
       return content.replace(directoryPattern, (match, directoryId) => {
         // 遍历所有组件查找对应的目录项
         for (const com of this.coms) {
-          const directoryAttr = com.attrs.find(attr => 
-            attr.type === 'Directory' && attr.id === directoryId
+          const directoryAttr = com.attrs.find(
+            (attr) => attr.type === "Directory" && attr.id === directoryId
           );
-          
+
           if (directoryAttr) {
             // 返回格式化的目录内容:编号 + 内容
             return `${directoryAttr.number} ${directoryAttr.content}`;
@@ -4213,33 +4231,33 @@ export default {
     // 修改预览处理方法
     handlePreview() {
       this.showViewForm = true;
-      
+
       // 处理预览内容
-      const previewContent = this.coms.map(com => {
+      const previewContent = this.coms.map((com) => {
         // 深拷贝以避免修改原始数据
         const previewCom = JSON.parse(JSON.stringify(com));
-        
+
         // 如果有内容字段,处理目录内容
         if (previewCom.content) {
           previewCom.content = this.parseDirectoryContent(previewCom.content);
         }
-        
+
         // 处理属性中的目录内容
         if (previewCom.attrs) {
-          previewCom.attrs = previewCom.attrs.map(attr => {
-            if (attr.type === 'Directory') {
+          previewCom.attrs = previewCom.attrs.map((attr) => {
+            if (attr.type === "Directory") {
               return {
                 ...attr,
-                content: `${attr.number} ${attr.content}`
+                content: `${attr.number} ${attr.content}`,
               };
             }
             return attr;
           });
         }
-        
+
         return previewCom;
       });
-      
+
       // 更新预览数据
       this.previewData = previewContent;
     },
@@ -4496,60 +4514,63 @@ export default {
 }
 
 /* 添加到组件的 <style> 部分 */
-.el-tree {
-  .el-tree-node {
-    position: relative;
 
-    /* 为每个节点添加左侧垂直线 */
-    &:before {
-      content: "";
-      position: absolute;
-      left: 8px; /* 调整线条位置 */
-      top: 0;
-      bottom: 0;
-      width: 2px;
-      background-color: #1aad19; /* 线条颜色 */
-      z-index: 1;
-    }
+.leftContent {
+  .el-tree {
+    .el-tree-node {
+      position: relative;
+
+      /* 为每个节点添加左侧垂直线 */
+      &:before {
+        content: "";
+        position: absolute;
+        left: 8px; /* 调整线条位置 */
+        top: 0;
+        bottom: 0;
+        width: 2px;
+        background-color: #1aad19; /* 线条颜色 */
+        z-index: 1;
+      }
 
-    /* 移除最后一个子节点的垂直线延伸 */
-    &:last-child:before {
-      height: 20px; /* 调整到节点中心位置 */
-    }
+      /* 移除最后一个子节点的垂直线延伸 */
+      &:last-child:before {
+        height: 20px; /* 调整到节点中心位置 */
+      }
 
-    /* 为每个节点添加水平连接线 */
-    .el-tree-node__content:before {
+      /* 为每个节点添加水平连接线 */ /* 与垂直线对齐 */ /* 水平线长度 */
+      /* .el-tree-node__content:before {
       content: "";
       position: absolute;
-      left: 8px; /* 与垂直线对齐 */
+      left: 8px; 
       top: 50%;
-      width: 16px; /* 水平线长度 */
+      width: 16px; 
       height: 2px;
       background-color: #1aad19;
       z-index: 1;
+    } */
     }
-  }
 
-  /* 移除根节点的垂直线 */
-  & > .el-tree-node:before {
-    display: none;
-  }
+    /* 移除根节点的垂直线 */
+    & > .el-tree-node:before {
+      display: none;
+    }
 
-  /* 移除第一层节点的连接线 */
-  & > .el-tree-node > .el-tree-node__content:before {
-    display: none;
-  }
+    /* 移除第一层节点的连接线 */
+    & > .el-tree-node > .el-tree-node__content:before {
+      display: none;
+    }
 
-  /* 调整节点内容的位置,为线条留出空间 */
-  .el-tree-node__content {
-    position: relative;
-     /* 调整缩进 */
-  }
+    /* 调整节点内容的位置,为线条留出空间 */
+    .el-tree-node__content {
+      position: relative;
+      /* 调整缩进 */
+    }
 
-  /* 确保展开箭头在正确位置 */
-  .el-tree-node__expand-icon {
-    padding: 6px;
-    margin-left: 10px;
+    /* 确保展开箭头在正确位置 */
+    .el-tree-node__expand-icon {
+      padding: 6px;
+      margin-left: 10px;
+    }
   }
 }
 
@@ -4583,4 +4604,15 @@ export default {
 .custom-tree-node:hover .directory-actions {
   opacity: 1;
 }
+.module-actions {
+  display: flex;
+  gap: 8px; /* 按钮之间的间距 */
+  align-items: center;
+  white-space: nowrap;
+  flex-direction: column;
+}
+.module-actions .el-button {
+  padding: 3px 0;
+ margin-left: 0;
+}
 </style>