index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <!-- #ifdef APP-VUE || H5 -->
  3. <view class="box" :style="boxStyle">
  4. <view
  5. ref="container"
  6. class="container"
  7. :change:prop="swipe.changeData"
  8. :prop="wxsData"
  9. @touchstart.stop="swipe.touchstart"
  10. @touchmove.stop="swipe.touchmove"
  11. @touchend.stop="swipe.touchend"
  12. :style="containerStyle"
  13. >
  14. <slot></slot>
  15. </view>
  16. </view>
  17. <!-- #endif -->
  18. <!-- #ifdef MP-WEIXIN -->
  19. <view class="box" :style="boxStyle">
  20. <view
  21. ref="container"
  22. class="container"
  23. :change:prop="swipe.changeData"
  24. :prop="wxsData"
  25. @touchstart="swipe.touchstart"
  26. @touchmove="swipe.touchmove"
  27. @touchend="swipe.touchend"
  28. :style="containerStyle"
  29. >
  30. <slot></slot>
  31. </view>
  32. </view>
  33. <!-- #endif -->
  34. <!-- #ifdef APP-NVUE -->
  35. <view class="box" :style="boxStyle">
  36. <view ref="container" class="container" @horizontalpan="touchstart" :style="containerStyle"><slot></slot></view>
  37. </view>
  38. <!-- #endif -->
  39. <!-- 其他平台使用 js ,长列表性能可能会有影响-->
  40. <!-- #ifndef APP-PLUS || MP-WEIXIN || H5 -->
  41. <view class="box" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend" :style="boxStyle">
  42. <view ref="container" class="container" :style="containerStyle"><slot></slot></view>
  43. </view>
  44. <!-- #endif -->
  45. </template>
  46. <script src="./mixins/index.wxs" module="swipe" lang="wxs"></script>
  47. <script>
  48. import SwiperMixin from './mixins/base.mixin.js';
  49. // #ifdef APP-VUE || MP-WEIXIN || H5
  50. import MpMixin from './mixins/mpwxs.js';
  51. // #endif
  52. // #ifdef APP-NVUE
  53. import BindingxMixin from './mixins/bindingx.js';
  54. // #endif
  55. // #ifndef APP-PLUS || MP-WEIXIN || H5
  56. import OtherMixin from './mixins/mpother.js';
  57. // #endif
  58. const mixins = [
  59. // #ifdef APP-VUE || MP-WEIXIN || H5
  60. MpMixin,
  61. // #endif
  62. // #ifdef APP-NVUE
  63. BindingxMixin,
  64. // #endif
  65. // #ifndef APP-PLUS || MP-WEIXIN || H5
  66. OtherMixin,
  67. // #endif
  68. SwiperMixin
  69. ];
  70. /**
  71. * esc-swiper
  72. * @description 自定义swiper (不支持使用class)
  73. * @property {String} mode = [normal|3d] 模式
  74. * @property {Number} scale 3D模式选中项的scale
  75. * @property {Number} width 宽
  76. * @property {Number} height 高
  77. * @property {Number} itemWidth 项宽
  78. * @property {Number} itemHeight 项高
  79. * @property {Number} space 间距
  80. * @property {Number} plus 左右追加个数(开启循环必填,至少为2)
  81. * @property {Number} current 选中项索引
  82. * @property {Boolean} autoplay 自动轮播
  83. * @property {Boolean} circular 是否循环,如果开启,至少需要3项
  84. * @property {Boolean} bounce 阻尼效果
  85. * @event {Function} change 索引变化
  86. */
  87. export default {
  88. name: 'esc-swiper',
  89. mixins,
  90. props: {
  91. mode: {
  92. type: String,
  93. default: 'normal'
  94. },
  95. scale: Number,
  96. width: Number,
  97. height: Number,
  98. itemWidth: {
  99. type: Number,
  100. default: 0
  101. },
  102. itemHeight: {
  103. type: Number,
  104. default: 0
  105. },
  106. space: {
  107. type: Number,
  108. default: 0
  109. },
  110. plus: {
  111. type: Number,
  112. default: 0
  113. },
  114. autoplay: {
  115. type: Boolean,
  116. default: false
  117. },
  118. current: {
  119. type: Number,
  120. default: 0
  121. },
  122. interval: {
  123. type: Number,
  124. default: 5000
  125. },
  126. duration: {
  127. type: Number,
  128. default: 500
  129. },
  130. circular: {
  131. type: Boolean,
  132. default: false
  133. },
  134. bounce: {
  135. type: Boolean,
  136. default: true
  137. },
  138. size: {
  139. type: Number,
  140. default: 0
  141. }
  142. },
  143. provide() {
  144. return {
  145. config: {
  146. is3D: this.is3D,
  147. isCircular: this.circular,
  148. scale: this.scale,
  149. size: this._size,
  150. width: this.width,
  151. height: this.height,
  152. itemWidth: this.itemWidth,
  153. itemHeight: this.itemHeight,
  154. space: this.space,
  155. plus: this.plus
  156. }
  157. };
  158. },
  159. mounted() {
  160. if (this.autoplay) {
  161. this.autoplayInterval = setInterval(() => {
  162. this.next();
  163. }, this.interval);
  164. }
  165. },
  166. watch: {
  167. autoplay(newV) {
  168. if (!newV) {
  169. clearInterval(this.autoplayInterval);
  170. } else {
  171. this.autoplayInterval = setInterval(() => {
  172. this.next();
  173. }, this.interval);
  174. }
  175. }
  176. },
  177. methods: {}
  178. };
  179. </script>
  180. <style scoped>
  181. .box {
  182. position: relative;
  183. overflow: hidden;
  184. }
  185. .container {
  186. position: absolute;
  187. top: 0;
  188. /* #ifndef APP-NVUE */
  189. display: flex;
  190. /* #endif */
  191. flex-direction: row;
  192. align-items: center;
  193. }
  194. </style>