u-swiper.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-swiper",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.props],
  6. data() {
  7. return {
  8. currentIndex: 0
  9. };
  10. },
  11. watch: {
  12. current(val, preVal) {
  13. if (val === preVal)
  14. return;
  15. this.currentIndex = val;
  16. }
  17. },
  18. emits: ["click", "change"],
  19. computed: {
  20. itemStyle() {
  21. return (index) => {
  22. const style = {};
  23. if (this.nextMargin && this.previousMargin) {
  24. style.borderRadius = common_vendor.addUnit(this.radius);
  25. if (index !== this.currentIndex)
  26. style.transform = "scale(0.92)";
  27. }
  28. return style;
  29. };
  30. }
  31. },
  32. methods: {
  33. addStyle: common_vendor.addStyle,
  34. addUnit: common_vendor.addUnit,
  35. testObject: common_vendor.test.object,
  36. testImage: common_vendor.test.image,
  37. getItemType(item) {
  38. if (typeof item === "string")
  39. return common_vendor.test.video(this.getSource(item)) ? "video" : "image";
  40. if (typeof item === "object" && this.keyName) {
  41. if (!item.type)
  42. return common_vendor.test.video(this.getSource(item)) ? "video" : "image";
  43. if (item.type === "image")
  44. return "image";
  45. if (item.type === "video")
  46. return "video";
  47. return "image";
  48. }
  49. },
  50. // 获取目标路径,可能数组中为字符串,对象的形式,额外可指定对象的目标属性名keyName
  51. getSource(item) {
  52. if (typeof item === "string")
  53. return item;
  54. if (typeof item === "object" && this.keyName)
  55. return item[this.keyName];
  56. else
  57. common_vendor.error("请按格式传递列表参数");
  58. return "";
  59. },
  60. // 轮播切换事件
  61. change(e) {
  62. const {
  63. current
  64. } = e.detail;
  65. this.pauseVideo(this.currentIndex);
  66. this.currentIndex = current;
  67. this.$emit("change", e.detail);
  68. },
  69. // 切换轮播时,暂停视频播放
  70. pauseVideo(index) {
  71. const lastItem = this.getSource(this.list[index]);
  72. if (common_vendor.test.video(lastItem)) {
  73. const video = common_vendor.index.createVideoContext(`video-${index}`, this);
  74. video.pause();
  75. }
  76. },
  77. // 当一个轮播item为视频时,获取它的视频海报
  78. getPoster(item) {
  79. return typeof item === "object" && item.poster ? item.poster : "";
  80. },
  81. // 点击某个item
  82. clickHandler(index) {
  83. this.$emit("click", index);
  84. }
  85. }
  86. };
  87. if (!Array) {
  88. const _easycom_u_loading_icon2 = common_vendor.resolveComponent("u-loading-icon");
  89. const _easycom_u_swiper_indicator2 = common_vendor.resolveComponent("u-swiper-indicator");
  90. (_easycom_u_loading_icon2 + _easycom_u_swiper_indicator2)();
  91. }
  92. const _easycom_u_loading_icon = () => "../u-loading-icon/u-loading-icon.js";
  93. const _easycom_u_swiper_indicator = () => "../u-swiper-indicator/u-swiper-indicator.js";
  94. if (!Math) {
  95. (_easycom_u_loading_icon + _easycom_u_swiper_indicator)();
  96. }
  97. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  98. return common_vendor.e({
  99. a: _ctx.loading
  100. }, _ctx.loading ? {
  101. b: common_vendor.p({
  102. mode: "circle"
  103. })
  104. } : {
  105. c: common_vendor.f(_ctx.list, (item, index, i0) => {
  106. return common_vendor.e({
  107. a: $options.getItemType(item) === "image"
  108. }, $options.getItemType(item) === "image" ? {
  109. b: $options.getSource(item),
  110. c: _ctx.imgMode,
  111. d: common_vendor.o(($event) => $options.clickHandler(index), index),
  112. e: $options.addUnit(_ctx.height),
  113. f: $options.addUnit(_ctx.radius)
  114. } : {}, {
  115. g: $options.getItemType(item) === "video"
  116. }, $options.getItemType(item) === "video" ? {
  117. h: `video-${index}`,
  118. i: $options.getSource(item),
  119. j: $options.getPoster(item),
  120. k: _ctx.showTitle && $options.testObject(item) && item.title ? item.title : "",
  121. l: $options.addUnit(_ctx.height),
  122. m: common_vendor.o(($event) => $options.clickHandler(index), index)
  123. } : {}, {
  124. n: _ctx.showTitle && $options.testObject(item) && item.title && $options.testImage($options.getSource(item))
  125. }, _ctx.showTitle && $options.testObject(item) && item.title && $options.testImage($options.getSource(item)) ? {
  126. o: common_vendor.t(item.title)
  127. } : {}, {
  128. p: common_vendor.s($options.itemStyle(index)),
  129. q: index
  130. });
  131. }),
  132. d: $options.addUnit(_ctx.height),
  133. e: common_vendor.o((...args) => $options.change && $options.change(...args)),
  134. f: _ctx.circular,
  135. g: _ctx.interval,
  136. h: _ctx.duration,
  137. i: _ctx.autoplay,
  138. j: _ctx.current,
  139. k: _ctx.currentItemId,
  140. l: $options.addUnit(_ctx.previousMargin),
  141. m: $options.addUnit(_ctx.nextMargin),
  142. n: _ctx.acceleration,
  143. o: _ctx.displayMultipleItems,
  144. p: _ctx.easingFunction
  145. }, {
  146. q: !_ctx.loading && _ctx.indicator && !_ctx.showTitle
  147. }, !_ctx.loading && _ctx.indicator && !_ctx.showTitle ? {
  148. r: common_vendor.p({
  149. indicatorActiveColor: _ctx.indicatorActiveColor,
  150. indicatorInactiveColor: _ctx.indicatorInactiveColor,
  151. length: _ctx.list.length,
  152. current: $data.currentIndex,
  153. indicatorMode: _ctx.indicatorMode
  154. })
  155. } : {}, {
  156. s: common_vendor.s($options.addStyle(_ctx.indicatorStyle)),
  157. t: _ctx.bgColor,
  158. v: $options.addUnit(_ctx.height),
  159. w: $options.addUnit(_ctx.radius)
  160. });
  161. }
  162. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-eda42115"], ["__file", "D:/project/学吧/learn_applet/node_modules/uview-plus/components/u-swiper/u-swiper.vue"]]);
  163. wx.createComponent(Component);