ソースを参照

Merge branch 'v2-dev' of https://github.com/jdf2e/nutui into v2-dev

Drjingfubo 4 年 前
コミット
897056dd27

+ 1 - 0
src/packages/calendar/calendar.vue

@@ -270,6 +270,7 @@ export default {
         if (this.isAutoBackFill && !isFirst) {
           this.confirm();
         }
+        this.$emit('choose-click', this.chooseData);
       }
     },
 

+ 1 - 0
src/packages/calendar/doc.md

@@ -116,4 +116,5 @@ export default {
 | 字段 | 说明 | 回调参数 
 |----- | ----- | ----- 
 | choose | 选择之后或是点击确认按钮触发 | 日期数组(包含年月日和星期) 
+| choose-click | 点击日期事件触发 | 日期数组(包含年月日和星期) 
 | close | 关闭时触发 | -

+ 21 - 20
src/packages/popup/popup.vue

@@ -34,52 +34,52 @@ const overflowScrollReg = /scroll|auto/i;
 const popupProps = {
   id: {
     type: String | Number,
-    default: '',
+    default: ''
   },
   position: {
     type: String,
-    default: 'center',
+    default: 'center'
   },
 
   transition: String,
 
   closeable: {
     type: Boolean,
-    default: false,
+    default: false
   },
   closeIconPosition: {
     type: String,
-    default: 'top-right',
+    default: 'top-right'
   },
   closeIcon: {
     type: String,
-    default: 'cross',
+    default: 'cross'
   },
 
   closeOnClickOverlay: {
     type: Boolean,
-    default: true,
+    default: true
   },
 
   destroyOnClose: {
     type: Boolean,
-    default: false,
+    default: false
   },
   getContainer: String,
   round: {
     type: Boolean,
-    default: false,
-  },
+    default: false
+  }
 };
 export default {
   name: 'nut-popup',
   mixins: [touchMixins],
   components: {
-    icon: Icon,
+    icon: Icon
   },
   props: {
     ...overlayProps,
-    ...popupProps,
+    ...popupProps
   },
   created() {
     this.transition ? (this.transitionName = this.transition) : (this.transitionName = `popup-slide-${this.position}`);
@@ -88,6 +88,7 @@ export default {
     if (this.value) {
       this.open();
     }
+    this.portal();
   },
   beforeDestroy() {
     if (this.value) {
@@ -115,19 +116,19 @@ export default {
       val === 'center' ? (this.transitionName = 'popup-fade') : (this.transitionName = `popup-slide-${this.position}`);
     },
     getContainer: 'portal',
-    overlay: 'renderOverlay',
+    overlay: 'renderOverlay'
   },
   data() {
     return {
       showSlot: true,
       transitionName: 'popup-fade-center',
-      overlayInstant: null,
+      overlayInstant: null
     };
   },
   computed: {
     transitionDuration() {
       return this.duration ? this.duration + 's' : 'initial';
-    },
+    }
   },
 
   methods: {
@@ -149,7 +150,7 @@ export default {
         overlayClass,
         overlayStyle,
         lockScroll,
-        closeOnClickOverlay,
+        closeOnClickOverlay
       };
 
       this.renderOverlay(config);
@@ -229,20 +230,20 @@ export default {
     },
     portal() {
       const { getContainer } = this;
-      const el = this.$el;
 
+      const el = this.$el;
       let container;
       if (getContainer) {
         container = this.getElement(getContainer);
-      } else if (this.$parent) {
-        container = this.$parent.$el;
+      } else {
+        return;
       }
 
       if (container && container !== el.parentNode) {
         container.appendChild(el);
       }
-    },
-  },
+    }
+  }
 };
 export { popupProps };
 </script>

+ 12 - 1
src/packages/swiper/demo.vue

@@ -22,12 +22,16 @@
       :loop="true"
       :canDragging="false"
       :paginationVisible="true"
+      :newCurrentPage="newCurrentPage"
     >
       <div v-for="(item, index) in dataImgItem" :key="index" class="nut-swiper-slide ">
         <img :src="item.imgSrc" style="max-width:100%;" />
       </div>
     </nut-swiper>
 
+    <div @click="add">下翻页</div>
+    <div @click="sub">上翻页</div>
+
     <h4>纵向自动播放</h4>
     <nut-swiper direction="vertical" :autoPlay="3000" :swiperData="dataImgItem">
       <div v-for="(item, index) in dataImgItem" :key="index" class="nut-swiper-slide ">
@@ -57,7 +61,8 @@ export default {
   data() {
     return {
       dataItem: [],
-      dataImgItem: []
+      dataImgItem: [],
+      newCurrentPage: 1
     };
   },
   mounted() {
@@ -102,6 +107,12 @@ export default {
     },
     slideChangeStart(page) {
       console.log(page);
+    },
+    add() {
+      this.newCurrentPage = this.newCurrentPage + 2;
+    },
+    sub() {
+      this.newCurrentPage = this.newCurrentPage - 1;
     }
   }
 };

+ 23 - 9
src/packages/swiper/swiper.vue

@@ -64,6 +64,10 @@ export default {
       type: Number,
       default: 1
     },
+    newCurrentPage: {
+      type: Number,
+      default: 1
+    },
     lazyLoad: {
       type: Boolean,
       default: false
@@ -82,12 +86,22 @@ export default {
   watch: {
     swiperData(newValue, oldValue) {
       this.updateEvent();
+    },
+    newCurrentPage(newPage) {
+      let modTempNum = newPage % this.slideEls.length;
+      newPage = modTempNum == 0 ? this.slideEls.length : modTempNum < 0 ? this.slideEls.length + modTempNum : modTempNum;
+
+      if (newPage >= this.currentPage) {
+        this.next(newPage - this.currentPage);
+      } else {
+        this.prev(this.currentPage - newPage);
+      }
     }
   },
   data() {
     return {
       dragging: false,
-      currentPage: this.initPage,
+      currentPage: this.initPage || this.newCurrentPage,
       lastPage: 1,
       translateX: 0,
       translateY: 0,
@@ -108,19 +122,19 @@ export default {
   },
   methods: {
     //下一张
-    next() {
+    next(turnPageCount = 1) {
       let page = this.currentPage;
-      if (page < this.slideEls.length || this.isLoop) {
-        this.setPage(page + 1, true, 'NEXT');
+      if (page + turnPageCount < this.slideEls.length || this.isLoop) {
+        this.setPage(page + turnPageCount, true, 'NEXT');
       } else {
         this._revert();
       }
     },
     //上一张
-    prev() {
+    prev(turnPageCount = 1) {
       let page = this.currentPage;
-      if (page > 1 || this.isLoop) {
-        this.setPage(page - 1, true, 'PREV');
+      if (page - turnPageCount > 1 || this.isLoop) {
+        this.setPage(page - turnPageCount, true, 'PREV');
       } else {
         this._revert();
       }
@@ -128,8 +142,8 @@ export default {
     setPage(page, isHasAnimation, type) {
       if (page === 0) {
         this.currentPage = this.slideEls.length;
-      } else if (page === this.slideEls.length + 1) {
-        this.currentPage = 1;
+      } else if (page > this.slideEls.length) {
+        this.currentPage = page - this.slideEls.length;
       } else {
         this.currentPage = page;
       }