u-swiper.js 5.5 KB

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