Просмотр исходного кода

feat(appUpdate): 添加删除版本功能

yusheng 1 неделя назад
Родитель
Сommit
920cffba61

+ 11 - 0
src/api/appUpdate/index.js

@@ -21,3 +21,14 @@ export async function addInformation(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+/**
+ * 删除
+ */
+export async function deleteList(data) {
+  const res = await request.delete(`/sys/appupdates/delete`, {data});
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 18 - 1
src/views/appUpdate/index.vue

@@ -35,6 +35,19 @@
             下载
           </el-link>
         </template>
+        <template v-slot:action="{ row }">
+          <el-popconfirm
+            class="ele-action"
+            title="确定要删除此版本吗?"
+            @confirm="deleteList(row)"
+          >
+            <template v-slot:reference>
+              <el-link type="danger" :underline="false" icon="el-icon-delete">
+                删除
+              </el-link>
+            </template>
+          </el-popconfirm>
+        </template>
       </ele-pro-table>
     </el-card>
     <!-- 新增/编辑/详情弹窗 -->
@@ -50,7 +63,7 @@
 <script>
   import addOrEditDialog from './components/addOrEditDialog.vue';
   import { getFile } from '@/api/system/file';
-  import { getTableList, addInformation } from '@/api/appUpdate';
+  import { getTableList, deleteList } from '@/api/appUpdate';
 
   export default {
     name: 'technologyProduction',
@@ -130,6 +143,10 @@
       reload(where) {
         this.$refs.table.reload({ page: 1, where: where });
       },
+      async deleteList({ id }) {
+        await deleteList([id]);
+        this.$refs.table.reload();
+      },
       /* 打开编辑弹窗 */
       openEdit(row = {}, type) {
         this.addOrEditDialogFlag = true;

+ 83 - 4
src/views/rulesManagement/releaseRules/components/experimentationProcessNew.vue

@@ -21,7 +21,7 @@
         group="project1"
         :animation="300"
         handle=".sort-handle"
-        style="flex: 1;max-height:calc(100vh - 500px);overflow: auto;"
+        style="flex: 1; max-height: calc(100vh - 500px); overflow: auto"
       >
         <div
           class="demo-drag-list-item ele-cell"
@@ -95,6 +95,33 @@
               @change="editInputChange"
             ></el-input>
           </el-form-item>
+          <el-form-item label="字段类型:" prop="fieldType" v-if="domObj.mode=='person'">
+            <el-select
+              v-model="domObj.fieldType"
+              placeholder="请选择"
+              @change="onFieldTypeChange"
+              clearable
+            >
+              <el-option
+                v-for="opt in fieldTypeOptions"
+                :key="opt.value"
+                :label="opt.label"
+                :value="opt.value"
+              />
+            </el-select>
+          </el-form-item>
+          <!-- 🆕 对齐方式下拉 -->
+          <el-form-item label="对齐方式:" prop="textAlign">
+            <el-select
+              v-model="domObj.textAlign"
+              placeholder="请选择"
+              @change="editInputChange"
+            >
+              <el-option label="左对齐" value="left"></el-option>
+              <el-option label="居中对齐" value="center"></el-option>
+              <el-option label="右对齐" value="right"></el-option>
+            </el-select>
+          </el-form-item>
           <el-form-item label="是否只读:" prop="readonly">
             <el-select
               v-model="domObj.readonly"
@@ -275,6 +302,13 @@
         templateDivRef: '',
         domObj: { units: {} },
         idList: [],
+        fieldTypeOptions: [
+          { label: '作业负责人', value: 'work_leader' },
+          { label: '监护人', value: 'guardian' },
+          { label: '作业人', value: 'worker' },
+          { label: '安全交底人', value: 'safety_briefer' },
+          { label: '接受交底人', value: 'safety_receiver' }
+        ],
         opSelectOptions: ['+', '-', '*', '/', '%', '(', ')'],
         equationUnit: {
           equation: [],
@@ -342,7 +376,47 @@
           }
         });
       },
+      onFieldTypeChange(val) {
+        const oldId = this.domObj.id;
+        const oldFieldType = this.domObj.fieldType;
 
+        if (val) {
+          // 获取当前编辑的 customTable 子组件实例
+          const childRef = this.$refs[this.templateDivRef];
+          // if (
+          //   !childRef ||
+          //   !childRef[0] ||
+          //   typeof childRef[0].isIdDuplicate !== 'function'
+          // ) {
+          //   // 若组件未加载或方法不存在,直接允许修改(降级)
+          //   this.domObj.id = val;
+          //   this.domObj.fieldType = val;
+          //   this.editInputChange();
+          //   return;
+          // }
+
+          // 调用子组件的重复检查方法
+
+          const isDuplicate = childRef[0].isIdDuplicate(val, this.domObj.id);
+          if (isDuplicate) {
+            this.$message.warning(
+              '该字段类型在当前表格中已被使用,请选择其他类型'
+            );
+            this.domObj.fieldType =  '';
+          } else {
+            // 唯一,允许修改
+            this.domObj.id = val;
+            this.domObj.fieldType = val;
+          }
+
+          this.editInputChange();
+        } else {
+          // 取消选择:随机生成 id,清空类型
+          this.domObj.id = generateRandomString(6);
+          this.domObj.fieldType = '';
+          this.editInputChange();
+        }
+      },
       truncateToFixedManual(num, decimalPlaces) {
         let factor = Math.pow(10, decimalPlaces);
         return Math.floor(num * factor) / factor;
@@ -476,10 +550,15 @@
         }
       },
       editShowFn({ templateDivRef, domObj }) {
-        if (!this.edit) {
-          return;
-        }
+        if (!this.edit) return;
         this.templateDivRef = templateDivRef;
+        // 根据 id 匹配类型(若 id 为预设值则回显,否则置空)
+        const found = this.fieldTypeOptions.find(
+          (opt) => opt.value === domObj.id
+        );
+        domObj.fieldType = found ? found.value : '';
+        // 确保 domObj 有 textAlign 默认值(若没有则设置)
+        if (!domObj.textAlign) domObj.textAlign = 'center';
         this.$set(this, 'domObj', domObj);
         this.editShow = true;
       },

