@@ -7,9 +7,12 @@ const template = `
77 <div class="adap-swiper__content">
88 <swiper
99 ref="swiperComponent"
10- class="swiper-container--sm-edge-preview"
10+ v-bind="vBind"
11+ v-on="vOn"
1112 :options="options"
13+ :cleanupStylesOnDestroy="cleanupStylesOnDestroy"
1214 @slideChange="pageChangeEvent"
15+ class="swiper-container--sm-edge-preview"
1316 >
1417 <swiper-slide
1518 v-for="(item, i) in slides"
@@ -35,7 +38,7 @@ const template = `
3538
3639import { Component , Prop , Watch , Mixins } from 'vue-property-decorator'
3740import { ExpansibleCollection , IResource } from '@simpli/resource-collection'
38- import { SwiperOptions } from 'swiper'
41+ import Swiper , { SwiperOptions } from 'swiper'
3942import { MixinAdapScreenSize } from './MixinAdapScreenSize'
4043// @ts -ignore
4144import { SwiperComponent } from 'vue-awesome-swiper'
@@ -45,10 +48,16 @@ import AdapTableWrapper from './index'
4548export class AdapSwiper extends Mixins ( MixinAdapScreenSize ) {
4649 @Prop ( { type : Object , required : true } )
4750 collection ! : ExpansibleCollection < IResource >
51+
4852 @Prop ( { type : String } )
4953 slideClass ?: string
54+
5055 @Prop ( { type : String , default : 'list' } )
5156 spinner ! : string
57+
58+ @Prop ( { type : Boolean , default : false } )
59+ cleanupStylesOnDestroy ?: boolean
60+
5261 @Prop ( { type : Object } )
5362 options ?: SwiperOptions
5463
@@ -61,6 +70,17 @@ export class AdapSwiper extends Mixins(MixinAdapScreenSize) {
6170 MEDIUM_SCREEN = AdapTableWrapper . screenMedium
6271 LARGE_SCREEN = AdapTableWrapper . screenLarge
6372
73+ get vBind ( ) {
74+ return { ...this . $attrs }
75+ }
76+
77+ get vOn ( ) {
78+ const listeners = { ...this . $listeners }
79+ delete listeners . input
80+ delete listeners . slideChange
81+ return listeners
82+ }
83+
6484 /**
6585 * In order to clean the cache, the collection empty its content and then repopulate it.
6686 * To prevent malfunction of swiper, this watch does not accept empty list
@@ -70,17 +90,6 @@ export class AdapSwiper extends Mixins(MixinAdapScreenSize) {
7090 async itemsEvent ( items : IResource [ ] ) {
7191 if ( items && items . length ) {
7292 this . slides = items
73-
74- await this . $nextTick ( )
75-
76- // https://github.com/surmon-china/vue-awesome-swiper/issues/317
77- const component = this . $refs . swiperComponent as SwiperComponent
78- if ( component ) {
79- component . swiper . destroy = ( ) => {
80- // Não executar a função nativa pois existe um bug de layout
81- // A falta do destroy não interfere na performace pois o VUE já cuida do lifecycle
82- }
83- }
8493 }
8594 }
8695
@@ -123,6 +132,13 @@ export class AdapSwiper extends Mixins(MixinAdapScreenSize) {
123132 this . collection . perPage = 4 * this . perPage
124133 }
125134
135+ mounted ( ) {
136+ const component = this . $refs . swiperComponent as SwiperComponent
137+ if ( component ) {
138+ this . $emit ( 'init' , component . $swiper )
139+ }
140+ }
141+
126142 nextSlide ( ) {
127143 const component = this . $refs . swiperComponent as SwiperComponent
128144 if ( component ) {
@@ -137,7 +153,9 @@ export class AdapSwiper extends Mixins(MixinAdapScreenSize) {
137153 }
138154 }
139155
140- async pageChangeEvent ( ) {
156+ async pageChangeEvent ( args : Swiper ) {
157+ this . $emit ( 'slideChange' , args )
158+
141159 this . isBeginning = Boolean (
142160 this . swiperComponent && this . swiperComponent . swiper && this . swiperComponent . swiper . isBeginning
143161 )
@@ -149,6 +167,8 @@ export class AdapSwiper extends Mixins(MixinAdapScreenSize) {
149167 await this . expand ( )
150168 this . isEnd = false
151169 }
170+
171+ this . $emit ( 'slideChangeAfterExpand' , args )
152172 }
153173
154174 async expand ( ) {
@@ -161,5 +181,7 @@ export class AdapSwiper extends Mixins(MixinAdapScreenSize) {
161181 await this . collection . expand ( )
162182 }
163183 this . locked = false
184+
185+ this . $emit ( 'expand' )
164186 }
165187}
0 commit comments