uni-swiper-dot.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "UniSwiperDot",
  5. emits: ["clickItem"],
  6. props: {
  7. info: {
  8. type: Array,
  9. default() {
  10. return [];
  11. }
  12. },
  13. current: {
  14. type: Number,
  15. default: 0
  16. },
  17. dotsStyles: {
  18. type: Object,
  19. default() {
  20. return {};
  21. }
  22. },
  23. // 类型 :default(默认) indexes long nav
  24. mode: {
  25. type: String,
  26. default: "default"
  27. },
  28. // 只在 nav 模式下生效,变量名称
  29. field: {
  30. type: String,
  31. default: ""
  32. }
  33. },
  34. data() {
  35. return {
  36. dots: {
  37. width: 6,
  38. height: 6,
  39. bottom: 10,
  40. color: "#fff",
  41. backgroundColor: "rgba(0, 0, 0, .3)",
  42. border: "1px rgba(0, 0, 0, .3) solid",
  43. selectedBackgroundColor: "#333",
  44. selectedBorder: "1px rgba(0, 0, 0, .9) solid"
  45. }
  46. };
  47. },
  48. watch: {
  49. dotsStyles(newVal) {
  50. this.dots = Object.assign(this.dots, this.dotsStyles);
  51. },
  52. mode(newVal) {
  53. if (newVal === "indexes") {
  54. this.dots.width = 14;
  55. this.dots.height = 14;
  56. } else {
  57. this.dots.width = 6;
  58. this.dots.height = 6;
  59. }
  60. }
  61. },
  62. created() {
  63. if (this.mode === "indexes") {
  64. this.dots.width = 12;
  65. this.dots.height = 12;
  66. }
  67. this.dots = Object.assign(this.dots, this.dotsStyles);
  68. },
  69. methods: {
  70. clickItem(index) {
  71. this.$emit("clickItem", index);
  72. }
  73. }
  74. };
  75. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  76. return common_vendor.e({
  77. a: $props.mode === "default"
  78. }, $props.mode === "default" ? {
  79. b: common_vendor.f($props.info, (item, index, i0) => {
  80. return {
  81. a: common_vendor.o(($event) => $options.clickItem(index), index),
  82. b: (index === $props.current ? $data.dots.width * 2 : $data.dots.width) + "px",
  83. c: index !== $props.current ? $data.dots.backgroundColor : $data.dots.selectedBackgroundColor,
  84. d: index
  85. };
  86. }),
  87. c: $data.dots.width / 2 + "px",
  88. d: $data.dots.bottom + "px"
  89. } : {}, {
  90. e: $props.mode === "dot"
  91. }, $props.mode === "dot" ? {
  92. f: common_vendor.f($props.info, (item, index, i0) => {
  93. return {
  94. a: common_vendor.o(($event) => $options.clickItem(index), index),
  95. b: index !== $props.current ? $data.dots.backgroundColor : $data.dots.selectedBackgroundColor,
  96. c: index !== $props.current ? $data.dots.border : $data.dots.selectedBorder,
  97. d: index
  98. };
  99. }),
  100. g: $data.dots.width + "px",
  101. h: $data.dots.height + "px",
  102. i: $data.dots.bottom + "px"
  103. } : {}, {
  104. j: $props.mode === "round"
  105. }, $props.mode === "round" ? {
  106. k: common_vendor.f($props.info, (item, index, i0) => {
  107. return {
  108. a: common_vendor.o(($event) => $options.clickItem(index), index),
  109. b: common_vendor.n(index === $props.current && "uni-swiper__dots-long"),
  110. c: (index === $props.current ? $data.dots.width * 3 : $data.dots.width) + "px",
  111. d: index !== $props.current ? $data.dots.backgroundColor : $data.dots.selectedBackgroundColor,
  112. e: index !== $props.current ? $data.dots.border : $data.dots.selectedBorder,
  113. f: index
  114. };
  115. }),
  116. l: $data.dots.height + "px",
  117. m: $data.dots.bottom + "px"
  118. } : {}, {
  119. n: $props.mode === "nav"
  120. }, $props.mode === "nav" ? {
  121. o: common_vendor.t($props.current + 1 + "/" + $props.info.length + " " + $props.info[$props.current][$props.field]),
  122. p: $props.dotsStyles.color,
  123. q: $props.dotsStyles.backgroundColor
  124. } : {}, {
  125. r: $props.mode === "indexes"
  126. }, $props.mode === "indexes" ? {
  127. s: common_vendor.f($props.info, (item, index, i0) => {
  128. return {
  129. a: common_vendor.t(index + 1),
  130. b: common_vendor.o(($event) => $options.clickItem(index), index),
  131. c: index === $props.current ? $data.dots.selectedColor : $data.dots.color,
  132. d: index !== $props.current ? $data.dots.backgroundColor : $data.dots.selectedBackgroundColor,
  133. e: index !== $props.current ? $data.dots.border : $data.dots.selectedBorder,
  134. f: index
  135. };
  136. }),
  137. t: $data.dots.width + "px",
  138. v: $data.dots.height + "px",
  139. w: $data.dots.bottom + "px"
  140. } : {});
  141. }
  142. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-0667e3db"], ["__file", "D:/zx/mall-front-app/uni_modules/uni-swiper-dot/components/uni-swiper-dot/uni-swiper-dot.vue"]]);
  143. wx.createComponent(Component);