wd-img.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const __default__ = {
  4. name: "wd-img",
  5. options: {
  6. virtualHost: true,
  7. addGlobalClass: true,
  8. styleIsolation: "shared"
  9. }
  10. };
  11. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  12. ...__default__,
  13. props: common_vendor.imgProps,
  14. emits: ["error", "click", "load"],
  15. setup(__props, { emit: __emit }) {
  16. const props = __props;
  17. const emit = __emit;
  18. const rootStyle = common_vendor.computed(() => {
  19. const style = {};
  20. if (common_vendor.isDef(props.height)) {
  21. style["height"] = common_vendor.addUnit(props.height);
  22. }
  23. if (common_vendor.isDef(props.width)) {
  24. style["width"] = common_vendor.addUnit(props.width);
  25. }
  26. if (common_vendor.isDef(props.radius)) {
  27. style["border-radius"] = common_vendor.addUnit(props.radius);
  28. style["overflow"] = "hidden";
  29. }
  30. return `${common_vendor.objToStyle(style)}${props.customStyle}`;
  31. });
  32. const rootClass = common_vendor.computed(() => {
  33. return `wd-img ${props.round ? "is-round" : ""} ${props.customClass}`;
  34. });
  35. const status = common_vendor.ref("loading");
  36. function handleError(event) {
  37. status.value = "error";
  38. emit("error", event);
  39. }
  40. function handleClick(event) {
  41. if (props.enablePreview && props.src && status.value == "success") {
  42. common_vendor.index.previewImage({
  43. urls: [props.previewSrc || props.src]
  44. });
  45. }
  46. emit("click", event);
  47. }
  48. function handleLoad(event) {
  49. status.value = "success";
  50. emit("load", event);
  51. }
  52. return (_ctx, _cache) => {
  53. return common_vendor.e({
  54. a: common_vendor.n(`wd-img__image ${_ctx.customImage}`),
  55. b: common_vendor.s(status.value !== "success" ? "width: 0;height: 0;" : ""),
  56. c: _ctx.src,
  57. d: _ctx.mode,
  58. e: _ctx.showMenuByLongpress,
  59. f: _ctx.lazyLoad,
  60. g: common_vendor.o(handleLoad),
  61. h: common_vendor.o(handleError),
  62. i: status.value === "loading"
  63. }, status.value === "loading" ? {} : {}, {
  64. j: status.value === "error"
  65. }, status.value === "error" ? {} : {}, {
  66. k: common_vendor.n(rootClass.value),
  67. l: common_vendor.o(handleClick),
  68. m: common_vendor.s(rootStyle.value)
  69. });
  70. };
  71. }
  72. });
  73. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2cf12824"]]);
  74. wx.createComponent(Component);