Browse Source

快速排序功能

duy 1 tháng trước cách đây
mục cha
commit
a2da4da98d
1 tập tin đã thay đổi với 34 bổ sung0 xóa
  1. 34 0
      src/views/manager/projectinfo/codeSet.vue

+ 34 - 0
src/views/manager/projectinfo/codeSet.vue

@@ -137,6 +137,19 @@
         style="width: 100%"
       >
         <el-table-column label="序号" type="index" width="50"></el-table-column>
+        <el-table-column label="快速排序" width="100">
+          <template slot-scope="scope">
+            <el-input-number
+            style="width: 80px;"
+              v-model="scope.row.sortOrder"
+              :min="1"
+              :max="sortedTableData.length"
+              :controls="false"
+              size="mini"
+              @change="handleQuickSort(scope.$index, scope.row.sortOrder)"
+            />
+          </template>
+        </el-table-column>
         <el-table-column label="规则">
           <template slot-scope="scope">
              <span >{{ getDictValueByRule(scope.row.rule) }}</span>
@@ -243,8 +256,29 @@ mounted(){
     },
     sortData() {
       this.sortedTableData = JSON.parse(JSON.stringify(this.tableData)); // 深拷贝tableData
+       this.sortedTableData.forEach((row, index) => {
+        row.sortOrder = index + 1; // 设置序号
+       
+       })
       this.sortDialogVisible = true; // 显示排序弹窗
     },
+   handleQuickSort(index, newOrder) {
+    if (newOrder < 1 || newOrder > this.sortedTableData.length) return;
+    
+    // 获取当前行
+    const currentRow = this.sortedTableData[index];
+    
+    // 移除当前行
+    this.sortedTableData.splice(index, 1);
+    
+    // 插入到新位置
+    this.sortedTableData.splice(newOrder - 1, 0, currentRow);
+    
+    // 重新计算所有行的 sortOrder(可选)
+    this.sortedTableData.forEach((row, idx) => {
+      row.sortOrder = idx + 1;
+    });
+  },
   handleSortUp(index) {
     if (index > 0) { // 确保不是第一行
       const temp = this.sortedTableData.splice(index, 1)[0]; // 移除当前行