SDataRangeTreeSelect.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. var F = Object.defineProperty;
  2. var k = Object.getOwnPropertySymbols;
  3. var z = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable;
  4. var O = (r, u, t) => u in r ? F(r, u, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[u] = t, I = (r, u) => {
  5. for (var t in u || (u = {}))
  6. z.call(u, t) && O(r, t, u[t]);
  7. if (k)
  8. for (var t of k(u))
  9. G.call(u, t) && O(r, t, u[t]);
  10. return r;
  11. };
  12. var T = (r, u, t) => new Promise((g, S) => {
  13. var m = (n) => {
  14. try {
  15. f(t.next(n));
  16. } catch (i) {
  17. S(i);
  18. }
  19. }, d = (n) => {
  20. try {
  21. f(t.throw(n));
  22. } catch (i) {
  23. S(i);
  24. }
  25. }, f = (n) => n.done ? g(n.value) : Promise.resolve(n.value).then(m, d);
  26. f((t = t.apply(r, u)).next());
  27. });
  28. import { ref as p, computed as C, onMounted as L, watch as y, openBlock as j, createElementBlock as U, createVNode as H } from "vue";
  29. import { ad as R, ae as M, af as q, ag as J } from "./index2.js";
  30. import { _ as K } from "./index7.js";
  31. const P = { class: "s-data-range-tree-select" }, Z = {
  32. __name: "SDataRangeTreeSelect",
  33. props: {
  34. // 选中的组织 id 集合(v-model 双向绑定)
  35. value: {
  36. type: [String, Array],
  37. default: null
  38. },
  39. // 允许清空
  40. allowClear: {
  41. type: Boolean,
  42. default: !0
  43. },
  44. // 显示搜索框
  45. showSearch: {
  46. type: Boolean,
  47. default: !0
  48. },
  49. multiple: {
  50. type: Boolean,
  51. default: !1
  52. },
  53. // 是否显示复选框
  54. treeCheckable: {
  55. type: Boolean,
  56. default: !1
  57. },
  58. // 是否默认展开全部
  59. treeDefaultExpandAll: {
  60. type: Boolean,
  61. default: !0
  62. },
  63. placeholder: {
  64. type: String,
  65. default: ""
  66. },
  67. // 对应 antd treeDataSimpleMode
  68. treeDataSimpleMode: {
  69. type: [Boolean, Array],
  70. default: !0
  71. },
  72. // 最多显示的 tag 数
  73. maxTagCount: {
  74. type: Number,
  75. default: 1
  76. },
  77. // 已分组的形式禁用数据:1 禁用组织 / 2 禁用校区 / 3 禁用单位
  78. // 传字符串匹配单个 type,传数组匹配多个 type
  79. disabledGroup: {
  80. type: [String, Array],
  81. default: ""
  82. },
  83. // 只展示组织(type 固定为 '1')
  84. showOnlyOrganization: {
  85. type: Boolean,
  86. default: !1
  87. },
  88. // 支持自定义数据源(传数组则不再请求接口)
  89. treeSelectData: {
  90. type: [Boolean, Array],
  91. default: !1
  92. },
  93. // 是否启用数据权限过滤
  94. isDataScopeFilter: {
  95. type: Boolean,
  96. default: !1
  97. },
  98. // 启用后自动托管系统配置(dataScope),数据范围与系统保持一致
  99. autoSysConfig: {
  100. type: Boolean,
  101. default: !1
  102. },
  103. // 默认值(为当前登录用户组织),仅 showOnlyOrganization 时生效
  104. defaultValue: {
  105. type: Boolean,
  106. default: !0
  107. }
  108. },
  109. emits: ["update:value", "change"],
  110. setup(r, { emit: u }) {
  111. const t = r, g = u, S = R(), m = p(!1), d = p(!1), f = p(""), n = p(!1), i = C(() => !!(m.value || t.multiple)), c = p([]), o = p([]), E = C(() => t.treeDataSimpleMode ? !(o.value || []).some((e) => Array.isArray(e.children) && e.children.length) : !1), b = p([]);
  112. let A = !1;
  113. const x = C(() => {
  114. const a = f.value;
  115. return a ? Array.isArray(a) ? a : [a] : [];
  116. }), w = (a) => (!a || !a.length || !x.value.length || a.forEach((e) => {
  117. x.value.includes(e.type) && (e.disabled = !0, e.disableCheckbox = !0);
  118. }), a), h = (a) => {
  119. const e = I({}, a);
  120. return e.parent ? e.pId = e.parent.id || null : e.pId = null, e.value = a.id, e.label = a.name, Array.isArray(e.children) && e.children.length && (e.children = e.children.map(h)), e;
  121. }, D = () => {
  122. if (!b.value.length || !o.value || !o.value.length) return;
  123. const a = o.value.map((l) => l.value), e = b.value.filter((l) => !a.includes(l.value));
  124. e.length && (e.forEach((l) => {
  125. l.disabled = !0, l.disableCheckbox = !0;
  126. }), o.value = [...o.value, ...e]);
  127. }, V = (a, e) => {
  128. var s, v;
  129. const l = (v = (s = e == null ? void 0 : e.name) != null ? s : e == null ? void 0 : e.label) != null ? v : "";
  130. return String(l).toLowerCase().indexOf(String(a).toLowerCase()) >= 0;
  131. }, B = (a) => {
  132. let e;
  133. typeof a == "string" ? e = [a] : Array.isArray(a) ? e = (a || []).map((l) => l && typeof l == "object" ? l.value : l) : a && typeof a == "object" ? e = [a.value] : t.autoSysConfig ? e = null : e = "", g("update:value", e), g("change", e);
  134. }, _ = () => T(this, null, function* () {
  135. if (t.defaultValue && d.value) {
  136. const e = S.user || {};
  137. e.campusId && M([e.campusId]).then((l) => {
  138. const s = (l || []).map((v) => h(v));
  139. c.value = i.value ? s : s[0] || [], B(c.value);
  140. });
  141. }
  142. if (t.autoSysConfig) {
  143. const e = yield q("dataScope");
  144. if (!e) return;
  145. e.value === "1" ? d.value = !0 : e.value === "3" && (d.value = !1), f.value = "2", m.value = !1, n.value = !0;
  146. }
  147. if (Array.isArray(t.treeSelectData) && t.treeSelectData.length) {
  148. o.value = w(t.treeSelectData.map(h)), A = !0;
  149. return;
  150. }
  151. const a = yield J({
  152. type: d.value ? "1" : "",
  153. isDataScopeFilter: !!n.value
  154. });
  155. o.value = w((a || []).map(h)), A = !0, D();
  156. });
  157. return L(() => {
  158. _();
  159. }), y(i, (a) => {
  160. const e = c.value;
  161. !a && Array.isArray(e) ? c.value = e[0] || [] : a && e && !Array.isArray(e) && (c.value = e ? [e] : []);
  162. }), y(
  163. () => t.treeCheckable,
  164. (a) => {
  165. m.value = a;
  166. },
  167. { immediate: !0 }
  168. ), y(
  169. () => t.value,
  170. (a) => {
  171. if (a && a.length > 0) {
  172. const e = Array.isArray(a) ? a : [a];
  173. M(e).then((l) => {
  174. const s = (l || []).map((v) => h(v));
  175. b.value = s, c.value = i.value ? s : s[0] || [], setTimeout(() => {
  176. A && D();
  177. }, 300);
  178. });
  179. return;
  180. }
  181. c.value = [];
  182. },
  183. { immediate: !0 }
  184. ), y(
  185. () => t.disabledGroup,
  186. (a) => {
  187. f.value = a;
  188. },
  189. { immediate: !0 }
  190. ), y(
  191. () => t.showOnlyOrganization,
  192. (a) => {
  193. d.value = a;
  194. },
  195. { immediate: !0 }
  196. ), y(
  197. () => t.isDataScopeFilter,
  198. (a) => {
  199. n.value = a;
  200. },
  201. { immediate: !0 }
  202. ), y(
  203. () => t.treeSelectData,
  204. (a) => {
  205. !a || !a.length || (o.value = w(a.map(h)));
  206. },
  207. { immediate: !0 }
  208. ), (a, e) => {
  209. const l = K;
  210. return j(), U("div", P, [
  211. H(l, {
  212. value: c.value,
  213. "onUpdate:value": e[0] || (e[0] = (s) => c.value = s),
  214. style: { width: "100%" },
  215. "popup-class-name": "s-tree-select-popup",
  216. "allow-clear": r.allowClear,
  217. "show-search": r.showSearch,
  218. "tree-checkable": m.value,
  219. multiple: i.value,
  220. "dropdown-style": { maxHeight: "400px", overflow: "auto" },
  221. "tree-data": o.value,
  222. placeholder: r.placeholder,
  223. "tree-default-expand-all": r.treeDefaultExpandAll,
  224. "tree-data-simple-mode": E.value,
  225. "tree-check-strictly": i.value,
  226. "label-in-value": !0,
  227. "max-tag-count": r.maxTagCount,
  228. "filter-tree-node": V,
  229. onChange: B
  230. }, null, 8, ["value", "allow-clear", "show-search", "tree-checkable", "multiple", "tree-data", "placeholder", "tree-default-expand-all", "tree-data-simple-mode", "tree-check-strictly", "max-tag-count"])
  231. ]);
  232. };
  233. }
  234. };
  235. export {
  236. Z as default
  237. };