u-swiper.js 5.5 KB

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