Card.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. cardProps: () => cardProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_tag = require("../tag");
  28. var import_image = require("../image");
  29. const [name, bem] = (0, import_utils.createNamespace)("card");
  30. const cardProps = {
  31. tag: String,
  32. num: import_utils.numericProp,
  33. desc: String,
  34. thumb: String,
  35. title: String,
  36. price: import_utils.numericProp,
  37. centered: Boolean,
  38. lazyLoad: Boolean,
  39. currency: (0, import_utils.makeStringProp)("\xA5"),
  40. thumbLink: String,
  41. originPrice: import_utils.numericProp
  42. };
  43. var stdin_default = (0, import_vue2.defineComponent)({
  44. name,
  45. props: cardProps,
  46. emits: ["clickThumb"],
  47. setup(props, {
  48. slots,
  49. emit
  50. }) {
  51. const renderTitle = () => {
  52. if (slots.title) {
  53. return slots.title();
  54. }
  55. if (props.title) {
  56. return (0, import_vue.createVNode)("div", {
  57. "class": [bem("title"), "van-multi-ellipsis--l2"]
  58. }, [props.title]);
  59. }
  60. };
  61. const renderThumbTag = () => {
  62. if (slots.tag || props.tag) {
  63. return (0, import_vue.createVNode)("div", {
  64. "class": bem("tag")
  65. }, [slots.tag ? slots.tag() : (0, import_vue.createVNode)(import_tag.Tag, {
  66. "mark": true,
  67. "type": "primary"
  68. }, {
  69. default: () => [props.tag]
  70. })]);
  71. }
  72. };
  73. const renderThumbImage = () => {
  74. if (slots.thumb) {
  75. return slots.thumb();
  76. }
  77. return (0, import_vue.createVNode)(import_image.Image, {
  78. "src": props.thumb,
  79. "fit": "cover",
  80. "width": "100%",
  81. "height": "100%",
  82. "lazyLoad": props.lazyLoad
  83. }, null);
  84. };
  85. const renderThumb = () => {
  86. if (slots.thumb || props.thumb) {
  87. return (0, import_vue.createVNode)("a", {
  88. "href": props.thumbLink,
  89. "class": bem("thumb"),
  90. "onClick": (event) => emit("clickThumb", event)
  91. }, [renderThumbImage(), renderThumbTag()]);
  92. }
  93. };
  94. const renderDesc = () => {
  95. if (slots.desc) {
  96. return slots.desc();
  97. }
  98. if (props.desc) {
  99. return (0, import_vue.createVNode)("div", {
  100. "class": [bem("desc"), "van-ellipsis"]
  101. }, [props.desc]);
  102. }
  103. };
  104. const renderPriceText = () => {
  105. const priceArr = props.price.toString().split(".");
  106. return (0, import_vue.createVNode)("div", null, [(0, import_vue.createVNode)("span", {
  107. "class": bem("price-currency")
  108. }, [props.currency]), (0, import_vue.createVNode)("span", {
  109. "class": bem("price-integer")
  110. }, [priceArr[0]]), (0, import_vue.createTextVNode)("."), (0, import_vue.createVNode)("span", {
  111. "class": bem("price-decimal")
  112. }, [priceArr[1]])]);
  113. };
  114. return () => {
  115. var _a, _b, _c;
  116. const showNum = slots.num || (0, import_utils.isDef)(props.num);
  117. const showPrice = slots.price || (0, import_utils.isDef)(props.price);
  118. const showOriginPrice = slots["origin-price"] || (0, import_utils.isDef)(props.originPrice);
  119. const showBottom = showNum || showPrice || showOriginPrice || slots.bottom;
  120. const Price = showPrice && (0, import_vue.createVNode)("div", {
  121. "class": bem("price")
  122. }, [slots.price ? slots.price() : renderPriceText()]);
  123. const OriginPrice = showOriginPrice && (0, import_vue.createVNode)("div", {
  124. "class": bem("origin-price")
  125. }, [slots["origin-price"] ? slots["origin-price"]() : `${props.currency} ${props.originPrice}`]);
  126. const Num = showNum && (0, import_vue.createVNode)("div", {
  127. "class": bem("num")
  128. }, [slots.num ? slots.num() : `x${props.num}`]);
  129. const Footer = slots.footer && (0, import_vue.createVNode)("div", {
  130. "class": bem("footer")
  131. }, [slots.footer()]);
  132. const Bottom = showBottom && (0, import_vue.createVNode)("div", {
  133. "class": bem("bottom")
  134. }, [(_a = slots["price-top"]) == null ? void 0 : _a.call(slots), Price, OriginPrice, Num, (_b = slots.bottom) == null ? void 0 : _b.call(slots)]);
  135. return (0, import_vue.createVNode)("div", {
  136. "class": bem()
  137. }, [(0, import_vue.createVNode)("div", {
  138. "class": bem("header")
  139. }, [renderThumb(), (0, import_vue.createVNode)("div", {
  140. "class": bem("content", {
  141. centered: props.centered
  142. })
  143. }, [(0, import_vue.createVNode)("div", null, [renderTitle(), renderDesc(), (_c = slots.tags) == null ? void 0 : _c.call(slots)]), Bottom])]), Footer]);
  144. };
  145. }
  146. });