z-swiper.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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'
  140. ],
  141. // #endif
  142. props: {
  143. customStyle: {
  144. type: Object,
  145. default: () => {
  146. return {};
  147. }
  148. },
  149. options: {
  150. type: Object,
  151. default: () => {
  152. return {}
  153. }
  154. },
  155. // #ifdef VUE2
  156. value: {
  157. type: Array,
  158. default: () => {
  159. return []
  160. }
  161. },
  162. // #endif
  163. // #ifdef VUE3
  164. modelValue: {
  165. type: Array,
  166. default: () => {
  167. return []
  168. }
  169. }
  170. // #endif
  171. },
  172. data() {
  173. return {
  174. wxsTransform: "",
  175. wrapperStyle: {},
  176. contentClass: '',
  177. nextElClass: [],
  178. prevElClass: [],
  179. paginationElClass: [],
  180. paginationItemElClass: [],
  181. loopBlankShow: false,
  182. loopBlankNumber: 0,
  183. cubeShadowShowWrapper: false,
  184. cubeShadowShowRoot: false,
  185. cubeShadowStyle: {},
  186. eventsListeners: {},
  187. showPrevButton: false,
  188. showPrevButtonSlot: false,
  189. showNextButton: false,
  190. showNextButtonSlot: false,
  191. showIndicators: false,
  192. paginationContent: [],
  193. paginationType: '',
  194. paginationStyle: {},
  195. scrollbarElClass: [],
  196. scrollbarStyle: {},
  197. scrollbarItemStyle: {},
  198. rectInfo: null,
  199. // vue2
  200. containerClasses: 'swiper',
  201. virtualData: null,
  202. firstLoad: true,
  203. originalDataList: [],
  204. loopUpdateData: false
  205. };
  206. },
  207. computed: {
  208. // #ifdef VUE3
  209. value() {
  210. return this.modelValue
  211. },
  212. // #endif
  213. // #ifdef VUE3
  214. _uid() {
  215. return this._.uid
  216. },
  217. // #endif
  218. nextClass() {
  219. return this.nextElClass.join(" ");
  220. },
  221. prevClass() {
  222. return this.prevElClass.join(" ");
  223. },
  224. paginationClass() {
  225. return this.paginationElClass.join(" ");
  226. },
  227. paginationItemClass() {
  228. return this.paginationItemElClass.join(" ");
  229. },
  230. scrollbarClass() {
  231. return this.scrollbarElClass.join(" ");
  232. },
  233. scrollbarShow() {
  234. return needsScrollbar(this.options)
  235. }
  236. },
  237. created() {
  238. const {
  239. params: swiperParams,
  240. passedParams
  241. } = getParams(this.options);
  242. this.swiperElRef = 'swiper';
  243. this.swiperParams = swiperParams;
  244. this.oldPassedParamsRef = passedParams;
  245. let slidesRef = this.slidesRef;
  246. swiperParams.onAny = (event, ...args) => {
  247. // #ifdef MP
  248. // 字节小程序此处报错,因此无法使用v-on监听事件
  249. // #ifndef MP-TOUTIAO
  250. this.$emit(event, {}, ...args.filter((item, index) => {
  251. return index > 0
  252. }));
  253. // #endif
  254. // #endif
  255. // #ifndef MP
  256. this.$emit(event, ...args);
  257. // #endif
  258. };
  259. Object.assign(swiperParams.on, {
  260. _containerClasses(swiper, classes) {
  261. this.containerClasses = classes;
  262. },
  263. });
  264. this.$watch(() => {
  265. return {
  266. value: this.value,
  267. options: this.options
  268. }
  269. }, (val) => {
  270. // virtual模式处理
  271. if (this.swiperParams && this.swiperParams.virtual) {
  272. if (!this.virtualData && val.options.virtual.slides.length) {
  273. this.swiperParams.virtual.slides = val.options.virtual.slides;
  274. // this.swiperParams.virtual.slides = val.value;
  275. const extendWith = {
  276. cache: false,
  277. slides: val.options.virtual.slides,
  278. // slides: val.value,
  279. renderExternal: data => {
  280. console.log("最终数据", data)
  281. this.virtualData = data;
  282. this.$emit("input", data.slides);
  283. // updateOnVirtualData(this.swiper);
  284. },
  285. renderExternalUpdate: false
  286. };
  287. extend(this.swiperParams.virtual, extendWith);
  288. // this.$emit("input", [val.options.virtual.slides[0]]);
  289. // this.virtualData = [val.options.virtual.slides[0]];
  290. this.loadSwiper();
  291. // console.log(this.swiper)
  292. }
  293. // extend(swiperRef.originalParams.virtual, extendWith);
  294. }
  295. // loop模式处理
  296. if (this.swiperParams && this.swiperParams.loop) {
  297. if (this.originalDataList.length && (this.originalDataList.toString() == val.value
  298. .toString())) {
  299. this.loopUpdateData = true;
  300. // 百度小程序watch晚于子组件加载
  301. // #ifdef MP-BAIDU
  302. if (this.firstLoad) {
  303. this.loadSwiper();
  304. }
  305. // #endif
  306. } else {
  307. this.loopUpdateData = false;
  308. let slides = renderLoop(this, this.swiperParams, this.value);
  309. if (this.swiperParams.loop && !this.loopUpdateData && slides.data.toString() !=
  310. val.value.toString()) {
  311. this.loopUpdateData = true;
  312. // #ifdef VUE2
  313. this.$emit("input", slides.data)
  314. // #endif
  315. // #ifdef VUE3
  316. this.$emit("update:modelValue", slides.data)
  317. // #endif
  318. return
  319. }
  320. }
  321. }
  322. if (this.swiper && !this.firstLoad) {
  323. if (this.virtualData && val.options.virtual.type == "cut") {
  324. const style = this.swiper.isHorizontal() ? {
  325. [this.swiper.rtlTranslate ? 'right' :
  326. 'left'
  327. ]: `${this.virtualData.offset}px`
  328. } : {
  329. top: `${this.virtualData.offset}px`
  330. };
  331. this.children
  332. // .filter((slide, index) => index >= this.virtualData.from && index <= this
  333. // .virtualData
  334. // .to)
  335. .map(slide => {
  336. slide.css(style)
  337. // if (!slide.props) slide.props = {};
  338. // if (!slide.props.style) slide.props.style = {};
  339. // slide.props.swiperRef = swiperRef;
  340. // slide.props.style = style;
  341. // return h(slide.type, {
  342. // ...slide.props
  343. // }, slide.children);
  344. });
  345. }
  346. this.updateSwiper(val.value, val.options, this.children);
  347. }
  348. }, {
  349. deep: true,
  350. immediate: true
  351. })
  352. this.$watch(() => {
  353. return this.$data
  354. }, (val) => {
  355. if (this.swiper && this.swiper.native) {
  356. Object.assign(this.swiper.native, {
  357. val
  358. });
  359. }
  360. }, {
  361. deep: true
  362. })
  363. this.$watch(() => {
  364. return this.virtualData
  365. }, (val) => {
  366. if (this.swiper && this.virtualData) {
  367. updateOnVirtualData(this.swiper);
  368. }
  369. }, {
  370. deep: true
  371. })
  372. uni.$on("childrenReady" + this._uid, async (children) => {
  373. children.dataSwiperSlideIndex = children.index;
  374. if (this.children.length == this.value.length) {
  375. Promise.all(this.children.map((item) => {
  376. return item.getSize();
  377. })).then((res) => {
  378. if (this.swiperParams && this.swiperParams.loop) {
  379. if (this.originalDataList.length && (this.originalDataList
  380. .toString() == this.value
  381. .toString())) {
  382. if (this.firstLoad) {
  383. this.loadSwiper();
  384. }
  385. } else {
  386. return
  387. }
  388. } else {
  389. if (this.firstLoad) {
  390. this.loadSwiper();
  391. }
  392. }
  393. this.updateSwiper(this.value, this.options, this.children);
  394. })
  395. }
  396. })
  397. },
  398. // #ifdef VUE2
  399. beforeDestroy() {
  400. if (this.swiper && !this.swiper.destroyed) {
  401. this.swiper.destroy(true, false);
  402. }
  403. },
  404. // #endif
  405. // #ifdef VUE3
  406. beforeUnmount() {
  407. if (this.swiper && !this.swiper.destroyed) {
  408. this.swiper.destroy(true, false);
  409. }
  410. },
  411. // #endif
  412. methods: {
  413. loadSwiper() {
  414. let swiperParams = this.swiperParams;
  415. this.slidesRef = this.children;
  416. this.oldSlidesRef = this.slidesRef;
  417. let swiperRef = initSwiper(swiperParams, {
  418. ...this.$data,
  419. ...this.$props,
  420. swiperElId: 'swiper' + this._uid,
  421. emit: this.emit.bind(this),
  422. updateData: this.updateData.bind(this),
  423. getRect: this.getRect.bind(this),
  424. getRectScrollbar: this.getRectScrollbar.bind(this),
  425. willChange: this.willChange.bind(this),
  426. transform: this.transform.bind(this),
  427. transition: this.transition.bind(this),
  428. scrollbarTransform: this.scrollbarTransform.bind(this),
  429. scrollbarTransition: this.scrollbarTransition.bind(this),
  430. scrollbarItemTransform: this.scrollbarItemTransform.bind(this),
  431. scrollbarItemTransition: this.scrollbarItemTransition.bind(this),
  432. addClass: this.addClass.bind(this),
  433. removeClass: this.removeClass.bind(this),
  434. addPaginationClass: this.addPaginationClass.bind(this),
  435. removePaginationClass: this.removePaginationClass.bind(this),
  436. addScrollbarClass: this.addScrollbarClass.bind(this),
  437. removeScrollbarClass: this.removeScrollbarClass.bind(this),
  438. setCss: this.setCss.bind(this),
  439. css: this.setCss.bind(this),
  440. paginationCss: this.setPaginationCss.bind(this),
  441. scrollbarCss: this.scrollbarCss.bind(this),
  442. scrollbarItemCss: this.scrollbarItemCss.bind(this),
  443. addNextElClass: this.addNextElClass.bind(this),
  444. addPrevElClass: this.addPrevElClass.bind(this),
  445. removeNextElClass: this.removeNextElClass.bind(this),
  446. removePrevElClass: this.removePrevElClass.bind(this),
  447. cubeShadowCss: this.cubeShadowCss.bind(this),
  448. cubeShadowTransform: this.cubeShadowTransform.bind(this),
  449. cubeShadowTransition: this.cubeShadowTransition.bind(this),
  450. });
  451. this.swiper = swiperRef;
  452. swiperRef.loopCreate = () => {};
  453. swiperRef.loopDestroy = () => {};
  454. if (swiperParams.loop) {
  455. swiperRef.loopedSlides = calcLoopedSlides(this.slidesRef, swiperParams);
  456. }
  457. if (!this.swiper) return;
  458. mountSwiper({
  459. el: this.swiperElRef,
  460. nextEl: this.nextElRef,
  461. prevEl: this.prevElRef,
  462. paginationEl: this.paginationElRef,
  463. scrollbarEl: this.scrollbarElRef,
  464. swiper: this.swiper,
  465. },
  466. this.swiperParams,
  467. );
  468. this.$emit('swiper');
  469. this.firstLoad = false;
  470. },
  471. updateSwiper(value, options, children) {
  472. this.swiper.slides = children;
  473. this.slidesRef = children;
  474. let initializedRef = this.initializedRef;
  475. let swiperRef = this.swiper;
  476. let slidesRef = this.slidesRef;
  477. let oldPassedParamsRef = this.oldPassedParamsRef;
  478. let oldSlidesRef = this.oldSlidesRef;
  479. let breakpointChanged = this.breakpointChanged;
  480. let nextElRef = this.nextElRef;
  481. let prevElRef = this.prevElRef;
  482. let paginationElRef = this.paginationElRef;
  483. let scrollbarElRef = this.scrollbarElRef;
  484. // set initialized flag
  485. if (!initializedRef && swiperRef) {
  486. swiperRef.emitSlidesClasses();
  487. initializedRef = true;
  488. }
  489. // watch for params change
  490. const {
  491. passedParams: newPassedParams
  492. } = getParams(options);
  493. const changedParams = getChangedParams(
  494. newPassedParams,
  495. oldPassedParamsRef,
  496. slidesRef,
  497. oldSlidesRef,
  498. );
  499. this.oldPassedParamsRef = newPassedParams;
  500. this.oldSlidesRef = slidesRef;
  501. if (
  502. (changedParams.length || breakpointChanged) &&
  503. swiperRef &&
  504. !swiperRef.destroyed
  505. ) {
  506. updateSwiper({
  507. swiper: swiperRef,
  508. slides: slidesRef,
  509. passedParams: newPassedParams,
  510. changedParams,
  511. nextEl: nextElRef,
  512. prevEl: prevElRef,
  513. scrollbarEl: scrollbarElRef,
  514. paginationEl: paginationElRef,
  515. });
  516. }
  517. breakpointChanged = false;
  518. },
  519. emit(event, data) {
  520. this.$emit(event, ...data)
  521. },
  522. async getRect() {
  523. let rectInfo = await getRect(this, '.swiper');
  524. this.rectInfo = rectInfo;
  525. return rectInfo;
  526. },
  527. async getRectScrollbar() {
  528. let rectInfo = await getRect(this, '.swiper-scrollbar');
  529. return rectInfo;
  530. },
  531. updateData(value) {
  532. Object.keys(value).forEach((item) => {
  533. this.$set(this, item, value[item])
  534. })
  535. },
  536. willChange(value) {
  537. this.$set(this.wrapperStyle, 'will-change', value)
  538. },
  539. transform(value) {
  540. // #ifndef MP-WEIXIN || MP-QQ
  541. this.$set(this.wrapperStyle, 'transform', value)
  542. // #endif
  543. // #ifdef MP-WEIXIN || MP-QQ
  544. this.wxsTransform = value;
  545. // #endif
  546. },
  547. transition(value) {
  548. // #ifdef MP-BAIDU
  549. this.$set(this.wrapperStyle, 'transitionDuration', `${value}ms`)
  550. // #endif
  551. // #ifndef MP-BAIDU
  552. this.$set(this.wrapperStyle, 'transition-duration', `${value}ms`)
  553. // #endif
  554. },
  555. setCss(value) {
  556. Object.keys(value).forEach((item) => {
  557. this.$set(this.wrapperStyle, item, value[item])
  558. })
  559. },
  560. scrollbarTransform(value) {
  561. this.$set(this.scrollbarStyle, 'transform', value)
  562. },
  563. scrollbarTransition(value) {
  564. this.$set(this.scrollbarStyle, 'transitionDuration', `${value}ms`)
  565. },
  566. scrollbarItemTransform(value) {
  567. this.$set(this.scrollbarItemStyle, 'transform', value)
  568. },
  569. scrollbarItemTransition(value) {
  570. this.$set(this.scrollbarItemStyle, 'transitionDuration', `${value}ms`)
  571. },
  572. addClass(value) {
  573. // #ifdef MP-ALIPAY || MP-TOUTIAO
  574. this.contentClass = Array.from(new Set([...this.contentClass.split(" "), ...value.split(" ")])).join(" ");
  575. // #endif
  576. // #ifndef MP-ALIPAY || MP-TOUTIAO
  577. this.contentClass = Array.from(new Set([...this.contentClass, ...value.split(" ")]));
  578. // #endif
  579. },
  580. removeClass(value) {
  581. // #ifdef MP-ALIPAY || MP-TOUTIAO
  582. this.contentClass = this.contentClass.split(" ").filter(item => !value.split(" ").includes(item)).join(
  583. " ");
  584. // #endif
  585. // #ifndef MP-ALIPAY || MP-TOUTIAO
  586. this.contentClass = this.contentClass.filter(item => !value.split(" ").includes(item));
  587. // #endif
  588. },
  589. addPaginationClass(value) {
  590. this.paginationElClass = Array.from(new Set([...this.paginationElClass, ...value.split(" ")]));
  591. },
  592. removePaginationClass(value) {
  593. this.paginationElClass = this.paginationElClass.filter(item => !value.split(" ").includes(item));
  594. },
  595. addScrollbarClass(value) {
  596. this.scrollbarElClass = Array.from(new Set([...this.scrollbarElClass, ...value.split(" ")]));
  597. },
  598. removeScrollbarClass(value) {
  599. this.scrollbarElClass = this.scrollbarElClass.filter(item => !value.split(" ").includes(item));
  600. },
  601. setPaginationCss(value) {
  602. Object.keys(value).forEach((item) => {
  603. this.$set(this.paginationStyle, item, value[item])
  604. })
  605. },
  606. scrollbarCss(value) {
  607. Object.keys(value).forEach((item) => {
  608. this.$set(this.scrollbarStyle, item, value[item])
  609. })
  610. },
  611. scrollbarItemCss(value) {
  612. Object.keys(value).forEach((item) => {
  613. this.$set(this.scrollbarItemStyle, item, value[item])
  614. })
  615. },
  616. addNextElClass(value) {
  617. this.nextElClass = Array.from(new Set([...this.nextElClass, ...value.split(" ")]));
  618. },
  619. addPrevElClass(value) {
  620. this.prevElClass = Array.from(new Set([...this.prevElClass, ...value.split(" ")]));
  621. },
  622. removeNextElClass(value) {
  623. this.nextElClass = this.nextElClass.filter(item => !value.split(" ").includes(item));
  624. },
  625. removePrevElClass(value) {
  626. this.prevElClass = this.prevElClass.filter(item => !value.split(" ").includes(item));
  627. },
  628. setSwiperOn(event, callback) {
  629. if (!this.eventsListeners[event]) this.eventsListeners[event] = {};
  630. this.eventsListeners[event] = callback;
  631. },
  632. paginationItemClick(index) {
  633. this.swiper.emit("paginationItemClick", index)
  634. },
  635. prevClick() {
  636. this.swiper.emit("prevClick");
  637. },
  638. nextClick() {
  639. this.swiper.emit("nextClick");
  640. },
  641. onTouchStart(event) {
  642. this.swiper.onTouchStart(event);
  643. },
  644. onTouchStartSwiperWxs(event) {
  645. this.swiper.onTouchStart(event);
  646. },
  647. onTouchMove(event) {
  648. this.swiper.onTouchMove(event);
  649. },
  650. onTouchMoveSwiperWxs(event) {
  651. this.swiper.onTouchMove(event);
  652. },
  653. onTouchEnd(event) {
  654. this.swiper.onTouchEnd(event);
  655. },
  656. onTouchEndSwiperWxs(event) {
  657. this.swiper.onTouchEnd(event);
  658. },
  659. onClickWrapper(event) {
  660. this.$emit("click", event);
  661. },
  662. onClickScrollbar(event) {
  663. this.$emit("scrollbarClick", event);
  664. },
  665. onTouchStartScrollbar(event) {
  666. this.swiper.emit('touchStartScrollbar', event);
  667. },
  668. onTouchMoveScrollbar(event) {
  669. this.swiper.emit('touchMoveScrollbar', event);
  670. },
  671. onTouchEndScrollbar(event) {
  672. this.swiper.emit('touchEndScrollbar', event);
  673. },
  674. cubeShadowCss(value) {
  675. Object.keys(value).forEach((item) => {
  676. this.$set(this.cubeShadowStyle, item, value[item])
  677. })
  678. },
  679. cubeShadowTransform(value) {
  680. this.$set(this.cubeShadowStyle, 'transform', value)
  681. },
  682. cubeShadowTransition(value) {
  683. this.$set(this.cubeShadowStyle, 'transitionDuration', `${value}ms`)
  684. },
  685. }
  686. }
  687. </script>
  688. <style scoped lang="scss">
  689. @import '../../libs/core.scss';
  690. @import "../../static/css/iconfont.css";
  691. .swiper {
  692. &__prev--button {
  693. position: absolute;
  694. left: 30rpx;
  695. top: 50%;
  696. display: flex;
  697. color: #1989fa;
  698. font-size: 44rpx;
  699. z-index: 10;
  700. }
  701. &__prev--button--disable {
  702. position: absolute;
  703. left: 30rpx;
  704. top: 50%;
  705. display: flex;
  706. color: #1989fa;
  707. font-size: 44rpx;
  708. opacity: .35;
  709. z-index: 10;
  710. }
  711. &__next--button {
  712. position: absolute;
  713. right: 30rpx;
  714. top: 50%;
  715. display: flex;
  716. color: #1989fa;
  717. font-size: 44rpx;
  718. z-index: 10;
  719. }
  720. &__next--button--disable {
  721. position: absolute;
  722. right: 30rpx;
  723. top: 50%;
  724. display: flex;
  725. color: #1989fa;
  726. font-size: 44rpx;
  727. opacity: .35;
  728. z-index: 10;
  729. }
  730. }
  731. </style>