STree.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. var m = (d, v, o) => new Promise((r, t) => {
  2. var i = (a) => {
  3. try {
  4. c(o.next(a));
  5. } catch (u) {
  6. t(u);
  7. }
  8. }, s = (a) => {
  9. try {
  10. c(o.throw(a));
  11. } catch (u) {
  12. t(u);
  13. }
  14. }, c = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(i, s);
  15. c((o = o.apply(d, v)).next());
  16. });
  17. import { ref as h, onMounted as b, openBlock as _, createElementBlock as k, createVNode as B, withCtx as y, createBlock as C, createElementVNode as x, toDisplayString as f, createTextVNode as D, normalizeClass as S } from "vue";
  18. import { n as V, x as I, y as E } from "./index2.js";
  19. const N = { class: "s-tree-common" }, O = { class: "node-title" }, T = {
  20. key: 1,
  21. class: "node-title"
  22. }, F = {
  23. __name: "STree",
  24. props: {
  25. // 是否展开所有节点
  26. expandAll: {
  27. type: Boolean,
  28. default: !1
  29. },
  30. // 树节点属性
  31. props: {
  32. type: Object,
  33. default: () => ({
  34. children: "children",
  35. label: "name",
  36. value: "value"
  37. })
  38. },
  39. // 是否添加复选框
  40. checkable: {
  41. type: Boolean,
  42. default: !1
  43. },
  44. // 树高度:默认不传,由外层容器(layout 的 .s-side-tree > .s-tree-common { height:100% })撑满并滚动。
  45. // 注意:a-tree 的 height 会让 antd 在 .ant-tree-list-holder 上写死 max-height 内联样式(vc-virtual-list/List.js
  46. // 在 fullHeight:false 时用 maxHeight),写死数值会让树被截断,故默认 undefined;业务确有固定高度需求时再显式传。
  47. height: {
  48. type: Number,
  49. default: void 0
  50. },
  51. // 获取一级节点数据
  52. levelOneChildren: {
  53. type: Function,
  54. default: () => {
  55. }
  56. },
  57. // 获取二级节点数据
  58. levelTwoChildren: {
  59. type: Function,
  60. default: () => {
  61. }
  62. },
  63. // 默认选中项,支持 v-model 双向绑定
  64. modelValue: {
  65. type: [String, Array],
  66. default() {
  67. return "";
  68. }
  69. },
  70. // 默认选中第一个节点
  71. selectFirstOne: {
  72. type: Boolean,
  73. default: !1
  74. },
  75. // 是否显示图标
  76. showIcon: {
  77. type: Boolean,
  78. default: !1
  79. },
  80. // 显示字数长度 超过15字符显示省略号并且鼠标悬浮tooltip显示
  81. showLength: {
  82. type: [Number, String],
  83. default: 15
  84. }
  85. },
  86. emits: ["select:modelValue"],
  87. setup(d, { emit: v }) {
  88. const o = d, r = v, t = h([]), i = h([]), s = h([]), c = h([]), a = (n, e) => m(this, null, function* () {
  89. e.expanded && (!e.node.dataRef.children || e.node.dataRef.children.length === 0) && (e.node.dataRef.children = yield o.levelOneChildren(e.node.dataRef.id)), n.value = n;
  90. }), u = (n, e) => {
  91. r("select:modelValue", n, e);
  92. }, K = () => m(this, null, function* () {
  93. var n, e, p;
  94. s.value = [], t.value = (yield o.levelTwoChildren("")) || [], (n = t.value) != null && n.length && t.value[0] && ((e = t.value[0].children) != null && e.length) && (o.selectFirstOne && (t.value[0].selected = !0, i.value.push(((p = t.value[0]) == null ? void 0 : p.id) || ""), r("select:modelValue", t.value[0].id || "", t.value[0])), s.value = [t.value[0].id]);
  95. }), g = (n) => ["D", "G", "C", "D"][n];
  96. return b(() => {
  97. K();
  98. }), (n, e) => {
  99. const p = E, w = I;
  100. return _(), k("div", N, [
  101. B(w, {
  102. selectedKeys: i.value,
  103. "onUpdate:selectedKeys": e[0] || (e[0] = (l) => i.value = l),
  104. checkedKeys: s.value,
  105. "onUpdate:checkedKeys": e[1] || (e[1] = (l) => s.value = l),
  106. expandedKeys: c.value,
  107. "onUpdate:expandedKeys": e[2] || (e[2] = (l) => c.value = l),
  108. "default-expand-all": d.expandAll,
  109. checkable: d.checkable,
  110. "tree-data": t.value,
  111. showIcon: d.showIcon,
  112. height: d.height,
  113. onExpand: a,
  114. onSelect: u
  115. }, {
  116. icon: y((l) => [
  117. x("div", {
  118. class: S(["node-icon", g(l.type)])
  119. }, f(g(l.type)), 3)
  120. ]),
  121. title: y((l) => [
  122. (l.title || "").length > 15 ? (_(), C(p, {
  123. key: 0,
  124. placement: "topLeft",
  125. mouseEnterDelay: 1.5,
  126. mouseLeaveDelay: 0.5
  127. }, {
  128. title: y(() => [
  129. D(f(l.title), 1)
  130. ]),
  131. default: y(() => [
  132. x("div", O, f((l.title || "").slice(0, 15)) + "...", 1)
  133. ]),
  134. _: 2
  135. }, 1024)) : (_(), k("div", T, f(l.title), 1))
  136. ]),
  137. _: 1
  138. }, 8, ["selectedKeys", "checkedKeys", "expandedKeys", "default-expand-all", "checkable", "tree-data", "showIcon", "height"])
  139. ]);
  140. };
  141. }
  142. }, U = /* @__PURE__ */ V(F, [["__scopeId", "data-v-63703ca2"]]);
  143. export {
  144. U as default
  145. };