swiper.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-swiper`;
  12. let Swiper = class Swiper extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = [
  16. `${prefix}-class`,
  17. `${prefix}-class-nav`,
  18. `${prefix}-class-image`,
  19. `${prefix}-class-prev-image`,
  20. `${prefix}-class-next-image`,
  21. ];
  22. this.options = {
  23. multipleSlots: true,
  24. };
  25. this.properties = props;
  26. this.observers = {
  27. navCurrent(v) {
  28. this.updateNav(v);
  29. },
  30. };
  31. this.$nav = null;
  32. this.relations = {
  33. '../swiper-nav/swiper-nav': {
  34. type: 'child',
  35. },
  36. };
  37. this.data = {
  38. prefix,
  39. classPrefix: name,
  40. };
  41. this.lifetimes = {
  42. ready() {
  43. const { current } = this.properties;
  44. this.setData({ navCurrent: current });
  45. },
  46. };
  47. this.methods = {
  48. updateNav(currentValue) {
  49. var _a;
  50. if (this.data.navigation)
  51. return;
  52. const $nav = (_a = this.getRelationNodes('./swiper-nav')) === null || _a === void 0 ? void 0 : _a[0];
  53. if (!$nav)
  54. return;
  55. const { direction, paginationPosition, list } = this.properties;
  56. $nav.setData({
  57. current: currentValue,
  58. total: list.length,
  59. direction,
  60. paginationPosition,
  61. });
  62. },
  63. onTap(e) {
  64. const { index } = e.currentTarget.dataset;
  65. this.triggerEvent('click', { index });
  66. },
  67. onChange(e) {
  68. const { current, source } = e.detail;
  69. this.setData({
  70. navCurrent: current,
  71. });
  72. this.triggerEvent('change', { current, source });
  73. },
  74. onNavBtnChange(e) {
  75. const { dir, source } = e.detail;
  76. this.doNavBtnChange(dir, source);
  77. },
  78. doNavBtnChange(dir, source) {
  79. const { current, list, loop } = this.data;
  80. const count = list.length;
  81. let nextPos = dir === 'next' ? current + 1 : current - 1;
  82. if (loop) {
  83. nextPos = dir === 'next' ? (current + 1) % count : (current - 1 + count) % count;
  84. }
  85. else {
  86. nextPos = nextPos < 0 || nextPos >= count ? current : nextPos;
  87. }
  88. if (nextPos === current)
  89. return;
  90. this.setData({
  91. current: nextPos,
  92. });
  93. this.triggerEvent('change', { current: nextPos, source });
  94. },
  95. };
  96. }
  97. };
  98. Swiper = __decorate([
  99. wxComponent()
  100. ], Swiper);
  101. export default Swiper;