STreeSelect.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. var j = Object.defineProperty;
  2. var T = Object.getOwnPropertySymbols;
  3. var O = Object.prototype.hasOwnProperty, U = Object.prototype.propertyIsEnumerable;
  4. var E = (n, u, o) => u in n ? j(n, u, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[u] = o, w = (n, u) => {
  5. for (var o in u || (u = {}))
  6. O.call(u, o) && E(n, o, u[o]);
  7. if (T)
  8. for (var o of T(u))
  9. U.call(u, o) && E(n, o, u[o]);
  10. return n;
  11. };
  12. import { ref as d, computed as z, watch as M, getCurrentInstance as P, onMounted as W, openBlock as f, createElementBlock as h, createVNode as q, unref as B, isRef as G, withCtx as J, Fragment as L, renderList as K, toDisplayString as A } from "vue";
  13. import { TreeSelect as Q } from "ant-design-vue";
  14. import { n as X } from "./index2.js";
  15. import { _ as Y } from "./index6.js";
  16. const Z = { class: "s-tree-select-common" }, ee = ["title"], te = ["title"], le = ["title"], ae = {
  17. __name: "STreeSelect",
  18. props: {
  19. // 过滤字段 - search为tree 时生效
  20. filterField: {
  21. type: String,
  22. default: "name"
  23. },
  24. // 树节点属性
  25. props: {
  26. type: Object,
  27. default: () => ({
  28. children: "children",
  29. label: "name",
  30. value: "value"
  31. })
  32. },
  33. // 是否支持查询
  34. search: {
  35. type: Boolean,
  36. default: !0
  37. },
  38. // 是否支持清空
  39. clear: {
  40. type: Boolean,
  41. default: !0
  42. },
  43. // 是否展开所有节点
  44. expandAll: {
  45. type: Boolean,
  46. default: !1
  47. },
  48. // 禁用
  49. disabled: {
  50. type: Boolean,
  51. default: !1
  52. },
  53. // 占位符 - 文案提示
  54. placeholder: {
  55. type: String,
  56. default() {
  57. return window.$l("请选择");
  58. }
  59. },
  60. // 默认值 - 默认选中项
  61. // 默认为空字符串,表示不选中任何项,也可以是字符串数组,表示选中项的 value 值
  62. // 默认选中项,支持 v-model 双向绑定
  63. value: {
  64. type: [String, Array],
  65. default() {
  66. return "";
  67. }
  68. },
  69. // 获取数据
  70. recursionChildren: {
  71. type: Function,
  72. default: () => []
  73. },
  74. // 是否添加全选节点
  75. appendRootNodeAll: {
  76. type: Boolean,
  77. default: !1
  78. },
  79. // 多选
  80. multiple: {
  81. type: Boolean,
  82. default: !1
  83. },
  84. // 显示数量
  85. maxTagCount: {
  86. type: Number,
  87. default: 1
  88. },
  89. //
  90. listHeight: {
  91. type: Number,
  92. default: 232
  93. }
  94. },
  95. emits: ["update:value", "change"],
  96. setup(n, { emit: u }) {
  97. const o = u, r = n, N = d(""), c = d([]), v = d([]), i = r.multiple ? d([]) : d(null), F = z(() => ({
  98. label: r.props.label,
  99. value: r.props.value,
  100. children: r.props.children
  101. })), y = d([]), p = d("");
  102. M(
  103. () => r.value,
  104. (e) => {
  105. r.multiple ? i.value = Array.isArray(e) ? e : e ? [e] : [] : i.value = e === void 0 || e === "" ? null : e;
  106. },
  107. { immediate: !0 }
  108. );
  109. const g = (e) => e && typeof e == "object" ? e.value : e, $ = (e) => {
  110. const l = Array.isArray(e) ? e.map(g) : g(e);
  111. i.value = l;
  112. const a = (Array.isArray(e) ? e : e == null ? [] : [e]).map((s) => {
  113. const m = g(s), x = b(c.value, m);
  114. return {
  115. value: m,
  116. label: s && typeof s == "object" && s.label || x && x.name || void 0,
  117. node: x
  118. };
  119. });
  120. o("update:value", l), o("change", i.value, a), C();
  121. }, V = P(), C = () => {
  122. setTimeout(() => {
  123. let e = V;
  124. for (; e; ) {
  125. const l = e.exposed;
  126. if (l && typeof l.onFieldChange == "function" && typeof l.clearValidate == "function") {
  127. l.onFieldChange();
  128. return;
  129. }
  130. e = e.parent;
  131. }
  132. }, 0);
  133. }, D = (e) => {
  134. if (!(e == null || Array.isArray(e) && !e.length)) return;
  135. const t = r.multiple ? [] : null;
  136. o("update:value", t), o("change", t, []), C();
  137. }, b = (e, l) => {
  138. for (const t of e || [])
  139. if (t) {
  140. if (t.value === l || t[r.props.value] === l) return t;
  141. if (Array.isArray(t.children)) {
  142. const a = b(t.children, l);
  143. if (a) return a;
  144. }
  145. }
  146. return null;
  147. }, H = (e) => {
  148. e.value = e;
  149. }, _ = () => {
  150. v.value = [], r.recursionChildren("", N.value).then((e) => {
  151. c.value = I(e), c.value && c.value.length > 0 && (r.value ? v.value = [r.value] : v.value = [c.value[0][r.props.value]]);
  152. });
  153. }, S = (e) => (e || []).map((l) => {
  154. const t = w({}, l);
  155. return (t[r.props.value] === void 0 || t[r.props.value] === null) && (t[r.props.value] = t.id), Array.isArray(t.children) && t.children.length && (t.children = S(t.children)), t;
  156. }), I = (e) => {
  157. if (r.appendRootNodeAll) {
  158. const l = {
  159. id: "all",
  160. key: "all",
  161. value: "all",
  162. label: window.$l("全选"),
  163. name: window.$l("全选"),
  164. title: window.$l("全选"),
  165. type: "1",
  166. typeLabel: window.$l("组织"),
  167. parent: { id: "0" },
  168. children: null,
  169. isLeaf: !0
  170. };
  171. k(e, y.value, "children"), y.value && y.value.length && (y.value = y.value.map((t) => t[r.props.value])), e.unshift(l);
  172. }
  173. return S(e);
  174. }, R = (e, l) => (l && l.name || "").toLowerCase().indexOf((e || "").toLowerCase()) >= 0, k = (e, l = [], t = "children") => {
  175. e && e.length > 0 && e.forEach((a) => {
  176. const s = w({}, a);
  177. l.push(s), a[t] instanceof Array && a[t].length > 0 && k(a[t], l, t);
  178. });
  179. };
  180. return W(() => {
  181. _();
  182. }), (e, l) => {
  183. const t = Y;
  184. return f(), h("div", Z, [
  185. q(t, {
  186. style: { width: "100%" },
  187. "popup-class-name": "s-tree-select-popup",
  188. multiple: n.multiple,
  189. "allow-clear": n.clear,
  190. "field-names": F.value,
  191. "show-search": n.search,
  192. "tree-data": c.value,
  193. listHeight: n.listHeight,
  194. maxTagCount: n.maxTagCount,
  195. placeholder: n.placeholder,
  196. disabled: n.disabled,
  197. value: B(i),
  198. "onUpdate:value": l[0] || (l[0] = (a) => G(i) ? i.value = a : null),
  199. showCheckedStrategy: B(Q).SHOW_ALL,
  200. searchValue: p.value,
  201. "onUpdate:searchValue": l[1] || (l[1] = (a) => p.value = a),
  202. "tree-node-filter-prop": n.filterField,
  203. "tree-default-expand-all": n.expandAll,
  204. treeExpandedKeys: v.value,
  205. "onUpdate:treeExpandedKeys": l[2] || (l[2] = (a) => v.value = a),
  206. filterTreeNode: R,
  207. onTreeExpand: H,
  208. onSelect: $,
  209. onChange: D
  210. }, {
  211. title: J(({ name: a }) => [
  212. p.value.length && a ? (f(!0), h(L, { key: 0 }, K(a.toString().split(new RegExp(`(?<=${p.value})|(?=${p.value})`, "i")), (s, m) => (f(), h(L, { key: m }, [
  213. s.toLowerCase() === p.value.toLowerCase() ? (f(), h("span", {
  214. key: 0,
  215. title: a,
  216. class: "s-theme-color"
  217. }, A(s), 9, ee)) : (f(), h("span", {
  218. key: 1,
  219. title: a
  220. }, A(s), 9, te))
  221. ], 64))), 128)) : (f(), h("div", {
  222. key: 1,
  223. title: a
  224. }, A(a && a.length > 15 ? a.slice(0, 15) + "..." : a), 9, le))
  225. ]),
  226. _: 1
  227. }, 8, ["multiple", "allow-clear", "field-names", "show-search", "tree-data", "listHeight", "maxTagCount", "placeholder", "disabled", "value", "showCheckedStrategy", "searchValue", "tree-node-filter-prop", "tree-default-expand-all", "treeExpandedKeys"])
  228. ]);
  229. };
  230. }
  231. }, ie = /* @__PURE__ */ X(ae, [["__scopeId", "data-v-4f9a740a"]]);
  232. export {
  233. ie as default
  234. };