SUserSelect.js 12 KB

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