@mingminghahayu/profession-select-dialog-vue3 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/profession-select-vue3.es.js +426 -0
- package/dist/profession-select-vue3.umd.js +1 -0
- package/dist/style.css +1 -0
- package/package.json +44 -0
- package/src/App.vue +104 -0
- package/src/ProfessionSelectDialog.vue +487 -0
- package/src/index.ts +4 -0
- package/src/main.ts +8 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { defineComponent as A, openBlock as _, createElementBlock as B, createElementVNode as m, computed as E, ref as b, watch as K, resolveComponent as I, resolveDirective as Q, createBlock as T, withCtx as u, createVNode as c, createTextVNode as N, unref as k, withDirectives as W, toDisplayString as X, createCommentVNode as Y, nextTick as L } from "vue";
|
|
2
|
+
import { ElMessageBox as Z, ElMessage as V } from "element-plus";
|
|
3
|
+
/*! Element Plus Icons Vue v2.3.2 */
|
|
4
|
+
var ee = /* @__PURE__ */ A({
|
|
5
|
+
name: "Check",
|
|
6
|
+
__name: "check",
|
|
7
|
+
setup(p) {
|
|
8
|
+
return (v, i) => (_(), B("svg", {
|
|
9
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
+
viewBox: "0 0 1024 1024"
|
|
11
|
+
}, [
|
|
12
|
+
m("path", {
|
|
13
|
+
fill: "currentColor",
|
|
14
|
+
d: "M406.656 706.944 195.84 496.256a32 32 0 1 0-45.248 45.248l256 256 512-512a32 32 0 0 0-45.248-45.248L406.592 706.944z"
|
|
15
|
+
})
|
|
16
|
+
]));
|
|
17
|
+
}
|
|
18
|
+
}), te = ee, oe = /* @__PURE__ */ A({
|
|
19
|
+
name: "Delete",
|
|
20
|
+
__name: "delete",
|
|
21
|
+
setup(p) {
|
|
22
|
+
return (v, i) => (_(), B("svg", {
|
|
23
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
24
|
+
viewBox: "0 0 1024 1024"
|
|
25
|
+
}, [
|
|
26
|
+
m("path", {
|
|
27
|
+
fill: "currentColor",
|
|
28
|
+
d: "M160 256H96a32 32 0 0 1 0-64h256V95.936a32 32 0 0 1 32-32h256a32 32 0 0 1 32 32V192h256a32 32 0 1 1 0 64h-64v672a32 32 0 0 1-32 32H192a32 32 0 0 1-32-32zm448-64v-64H416v64zM224 896h576V256H224zm192-128a32 32 0 0 1-32-32V416a32 32 0 0 1 64 0v320a32 32 0 0 1-32 32m192 0a32 32 0 0 1-32-32V416a32 32 0 0 1 64 0v320a32 32 0 0 1-32 32"
|
|
29
|
+
})
|
|
30
|
+
]));
|
|
31
|
+
}
|
|
32
|
+
}), P = oe;
|
|
33
|
+
const se = (p, v) => {
|
|
34
|
+
const i = p.__vccOpts || p;
|
|
35
|
+
for (const [h, S] of v)
|
|
36
|
+
i[h] = S;
|
|
37
|
+
return i;
|
|
38
|
+
}, ae = { class: "dialog-body" }, le = { class: "left-panel" }, ne = { class: "select-all-btn-wrap" }, ie = { class: "right-panel" }, re = { class: "selected-header" }, de = {
|
|
39
|
+
__name: "ProfessionSelectDialog",
|
|
40
|
+
props: {
|
|
41
|
+
modelValue: { type: Boolean, default: !1 },
|
|
42
|
+
dialogTitle: { type: String, default: "\u9009\u62E9\u4E13\u4E1A" },
|
|
43
|
+
selectedItems: { type: Array, default: () => [] },
|
|
44
|
+
api: { type: Object, required: !0 },
|
|
45
|
+
multiple: { type: Boolean, default: !0 },
|
|
46
|
+
multipleLimit: { type: Number, default: 0 },
|
|
47
|
+
disabledItems: { type: Array, default: () => [] }
|
|
48
|
+
},
|
|
49
|
+
emits: ["update:modelValue", "confirm"],
|
|
50
|
+
setup(p, { emit: v }) {
|
|
51
|
+
const i = p, h = v, S = E({
|
|
52
|
+
get: () => i.modelValue,
|
|
53
|
+
set: (o) => h("update:modelValue", o)
|
|
54
|
+
}), y = b(!1), f = b([]), n = b([]), g = b(), D = E(() => i.multiple ? i.multipleLimit > 0 && n.value.length > i.multipleLimit ? !1 : n.value.length > 0 : n.value.length === 1);
|
|
55
|
+
function C(o) {
|
|
56
|
+
return n.value.some((e) => String(e.professionId) === String(o));
|
|
57
|
+
}
|
|
58
|
+
function z(o) {
|
|
59
|
+
return i.disabledItems.some((e) => String(e.id) === String(o));
|
|
60
|
+
}
|
|
61
|
+
function $(o) {
|
|
62
|
+
const e = o.users || o.userList || o.members || o.children || [], a = (Array.isArray(e) ? e : []).map((t) => {
|
|
63
|
+
var l, r;
|
|
64
|
+
return {
|
|
65
|
+
id: (r = (l = t.id) != null ? l : t.userId) != null ? r : t.value,
|
|
66
|
+
name: t.name || t.nickName || t.username || t.userName || t.label || "-",
|
|
67
|
+
userType: t.userType || "",
|
|
68
|
+
majorCode: t.majorCode || ""
|
|
69
|
+
};
|
|
70
|
+
}), s = a.map((t) => t.name).filter(Boolean).join("\u3001");
|
|
71
|
+
return {
|
|
72
|
+
id: o.id,
|
|
73
|
+
profession: o.profession || o.departmentName || o.name || "-",
|
|
74
|
+
majorName: o.majorName || o.profession || o.name || "-",
|
|
75
|
+
majorCode: o.majorCode || "",
|
|
76
|
+
users: a,
|
|
77
|
+
userNames: s
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function w(o) {
|
|
81
|
+
const e = o.id, a = o.profession, s = o.majorName || a, t = o.majorCode || "", l = o.users || [];
|
|
82
|
+
return l.length === 0 ? [{
|
|
83
|
+
id: `p_${e}`,
|
|
84
|
+
professionId: e,
|
|
85
|
+
profession: a,
|
|
86
|
+
majorName: s,
|
|
87
|
+
majorCode: t,
|
|
88
|
+
userType: "",
|
|
89
|
+
userId: "",
|
|
90
|
+
userName: "-"
|
|
91
|
+
}] : l.map((r) => ({
|
|
92
|
+
id: `p_${e}_u_${r.id}`,
|
|
93
|
+
professionId: e,
|
|
94
|
+
profession: a,
|
|
95
|
+
majorName: s,
|
|
96
|
+
majorCode: r.majorCode || t,
|
|
97
|
+
userType: r.userType || "",
|
|
98
|
+
userId: r.id,
|
|
99
|
+
userName: r.name || "-"
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
function H(o) {
|
|
103
|
+
const e = o.professionId;
|
|
104
|
+
if (n.value = n.value.filter((s) => String(s.id) !== String(o.id)), !n.value.some((s) => String(s.professionId) === String(e))) {
|
|
105
|
+
const s = g.value;
|
|
106
|
+
if (s) {
|
|
107
|
+
const t = f.value.find((l) => String(l.id) === String(e));
|
|
108
|
+
t && s.toggleRowSelection(t, !1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function M() {
|
|
113
|
+
Z.confirm("\u786E\u5B9A\u8981\u6E05\u7A7A\u6240\u6709\u5DF2\u9009\u4E2D\u7684\u4E13\u4E1A\u5417\uFF1F", "\u63D0\u793A", {
|
|
114
|
+
confirmButtonText: "\u786E\u5B9A",
|
|
115
|
+
cancelButtonText: "\u53D6\u6D88",
|
|
116
|
+
type: "warning"
|
|
117
|
+
}).then(() => {
|
|
118
|
+
n.value = [], g.value && g.value.clearSelection(), V.success("\u5DF2\u6E05\u7A7A\u6240\u6709\u9009\u4E2D\u4E13\u4E1A");
|
|
119
|
+
}).catch(() => {
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function R() {
|
|
123
|
+
const o = i.api.getUserPageList || i.api.getUserList;
|
|
124
|
+
if (!!o) {
|
|
125
|
+
y.value = !0;
|
|
126
|
+
try {
|
|
127
|
+
let e;
|
|
128
|
+
try {
|
|
129
|
+
e = await o();
|
|
130
|
+
} catch {
|
|
131
|
+
e = await o({ page: 1, pageSize: 99999 }, { page: 1, pageSize: 99999 });
|
|
132
|
+
}
|
|
133
|
+
let a = Array.isArray(e) ? e : e || (e == null ? void 0 : e.data) || (e == null ? void 0 : e.content) || [];
|
|
134
|
+
Array.isArray(a) || (a = []), f.value = a.map((s) => $(s));
|
|
135
|
+
} catch (e) {
|
|
136
|
+
console.error("\u83B7\u53D6\u4E13\u4E1A\u5931\u8D25:", e), V.error("\u83B7\u53D6\u4E13\u4E1A\u5931\u8D25");
|
|
137
|
+
} finally {
|
|
138
|
+
y.value = !1, L(() => {
|
|
139
|
+
U();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function U() {
|
|
145
|
+
const o = g.value;
|
|
146
|
+
if (!o)
|
|
147
|
+
return;
|
|
148
|
+
const e = new Set(
|
|
149
|
+
n.value.map((a) => String(a.professionId))
|
|
150
|
+
);
|
|
151
|
+
f.value.forEach((a) => {
|
|
152
|
+
e.has(String(a.id)) && o.toggleRowSelection(a, !0);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function O() {
|
|
156
|
+
const o = new Set(i.disabledItems.map((t) => String(t.id))), e = new Set(n.value.map((t) => String(t.professionId))), a = f.value.filter((t) => {
|
|
157
|
+
const l = String(t.id);
|
|
158
|
+
return !e.has(l) && !o.has(l);
|
|
159
|
+
});
|
|
160
|
+
let s = [];
|
|
161
|
+
if (a.forEach((t) => {
|
|
162
|
+
s = s.concat(w(t));
|
|
163
|
+
}), i.multiple) {
|
|
164
|
+
if (i.multipleLimit > 0) {
|
|
165
|
+
const t = i.multipleLimit - n.value.length;
|
|
166
|
+
s.slice(0, t).forEach((l) => {
|
|
167
|
+
n.value.push(l);
|
|
168
|
+
});
|
|
169
|
+
} else
|
|
170
|
+
s.forEach((t) => {
|
|
171
|
+
n.value.push(t);
|
|
172
|
+
});
|
|
173
|
+
V.success(`\u5DF2\u9009\u4E2D ${a.length} \u4E2A\u4E13\u4E1A\uFF0C\u5171 ${s.length} \u6761\u8BB0\u5F55`);
|
|
174
|
+
}
|
|
175
|
+
L(() => {
|
|
176
|
+
const t = g.value;
|
|
177
|
+
t && a.forEach((l) => {
|
|
178
|
+
t.toggleRowSelection(l, !0);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
function q(o) {
|
|
183
|
+
if (o.length > 0) {
|
|
184
|
+
const e = new Set(n.value.map((t) => String(t.professionId))), a = new Set(i.disabledItems.map((t) => String(t.id))), s = o.filter((t) => {
|
|
185
|
+
const l = String(t.id);
|
|
186
|
+
return !e.has(l) && !a.has(l);
|
|
187
|
+
});
|
|
188
|
+
if (i.multiple) {
|
|
189
|
+
let t = [];
|
|
190
|
+
if (s.forEach((l) => {
|
|
191
|
+
t = t.concat(w(l));
|
|
192
|
+
}), i.multipleLimit > 0) {
|
|
193
|
+
const l = i.multipleLimit - n.value.length;
|
|
194
|
+
t.slice(0, l).forEach((r) => {
|
|
195
|
+
n.value.push(r);
|
|
196
|
+
});
|
|
197
|
+
} else
|
|
198
|
+
t.forEach((l) => {
|
|
199
|
+
n.value.push(l);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function F(o) {
|
|
205
|
+
const e = new Set(o.map((t) => String(t.id))), a = new Set(i.disabledItems.map((t) => String(t.id)));
|
|
206
|
+
o.forEach((t) => {
|
|
207
|
+
const l = String(t.id);
|
|
208
|
+
if (!C(t.id) && !a.has(l))
|
|
209
|
+
if (i.multiple) {
|
|
210
|
+
const r = w(t);
|
|
211
|
+
if (i.multipleLimit > 0) {
|
|
212
|
+
const d = i.multipleLimit - n.value.length;
|
|
213
|
+
if (d <= 0)
|
|
214
|
+
return;
|
|
215
|
+
r.slice(0, d).forEach((x) => {
|
|
216
|
+
n.value.push(x);
|
|
217
|
+
});
|
|
218
|
+
} else
|
|
219
|
+
r.forEach((d) => {
|
|
220
|
+
n.value.push(d);
|
|
221
|
+
});
|
|
222
|
+
} else
|
|
223
|
+
n.value = w(t);
|
|
224
|
+
});
|
|
225
|
+
const s = new Set(f.value.map((t) => String(t.id)));
|
|
226
|
+
n.value = n.value.filter((t) => {
|
|
227
|
+
const l = String(t.professionId);
|
|
228
|
+
return !(s.has(l) && !e.has(l));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function G(o) {
|
|
232
|
+
return !i.multiple && n.value.length >= 1 ? C(o.id) : C(o.id) ? !0 : !z(o.id);
|
|
233
|
+
}
|
|
234
|
+
function J() {
|
|
235
|
+
let o = n.value.map((e) => ({
|
|
236
|
+
id: e.userId || e.id,
|
|
237
|
+
professionId: e.professionId,
|
|
238
|
+
profession: e.profession,
|
|
239
|
+
majorName: e.majorName,
|
|
240
|
+
majorCode: e.majorCode,
|
|
241
|
+
userType: e.userType,
|
|
242
|
+
userId: e.userId,
|
|
243
|
+
userName: e.userName
|
|
244
|
+
}));
|
|
245
|
+
h("confirm", o), j();
|
|
246
|
+
}
|
|
247
|
+
function j() {
|
|
248
|
+
f.value = [], h("update:modelValue", !1);
|
|
249
|
+
}
|
|
250
|
+
return K(
|
|
251
|
+
() => i.modelValue,
|
|
252
|
+
(o) => {
|
|
253
|
+
o && (n.value = i.selectedItems.flatMap((e) => {
|
|
254
|
+
var a;
|
|
255
|
+
if (e.users && e.users.length > 0) {
|
|
256
|
+
const s = e.id, t = e.profession || e.departmentName, l = e.majorName || t, r = e.majorCode || "";
|
|
257
|
+
return e.users.map((d) => ({
|
|
258
|
+
id: `p_${s}_u_${d.id}`,
|
|
259
|
+
professionId: s,
|
|
260
|
+
profession: t,
|
|
261
|
+
majorName: l,
|
|
262
|
+
majorCode: r,
|
|
263
|
+
userType: d.userType || e.userType || "",
|
|
264
|
+
userId: d.id,
|
|
265
|
+
userName: d.name || "-"
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
return [{
|
|
269
|
+
id: e.id,
|
|
270
|
+
professionId: (a = e.professionId) != null ? a : e.id,
|
|
271
|
+
profession: e.profession || e.departmentName,
|
|
272
|
+
majorName: e.majorName || e.profession || e.departmentName,
|
|
273
|
+
majorCode: e.majorCode || "",
|
|
274
|
+
userType: e.userType || "",
|
|
275
|
+
userId: e.userId || "",
|
|
276
|
+
userName: e.userName || e.userNames || "-"
|
|
277
|
+
}];
|
|
278
|
+
}), R());
|
|
279
|
+
},
|
|
280
|
+
{ immediate: !0 }
|
|
281
|
+
), (o, e) => {
|
|
282
|
+
const a = I("el-button"), s = I("el-table-column"), t = I("el-table"), l = I("el-dialog"), r = Q("loading");
|
|
283
|
+
return _(), T(l, {
|
|
284
|
+
title: p.dialogTitle,
|
|
285
|
+
modelValue: S.value,
|
|
286
|
+
"onUpdate:modelValue": e[0] || (e[0] = (d) => S.value = d),
|
|
287
|
+
width: "960px",
|
|
288
|
+
"before-close": j,
|
|
289
|
+
"append-to-body": "",
|
|
290
|
+
class: "profession-select-dialog"
|
|
291
|
+
}, {
|
|
292
|
+
footer: u(() => [
|
|
293
|
+
c(a, {
|
|
294
|
+
type: "primary",
|
|
295
|
+
disabled: !D.value,
|
|
296
|
+
onClick: J
|
|
297
|
+
}, {
|
|
298
|
+
default: u(() => [...e[3] || (e[3] = [
|
|
299
|
+
N("\u786E\u5B9A", -1)
|
|
300
|
+
])]),
|
|
301
|
+
_: 1
|
|
302
|
+
}, 8, ["disabled"]),
|
|
303
|
+
c(a, { onClick: j }, {
|
|
304
|
+
default: u(() => [...e[4] || (e[4] = [
|
|
305
|
+
N("\u53D6\u6D88", -1)
|
|
306
|
+
])]),
|
|
307
|
+
_: 1
|
|
308
|
+
})
|
|
309
|
+
]),
|
|
310
|
+
default: u(() => [
|
|
311
|
+
m("div", ae, [
|
|
312
|
+
m("div", le, [
|
|
313
|
+
m("div", ne, [
|
|
314
|
+
c(a, {
|
|
315
|
+
type: "primary",
|
|
316
|
+
size: "default",
|
|
317
|
+
icon: k(te),
|
|
318
|
+
disabled: y.value,
|
|
319
|
+
onClick: O
|
|
320
|
+
}, {
|
|
321
|
+
default: u(() => [...e[1] || (e[1] = [
|
|
322
|
+
N("\u5168\u90E8\u9009\u4E2D", -1)
|
|
323
|
+
])]),
|
|
324
|
+
_: 1
|
|
325
|
+
}, 8, ["icon", "disabled"])
|
|
326
|
+
]),
|
|
327
|
+
W((_(), T(t, {
|
|
328
|
+
ref_key: "professionTable",
|
|
329
|
+
ref: g,
|
|
330
|
+
data: f.value,
|
|
331
|
+
height: "540",
|
|
332
|
+
"row-key": "id",
|
|
333
|
+
class: "profession-table",
|
|
334
|
+
onSelectAll: q,
|
|
335
|
+
onSelectionChange: F
|
|
336
|
+
}, {
|
|
337
|
+
default: u(() => [
|
|
338
|
+
c(s, {
|
|
339
|
+
type: "selection",
|
|
340
|
+
width: "50",
|
|
341
|
+
align: "center",
|
|
342
|
+
selectable: G
|
|
343
|
+
}),
|
|
344
|
+
c(s, {
|
|
345
|
+
label: "\u4E13\u4E1A",
|
|
346
|
+
prop: "majorName",
|
|
347
|
+
"show-overflow-tooltip": !0
|
|
348
|
+
})
|
|
349
|
+
]),
|
|
350
|
+
_: 1
|
|
351
|
+
}, 8, ["data"])), [
|
|
352
|
+
[r, y.value]
|
|
353
|
+
])
|
|
354
|
+
]),
|
|
355
|
+
m("div", ie, [
|
|
356
|
+
m("div", re, [
|
|
357
|
+
m("div", null, "\u5DF2\u9009\u4E2D\u5217\u8868 (" + X(n.value.length) + ")", 1),
|
|
358
|
+
n.value.length > 0 ? (_(), T(a, {
|
|
359
|
+
key: 0,
|
|
360
|
+
type: "text",
|
|
361
|
+
size: "default",
|
|
362
|
+
icon: k(P),
|
|
363
|
+
onClick: M,
|
|
364
|
+
class: "clear-btn"
|
|
365
|
+
}, {
|
|
366
|
+
default: u(() => [...e[2] || (e[2] = [
|
|
367
|
+
N("\u6E05\u7A7A", -1)
|
|
368
|
+
])]),
|
|
369
|
+
_: 1
|
|
370
|
+
}, 8, ["icon"])) : Y("", !0)
|
|
371
|
+
]),
|
|
372
|
+
c(t, {
|
|
373
|
+
data: n.value,
|
|
374
|
+
height: "540",
|
|
375
|
+
"row-key": "id",
|
|
376
|
+
class: "selected-table"
|
|
377
|
+
}, {
|
|
378
|
+
default: u(() => [
|
|
379
|
+
c(s, {
|
|
380
|
+
align: "center",
|
|
381
|
+
width: "60",
|
|
382
|
+
label: "\u64CD\u4F5C"
|
|
383
|
+
}, {
|
|
384
|
+
default: u(({ row: d }) => [
|
|
385
|
+
c(a, {
|
|
386
|
+
type: "primary",
|
|
387
|
+
link: "",
|
|
388
|
+
icon: k(P),
|
|
389
|
+
onClick: (x) => H(d)
|
|
390
|
+
}, null, 8, ["icon", "onClick"])
|
|
391
|
+
]),
|
|
392
|
+
_: 1
|
|
393
|
+
}),
|
|
394
|
+
c(s, {
|
|
395
|
+
label: "\u4E13\u4E1A",
|
|
396
|
+
prop: "profession",
|
|
397
|
+
"show-overflow-tooltip": !0,
|
|
398
|
+
"min-width": "120"
|
|
399
|
+
}),
|
|
400
|
+
c(s, {
|
|
401
|
+
label: "\u7528\u6237\u7C7B\u578B",
|
|
402
|
+
prop: "userType",
|
|
403
|
+
width: "100",
|
|
404
|
+
"show-overflow-tooltip": !0
|
|
405
|
+
}),
|
|
406
|
+
c(s, {
|
|
407
|
+
label: "\u7528\u6237\u540D\u79F0",
|
|
408
|
+
prop: "userName",
|
|
409
|
+
"min-width": "140",
|
|
410
|
+
"show-overflow-tooltip": !0
|
|
411
|
+
})
|
|
412
|
+
]),
|
|
413
|
+
_: 1
|
|
414
|
+
}, 8, ["data"])
|
|
415
|
+
])
|
|
416
|
+
])
|
|
417
|
+
]),
|
|
418
|
+
_: 1
|
|
419
|
+
}, 8, ["title", "modelValue"]);
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
}, me = /* @__PURE__ */ se(de, [["__scopeId", "data-v-030101a8"]]);
|
|
423
|
+
export {
|
|
424
|
+
me as ProfessionSelectDialog,
|
|
425
|
+
me as default
|
|
426
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(m,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("element-plus")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus"],t):(m=typeof globalThis<"u"?globalThis:m||self,t(m.ProfessionSelectVue3={},m.Vue,m.ElementPlus))})(this,function(m,t,_){"use strict";/*! Element Plus Icons Vue v2.3.2 */var v=t.defineComponent({name:"Check",__name:"check",setup(p){return(g,r)=>(t.openBlock(),t.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[t.createElementVNode("path",{fill:"currentColor",d:"M406.656 706.944 195.84 496.256a32 32 0 1 0-45.248 45.248l256 256 512-512a32 32 0 0 0-45.248-45.248L406.592 706.944z"})]))}}),j=v,x=t.defineComponent({name:"Delete",__name:"delete",setup(p){return(g,r)=>(t.openBlock(),t.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[t.createElementVNode("path",{fill:"currentColor",d:"M160 256H96a32 32 0 0 1 0-64h256V95.936a32 32 0 0 1 32-32h256a32 32 0 0 1 32 32V192h256a32 32 0 1 1 0 64h-64v672a32 32 0 0 1-32 32H192a32 32 0 0 1-32-32zm448-64v-64H416v64zM224 896h576V256H224zm192-128a32 32 0 0 1-32-32V416a32 32 0 0 1 64 0v320a32 32 0 0 1-32 32m192 0a32 32 0 0 1-32-32V416a32 32 0 0 1 64 0v320a32 32 0 0 1-32 32"})]))}}),C=x;const J="",K="",T=(p,g)=>{const r=p.__vccOpts||p;for(const[h,S]of g)r[h]=S;return r},k={class:"dialog-body"},E={class:"left-panel"},B={class:"select-all-btn-wrap"},L={class:"right-panel"},P={class:"selected-header"},I=T({__name:"ProfessionSelectDialog",props:{modelValue:{type:Boolean,default:!1},dialogTitle:{type:String,default:"\u9009\u62E9\u4E13\u4E1A"},selectedItems:{type:Array,default:()=>[]},api:{type:Object,required:!0},multiple:{type:Boolean,default:!0},multipleLimit:{type:Number,default:0},disabledItems:{type:Array,default:()=>[]}},emits:["update:modelValue","confirm"],setup(p,{emit:g}){const r=p,h=g,S=t.computed({get:()=>r.modelValue,set:s=>h("update:modelValue",s)}),y=t.ref(!1),f=t.ref([]),i=t.ref([]),u=t.ref(),A=t.computed(()=>r.multiple?r.multipleLimit>0&&i.value.length>r.multipleLimit?!1:i.value.length>0:i.value.length===1);function N(s){return i.value.some(e=>String(e.professionId)===String(s))}function D(s){return r.disabledItems.some(e=>String(e.id)===String(s))}function M(s){const e=s.users||s.userList||s.members||s.children||[],l=(Array.isArray(e)?e:[]).map(o=>{var n,d;return{id:(d=(n=o.id)!=null?n:o.userId)!=null?d:o.value,name:o.name||o.nickName||o.username||o.userName||o.label||"-",userType:o.userType||"",majorCode:o.majorCode||""}}),a=l.map(o=>o.name).filter(Boolean).join("\u3001");return{id:s.id,profession:s.profession||s.departmentName||s.name||"-",majorName:s.majorName||s.profession||s.name||"-",majorCode:s.majorCode||"",users:l,userNames:a}}function w(s){const e=s.id,l=s.profession,a=s.majorName||l,o=s.majorCode||"",n=s.users||[];return n.length===0?[{id:`p_${e}`,professionId:e,profession:l,majorName:a,majorCode:o,userType:"",userId:"",userName:"-"}]:n.map(d=>({id:`p_${e}_u_${d.id}`,professionId:e,profession:l,majorName:a,majorCode:d.majorCode||o,userType:d.userType||"",userId:d.id,userName:d.name||"-"}))}function z(s){const e=s.professionId;if(i.value=i.value.filter(a=>String(a.id)!==String(s.id)),!i.value.some(a=>String(a.professionId)===String(e))){const a=u.value;if(a){const o=f.value.find(n=>String(n.id)===String(e));o&&a.toggleRowSelection(o,!1)}}}function $(){_.ElMessageBox.confirm("\u786E\u5B9A\u8981\u6E05\u7A7A\u6240\u6709\u5DF2\u9009\u4E2D\u7684\u4E13\u4E1A\u5417\uFF1F","\u63D0\u793A",{confirmButtonText:"\u786E\u5B9A",cancelButtonText:"\u53D6\u6D88",type:"warning"}).then(()=>{i.value=[],u.value&&u.value.clearSelection(),_.ElMessage.success("\u5DF2\u6E05\u7A7A\u6240\u6709\u9009\u4E2D\u4E13\u4E1A")}).catch(()=>{})}async function H(){const s=r.api.getUserPageList||r.api.getUserList;if(!!s){y.value=!0;try{let e;try{e=await s()}catch{e=await s({page:1,pageSize:99999},{page:1,pageSize:99999})}let l=Array.isArray(e)?e:e||(e==null?void 0:e.data)||(e==null?void 0:e.content)||[];Array.isArray(l)||(l=[]),f.value=l.map(a=>M(a))}catch(e){console.error("\u83B7\u53D6\u4E13\u4E1A\u5931\u8D25:",e),_.ElMessage.error("\u83B7\u53D6\u4E13\u4E1A\u5931\u8D25")}finally{y.value=!1,t.nextTick(()=>{R()})}}}function R(){const s=u.value;if(!s)return;const e=new Set(i.value.map(l=>String(l.professionId)));f.value.forEach(l=>{e.has(String(l.id))&&s.toggleRowSelection(l,!0)})}function U(){const s=new Set(r.disabledItems.map(o=>String(o.id))),e=new Set(i.value.map(o=>String(o.professionId))),l=f.value.filter(o=>{const n=String(o.id);return!e.has(n)&&!s.has(n)});let a=[];if(l.forEach(o=>{a=a.concat(w(o))}),r.multiple){if(r.multipleLimit>0){const o=r.multipleLimit-i.value.length;a.slice(0,o).forEach(n=>{i.value.push(n)})}else a.forEach(o=>{i.value.push(o)});_.ElMessage.success(`\u5DF2\u9009\u4E2D ${l.length} \u4E2A\u4E13\u4E1A\uFF0C\u5171 ${a.length} \u6761\u8BB0\u5F55`)}t.nextTick(()=>{const o=u.value;o&&l.forEach(n=>{o.toggleRowSelection(n,!0)})})}function q(s){if(s.length>0){const e=new Set(i.value.map(o=>String(o.professionId))),l=new Set(r.disabledItems.map(o=>String(o.id))),a=s.filter(o=>{const n=String(o.id);return!e.has(n)&&!l.has(n)});if(r.multiple){let o=[];if(a.forEach(n=>{o=o.concat(w(n))}),r.multipleLimit>0){const n=r.multipleLimit-i.value.length;o.slice(0,n).forEach(d=>{i.value.push(d)})}else o.forEach(n=>{i.value.push(n)})}}}function O(s){const e=new Set(s.map(o=>String(o.id))),l=new Set(r.disabledItems.map(o=>String(o.id)));s.forEach(o=>{const n=String(o.id);if(!N(o.id)&&!l.has(n))if(r.multiple){const d=w(o);if(r.multipleLimit>0){const c=r.multipleLimit-i.value.length;if(c<=0)return;d.slice(0,c).forEach(V=>{i.value.push(V)})}else d.forEach(c=>{i.value.push(c)})}else i.value=w(o)});const a=new Set(f.value.map(o=>String(o.id)));i.value=i.value.filter(o=>{const n=String(o.professionId);return!(a.has(n)&&!e.has(n))})}function F(s){return!r.multiple&&i.value.length>=1?N(s.id):N(s.id)?!0:!D(s.id)}function G(){let s=i.value.map(e=>({id:e.userId||e.id,professionId:e.professionId,profession:e.profession,majorName:e.majorName,majorCode:e.majorCode,userType:e.userType,userId:e.userId,userName:e.userName}));h("confirm",s),b()}function b(){f.value=[],h("update:modelValue",!1)}return t.watch(()=>r.modelValue,s=>{s&&(i.value=r.selectedItems.flatMap(e=>{var l;if(e.users&&e.users.length>0){const a=e.id,o=e.profession||e.departmentName,n=e.majorName||o,d=e.majorCode||"";return e.users.map(c=>({id:`p_${a}_u_${c.id}`,professionId:a,profession:o,majorName:n,majorCode:d,userType:c.userType||e.userType||"",userId:c.id,userName:c.name||"-"}))}return[{id:e.id,professionId:(l=e.professionId)!=null?l:e.id,profession:e.profession||e.departmentName,majorName:e.majorName||e.profession||e.departmentName,majorCode:e.majorCode||"",userType:e.userType||"",userId:e.userId||"",userName:e.userName||e.userNames||"-"}]}),H())},{immediate:!0}),(s,e)=>{const l=t.resolveComponent("el-button"),a=t.resolveComponent("el-table-column"),o=t.resolveComponent("el-table"),n=t.resolveComponent("el-dialog"),d=t.resolveDirective("loading");return t.openBlock(),t.createBlock(n,{title:p.dialogTitle,modelValue:S.value,"onUpdate:modelValue":e[0]||(e[0]=c=>S.value=c),width:"960px","before-close":b,"append-to-body":"",class:"profession-select-dialog"},{footer:t.withCtx(()=>[t.createVNode(l,{type:"primary",disabled:!A.value,onClick:G},{default:t.withCtx(()=>[...e[3]||(e[3]=[t.createTextVNode("\u786E\u5B9A",-1)])]),_:1},8,["disabled"]),t.createVNode(l,{onClick:b},{default:t.withCtx(()=>[...e[4]||(e[4]=[t.createTextVNode("\u53D6\u6D88",-1)])]),_:1})]),default:t.withCtx(()=>[t.createElementVNode("div",k,[t.createElementVNode("div",E,[t.createElementVNode("div",B,[t.createVNode(l,{type:"primary",size:"default",icon:t.unref(j),disabled:y.value,onClick:U},{default:t.withCtx(()=>[...e[1]||(e[1]=[t.createTextVNode("\u5168\u90E8\u9009\u4E2D",-1)])]),_:1},8,["icon","disabled"])]),t.withDirectives((t.openBlock(),t.createBlock(o,{ref_key:"professionTable",ref:u,data:f.value,height:"540","row-key":"id",class:"profession-table",onSelectAll:q,onSelectionChange:O},{default:t.withCtx(()=>[t.createVNode(a,{type:"selection",width:"50",align:"center",selectable:F}),t.createVNode(a,{label:"\u4E13\u4E1A",prop:"majorName","show-overflow-tooltip":!0})]),_:1},8,["data"])),[[d,y.value]])]),t.createElementVNode("div",L,[t.createElementVNode("div",P,[t.createElementVNode("div",null,"\u5DF2\u9009\u4E2D\u5217\u8868 ("+t.toDisplayString(i.value.length)+")",1),i.value.length>0?(t.openBlock(),t.createBlock(l,{key:0,type:"text",size:"default",icon:t.unref(C),onClick:$,class:"clear-btn"},{default:t.withCtx(()=>[...e[2]||(e[2]=[t.createTextVNode("\u6E05\u7A7A",-1)])]),_:1},8,["icon"])):t.createCommentVNode("",!0)]),t.createVNode(o,{data:i.value,height:"540","row-key":"id",class:"selected-table"},{default:t.withCtx(()=>[t.createVNode(a,{align:"center",width:"60",label:"\u64CD\u4F5C"},{default:t.withCtx(({row:c})=>[t.createVNode(l,{type:"primary",link:"",icon:t.unref(C),onClick:V=>z(c)},null,8,["icon","onClick"])]),_:1}),t.createVNode(a,{label:"\u4E13\u4E1A",prop:"profession","show-overflow-tooltip":!0,"min-width":"120"}),t.createVNode(a,{label:"\u7528\u6237\u7C7B\u578B",prop:"userType",width:"100","show-overflow-tooltip":!0}),t.createVNode(a,{label:"\u7528\u6237\u540D\u79F0",prop:"userName","min-width":"140","show-overflow-tooltip":!0})]),_:1},8,["data"])])])]),_:1},8,["title","modelValue"])}}},[["__scopeId","data-v-030101a8"]]);m.ProfessionSelectDialog=I,m.default=I,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.dialog-body[data-v-030101a8]{display:flex;gap:16px;min-height:580px}.left-panel[data-v-030101a8]{flex:1;min-width:0;display:flex;flex-direction:column}.select-all-btn-wrap[data-v-030101a8]{margin-bottom:10px}.right-panel[data-v-030101a8]{width:460px;flex-shrink:0;border:1px solid #ebeef5;border-radius:4px;overflow:hidden}.selected-header[data-v-030101a8]{padding:6px 12px;background:#ecf5ff;color:#409eff;font-size:14px;font-weight:500;display:flex;align-items:center;justify-content:space-between;height:40px;box-sizing:border-box;white-space:nowrap}.clear-btn[data-v-030101a8]{color:#f56c6c;padding:0;margin-left:10px}.clear-btn[data-v-030101a8]:hover{color:#ef4444}.profession-table[data-v-030101a8],.selected-table[data-v-030101a8]{flex:1}.selected-table[data-v-030101a8] .el-table__cell{padding:6px 0}.row-type-select[data-v-030101a8]{width:100%}.profession-select-dialog .el-dialog__body{padding:20px}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mingminghahayu/profession-select-dialog-vue3",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Vue 3 Element Plus Profession Select Dialog Component",
|
|
5
|
+
"main": "./dist/profession-select-vue3.umd.js",
|
|
6
|
+
"module": "./dist/profession-select-vue3.es.js",
|
|
7
|
+
"unpkg": "./dist/profession-select-vue3.umd.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/profession-select-vue3.es.js",
|
|
11
|
+
"require": "./dist/profession-select-vue3.umd.js"
|
|
12
|
+
},
|
|
13
|
+
"./dist/style.css": "./dist/style.css"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "vite build",
|
|
17
|
+
"dev": "vite"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"vue": "^3.2.0",
|
|
21
|
+
"element-plus": "^2.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@vitejs/plugin-vue": "^3.0.0",
|
|
25
|
+
"typescript": "^4.7.0",
|
|
26
|
+
"vite": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vue": "^3.2.0",
|
|
30
|
+
"element-plus": "^2.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"src"
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"vue",
|
|
38
|
+
"element-plus",
|
|
39
|
+
"profession-select",
|
|
40
|
+
"dialog"
|
|
41
|
+
],
|
|
42
|
+
"author": "",
|
|
43
|
+
"license": "MIT"
|
|
44
|
+
}
|
package/src/App.vue
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="app-container">
|
|
3
|
+
<h1>Profession Select Dialog - Vue 3 Demo</h1>
|
|
4
|
+
<el-button @click="dialogVisible = true">选择专业</el-button>
|
|
5
|
+
<el-divider />
|
|
6
|
+
|
|
7
|
+
<profession-select-dialog
|
|
8
|
+
v-model="dialogVisible"
|
|
9
|
+
:api="api"
|
|
10
|
+
:selected-items="selectedItems"
|
|
11
|
+
@confirm="handleConfirm"
|
|
12
|
+
/>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup>
|
|
17
|
+
import { ref } from 'vue'
|
|
18
|
+
import ProfessionSelectDialog from './ProfessionSelectDialog.vue'
|
|
19
|
+
|
|
20
|
+
const dialogVisible = ref(false)
|
|
21
|
+
const selectedItems = ref([])
|
|
22
|
+
|
|
23
|
+
const api = {
|
|
24
|
+
async getUserPageList(pageDto, params) {
|
|
25
|
+
const mockData = [
|
|
26
|
+
{ id: '1', departmentName: '计算机科学与技术', userType: '总体', users: [
|
|
27
|
+
{ id: '101', name: '张三' },
|
|
28
|
+
{ id: '102', name: '李四' },
|
|
29
|
+
{ id: '103', name: '王五' }
|
|
30
|
+
] },
|
|
31
|
+
{ id: '2', departmentName: '软件工程', userType: '副总体', users: [
|
|
32
|
+
{ id: '201', name: '赵六' },
|
|
33
|
+
{ id: '202', name: '钱七' }
|
|
34
|
+
] },
|
|
35
|
+
{ id: '3', departmentName: '网络工程', userType: '专册', users: [
|
|
36
|
+
{ id: '301', name: '孙八' },
|
|
37
|
+
{ id: '302', name: '周九' }
|
|
38
|
+
] },
|
|
39
|
+
{ id: '4', departmentName: '信息安全', userType: '副专册', users: [
|
|
40
|
+
{ id: '401', name: '吴十' }
|
|
41
|
+
] },
|
|
42
|
+
{ id: '5', departmentName: '人工智能', userType: '设计人员', users: [
|
|
43
|
+
{ id: '501', name: '郑十一' },
|
|
44
|
+
{ id: '502', name: '冯十二' }
|
|
45
|
+
] },
|
|
46
|
+
{ id: '6', departmentName: '数据科学与大数据技术', userType: '总体', users: [
|
|
47
|
+
{ id: '601', name: '陈十三' },
|
|
48
|
+
{ id: '602', name: '褚十四' }
|
|
49
|
+
] },
|
|
50
|
+
{ id: '7', departmentName: '物联网工程', userType: '副总体', users: [
|
|
51
|
+
{ id: '701', name: '卫十五' }
|
|
52
|
+
] },
|
|
53
|
+
{ id: '8', departmentName: '电子信息工程', userType: '专册', users: [
|
|
54
|
+
{ id: '801', name: '蒋十六' },
|
|
55
|
+
{ id: '802', name: '沈十七' }
|
|
56
|
+
] },
|
|
57
|
+
{ id: '9', departmentName: '通信工程', userType: '副专册', users: [
|
|
58
|
+
{ id: '901', name: '韩十八' }
|
|
59
|
+
] },
|
|
60
|
+
{ id: '10', departmentName: '自动化', userType: '设计人员', users: [
|
|
61
|
+
{ id: '1001', name: '杨十九' },
|
|
62
|
+
{ id: '1002', name: '朱二十' }
|
|
63
|
+
] },
|
|
64
|
+
{ id: '11', departmentName: '机械设计制造及其自动化', userType: '总体', users: [
|
|
65
|
+
{ id: '1101', name: '秦廿一' }
|
|
66
|
+
] },
|
|
67
|
+
{ id: '12', departmentName: '土木工程', userType: '副总体', users: [
|
|
68
|
+
{ id: '1201', name: '尤廿二' },
|
|
69
|
+
{ id: '1202', name: '许廿三' }
|
|
70
|
+
] }
|
|
71
|
+
]
|
|
72
|
+
const page = params?.page || pageDto?.page || 1
|
|
73
|
+
const pageSize = params?.pageSize || pageDto?.pageSize || 10
|
|
74
|
+
const start = (page - 1) * pageSize
|
|
75
|
+
const rows = mockData.slice(start, start + pageSize)
|
|
76
|
+
return {
|
|
77
|
+
data: rows,
|
|
78
|
+
pagination: { totalCount: mockData.length }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function handleConfirm(list) {
|
|
84
|
+
selectedItems.value = list
|
|
85
|
+
console.log('Selected items:', list)
|
|
86
|
+
}
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<style scoped>
|
|
90
|
+
.app-container {
|
|
91
|
+
max-width: 800px;
|
|
92
|
+
margin: 40px auto;
|
|
93
|
+
padding: 20px;
|
|
94
|
+
background: #f9f9f9;
|
|
95
|
+
border-radius: 8px;
|
|
96
|
+
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
h1 {
|
|
100
|
+
text-align: center;
|
|
101
|
+
color: #303133;
|
|
102
|
+
margin-bottom: 20px;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-dialog
|
|
3
|
+
:title="dialogTitle"
|
|
4
|
+
v-model="visibleDialog"
|
|
5
|
+
width="960px"
|
|
6
|
+
:before-close="handleClose"
|
|
7
|
+
append-to-body
|
|
8
|
+
class="profession-select-dialog"
|
|
9
|
+
>
|
|
10
|
+
<div class="dialog-body">
|
|
11
|
+
<div class="left-panel">
|
|
12
|
+
<div class="select-all-btn-wrap">
|
|
13
|
+
<el-button
|
|
14
|
+
type="primary"
|
|
15
|
+
size="default"
|
|
16
|
+
:icon="Check"
|
|
17
|
+
:disabled="loading"
|
|
18
|
+
@click="selectAllUsers"
|
|
19
|
+
>全部选中</el-button>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<el-table
|
|
23
|
+
ref="professionTable"
|
|
24
|
+
:data="professionList"
|
|
25
|
+
v-loading="loading"
|
|
26
|
+
height="540"
|
|
27
|
+
row-key="id"
|
|
28
|
+
class="profession-table"
|
|
29
|
+
@select-all="handleSelectAll"
|
|
30
|
+
@selection-change="handleSelectionChange"
|
|
31
|
+
>
|
|
32
|
+
<el-table-column type="selection" width="50" align="center" :selectable="selectable" />
|
|
33
|
+
<el-table-column label="专业" prop="majorName" :show-overflow-tooltip="true" />
|
|
34
|
+
</el-table>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div class="right-panel">
|
|
38
|
+
<div class="selected-header">
|
|
39
|
+
<div>已选中列表 ({{ multiSelect.length }})</div>
|
|
40
|
+
<el-button
|
|
41
|
+
v-if="multiSelect.length > 0"
|
|
42
|
+
type="text"
|
|
43
|
+
size="default"
|
|
44
|
+
:icon="Delete"
|
|
45
|
+
@click="clearAllSelected"
|
|
46
|
+
class="clear-btn"
|
|
47
|
+
>清空</el-button>
|
|
48
|
+
</div>
|
|
49
|
+
<el-table :data="multiSelect" height="540" row-key="id" class="selected-table">
|
|
50
|
+
<el-table-column align="center" width="60" label="操作">
|
|
51
|
+
<template #default="{ row }">
|
|
52
|
+
<el-button type="primary" link :icon="Delete" @click="removeFromSelected(row)" />
|
|
53
|
+
</template>
|
|
54
|
+
</el-table-column>
|
|
55
|
+
<el-table-column label="专业" prop="profession" :show-overflow-tooltip="true" min-width="120" />
|
|
56
|
+
<el-table-column label="用户类型" prop="userType" width="100" :show-overflow-tooltip="true" />
|
|
57
|
+
<el-table-column label="用户名称" prop="userName" min-width="140" :show-overflow-tooltip="true" />
|
|
58
|
+
</el-table>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<template #footer>
|
|
63
|
+
<el-button type="primary" :disabled="!canCommit" @click="saveDialog">确定</el-button>
|
|
64
|
+
<el-button @click="handleClose">取消</el-button>
|
|
65
|
+
</template>
|
|
66
|
+
</el-dialog>
|
|
67
|
+
</template>
|
|
68
|
+
|
|
69
|
+
<script setup>
|
|
70
|
+
import { ref, computed, watch, nextTick } from 'vue'
|
|
71
|
+
import { Check, Delete } from '@element-plus/icons-vue'
|
|
72
|
+
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
73
|
+
|
|
74
|
+
const props = defineProps({
|
|
75
|
+
modelValue: { type: Boolean, default: false },
|
|
76
|
+
dialogTitle: { type: String, default: '选择专业' },
|
|
77
|
+
selectedItems: { type: Array, default: () => [] },
|
|
78
|
+
api: { type: Object, required: true },
|
|
79
|
+
multiple: { type: Boolean, default: true },
|
|
80
|
+
multipleLimit: { type: Number, default: 0 },
|
|
81
|
+
disabledItems: { type: Array, default: () => [] }
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const emit = defineEmits(['update:modelValue', 'confirm'])
|
|
85
|
+
|
|
86
|
+
const visibleDialog = computed({
|
|
87
|
+
get: () => props.modelValue,
|
|
88
|
+
set: (v) => emit('update:modelValue', v)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const loading = ref(false)
|
|
92
|
+
const professionList = ref([])
|
|
93
|
+
const multiSelect = ref([])
|
|
94
|
+
|
|
95
|
+
const professionTable = ref()
|
|
96
|
+
|
|
97
|
+
const canCommit = computed(() => {
|
|
98
|
+
if (props.multiple) {
|
|
99
|
+
if (props.multipleLimit > 0 && multiSelect.value.length > props.multipleLimit) return false
|
|
100
|
+
return multiSelect.value.length > 0
|
|
101
|
+
}
|
|
102
|
+
return multiSelect.value.length === 1
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
function isSelected(professionId) {
|
|
106
|
+
return multiSelect.value.some(u => String(u.professionId) === String(professionId))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isItemDisabled(id) {
|
|
110
|
+
return props.disabledItems.some(item => String(item.id) === String(id))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 把接口返回的专业项格式化为标准结构
|
|
114
|
+
// 每个专业下面有对应的人员,选中专业即选中该专业下所有人员
|
|
115
|
+
function formatProfessionItem(item) {
|
|
116
|
+
// 兼容多种字段名
|
|
117
|
+
const rawUsers = item.users || item.userList || item.members || item.children || []
|
|
118
|
+
const users = (Array.isArray(rawUsers) ? rawUsers : []).map(u => ({
|
|
119
|
+
id: u.id ?? u.userId ?? u.value,
|
|
120
|
+
name: u.name || u.nickName || u.username || u.userName || u.label || '-',
|
|
121
|
+
userType: u.userType || '',
|
|
122
|
+
majorCode: u.majorCode || ''
|
|
123
|
+
}))
|
|
124
|
+
const userNames = users.map(u => u.name).filter(Boolean).join('、')
|
|
125
|
+
return {
|
|
126
|
+
id: item.id,
|
|
127
|
+
profession: item.profession || item.departmentName || item.name || '-',
|
|
128
|
+
majorName: item.majorName || item.profession || item.name || '-',
|
|
129
|
+
majorCode: item.majorCode || '',
|
|
130
|
+
users,
|
|
131
|
+
userNames
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 把一个专业展开为按用户罗列的多条记录
|
|
136
|
+
// 每个用户一条;若专业下无用户则保留一条占位记录
|
|
137
|
+
function expandProfessionToRows(prof) {
|
|
138
|
+
const professionId = prof.id
|
|
139
|
+
const profession = prof.profession
|
|
140
|
+
const majorName = prof.majorName || profession
|
|
141
|
+
const majorCode = prof.majorCode || ''
|
|
142
|
+
const users = prof.users || []
|
|
143
|
+
if (users.length === 0) {
|
|
144
|
+
return [{
|
|
145
|
+
id: `p_${professionId}`,
|
|
146
|
+
professionId,
|
|
147
|
+
profession,
|
|
148
|
+
majorName,
|
|
149
|
+
majorCode,
|
|
150
|
+
userType: '',
|
|
151
|
+
userId: '',
|
|
152
|
+
userName: '-'
|
|
153
|
+
}]
|
|
154
|
+
}
|
|
155
|
+
return users.map(u => ({
|
|
156
|
+
id: `p_${professionId}_u_${u.id}`,
|
|
157
|
+
professionId,
|
|
158
|
+
profession,
|
|
159
|
+
majorName,
|
|
160
|
+
majorCode: u.majorCode || majorCode,
|
|
161
|
+
userType: u.userType || '',
|
|
162
|
+
userId: u.id,
|
|
163
|
+
userName: u.name || '-'
|
|
164
|
+
}))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function removeFromSelected(row) {
|
|
168
|
+
const professionId = row.professionId
|
|
169
|
+
// 单条删除:移除这一条用户记录
|
|
170
|
+
multiSelect.value = multiSelect.value.filter(u => String(u.id) !== String(row.id))
|
|
171
|
+
|
|
172
|
+
// 如果该专业下所有用户都被移除,则取消左侧该专业的勾选状态
|
|
173
|
+
const stillHas = multiSelect.value.some(u => String(u.professionId) === String(professionId))
|
|
174
|
+
if (!stillHas) {
|
|
175
|
+
const table = professionTable.value
|
|
176
|
+
if (table) {
|
|
177
|
+
const target = professionList.value.find(item => String(item.id) === String(professionId))
|
|
178
|
+
if (target) {
|
|
179
|
+
table.toggleRowSelection(target, false)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function clearAllSelected() {
|
|
186
|
+
ElMessageBox.confirm('确定要清空所有已选中的专业吗?', '提示', {
|
|
187
|
+
confirmButtonText: '确定',
|
|
188
|
+
cancelButtonText: '取消',
|
|
189
|
+
type: 'warning'
|
|
190
|
+
}).then(() => {
|
|
191
|
+
multiSelect.value = []
|
|
192
|
+
if (professionTable.value) {
|
|
193
|
+
professionTable.value.clearSelection()
|
|
194
|
+
}
|
|
195
|
+
ElMessage.success('已清空所有选中专业')
|
|
196
|
+
}).catch(() => {})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 取消分页:一次性加载全部数据
|
|
200
|
+
async function getPageList() {
|
|
201
|
+
const method = props.api.getUserPageList || props.api.getUserList
|
|
202
|
+
if (!method) return
|
|
203
|
+
loading.value = true
|
|
204
|
+
try {
|
|
205
|
+
let res
|
|
206
|
+
try {
|
|
207
|
+
// 优先无参调用(不分页)
|
|
208
|
+
res = await method()
|
|
209
|
+
} catch (e) {
|
|
210
|
+
// 兼容需要参数的接口:传一个大 pageSize 拉取全部
|
|
211
|
+
res = await method({ page: 1, pageSize: 99999 }, { page: 1, pageSize: 99999 })
|
|
212
|
+
}
|
|
213
|
+
// 兼容 res 直接是数组,或 res.data / res.content 是数组
|
|
214
|
+
let rows = Array.isArray(res) ? res : (res||res?.data || res?.content || [])
|
|
215
|
+
if (!Array.isArray(rows)) {
|
|
216
|
+
rows = []
|
|
217
|
+
}
|
|
218
|
+
professionList.value = rows.map(item => formatProfessionItem(item))
|
|
219
|
+
} catch (e) {
|
|
220
|
+
console.error('获取专业失败:', e)
|
|
221
|
+
ElMessage.error('获取专业失败')
|
|
222
|
+
} finally {
|
|
223
|
+
loading.value = false
|
|
224
|
+
nextTick(() => {
|
|
225
|
+
restoreSelection()
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function restoreSelection() {
|
|
231
|
+
const table = professionTable.value
|
|
232
|
+
if (!table) return
|
|
233
|
+
|
|
234
|
+
// 已选列表中存在哪些专业(按 professionId 判断)
|
|
235
|
+
const selectedProfessionIds = new Set(
|
|
236
|
+
multiSelect.value.map(u => String(u.professionId))
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
professionList.value.forEach(row => {
|
|
240
|
+
if (selectedProfessionIds.has(String(row.id))) {
|
|
241
|
+
table.toggleRowSelection(row, true)
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 全部选中:直接基于当前已加载的专业列表全选
|
|
247
|
+
function selectAllUsers() {
|
|
248
|
+
const disabledIds = new Set(props.disabledItems.map(item => String(item.id)))
|
|
249
|
+
const selectedProfessionIds = new Set(multiSelect.value.map(u => String(u.professionId)))
|
|
250
|
+
|
|
251
|
+
const newProfessions = professionList.value.filter(row => {
|
|
252
|
+
const id = String(row.id)
|
|
253
|
+
return !selectedProfessionIds.has(id) && !disabledIds.has(id)
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
let newRows = []
|
|
257
|
+
newProfessions.forEach(prof => {
|
|
258
|
+
newRows = newRows.concat(expandProfessionToRows(prof))
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
if (props.multiple) {
|
|
262
|
+
if (props.multipleLimit > 0) {
|
|
263
|
+
const remainingSlots = props.multipleLimit - multiSelect.value.length
|
|
264
|
+
newRows.slice(0, remainingSlots).forEach(item => {
|
|
265
|
+
multiSelect.value.push(item)
|
|
266
|
+
})
|
|
267
|
+
} else {
|
|
268
|
+
newRows.forEach(item => {
|
|
269
|
+
multiSelect.value.push(item)
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
ElMessage.success(`已选中 ${newProfessions.length} 个专业,共 ${newRows.length} 条记录`)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 同步左侧表格勾选状态
|
|
276
|
+
nextTick(() => {
|
|
277
|
+
const table = professionTable.value
|
|
278
|
+
if (table) {
|
|
279
|
+
newProfessions.forEach(row => {
|
|
280
|
+
table.toggleRowSelection(row, true)
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function handleSelectAll(selection) {
|
|
287
|
+
if (selection.length > 0) {
|
|
288
|
+
const selectedProfessionIds = new Set(multiSelect.value.map(u => String(u.professionId)))
|
|
289
|
+
const disabledIds = new Set(props.disabledItems.map(item => String(item.id)))
|
|
290
|
+
|
|
291
|
+
const newItems = selection.filter(row => {
|
|
292
|
+
const id = String(row.id)
|
|
293
|
+
return !selectedProfessionIds.has(id) && !disabledIds.has(id)
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
if (props.multiple) {
|
|
297
|
+
let newRows = []
|
|
298
|
+
newItems.forEach(prof => {
|
|
299
|
+
newRows = newRows.concat(expandProfessionToRows(prof))
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
if (props.multipleLimit > 0) {
|
|
303
|
+
const remainingSlots = props.multipleLimit - multiSelect.value.length
|
|
304
|
+
newRows.slice(0, remainingSlots).forEach(item => {
|
|
305
|
+
multiSelect.value.push(item)
|
|
306
|
+
})
|
|
307
|
+
} else {
|
|
308
|
+
newRows.forEach(item => {
|
|
309
|
+
multiSelect.value.push(item)
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function handleSelectionChange(selection) {
|
|
317
|
+
const selectionIds = new Set(selection.map(row => String(row.id)))
|
|
318
|
+
const disabledIds = new Set(props.disabledItems.map(item => String(item.id)))
|
|
319
|
+
|
|
320
|
+
// 处理新增勾选的专业:展开为按用户的多条记录
|
|
321
|
+
selection.forEach(row => {
|
|
322
|
+
const id = String(row.id)
|
|
323
|
+
if (!isSelected(row.id) && !disabledIds.has(id)) {
|
|
324
|
+
if (props.multiple) {
|
|
325
|
+
const rows = expandProfessionToRows(row)
|
|
326
|
+
if (props.multipleLimit > 0) {
|
|
327
|
+
const remainingSlots = props.multipleLimit - multiSelect.value.length
|
|
328
|
+
if (remainingSlots <= 0) return
|
|
329
|
+
rows.slice(0, remainingSlots).forEach(item => {
|
|
330
|
+
multiSelect.value.push(item)
|
|
331
|
+
})
|
|
332
|
+
} else {
|
|
333
|
+
rows.forEach(item => {
|
|
334
|
+
multiSelect.value.push(item)
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
multiSelect.value = expandProfessionToRows(row)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
// 处理取消勾选的专业:移除该专业下所有用户记录
|
|
344
|
+
const allPageIds = new Set(professionList.value.map(row => String(row.id)))
|
|
345
|
+
multiSelect.value = multiSelect.value.filter(item => {
|
|
346
|
+
const pid = String(item.professionId)
|
|
347
|
+
if (allPageIds.has(pid) && !selectionIds.has(pid)) {
|
|
348
|
+
return false
|
|
349
|
+
}
|
|
350
|
+
return true
|
|
351
|
+
})
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function selectable(row) {
|
|
355
|
+
if (!props.multiple && multiSelect.value.length >= 1) {
|
|
356
|
+
return isSelected(row.id)
|
|
357
|
+
}
|
|
358
|
+
if (isSelected(row.id)) {
|
|
359
|
+
return true
|
|
360
|
+
}
|
|
361
|
+
return !isItemDisabled(row.id)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function saveDialog() {
|
|
365
|
+
// 输出按用户罗列的多条记录
|
|
366
|
+
let list = multiSelect.value.map(u => ({
|
|
367
|
+
id: u.userId || u.id,
|
|
368
|
+
professionId: u.professionId,
|
|
369
|
+
profession: u.profession,
|
|
370
|
+
majorName: u.majorName,
|
|
371
|
+
majorCode: u.majorCode,
|
|
372
|
+
userType: u.userType,
|
|
373
|
+
userId: u.userId,
|
|
374
|
+
userName: u.userName
|
|
375
|
+
}))
|
|
376
|
+
emit('confirm', list)
|
|
377
|
+
handleClose()
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function handleClose() {
|
|
381
|
+
professionList.value = []
|
|
382
|
+
emit('update:modelValue', false)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
watch(
|
|
386
|
+
() => props.modelValue,
|
|
387
|
+
(visible) => {
|
|
388
|
+
if (visible) {
|
|
389
|
+
// 把外部传入的已选数据按用户展开为多条记录
|
|
390
|
+
multiSelect.value = props.selectedItems.flatMap(u => {
|
|
391
|
+
// 兼容两种数据结构:
|
|
392
|
+
// 1. 已经是按用户展开的记录(含 professionId 和 userName)
|
|
393
|
+
// 2. 按专业展开的记录(含 users 数组)
|
|
394
|
+
if (u.users && u.users.length > 0) {
|
|
395
|
+
const professionId = u.id
|
|
396
|
+
const profession = u.profession || u.departmentName
|
|
397
|
+
const majorName = u.majorName || profession
|
|
398
|
+
const majorCode = u.majorCode || ''
|
|
399
|
+
return u.users.map(x => ({
|
|
400
|
+
id: `p_${professionId}_u_${x.id}`,
|
|
401
|
+
professionId,
|
|
402
|
+
profession,
|
|
403
|
+
majorName,
|
|
404
|
+
majorCode,
|
|
405
|
+
userType: x.userType || u.userType || '',
|
|
406
|
+
userId: x.id,
|
|
407
|
+
userName: x.name || '-'
|
|
408
|
+
}))
|
|
409
|
+
}
|
|
410
|
+
// 已是单条用户记录
|
|
411
|
+
return [{
|
|
412
|
+
id: u.id,
|
|
413
|
+
professionId: u.professionId ?? u.id,
|
|
414
|
+
profession: u.profession || u.departmentName,
|
|
415
|
+
majorName: u.majorName || u.profession || u.departmentName,
|
|
416
|
+
majorCode: u.majorCode || '',
|
|
417
|
+
userType: u.userType || '',
|
|
418
|
+
userId: u.userId || '',
|
|
419
|
+
userName: u.userName || u.userNames || '-'
|
|
420
|
+
}]
|
|
421
|
+
})
|
|
422
|
+
getPageList()
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
{ immediate: true }
|
|
426
|
+
)
|
|
427
|
+
</script>
|
|
428
|
+
|
|
429
|
+
<style scoped>
|
|
430
|
+
.dialog-body {
|
|
431
|
+
display: flex;
|
|
432
|
+
gap: 16px;
|
|
433
|
+
min-height: 580px;
|
|
434
|
+
}
|
|
435
|
+
.left-panel {
|
|
436
|
+
flex: 1;
|
|
437
|
+
min-width: 0;
|
|
438
|
+
display: flex;
|
|
439
|
+
flex-direction: column;
|
|
440
|
+
}
|
|
441
|
+
.select-all-btn-wrap {
|
|
442
|
+
margin-bottom: 10px;
|
|
443
|
+
}
|
|
444
|
+
.right-panel {
|
|
445
|
+
width: 460px;
|
|
446
|
+
flex-shrink: 0;
|
|
447
|
+
border: 1px solid #ebeef5;
|
|
448
|
+
border-radius: 4px;
|
|
449
|
+
overflow: hidden;
|
|
450
|
+
}
|
|
451
|
+
.selected-header {
|
|
452
|
+
padding: 6px 12px;
|
|
453
|
+
background: #ecf5ff;
|
|
454
|
+
color: #409eff;
|
|
455
|
+
font-size: 14px;
|
|
456
|
+
font-weight: 500;
|
|
457
|
+
display: flex;
|
|
458
|
+
align-items: center;
|
|
459
|
+
justify-content: space-between;
|
|
460
|
+
height: 40px;
|
|
461
|
+
box-sizing: border-box;
|
|
462
|
+
white-space: nowrap;
|
|
463
|
+
}
|
|
464
|
+
.clear-btn {
|
|
465
|
+
color: #f56c6c;
|
|
466
|
+
padding: 0;
|
|
467
|
+
margin-left: 10px;
|
|
468
|
+
}
|
|
469
|
+
.clear-btn:hover {
|
|
470
|
+
color: #ef4444;
|
|
471
|
+
}
|
|
472
|
+
.profession-table, .selected-table {
|
|
473
|
+
flex: 1;
|
|
474
|
+
}
|
|
475
|
+
.selected-table :deep(.el-table__cell) {
|
|
476
|
+
padding: 6px 0;
|
|
477
|
+
}
|
|
478
|
+
.row-type-select {
|
|
479
|
+
width: 100%;
|
|
480
|
+
}
|
|
481
|
+
</style>
|
|
482
|
+
|
|
483
|
+
<style>
|
|
484
|
+
.profession-select-dialog .el-dialog__body {
|
|
485
|
+
padding: 20px 20px;
|
|
486
|
+
}
|
|
487
|
+
</style>
|
package/src/index.ts
ADDED