SDataRangeTreeSelect.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 { ae as R, af as M, ag as q, ah 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. // 是否多选
  50. multiple: {
  51. type: Boolean,
  52. default: !1
  53. },
  54. // 是否显示复选框
  55. treeCheckable: {
  56. type: Boolean,
  57. default: !1
  58. },
  59. // 是否默认展开全部
  60. treeDefaultExpandAll: {
  61. type: Boolean,
  62. default: !0
  63. },
  64. // 占位文案
  65. placeholder: {
  66. type: String,
  67. default: ""
  68. },
  69. // 对应 antd treeDataSimpleMode
  70. treeDataSimpleMode: {
  71. type: [Boolean, Array],
  72. default: !0
  73. },
  74. // 最多显示的 tag 数
  75. maxTagCount: {
  76. type: Number,
  77. default: 1
  78. },
  79. // 已分组的形式禁用数据:1 禁用组织 / 2 禁用校区 / 3 禁用单位
  80. // 传字符串匹配单个 type,传数组匹配多个 type
  81. disabledGroup: {
  82. type: [String, Array],
  83. default: ""
  84. },
  85. // 只展示组织(type 固定为 '1')
  86. showOnlyOrganization: {
  87. type: Boolean,
  88. default: !1
  89. },
  90. // 支持自定义数据源(传数组则不再请求接口)
  91. treeSelectData: {
  92. type: [Boolean, Array],
  93. default: !1
  94. },
  95. // 是否启用数据权限过滤
  96. isDataScopeFilter: {
  97. type: Boolean,
  98. default: !1
  99. },
  100. // 启用后自动托管系统配置(dataScope),数据范围与系统保持一致
  101. autoSysConfig: {
  102. type: Boolean,
  103. default: !1
  104. },
  105. // 默认值(为当前登录用户组织),仅 showOnlyOrganization 时生效
  106. defaultValue: {
  107. type: Boolean,
  108. default: !0
  109. }
  110. },
  111. emits: ["update:value", "change"],
  112. setup(r, { emit: u }) {
  113. 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([]);
  114. let A = !1;
  115. const x = C(() => {
  116. const a = f.value;
  117. return a ? Array.isArray(a) ? a : [a] : [];
  118. }), w = (a) => (!a || !a.length || !x.value.length || a.forEach((e) => {
  119. x.value.includes(e.type) && (e.disabled = !0, e.disableCheckbox = !0);
  120. }), a), h = (a) => {
  121. const e = I({}, a);
  122. 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;
  123. }, D = () => {
  124. if (!b.value.length || !o.value || !o.value.length) return;
  125. const a = o.value.map((l) => l.value), e = b.value.filter((l) => !a.includes(l.value));
  126. e.length && (e.forEach((l) => {
  127. l.disabled = !0, l.disableCheckbox = !0;
  128. }), o.value = [...o.value, ...e]);
  129. }, V = (a, e) => {
  130. var s, v;
  131. const l = (v = (s = e == null ? void 0 : e.name) != null ? s : e == null ? void 0 : e.label) != null ? v : "";
  132. return String(l).toLowerCase().indexOf(String(a).toLowerCase()) >= 0;
  133. }, B = (a) => {
  134. let e;
  135. 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);
  136. }, _ = () => T(this, null, function* () {
  137. if (t.defaultValue && d.value) {
  138. const e = S.user || {};
  139. e.campusId && M([e.campusId]).then((l) => {
  140. const s = (l || []).map((v) => h(v));
  141. c.value = i.value ? s : s[0] || [], B(c.value);
  142. });
  143. }
  144. if (t.autoSysConfig) {
  145. const e = yield q("dataScope");
  146. if (!e) return;
  147. e.value === "1" ? d.value = !0 : e.value === "3" && (d.value = !1), f.value = "2", m.value = !1, n.value = !0;
  148. }
  149. if (Array.isArray(t.treeSelectData) && t.treeSelectData.length) {
  150. o.value = w(t.treeSelectData.map(h)), A = !0;
  151. return;
  152. }
  153. const a = yield J({
  154. type: d.value ? "1" : "",
  155. isDataScopeFilter: !!n.value
  156. });
  157. o.value = w((a || []).map(h)), A = !0, D();
  158. });
  159. return L(() => {
  160. _();
  161. }), y(i, (a) => {
  162. const e = c.value;
  163. !a && Array.isArray(e) ? c.value = e[0] || [] : a && e && !Array.isArray(e) && (c.value = e ? [e] : []);
  164. }), y(
  165. () => t.treeCheckable,
  166. (a) => {
  167. m.value = a;
  168. },
  169. { immediate: !0 }
  170. ), y(
  171. () => t.value,
  172. (a) => {
  173. if (a && a.length > 0) {
  174. const e = Array.isArray(a) ? a : [a];
  175. M(e).then((l) => {
  176. const s = (l || []).map((v) => h(v));
  177. b.value = s, c.value = i.value ? s : s[0] || [], setTimeout(() => {
  178. A && D();
  179. }, 300);
  180. });
  181. return;
  182. }
  183. c.value = [];
  184. },
  185. { immediate: !0 }
  186. ), y(
  187. () => t.disabledGroup,
  188. (a) => {
  189. f.value = a;
  190. },
  191. { immediate: !0 }
  192. ), y(
  193. () => t.showOnlyOrganization,
  194. (a) => {
  195. d.value = a;
  196. },
  197. { immediate: !0 }
  198. ), y(
  199. () => t.isDataScopeFilter,
  200. (a) => {
  201. n.value = a;
  202. },
  203. { immediate: !0 }
  204. ), y(
  205. () => t.treeSelectData,
  206. (a) => {
  207. !a || !a.length || (o.value = w(a.map(h)));
  208. },
  209. { immediate: !0 }
  210. ), (a, e) => {
  211. const l = K;
  212. return j(), U("div", P, [
  213. H(l, {
  214. value: c.value,
  215. "onUpdate:value": e[0] || (e[0] = (s) => c.value = s),
  216. style: { width: "100%" },
  217. "popup-class-name": "s-tree-select-popup",
  218. "allow-clear": r.allowClear,
  219. "show-search": r.showSearch,
  220. "tree-checkable": m.value,
  221. multiple: i.value,
  222. "dropdown-style": { maxHeight: "400px", overflow: "auto" },
  223. "tree-data": o.value,
  224. placeholder: r.placeholder,
  225. "tree-default-expand-all": r.treeDefaultExpandAll,
  226. "tree-data-simple-mode": E.value,
  227. "tree-check-strictly": i.value,
  228. "label-in-value": !0,
  229. "max-tag-count": r.maxTagCount,
  230. "filter-tree-node": V,
  231. onChange: B
  232. }, 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"])
  233. ]);
  234. };
  235. }
  236. };
  237. export {
  238. Z as default
  239. };