STree.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var m = (d, y, 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, y)).next());
  16. });
  17. import { ref as h, onMounted as b, openBlock as _, createElementBlock as k, createVNode as B, withCtx as f, createElementVNode as x, normalizeClass as C, toDisplayString as v, createBlock as S, createTextVNode as V } from "vue";
  18. import { l as I, a9 as D } from "./index2.js";
  19. import { _ as N } from "./index10.js";
  20. const O = { class: "s-tree-common" }, T = { class: "node-title" }, E = {
  21. key: 1,
  22. class: "node-title"
  23. }, F = {
  24. __name: "STree",
  25. props: {
  26. // 是否展开所有节点
  27. expandAll: {
  28. type: Boolean,
  29. default: !1
  30. },
  31. // 树节点属性
  32. props: {
  33. type: Object,
  34. default: () => ({
  35. children: "children",
  36. label: "name",
  37. value: "value"
  38. })
  39. },
  40. // 是否添加复选框
  41. checkable: {
  42. type: Boolean,
  43. default: !1
  44. },
  45. // 树高度
  46. height: {
  47. type: Number,
  48. default: 300
  49. },
  50. // 获取一级节点数据
  51. levelOneChildren: {
  52. type: Function,
  53. default: () => {
  54. }
  55. },
  56. // 获取二级节点数据
  57. levelTwoChildren: {
  58. type: Function,
  59. default: () => {
  60. }
  61. },
  62. // 默认选中项,支持 v-model 双向绑定
  63. modelValue: {
  64. type: [String, Array],
  65. default() {
  66. return "";
  67. }
  68. },
  69. // 默认选中第一个节点
  70. selectFirstOne: {
  71. type: Boolean,
  72. default: !1
  73. },
  74. // 是否显示图标
  75. showIcon: {
  76. type: Boolean,
  77. default: !1
  78. },
  79. // 显示字数长度 超过15字符显示省略号并且鼠标悬浮tooltip显示
  80. showLength: {
  81. type: [Number, String],
  82. default: 15
  83. }
  84. },
  85. emits: ["select:modelValue"],
  86. setup(d, { emit: y }) {
  87. const o = d, r = y, t = h([]), i = h([]), s = h([]), c = h([]), a = (n, e) => m(this, null, function* () {
  88. 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;
  89. }), u = (n, e) => {
  90. r("select:modelValue", n, e);
  91. }, K = () => m(this, null, function* () {
  92. var n, e, p;
  93. 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]);
  94. }), g = (n) => ["D", "G", "C", "D"][n];
  95. return b(() => {
  96. K();
  97. }), (n, e) => {
  98. const p = D, w = N;
  99. return _(), k("div", O, [
  100. B(w, {
  101. selectedKeys: i.value,
  102. "onUpdate:selectedKeys": e[0] || (e[0] = (l) => i.value = l),
  103. checkedKeys: s.value,
  104. "onUpdate:checkedKeys": e[1] || (e[1] = (l) => s.value = l),
  105. expandedKeys: c.value,
  106. "onUpdate:expandedKeys": e[2] || (e[2] = (l) => c.value = l),
  107. "default-expand-all": d.expandAll,
  108. checkable: d.checkable,
  109. "tree-data": t.value,
  110. showIcon: d.showIcon,
  111. height: d.height,
  112. onExpand: a,
  113. onSelect: u
  114. }, {
  115. icon: f((l) => [
  116. x("div", {
  117. class: C(["node-icon", g(l.type)])
  118. }, v(g(l.type)), 3)
  119. ]),
  120. title: f((l) => [
  121. l.title.length > 15 ? (_(), S(p, {
  122. key: 0,
  123. placement: "topLeft"
  124. }, {
  125. title: f(() => [
  126. V(v(l.title), 1)
  127. ]),
  128. default: f(() => [
  129. x("div", T, v(l.title.slice(0, 15)) + "...", 1)
  130. ]),
  131. _: 2
  132. }, 1024)) : (_(), k("div", E, v(l.title), 1))
  133. ]),
  134. _: 1
  135. }, 8, ["selectedKeys", "checkedKeys", "expandedKeys", "default-expand-all", "checkable", "tree-data", "showIcon", "height"])
  136. ]);
  137. };
  138. }
  139. }, j = /* @__PURE__ */ I(F, [["__scopeId", "data-v-387e921d"]]);
  140. export {
  141. j as default
  142. };