z-swiper.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <template>
  2. <view :id="'swiper'+_uid"
  3. :class="['swiper',contentClass,containerClasses,options.direction === 'vertical'?'swiper-vertical':'']"
  4. :style="[customStyle]">
  5. <!-- #ifndef MP-WEIXIN || MP-QQ -->
  6. <view :class="['swiper-wrapper']" :style="[wrapperStyle]" @click="onClickWrapper" @touchstart="onTouchStart"
  7. @touchmove="onTouchMove" @touchend="onTouchEnd" @touchcancel="onTouchEnd">
  8. <!-- #endif -->
  9. <!-- #ifdef MP-WEIXIN || MP-QQ -->
  10. <view :class="['swiper-wrapper']" :style="[wrapperStyle]" @click="onClickWrapper"
  11. @touchstart="zSwiperWxs.onTouchStartWxs" @touchmove="zSwiperWxs.onTouchMoveWxs"
  12. @touchend="zSwiperWxs.onTouchEndWxs" @touchcancel="zSwiperWxs.onTouchEndWxs"
  13. :swiperTransform="wxsTransform" :change:swiperTransform="zSwiperWxs.wxsTransformObserver">
  14. <!-- #endif -->
  15. <slot></slot>
  16. <!-- 在loop模式下,为group填充空白slide -->
  17. <template v-if="loopBlankShow">
  18. <z-swiper-item v-for="(item,index) in loopBlankNumber" :key="index">
  19. </z-swiper-item>
  20. </template>
  21. <template v-if="cubeShadowShowWrapper">
  22. <view class="swiper-cube-shadow" :style="[cubeShadowStyle]"></view>
  23. </template>
  24. </view>
  25. <template v-if="cubeShadowShowRoot">
  26. <view class="swiper-cube-shadow" :style="[cubeShadowStyle]"></view>
  27. </template>
  28. <slot name="indicator"></slot>
  29. <template v-if="showIndicators">
  30. <view :class="['swiper-pagination',paginationClass]" :style="[paginationStyle]">
  31. <template v-if="paginationType == 'bullets'">
  32. <view v-for="(item,index) in paginationContent" :key="index"
  33. :class="[item.classContent.join(' ')]" :style="[item.styleContent]"
  34. @click="paginationItemClick(index)">
  35. </view>
  36. </template>
  37. <template v-if="paginationType == 'fraction'">
  38. <text :class="paginationContent.currentClass">{{paginationContent.text}}</text>/<text
  39. :class="paginationContent.totalClass">{{paginationContent.total}}</text>
  40. </template>
  41. <template v-if="paginationType == 'progressbar'">
  42. <text :class="paginationContent.progressbarFillClass"
  43. :style="[paginationContent.styleContent]"></text>
  44. </template>
  45. </view>
  46. </template>
  47. <template v-if="(showPrevButton||showPrevButtonSlot)">
  48. <view :class="['swiper-button-prev',prevClass]" @click="prevClick">
  49. <view v-if="!showPrevButtonSlot" class="zebra-icon zebra-icon-circle_chevron_left"></view>
  50. <slot v-else name="pre-button"></slot>
  51. </view>
  52. </template>
  53. <template v-if="(showNextButton||showNextButtonSlot)">
  54. <view :class="['swiper-button-next',nextClass]" @click="nextClick">
  55. <view v-if="!showNextButtonSlot" class="zebra-icon zebra-icon-circle_chevron_right"></view>
  56. <slot v-else name="next-button"></slot>
  57. </view>
  58. </template>
  59. <template v-if="scrollbarShow">
  60. <view :class="['swiper-scrollbar',scrollbarClass]" :style="[scrollbarStyle]"
  61. @click.stop="onClickScrollbar" @touchstart.stop="onTouchStartScrollbar"
  62. @touchmove.stop.prevent="onTouchMoveScrollbar" @touchend.stop="onTouchEndScrollbar">
  63. <view class="swiper-scrollbar-drag" :style="[scrollbarItemStyle]">
  64. </view>
  65. </view>
  66. </template>
  67. </view>
  68. </template>
  69. <!-- #ifdef MP-WEIXIN || MP-QQ -->
  70. <script src="../../wxs/z-swiper-wxs.wxs" module="zSwiperWxs" lang="wxs"></script>
  71. <!-- #endif -->
  72. <script>
  73. import {
  74. getAllRect,
  75. getRect
  76. } from '../../libs/utils/utils.js';
  77. // vue2
  78. import {
  79. getParams
  80. } from '../../libs/vue2/get-params.js';
  81. import {
  82. initSwiper,
  83. mountSwiper
  84. } from '../../libs/vue2/init-swiper.js';
  85. import {
  86. needsScrollbar,
  87. needsNavigation,
  88. needsPagination,
  89. uniqueClasses,
  90. extend,
  91. } from '../../libs/vue2/utils.js';
  92. import {
  93. renderLoop,
  94. calcLoopedSlides
  95. } from '../../libs/vue2/loop.js';
  96. import {
  97. getChangedParams
  98. } from '../../libs/vue2/get-changed-params.js';
  99. import {
  100. updateSwiper
  101. } from '../../libs/vue2/update-swiper.js';
  102. import {
  103. renderVirtual,
  104. updateOnVirtualData
  105. } from '../../libs/vue2/virtual.js';
  106. //mixin
  107. import {
  108. ParentMixin
  109. } from '../../libs/mixins/relation.js';
  110. export default {
  111. name: "z-swipe",
  112. // #ifdef MP-WEIXIN
  113. options: {
  114. virtualHost: true
  115. },
  116. // #endif
  117. mixins: [
  118. ParentMixin('zSwipe')
  119. ],
  120. // #ifdef VUE3
  121. emits: ['update:modelValue', 'touch-start', 'touch-move', 'touch-end', 'transitionend', 'slideClick',
  122. '_beforeBreakpoint',
  123. '_containerClasses',
  124. '_slideClass',
  125. '_slideClasses', '_swiper',
  126. 'activeIndexChange', 'afterInit', 'autoplay', 'autoplayStart', 'autoplayStop', 'autoplayPause',
  127. 'autoplayResume', 'beforeDestroy', 'beforeInit', 'beforeLoopFix', 'beforeResize', 'beforeSlideChangeStart',
  128. 'beforeTransitionStart', 'breakpoint', 'changeDirection', 'click', 'disable', 'doubleTap', 'doubleClick',
  129. 'destroy', 'enable', 'fromEdge', 'hashChange', 'hashSet', 'imagesReady', 'init', 'keyPress',
  130. 'lazyImageLoad', 'lazyImageReady', 'lock', 'loopFix', 'momentumBounce', 'navigationHide', 'navigationShow',
  131. 'observerUpdate', 'orientationchange', 'paginationHide', 'paginationRender', 'paginationShow',
  132. 'paginationUpdate', 'progress', 'reachBeginning', 'reachEnd', 'realIndexChange', 'resize', 'scroll',
  133. 'scrollbarDragEnd', 'scrollbarDragMove', 'scrollbarDragStart', 'setTransition', 'setTranslate',
  134. 'slideChange', 'slideChangeTransitionEnd', 'slideChangeTransitionStart', 'slideNextTransitionEnd',
  135. 'slideNextTransitionStart', 'slidePrevTransitionEnd', 'slidePrevTransitionStart',
  136. 'slideResetTransitionStart', 'slideResetTransitionEnd', 'sliderMove', 'sliderFirstMove',
  137. 'slidesLengthChange', 'slidesGridLengthChange', 'snapGridLengthChange', 'snapIndexChange', 'swiper', 'tap',
  138. 'toEdge', 'touchEnd', 'touchMove', 'touchMoveOpposite', 'touchStart', 'transitionEnd', 'transitionStart',
  139. 'unlock', 'update', 'zoomChange', 'beforeMount', 'nextClick', 'prevClick', 'touchStartScrollbar',
  140. 'touchMoveScrollbar', 'touchEndScrollbar', 'beforeUpdate', 'paginationItemClick'
  141. ],
  142. // #endif
  143. props: {
  144. customStyle: {
  145. type: Object,
  146. default: () => {
  147. return {};
  148. }
  149. },
  150. options: {
  151. type: Object,
  152. default: () => {
  153. return {}
  154. }
  155. },
  156. // #ifdef VUE2
  157. value: {
  158. type: Array,
  159. default: () => {
  160. return []
  161. }
  162. },
  163. // #endif
  164. // #ifdef VUE3
  165. modelValue: {
  166. type: Array,
  167. default: () => {
  168. return []
  169. }
  170. }
  171. // #endif
  172. },
  173. data() {
  174. return {
  175. wxsTransform: "",
  176. wrapperStyle: {},
  177. contentClass: '',
  178. nextElClass: [],
  179. prevElClass: [],
  180. paginationElClass: [],
  181. paginationItemElClass: [],
  182. loopBlankShow: false,
  183. loopBlankNumber: 0,
  184. cubeShadowShowWrapper: false,
  185. cubeShadowShowRoot: false,
  186. cubeShadowStyle: {},
  187. eventsListeners: {},
  188. showPrevButton: false,
  189. showPrevButtonSlot: false,
  190. showNextButton: false,
  191. showNextButtonSlot: false,
  192. showIndicators: false,
  193. paginationContent: [],
  194. paginationType: '',
  195. paginationStyle: {},
  196. scrollbarElClass: [],
  197. scrollbarStyle: {},
  198. scrollbarItemStyle: {},
  199. rectInfo: null,
  200. // vue2
  201. containerClasses: 'swiper',
  202. virtualData: null,
  203. firstLoad: true,
  204. originalDataList: [],
  205. loopUpdateData: false
  206. };
  207. },
  208. computed: {
  209. // #ifdef VUE3
  210. value() {
  211. return this.modelValue
  212. },
  213. // #endif
  214. // #ifdef VUE3
  215. _uid() {
  216. return this._.uid
  217. },
  218. // #endif
  219. nextClass() {
  220. return this.nextElClass.join(" ");
  221. },
  222. prevClass() {
  223. return this.prevElClass.join(" ");
  224. },
  225. paginationClass() {
  226. return this.paginationElClass.join(" ");
  227. },
  228. paginationItemClass() {
  229. return this.paginationItemElClass.join(" ");
  230. },
  231. scrollbarClass() {
  232. return this.scrollbarElClass.join(" ");
  233. },
  234. scrollbarShow() {
  235. return needsScrollbar(this.options)
  236. }
  237. },
  238. created() {
  239. const {
  240. params: swiperParams,
  241. passedParams
  242. } = getParams(this.options);
  243. this.swiperElRef = 'swiper';
  244. this.swiperParams = swiperParams;
  245. this.oldPassedParamsRef = passedParams;
  246. let slidesRef = this.slidesRef;
  247. swiperParams.onAny = (event, ...args) => {
  248. // #ifdef MP
  249. // 字节小程序此处报错,因此无法使用v-on监听事件
  250. // #ifndef MP-TOUTIAO
  251. this.$emit(event, {}, ...args.filter((item, index) => {
  252. return index > 0
  253. }));
  254. // #endif
  255. // #endif
  256. // #ifndef MP
  257. this.$emit(event, ...args);
  258. // #endif
  259. };
  260. Object.assign(swiperParams.on, {
  261. _containerClasses(swiper, classes) {
  262. this.containerClasses = classes;
  263. },
  264. });
  265. this.$watch(() => {
  266. return {
  267. value: this.value,
  268. options: this.options
  269. }
  270. }, (val) => {
  271. // virtual模式处理
  272. if (this.swiperParams && this.swiperParams.virtual) {
  273. if (!this.virtualData && val.options.virtual.slides.length) {
  274. this.swiperParams.virtual.slides = val.options.virtual.slides;
  275. const extendWith = {
  276. cache: false,
  277. slides: val.options.virtual.slides,
  278. renderExternal: data => {
  279. this.virtualData = data;
  280. // #ifdef VUE2
  281. this.$emit("input", data.slides);
  282. // #endif
  283. // #ifdef VUE3
  284. this.$emit("update:modelValue", data.slides);
  285. // #endif
  286. },
  287. renderExternalUpdate: false
  288. };
  289. extend(this.swiperParams.virtual, extendWith);
  290. this.loadSwiper();
  291. }
  292. }
  293. // loop模式处理
  294. if (this.swiperParams && this.swiperParams.loop) {
  295. if (this.originalDataList.length && (this.originalDataList.toString() == val.value
  296. .toString())) {
  297. this.loopUpdateData = true;
  298. // 百度小程序watch晚于子组件加载
  299. // #ifdef MP-BAIDU
  300. if (this.firstLoad) {
  301. this.loadSwiper();
  302. }
  303. // #endif
  304. } else {
  305. this.loopUpdateData = false;
  306. let slides = renderLoop(this, this.swiperParams, this.value);
  307. if (this.swiperParams.loop && !this.loopUpdateData && slides.data.toString() !=
  308. val.value.toString()) {
  309. this.loopUpdateData = true;
  310. // #ifdef VUE2
  311. this.$emit("input", slides.data)
  312. // #endif
  313. // #ifdef VUE3
  314. this.$emit("update:modelValue", slides.data)
  315. // #endif
  316. return
  317. }
  318. }
  319. }
  320. if (this.swiper && !this.firstLoad) {
  321. if (this.virtualData && val.options.virtual.type == "cut") {
  322. const style = this.swiper.isHorizontal() ? {
  323. [this.swiper.rtlTranslate ? 'right' :
  324. 'left'
  325. ]: `${this.virtualData.offset}px`
  326. } : {
  327. top: `${this.virtualData.offset}px`
  328. };
  329. this.children
  330. .map(slide => {
  331. slide.css(style)
  332. });
  333. }
  334. this.updateSwiper(val.value, val.options, this.children);
  335. }
  336. }, {
  337. deep: true,
  338. immediate: true
  339. })
  340. this.$watch(() => {
  341. return this.$data
  342. }, (val) => {
  343. if (this.swiper && this.swiper.native) {
  344. Object.assign(this.swiper.native, {
  345. val
  346. });
  347. }
  348. }, {
  349. deep: true
  350. })
  351. this.$watch(() => {
  352. return this.virtualData
  353. }, (val) => {
  354. if (this.swiper && this.virtualData) {
  355. updateOnVirtualData(this.swiper);
  356. }
  357. }, {
  358. deep: true
  359. })
  360. uni.$on("childrenReady" + this._uid, async (children) => {
  361. children.dataSwiperSlideIndex = children.index;
  362. if (this.children.length == this.value.length) {
  363. Promise.all(this.children.map((item) => {
  364. return item.getSize();
  365. })).then((res) => {
  366. if (this.swiperParams && this.swiperParams.loop) {
  367. if (this.originalDataList.length && (this.originalDataList
  368. .toString() == this.value
  369. .toString())) {
  370. if (this.firstLoad) {
  371. this.loadSwiper();
  372. }
  373. } else {
  374. return
  375. }
  376. } else {
  377. if (this.firstLoad) {
  378. this.loadSwiper();
  379. }
  380. }
  381. this.updateSwiper(this.value, this.options, this.children);
  382. })
  383. }
  384. })
  385. },
  386. // #ifdef VUE2
  387. beforeDestroy() {
  388. if (this.swiper && !this.swiper.destroyed) {
  389. this.swiper.destroy(true, false);
  390. }
  391. },
  392. // #endif
  393. // #ifdef VUE3
  394. beforeUnmount() {
  395. if (this.swiper && !this.swiper.destroyed) {
  396. this.swiper.destroy(true, false);
  397. }
  398. },
  399. // #endif
  400. methods: {
  401. loadSwiper() {
  402. let swiperParams = this.swiperParams;
  403. this.slidesRef = this.children;
  404. this.oldSlidesRef = this.slidesRef;
  405. let swiperRef = initSwiper(swiperParams, {
  406. ...this.$data,
  407. ...this.$props,
  408. swiperElId: 'swiper' + this._uid,
  409. emit: this.emit.bind(this),
  410. updateData: this.updateData.bind(this),
  411. getRect: this.getRect.bind(this),
  412. getRectScrollbar: this.getRectScrollbar.bind(this),
  413. willChange: this.willChange.bind(this),
  414. transform: this.transform.bind(this),
  415. transition: this.transition.bind(this),
  416. scrollbarTransform: this.scrollbarTransform.bind(this),
  417. scrollbarTransition: this.scrollbarTransition.bind(this),
  418. scrollbarItemTransform: this.scrollbarItemTransform.bind(this),
  419. scrollbarItemTransition: this.scrollbarItemTransition.bind(this),
  420. addClass: this.addClass.bind(this),
  421. removeClass: this.removeClass.bind(this),
  422. addPaginationClass: this.addPaginationClass.bind(this),
  423. removePaginationClass: this.removePaginationClass.bind(this),
  424. addScrollbarClass: this.addScrollbarClass.bind(this),
  425. removeScrollbarClass: this.removeScrollbarClass.bind(this),
  426. setCss: this.setCss.bind(this),
  427. css: this.setCss.bind(this),
  428. paginationCss: this.setPaginationCss.bind(this),
  429. scrollbarCss: this.scrollbarCss.bind(this),
  430. scrollbarItemCss: this.scrollbarItemCss.bind(this),
  431. addNextElClass: this.addNextElClass.bind(this),
  432. addPrevElClass: this.addPrevElClass.bind(this),
  433. removeNextElClass: this.removeNextElClass.bind(this),
  434. removePrevElClass: this.removePrevElClass.bind(this),
  435. cubeShadowCss: this.cubeShadowCss.bind(this),
  436. cubeShadowTransform: this.cubeShadowTransform.bind(this),
  437. cubeShadowTransition: this.cubeShadowTransition.bind(this),
  438. });
  439. this.swiper = swiperRef;
  440. swiperRef.loopCreate = () => {};
  441. swiperRef.loopDestroy = () => {};
  442. if (swiperParams.loop) {
  443. swiperRef.loopedSlides = calcLoopedSlides(this.slidesRef, swiperParams);
  444. }
  445. if (!this.swiper) return;
  446. mountSwiper({
  447. el: this.swiperElRef,
  448. nextEl: this.nextElRef,
  449. prevEl: this.prevElRef,
  450. paginationEl: this.paginationElRef,
  451. scrollbarEl: this.scrollbarElRef,
  452. swiper: this.swiper,
  453. },
  454. this.swiperParams,
  455. );
  456. this.$emit('swiper');
  457. this.firstLoad = false;
  458. },
  459. updateSwiper(value, options, children) {
  460. this.swiper.slides = children;
  461. this.slidesRef = children;
  462. let initializedRef = this.initializedRef;
  463. let swiperRef = this.swiper;
  464. let slidesRef = this.slidesRef;
  465. let oldPassedParamsRef = this.oldPassedParamsRef;
  466. let oldSlidesRef = this.oldSlidesRef;
  467. let breakpointChanged = this.breakpointChanged;
  468. let nextElRef = this.nextElRef;
  469. let prevElRef = this.prevElRef;
  470. let paginationElRef = this.paginationElRef;
  471. let scrollbarElRef = this.scrollbarElRef;
  472. // set initialized flag
  473. if (!initializedRef && swiperRef) {
  474. swiperRef.emitSlidesClasses();
  475. initializedRef = true;
  476. }
  477. // watch for params change
  478. const {
  479. passedParams: newPassedParams
  480. } = getParams(options);
  481. const changedParams = getChangedParams(
  482. newPassedParams,
  483. oldPassedParamsRef,
  484. slidesRef,
  485. oldSlidesRef,
  486. );
  487. this.oldPassedParamsRef = newPassedParams;
  488. this.oldSlidesRef = slidesRef;
  489. if (
  490. (changedParams.length || breakpointChanged) &&
  491. swiperRef &&
  492. !swiperRef.destroyed
  493. ) {
  494. updateSwiper({
  495. swiper: swiperRef,
  496. slides: slidesRef,
  497. passedParams: newPassedParams,
  498. changedParams,
  499. nextEl: nextElRef,
  500. prevEl: prevElRef,
  501. scrollbarEl: scrollbarElRef,
  502. paginationEl: paginationElRef,
  503. });
  504. }
  505. breakpointChanged = false;
  506. },
  507. emit(event, data) {
  508. this.$emit(event, ...data)
  509. },
  510. async getRect() {
  511. let rectInfo = await getRect(this, '.swiper');
  512. this.rectInfo = rectInfo;
  513. return rectInfo;
  514. },
  515. async getRectScrollbar() {
  516. let rectInfo = await getRect(this, '.swiper-scrollbar');
  517. return rectInfo;
  518. },
  519. updateData(value) {
  520. Object.keys(value).forEach((item) => {
  521. this.$set(this, item, value[item])
  522. })
  523. },
  524. willChange(value) {
  525. this.$set(this.wrapperStyle, 'will-change', value)
  526. },
  527. transform(value) {
  528. // #ifndef MP-WEIXIN || MP-QQ
  529. this.$set(this.wrapperStyle, 'transform', value)
  530. // #endif
  531. // #ifdef MP-WEIXIN || MP-QQ
  532. this.wxsTransform = value;
  533. // #endif
  534. },
  535. transition(value) {
  536. // #ifdef MP-BAIDU
  537. this.$set(this.wrapperStyle, 'transitionDuration', `${value}ms`)
  538. // #endif
  539. // #ifndef MP-BAIDU
  540. this.$set(this.wrapperStyle, 'transition-duration', `${value}ms`)
  541. // #endif
  542. },
  543. setCss(value) {
  544. Object.keys(value).forEach((item) => {
  545. this.$set(this.wrapperStyle, item, value[item])
  546. })
  547. },
  548. scrollbarTransform(value) {
  549. this.$set(this.scrollbarStyle, 'transform', value)
  550. },
  551. scrollbarTransition(value) {
  552. this.$set(this.scrollbarStyle, 'transitionDuration', `${value}ms`)
  553. },
  554. scrollbarItemTransform(value) {
  555. this.$set(this.scrollbarItemStyle, 'transform', value)
  556. },
  557. scrollbarItemTransition(value) {
  558. this.$set(this.scrollbarItemStyle, 'transitionDuration', `${value}ms`)
  559. },
  560. addClass(value) {
  561. // #ifdef MP-ALIPAY || MP-TOUTIAO
  562. this.contentClass = Array.from(new Set([...this.contentClass.split(" "), ...value.split(" ")])).join(" ");
  563. // #endif
  564. // #ifndef MP-ALIPAY || MP-TOUTIAO
  565. this.contentClass = Array.from(new Set([...this.contentClass, ...value.split(" ")]));
  566. // #endif
  567. },
  568. removeClass(value) {
  569. // #ifdef MP-ALIPAY || MP-TOUTIAO
  570. this.contentClass = this.contentClass.split(" ").filter(item => !value.split(" ").includes(item)).join(
  571. " ");
  572. // #endif
  573. // #ifndef MP-ALIPAY || MP-TOUTIAO
  574. this.contentClass = this.contentClass.filter(item => !value.split(" ").includes(item));
  575. // #endif
  576. },
  577. addPaginationClass(value) {
  578. this.paginationElClass = Array.from(new Set([...this.paginationElClass, ...value.split(" ")]));
  579. },
  580. removePaginationClass(value) {
  581. this.paginationElClass = this.paginationElClass.filter(item => !value.split(" ").includes(item));
  582. },
  583. addScrollbarClass(value) {
  584. this.scrollbarElClass = Array.from(new Set([...this.scrollbarElClass, ...value.split(" ")]));
  585. },
  586. removeScrollbarClass(value) {
  587. this.scrollbarElClass = this.scrollbarElClass.filter(item => !value.split(" ").includes(item));
  588. },
  589. setPaginationCss(value) {
  590. Object.keys(value).forEach((item) => {
  591. this.$set(this.paginationStyle, item, value[item])
  592. })
  593. },
  594. scrollbarCss(value) {
  595. Object.keys(value).forEach((item) => {
  596. this.$set(this.scrollbarStyle, item, value[item])
  597. })
  598. },
  599. scrollbarItemCss(value) {
  600. Object.keys(value).forEach((item) => {
  601. this.$set(this.scrollbarItemStyle, item, value[item])
  602. })
  603. },
  604. addNextElClass(value) {
  605. this.nextElClass = Array.from(new Set([...this.nextElClass, ...value.split(" ")]));
  606. },
  607. addPrevElClass(value) {
  608. this.prevElClass = Array.from(new Set([...this.prevElClass, ...value.split(" ")]));
  609. },
  610. removeNextElClass(value) {
  611. this.nextElClass = this.nextElClass.filter(item => !value.split(" ").includes(item));
  612. },
  613. removePrevElClass(value) {
  614. this.prevElClass = this.prevElClass.filter(item => !value.split(" ").includes(item));
  615. },
  616. setSwiperOn(event, callback) {
  617. if (!this.eventsListeners[event]) this.eventsListeners[event] = {};
  618. this.eventsListeners[event] = callback;
  619. },
  620. paginationItemClick(index) {
  621. this.swiper.emit("paginationItemClick", index)
  622. },
  623. prevClick() {
  624. this.swiper.emit("prevClick");
  625. },
  626. nextClick() {
  627. this.swiper.emit("nextClick");
  628. },
  629. onTouchStart(event) {
  630. this.swiper.onTouchStart(event);
  631. },
  632. onTouchStartSwiperWxs(event) {
  633. this.swiper.onTouchStart(event);
  634. },
  635. onTouchMove(event) {
  636. this.swiper.onTouchMove(event);
  637. },
  638. onTouchMoveSwiperWxs(event) {
  639. this.swiper.onTouchMove(event);
  640. },
  641. onTouchEnd(event) {
  642. this.swiper.onTouchEnd(event);
  643. },
  644. onTouchEndSwiperWxs(event) {
  645. this.swiper.onTouchEnd(event);
  646. },
  647. onClickWrapper(event) {
  648. this.$emit("click", event);
  649. },
  650. onClickScrollbar(event) {
  651. this.$emit("scrollbarClick", event);
  652. },
  653. onTouchStartScrollbar(event) {
  654. this.swiper.emit('touchStartScrollbar', event);
  655. },
  656. onTouchMoveScrollbar(event) {
  657. this.swiper.emit('touchMoveScrollbar', event);
  658. },
  659. onTouchEndScrollbar(event) {
  660. this.swiper.emit('touchEndScrollbar', event);
  661. },
  662. cubeShadowCss(value) {
  663. Object.keys(value).forEach((item) => {
  664. this.$set(this.cubeShadowStyle, item, value[item])
  665. })
  666. },
  667. cubeShadowTransform(value) {
  668. this.$set(this.cubeShadowStyle, 'transform', value)
  669. },
  670. cubeShadowTransition(value) {
  671. this.$set(this.cubeShadowStyle, 'transitionDuration', `${value}ms`)
  672. },
  673. }
  674. }
  675. </script>
  676. <style scoped lang="scss">
  677. @import '../../libs/core.scss';
  678. @import "../../static/css/iconfont.css";
  679. .swiper {
  680. &__prev--button {
  681. position: absolute;
  682. left: 30rpx;
  683. top: 50%;
  684. display: flex;
  685. color: #1989fa;
  686. font-size: 44rpx;
  687. z-index: 10;
  688. }
  689. &__prev--button--disable {
  690. position: absolute;
  691. left: 30rpx;
  692. top: 50%;
  693. display: flex;
  694. color: #1989fa;
  695. font-size: 44rpx;
  696. opacity: .35;
  697. z-index: 10;
  698. }
  699. &__next--button {
  700. position: absolute;
  701. right: 30rpx;
  702. top: 50%;
  703. display: flex;
  704. color: #1989fa;
  705. font-size: 44rpx;
  706. z-index: 10;
  707. }
  708. &__next--button--disable {
  709. position: absolute;
  710. right: 30rpx;
  711. top: 50%;
  712. display: flex;
  713. color: #1989fa;
  714. font-size: 44rpx;
  715. opacity: .35;
  716. z-index: 10;
  717. }
  718. }
  719. </style>