SUserSelect.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. var j = (S, F, w) => new Promise((I, m) => {
  2. var M = (h) => {
  3. try {
  4. g(w.next(h));
  5. } catch (y) {
  6. m(y);
  7. }
  8. }, T = (h) => {
  9. try {
  10. g(w.throw(h));
  11. } catch (y) {
  12. m(y);
  13. }
  14. }, g = (h) => h.done ? I(h.value) : Promise.resolve(h.value).then(M, T);
  15. g((w = w.apply(S, F)).next());
  16. });
  17. import { ref as u, watch as Ce, onMounted as ke, resolveComponent as J, openBlock as d, createElementBlock as v, createVNode as f, withCtx as $, createElementVNode as s, toDisplayString as i, createTextVNode as b, createCommentVNode as te, Fragment as q, renderList as ae } from "vue";
  18. import { aC as Se, B as we, dx as se, df as $e, dg as be, dy as Ee } from "./index2.js";
  19. const Ae = { class: "s-office-select-common" }, Le = { class: "modal-container" }, Ne = { class: "side" }, Ie = { class: "main" }, Te = { class: "filter" }, Ue = { class: "list-wrap" }, Ve = { class: "item left-wrap" }, Oe = { class: "head" }, Be = { class: "sub-title" }, Re = {
  20. key: 0,
  21. class: "right"
  22. }, je = ["onClick"], qe = { class: "icon s-theme-icon-bg" }, Fe = ["src", "onError"], Me = { class: "cont" }, xe = { class: "name" }, Pe = { class: "job" }, ze = {
  23. key: 0,
  24. class: "not-more"
  25. }, Je = { class: "item right-wrap" }, De = { class: "head" }, Ke = { class: "sub-title" }, Ge = { class: "icon s-theme-icon-bg" }, He = ["src", "onError"], Qe = { class: "cont" }, We = { class: "name" }, Xe = { class: "job" }, Ye = ["onClick"], tl = {
  26. __name: "SUserSelect",
  27. props: {
  28. // 选中值(v-model:value)
  29. value: {
  30. type: [String, Array],
  31. default() {
  32. return "";
  33. }
  34. },
  35. // 占位文案
  36. placeholder: {
  37. type: String,
  38. default() {
  39. return window.$l("请选择");
  40. }
  41. },
  42. // 弹窗标题
  43. title: {
  44. type: String,
  45. default() {
  46. return window.$l("人员选择");
  47. }
  48. },
  49. // 是否多选,传 false 为单选(只保留最后选中的一个)
  50. multiple: {
  51. type: Boolean,
  52. default: !0
  53. }
  54. },
  55. emits: ["change", "update:value"],
  56. setup(S, { expose: F, emit: w }) {
  57. var ee, le;
  58. const I = w, m = S, M = (((le = (ee = window.$utils) == null ? void 0 : ee.env) == null ? void 0 : le.VITE_APP_API_FILE_URL) || "/") + "", T = (e) => /^https?:\/\//.test(e) ? e : `${M}file/preview?id=${e}`, g = u(""), h = u(""), y = u(""), p = u(!1), E = u(!1), U = u({}), C = u([]), n = u([]), k = u(1), A = u(0), L = u(!1);
  59. let V = null;
  60. const D = u(""), c = u([]), O = u(1), K = u(20), x = u(0);
  61. let G = 0, H = "", Q = !1;
  62. const W = (e) => {
  63. if (e && e.length) {
  64. const l = Array.isArray(e) ? e : [e];
  65. n.value = m.multiple ? l : l.slice(0, 1);
  66. } else
  67. n.value = [];
  68. };
  69. Ce(
  70. () => m.value,
  71. (e) => {
  72. W(e), Q && B();
  73. },
  74. { immediate: !0 }
  75. );
  76. const X = () => {
  77. E.value = !0, B();
  78. }, Y = () => {
  79. X();
  80. }, ne = () => {
  81. E.value = !1, W(m.value), B();
  82. }, N = (e = 1, l = 0) => j(this, null, function* () {
  83. if (p.value) {
  84. p.value = !1;
  85. return;
  86. }
  87. e === 1 && (c.value = []);
  88. let a = [];
  89. if (n.value.length < 100 ? (O.value = 1, x.value = 0, a = n.value) : a = n.value.slice(l * (K.value || 20), e * (K.value || 20)), !a.length || c.value.length && a.length >= n.value.length && a.length >= c.value.length)
  90. return;
  91. p.value = !0;
  92. const o = yield se(a), _ = c.value.concat(o || []);
  93. c.value = [...new Map(_.map((r) => [r.id, r])).values()], V = setTimeout(() => {
  94. p.value = !1, clearTimeout(V);
  95. }, 200);
  96. }), oe = () => {
  97. k.value = 1, A.value = 0, C.value = [], P();
  98. }, Z = () => {
  99. const l = c.value.filter((o) => n.value.includes(o.id)).map((o) => o.name), a = l.length - 1;
  100. g.value = l.slice(0, 1).join(",") + (a > 0 ? " +" + a : "");
  101. }, B = () => j(this, null, function* () {
  102. if (!n.value.length) {
  103. g.value = "", c.value = [];
  104. return;
  105. }
  106. const e = yield se(n.value);
  107. c.value = e || [], Z();
  108. });
  109. ke(() => {
  110. Q = !0, B();
  111. });
  112. const ue = () => {
  113. C.value.forEach((e) => {
  114. if (n.value.includes(e.id)) {
  115. const l = n.value.indexOf(e.id);
  116. n.value.splice(l, 1);
  117. }
  118. }), N();
  119. }, ce = () => {
  120. L.value = !L.value, L.value ? ie() : ue();
  121. }, ie = () => {
  122. C.value.forEach((e) => {
  123. n.value.includes(e.id) || n.value.push(e.id);
  124. }), N();
  125. }, re = () => {
  126. L.value = !1, n.value = [], c.value = [];
  127. }, de = () => {
  128. E.value = !1;
  129. const e = c.value.filter((r) => n.value.includes(r.id)), l = e.map((r) => r.name), a = l.length - 1, o = l.slice(0, 1).join(",") + (a > 0 ? " +" + a : ""), _ = e.map((r) => r.id);
  130. I("update:value", m.multiple ? _ : _[0] || ""), I("change", o, l, _, e), Z();
  131. }, ve = (e, l) => {
  132. var o;
  133. const a = Array.isArray(e) ? e : e ? [e] : [];
  134. a.length && (U.value = ((o = l == null ? void 0 : l.node) == null ? void 0 : o.dataRef) || (l == null ? void 0 : l.node) || {}, D.value = a, k.value = 1, A.value = 0, C.value = [], P());
  135. }, P = () => j(this, null, function* () {
  136. const e = ++G, l = U.value || {}, a = `${(D.value || [])[0]}_${k.value}_${y.value}`;
  137. if (a === H && p.value) return;
  138. H = a;
  139. const o = {
  140. pageNum: k.value,
  141. pageSize: 20,
  142. searchValue: y.value,
  143. unitId: l.id,
  144. unitType: l.type,
  145. containsChild: !0,
  146. isEnabled: !0
  147. };
  148. p.value = !0;
  149. const _ = yield Ee(o);
  150. if (e !== G) return;
  151. const r = C.value.concat(_.list || []);
  152. C.value = [...new Map(r.map((R) => [R.id, R])).values()], A.value = _.pages, V = setTimeout(() => {
  153. p.value = !1, clearTimeout(V);
  154. }, 200);
  155. }), he = (e) => {
  156. if (!m.multiple) {
  157. n.value = [e.id], c.value = [e];
  158. return;
  159. }
  160. n.value.includes(e.id) || n.value.push(e.id), N();
  161. }, pe = (e, l) => {
  162. c.value.splice(l, 1), n.value.splice(n.value.indexOf(e.id), 1), N();
  163. }, _e = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => {
  164. p.value || e + a >= l - 20 && k.value < A.value && (k.value++, P());
  165. }, fe = ({ target: { offsetHeight: e, scrollHeight: l, scrollTop: a } }) => {
  166. p.value || e + a >= l - 20 && (x.value = O.value, O.value++, N(O.value, x.value));
  167. }, me = (e) => be(e), ge = (e) => $e(e);
  168. return F({ open: X }), (e, l) => {
  169. const a = Se, o = we, _ = J("s-tree"), r = J("CloseCircleOutlined"), R = J("s-modal");
  170. return d(), v("div", Ae, [
  171. f(a, {
  172. value: g.value,
  173. "onUpdate:value": l[0] || (l[0] = (t) => g.value = t),
  174. readonly: !0,
  175. placeholder: S.placeholder,
  176. onClick: Y,
  177. onSearch: Y
  178. }, null, 8, ["value", "placeholder"]),
  179. f(R, {
  180. value: E.value,
  181. "onUpdate:value": l[3] || (l[3] = (t) => E.value = t),
  182. title: S.title,
  183. width: "1000px",
  184. showFullScreen: !1
  185. }, {
  186. footer: $(() => [
  187. f(o, {
  188. key: "back",
  189. onClick: ne
  190. }, {
  191. default: $(() => [
  192. b(i(e.$l("取消")), 1)
  193. ]),
  194. _: 1
  195. }),
  196. f(o, {
  197. key: "submit",
  198. type: "primary",
  199. loading: p.value,
  200. onClick: de
  201. }, {
  202. default: $(() => [
  203. b(i(e.$l("确认")), 1)
  204. ]),
  205. _: 1
  206. }, 8, ["loading"])
  207. ]),
  208. default: $(() => [
  209. s("div", Le, [
  210. s("div", Ne, [
  211. f(_, {
  212. levelOneChildren: me,
  213. levelTwoChildren: ge,
  214. "onSelect:modelValue": ve,
  215. select: h.value,
  216. "onUpdate:select": l[1] || (l[1] = (t) => h.value = t),
  217. height: 470
  218. }, null, 8, ["select"])
  219. ]),
  220. s("div", Ie, [
  221. s("div", Te, [
  222. f(a, {
  223. value: y.value,
  224. "onUpdate:value": l[2] || (l[2] = (t) => y.value = t),
  225. placeholder: e.$l("请输入"),
  226. style: { width: "330px" },
  227. onSearch: oe
  228. }, null, 8, ["value", "placeholder"])
  229. ]),
  230. s("div", Ue, [
  231. s("div", Ve, [
  232. s("div", Oe, [
  233. s("div", Be, i(U.value.title || U.value.name), 1),
  234. S.multiple ? (d(), v("div", Re, [
  235. f(o, {
  236. type: "link",
  237. onClick: ce
  238. }, {
  239. default: $(() => [
  240. b(i(L.value ? e.$l("反选") : e.$l("全选")), 1)
  241. ]),
  242. _: 1
  243. })
  244. ])) : te("", !0)
  245. ]),
  246. s("div", {
  247. class: "user-list",
  248. onScroll: _e
  249. }, [
  250. (d(!0), v(q, null, ae(C.value, (t) => (d(), v("div", {
  251. class: "item",
  252. key: t.id,
  253. onClick: (z) => he(t)
  254. }, [
  255. s("div", qe, [
  256. t.avatar || t.cover ? (d(), v("img", {
  257. key: 0,
  258. class: "avatar-img",
  259. src: T(t.avatar || t.cover),
  260. alt: "",
  261. onError: (z) => t.cover = ""
  262. }, null, 40, Fe)) : (d(), v(q, { key: 1 }, [
  263. b(i(t.name && t.name.slice(0, 1)), 1)
  264. ], 64))
  265. ]),
  266. s("div", Me, [
  267. s("div", xe, i(t.name + (t.userid || t.loginName ? "(" + (t.userid || t.loginName) + ")" : "")), 1),
  268. s("div", Pe, i(t.mainJobName), 1)
  269. ])
  270. ], 8, je))), 128)),
  271. k.value >= A.value ? (d(), v("div", ze, i(e.$l("没有更多了")), 1)) : te("", !0)
  272. ], 32)
  273. ]),
  274. s("div", Je, [
  275. s("div", De, [
  276. s("div", Ke, i(e.$l("本次已选")), 1),
  277. f(o, {
  278. type: "link",
  279. onClick: re
  280. }, {
  281. default: $(() => [
  282. b(i(e.$l("清除")), 1)
  283. ]),
  284. _: 1
  285. })
  286. ]),
  287. s("div", {
  288. class: "user-list select-list",
  289. onScroll: fe
  290. }, [
  291. (d(!0), v(q, null, ae(c.value, (t, z) => (d(), v("div", {
  292. class: "item",
  293. key: t.id
  294. }, [
  295. s("div", Ge, [
  296. t.avatar || t.cover ? (d(), v("img", {
  297. key: 0,
  298. class: "avatar-img",
  299. src: T(t.avatar || t.cover),
  300. alt: "",
  301. onError: (ye) => t.cover = ""
  302. }, null, 40, He)) : (d(), v(q, { key: 1 }, [
  303. b(i(t.name && t.name.slice(0, 1)), 1)
  304. ], 64))
  305. ]),
  306. s("div", Qe, [
  307. s("div", We, i(t.name || t.title), 1),
  308. s("div", Xe, i(t.mainJobName), 1)
  309. ]),
  310. s("div", {
  311. class: "icon no-bg",
  312. onClick: (ye) => pe(t, z)
  313. }, [
  314. f(r)
  315. ], 8, Ye)
  316. ]))), 128))
  317. ], 32)
  318. ])
  319. ])
  320. ])
  321. ])
  322. ]),
  323. _: 1
  324. }, 8, ["value", "title"])
  325. ]);
  326. };
  327. }
  328. };
  329. export {
  330. tl as default
  331. };