wd-cell.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. if (!Math) {
  4. wdIcon();
  5. }
  6. const wdIcon = () => "../wd-icon/wd-icon.js";
  7. const __default__ = {
  8. name: "wd-cell",
  9. options: {
  10. addGlobalClass: true,
  11. virtualHost: true,
  12. styleIsolation: "shared"
  13. }
  14. };
  15. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  16. ...__default__,
  17. props: common_vendor.cellProps,
  18. emits: ["click"],
  19. setup(__props, { emit: __emit }) {
  20. const props = __props;
  21. const emit = __emit;
  22. const cell = common_vendor.useCell();
  23. const isBorder = common_vendor.computed(() => {
  24. return Boolean(common_vendor.isDef(props.border) ? props.border : cell.border.value);
  25. });
  26. const { parent: form } = common_vendor.useParent(common_vendor.FORM_KEY);
  27. const errorMessage = common_vendor.computed(() => {
  28. if (form && props.prop && form.errorMessages && form.errorMessages[props.prop]) {
  29. return form.errorMessages[props.prop];
  30. } else {
  31. return "";
  32. }
  33. });
  34. const isRequired = common_vendor.computed(() => {
  35. let formRequired = false;
  36. if (form && form.props.rules) {
  37. const rules = form.props.rules;
  38. for (const key in rules) {
  39. if (Object.prototype.hasOwnProperty.call(rules, key) && key === props.prop && Array.isArray(rules[key])) {
  40. formRequired = rules[key].some((rule) => rule.required);
  41. }
  42. }
  43. }
  44. return props.required || props.rules.some((rule) => rule.required) || formRequired;
  45. });
  46. function onClick() {
  47. const url = props.to;
  48. if (props.clickable || props.isLink) {
  49. emit("click");
  50. }
  51. if (url && props.isLink) {
  52. if (props.replace) {
  53. common_vendor.index.redirectTo({ url });
  54. } else {
  55. common_vendor.index.navigateTo({ url });
  56. }
  57. }
  58. }
  59. return (_ctx, _cache) => {
  60. return common_vendor.e({
  61. a: _ctx.icon
  62. }, _ctx.icon ? {
  63. b: common_vendor.p({
  64. name: _ctx.icon,
  65. ["custom-class"]: `wd-cell__icon ${_ctx.customIconClass}`
  66. })
  67. } : {}, {
  68. c: _ctx.title
  69. }, _ctx.title ? {
  70. d: common_vendor.t(_ctx.title),
  71. e: common_vendor.n(_ctx.customTitleClass)
  72. } : {}, {
  73. f: _ctx.label
  74. }, _ctx.label ? {
  75. g: common_vendor.t(_ctx.label),
  76. h: common_vendor.n(`wd-cell__label ${_ctx.customLabelClass}`)
  77. } : {}, {
  78. i: common_vendor.n(isRequired.value ? "is-required" : ""),
  79. j: common_vendor.s(_ctx.titleWidth ? "min-width:" + _ctx.titleWidth + ";max-width:" + _ctx.titleWidth + ";" : ""),
  80. k: common_vendor.t(_ctx.value),
  81. l: common_vendor.n(`wd-cell__value ${_ctx.customValueClass}`),
  82. m: _ctx.isLink
  83. }, _ctx.isLink ? {
  84. n: common_vendor.p({
  85. ["custom-class"]: "wd-cell__arrow-right",
  86. name: "arrow-right"
  87. })
  88. } : {}, {
  89. o: errorMessage.value
  90. }, errorMessage.value ? {
  91. p: common_vendor.t(errorMessage.value)
  92. } : {}, {
  93. q: common_vendor.n(_ctx.vertical ? "is-vertical" : ""),
  94. r: common_vendor.n(isBorder.value ? "is-border" : ""),
  95. s: common_vendor.n(_ctx.size ? "is-" + _ctx.size : ""),
  96. t: common_vendor.n(_ctx.center ? "is-center" : ""),
  97. v: common_vendor.n(_ctx.customClass),
  98. w: common_vendor.s(_ctx.customStyle),
  99. x: _ctx.isLink || _ctx.clickable ? "is-hover" : "none",
  100. y: common_vendor.o(onClick)
  101. });
  102. };
  103. }
  104. });
  105. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a65b3963"]]);
  106. wx.createComponent(Component);