浏览代码

feature:修改音乐专辑插入下标的规则

zeng.chen 1 月之前
父节点
当前提交
36cc41f7e5
共有 1 个文件被更改,包括 13 次插入14 次删除
  1. 13 14
      src/views/music/album/detail.vue

+ 13 - 14
src/views/music/album/detail.vue

@@ -296,33 +296,31 @@ export default {
     onNumberBlur(row, index) {
 
       let newValue = Number(this.editData.sortIndex);
-      console.log('序号修改:', newValue, '当前索引:', index, this.currentEditIndex);
       const maxLen = this.form.programList.length;
-      this.currentEditIndex = -1;
 
       if (isNaN(newValue) || newValue === null || newValue === undefined) {
-
+        console.log('序号未修改:', newValue);
         return;
       }
       if (newValue < 1) {
         this.$message.warning('序号必须大于0');
-        // this.currentEditIndex = -1;
+        this.currentEditIndex = -1;
 
         return;
       }
       if (newValue > maxLen) {
-        this.$message.warning(`序号不能超过${maxLen}`);
-        // this.currentEditIndex = -1;
-
-        return;
+        // 超出就是最后一位
+        newValue = maxLen
       }
 
       if (newValue === -1 || newValue === '') {
         // 新值为空时处理
-        // this.currentEditIndex = -1;
+        this.currentEditIndex = -1;
         console.log('序号未修改:', newValue);
         return
       }
+      console.log('序号修改:', newValue, '当前索引:', index, this.currentEditIndex);
+
       // 计算目标下标
       const targetIndex = newValue - 1;
       if (targetIndex === index) {
@@ -330,11 +328,12 @@ export default {
         return;
       }
       // 交换两个元素
-      const temp = this.form.programList[index];
-      this.$set(this.form.programList, index, this.form.programList[targetIndex]);
-      this.$set(this.form.programList, targetIndex, temp);
-
-      // this.currentEditIndex = -1;
+      // ...existing code...
+      // 插入到目标位置,原本序号顺延
+      const movingItem = this.form.programList.splice(index, 1)[0];
+      this.form.programList.splice(targetIndex, 0, movingItem);
+      // ...existing code...
+      this.currentEditIndex = -1;
       this.$message.success("操作成功!");