+ 54 - 6
src/views/rulesManagement/releaseRules/components/templateDiv/customTableNew.vue

@@ -75,15 +75,23 @@
 
                 <!-- ========== 🆕 人员选择模式 ========== -->
                 <template v-else-if="cell.mode === 'person'">
-                  <div style="width: 100%"  @dblclick.stop="openPersonConfig(cell, rowIndex, colIndex)">
+                  <div
+                    style="width: 100%; position: relative; min-height: 30px"
+                  >
+                    <!-- 人员选择组件 -->
                     <personSelect
                       v-model="cell.value"
-                    
                       :disabled="!edit"
                       :readonly="readonly || cell.readonly === 2"
                       @change="onPersonChange(rowIndex, colIndex)"
-                      style="width: 100%"
+                      style="width: 95%"
                     />
+                    <!-- 编辑图标(仅在编辑模式下显示) -->
+                    <i
+                      v-if="edit"
+                      class="el-icon-edit person-edit-icon"
+                      @click.stop="openPersonConfig(cell, rowIndex, colIndex)"
+                    ></i>
                   </div>
                 </template>
 
@@ -92,6 +100,7 @@
                   <textarea
                     v-model="cell.value"
                     class="templateInput"
+                    :style="{ textAlign: cell.textAlign || 'center' }"
                     :id="cell.id"
                     :ref="cell.id + 'ref'"
                     :readonly="cell.readonly === 2 || readonly"
@@ -154,7 +163,9 @@
         // 防抖定时器
         calcTimer: null,
         // 右键菜单关闭监听
-        menuCloseHandler: null
+        menuCloseHandler: null,
+        userMap: {},
+        userMapLoaded: false
       };
     },
     computed: {
@@ -232,7 +243,11 @@
       getCellStyle(cell) {
         let width = parseFloat(cell.style?.width || cell.width || 100);
         if (isNaN(width)) width = 100;
-        return { ...cell.style, width: width + 'px' };
+        return {
+          ...cell.style,
+          width: width + 'px',
+          'text-align': cell.textAlign || 'center' // 默认居中
+        };
       },
 
       getInput(width) {
@@ -247,6 +262,7 @@
           style: { width: safeWidth },
           readonly: 1,
           mode: 'text', // 'text' | 'checkbox' | 'person'
+          textAlign: 'center',
           checkboxes: []
         };
       },
@@ -270,7 +286,24 @@
         }
         return false;
       },
-
+      /**
+       * 检查指定 id 在当前表格中是否重复(排除某个单元格)
+       * @param {string} id - 要检查的 id
+       * @param {string} excludeId - 排除的单元格 id(通常是当前编辑的)
+       * @returns {boolean} 是否重复
+       */
+      isIdDuplicate(id, excludeId) {
+        // 遍历所有行和列
+        for (let r = 0; r < this.tableData.length; r++) {
+          for (let c = 0; c < this.tableData[r].length; c++) {
+            const cell = this.tableData[r][c];
+            if (cell.id === id && cell.id !== excludeId) {
+              return true;
+            }
+          }
+        }
+        return false;
+      },
       // ========== 自动调整高度 ==========
       autoResizeAll() {
         this.$nextTick(() => {
@@ -729,6 +762,7 @@
       },
       openPersonConfig(cell, rowIndex, colIndex) {
         if (!this.edit) return;
+        this.domId = cell.id;
         // 获取单元格真实宽度
         let realWidth = cell.width || 100;
         const td = this.$el.querySelector(
@@ -1071,4 +1105,18 @@
       break-inside: avoid;
     }
   }
+  .person-edit-icon {
+    position: absolute;
+    right: 4px;
+    top: 50%;
+    transform: translateY(-50%);
+    color: #409eff;
+    font-size: 14px;
+    cursor: pointer;
+    opacity: 0.6;
+    transition: opacity 0.2s;
+    &:hover {
+      opacity: 1;
+    }
+  }
 </style>