Explorar o código

修复轮播图换位bug

shaogen1995 %!s(int64=4) %!d(string=hai) anos
pai
achega
9b14a80981
Modificáronse 3 ficheiros con 20 adicións e 10 borrados
  1. 8 8
      src/pages/home/rotation.vue
  2. 11 1
      src/pages/home/rotationEdit.vue
  3. 1 1
      src/pages/layout/head.vue

+ 8 - 8
src/pages/home/rotation.vue

@@ -14,8 +14,8 @@
             </div>
 
             <div class="my-move">
-              <div class="pre" @click.stop="switchPic('pre',item)" v-if="index!==0">上一张</div>
-              <div class="next" @click.stop="switchPic('next',item)" v-if="index!==dataList.length-1">下一张</div>
+              <div class="pre" @click.stop="switchPic('pre',item,index)" v-if="index!==0">上一张</div>
+              <div class="next" @click.stop="switchPic('next',item,index)" v-if="index!==dataList.length-1">下一张</div>
             </div>
           </li>
           <li v-if="dataList.length < 5" @click="edit({}, 'add')">
@@ -136,7 +136,7 @@ export default {
           });
         });
     },
-    switchPic(type,item){
+    switchPic(type,item,index){
       this.bigBoxShow=true
       let len = this.dataList.length;
       if(len === 1) {
@@ -148,14 +148,14 @@ export default {
       let nextCurrentItem = {};
       if(currentItem.sort === 1) {
           preCurrentItem = this.dataList[this.dataList.length-1];
-          nextCurrentItem = this.dataList.filter(e=>e.sort === currentItem.sort+1)[0];
+          nextCurrentItem = this.dataList.filter(e=>e.sort === this.dataList[index+1].sort)[0];
       }
-      else if(currentItem.sort === this.dataList.length) {
-          preCurrentItem = this.dataList.filter(e=>e.sort === currentItem.sort-1)[0];
+      else if(index===4) {
+          preCurrentItem = this.dataList.filter(e=>e.sort === this.dataList[index-1].sort)[0];
           nextCurrentItem = this.dataList[0];
       } else {
-        preCurrentItem = this.dataList.filter(e=>e.sort === currentItem.sort-1)[0] ;
-        nextCurrentItem = this.dataList.filter(e=>e.sort === currentItem.sort+1)[0];
+        preCurrentItem = this.dataList.filter(e=>e.sort === this.dataList[index-1].sort)[0] ;
+        nextCurrentItem = this.dataList.filter(e=>e.sort === this.dataList[index+1].sort)[0];
       }
       if(type === 'pre') {
         [preCurrentItem.sort,currentItem.sort] = [currentItem.sort,preCurrentItem.sort]

+ 11 - 1
src/pages/home/rotationEdit.vue

@@ -116,6 +116,7 @@ export default {
       }
     },
     submitForm(formName) {
+      // console.log(999,this.$parent.dataList);
       this.$refs[formName].validate((valid) => {
         if (valid) {
           if (!this["ruleForm"].ossPath) {
@@ -143,7 +144,16 @@ export default {
         url
       };
       if(this.type === "add"){
-        data = {...data,sort:this.$parent.dataList.length + 1}
+        //选出序号最大的sort,并且加1
+        let temp=[]
+        this.$parent.dataList.forEach(v=>{
+          temp.push(v.sort)
+        })
+        // console.log(99999,Math.max(...temp));
+        if(temp.length) data = {...data,sort:Math.max(...temp)+1}
+        else data = {...data,sort:1}
+
+        
       }
       let result = await this.$http({
         method: "post",

+ 1 - 1
src/pages/layout/head.vue

@@ -11,7 +11,7 @@
       <img style="height:70%" src="@/assets/img/user.png" alt="">
       <span>{{userName}}</span>
     </div>
-    <div @click="logout" class="logout"><img src="@/assets/img/logout.png" alt="">退出</div>
+    <!-- <div @click="logout" class="logout"><img src="@/assets/img/logout.png" alt="">退出</div> -->
   </div>
 </div>
 </template>