@ithinkdt/ui 4.0.0-10 → 4.0.0-11
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/package.json +4 -7
- package/src/components/Checkboxes.jsx +128 -0
- package/src/components/DataActions.jsx +107 -0
- package/src/components/DataCustom.jsx +172 -0
- package/src/components/DataFilter.jsx +113 -0
- package/src/components/DataForm.jsx +264 -0
- package/src/components/DataLocaleInput.jsx +121 -0
- package/src/components/DataPagination.jsx +62 -0
- package/src/components/DataSelection.jsx +57 -0
- package/src/components/DataTable.jsx +243 -0
- package/src/components/Radios.jsx +120 -0
- package/src/components/UserDept.jsx +643 -0
- package/src/components/assets.jsx +274 -0
- package/src/components/index.js +11 -0
- package/src/design/Account.jsx +152 -0
- package/src/design/Appearance.jsx +89 -0
- package/src/design/Breadcrumb.jsx +67 -0
- package/src/design/Fullscreen.jsx +65 -0
- package/src/design/Language.jsx +45 -0
- package/src/design/Layout.jsx +241 -0
- package/src/design/Logo.jsx +91 -0
- package/src/design/Menu.jsx +133 -0
- package/src/design/MultiTabs.jsx +501 -0
- package/src/design/Notification.jsx +322 -0
- package/src/design/common.jsx +19 -0
- package/src/design/index.js +10 -0
- package/src/directives/index.js +2 -0
- package/src/directives/spin.js +181 -0
- package/src/directives/tooltip.jsx +121 -0
- package/src/index.js +18 -1361
- package/src/page.jsx +626 -0
- package/src/use-i18n.js +8 -0
- package/src/use-style.js +58 -0
- package/src/utils.js +20 -0
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NAvatar, NAvatarGroup, NButton, NCard, NCheckbox, NDropdown, NEmpty, NH4, NIcon,
|
|
3
|
+
NList, NListItem, NPopover, NRadio, NSelect, NSpin, NTag, NTransfer, NTree, NTreeSelect,
|
|
4
|
+
} from 'ithinkdt-ui'
|
|
5
|
+
import { computed, defineComponent, nextTick, reactive, ref, shallowRef, watch } from 'vue'
|
|
6
|
+
|
|
7
|
+
import { flattenTree, walkTree } from '@ithinkdt/common'
|
|
8
|
+
|
|
9
|
+
import { useI18n } from '../use-i18n.js'
|
|
10
|
+
|
|
11
|
+
import { IAccount, IDept, IGroup, ILeft, IRight } from './assets.jsx'
|
|
12
|
+
|
|
13
|
+
export const DtUserDept = defineComponent({
|
|
14
|
+
name: 'UserDept',
|
|
15
|
+
inheritAttrs: false,
|
|
16
|
+
props: {
|
|
17
|
+
users: { type: Array, default: () => [] },
|
|
18
|
+
groups: { type: Array, default: () => [] },
|
|
19
|
+
depts: { type: Array, default: () => [] },
|
|
20
|
+
value: { type: [Array, String], default: undefined },
|
|
21
|
+
placeholder: { type: String, default: undefined },
|
|
22
|
+
size: { type: String, default: undefined },
|
|
23
|
+
type: { type: String, default: 'user' },
|
|
24
|
+
selectType: { type: String, default: 'dropdown' },
|
|
25
|
+
max: { type: Number, default: undefined },
|
|
26
|
+
multiple: { type: Boolean, default: false },
|
|
27
|
+
defaultExpandAll: { type: Boolean, default: false },
|
|
28
|
+
filterable: { type: Boolean, default: false },
|
|
29
|
+
disabled: { type: Boolean, default: undefined },
|
|
30
|
+
getUsersByGroup: { type: Function, default: () => [] },
|
|
31
|
+
getUsersByDept: { type: Function, default: () => [] },
|
|
32
|
+
},
|
|
33
|
+
emits: ['update:modelValue', 'updateModelValue'],
|
|
34
|
+
setup(props, { emit, attrs }) {
|
|
35
|
+
const { t } = useI18n()
|
|
36
|
+
|
|
37
|
+
const valueArray = computed(() => {
|
|
38
|
+
if (props.multiple) {
|
|
39
|
+
return props.value || []
|
|
40
|
+
}
|
|
41
|
+
const value = props.value?.trim()
|
|
42
|
+
return value ? [value] : []
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const userMap = new Map()
|
|
46
|
+
const users2 = computed(() => {
|
|
47
|
+
userMap.clear()
|
|
48
|
+
return props.users.map((u) => {
|
|
49
|
+
u = reactive(u)
|
|
50
|
+
u.label = u.nickname
|
|
51
|
+
u.value = u.username
|
|
52
|
+
u.type = 'user'
|
|
53
|
+
|
|
54
|
+
userMap.set(u.username, u)
|
|
55
|
+
return u
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
const deptArray = shallowRef([])
|
|
59
|
+
|
|
60
|
+
watch(
|
|
61
|
+
() => props.depts,
|
|
62
|
+
(depts) => {
|
|
63
|
+
walkTree(depts, (d) => {
|
|
64
|
+
d.label = d.name
|
|
65
|
+
d.value = d.code
|
|
66
|
+
d.type = 'dept'
|
|
67
|
+
if (!d.children?.length) {
|
|
68
|
+
delete d.children
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
deptArray.value = flattenTree(depts)
|
|
72
|
+
},
|
|
73
|
+
{ immediate: true },
|
|
74
|
+
)
|
|
75
|
+
const userArray = computed(() => {
|
|
76
|
+
return [
|
|
77
|
+
...props.depts,
|
|
78
|
+
...props.groups.map((g) => {
|
|
79
|
+
return { label: g.name, value: g.code, type: 'group' }
|
|
80
|
+
}),
|
|
81
|
+
...users2.value,
|
|
82
|
+
]
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const depth = ref([])
|
|
86
|
+
const current = ref()
|
|
87
|
+
|
|
88
|
+
const loadChildren = async (it) => {
|
|
89
|
+
const data = await (it.type === 'group' ? props.getUsersByGroup(it.value) : props.getUsersByDept(it.value))
|
|
90
|
+
|
|
91
|
+
for (const u of users2.value) {
|
|
92
|
+
u.disabled = true
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
current.value = [
|
|
96
|
+
...(it.type === 'dept' ? it.children ?? [] : []),
|
|
97
|
+
...data.map((u) => {
|
|
98
|
+
const u2 = userMap.get(u.username)
|
|
99
|
+
if (u2) u2.disabled = false
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...u,
|
|
103
|
+
label: u.nickname,
|
|
104
|
+
value: u.username,
|
|
105
|
+
type: 'user',
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const valuesMap = new WeakMap()
|
|
112
|
+
|
|
113
|
+
const renderSourceList = (value, onUpdateValue, pattern) => {
|
|
114
|
+
if (props.type === 'dept') {
|
|
115
|
+
return (
|
|
116
|
+
<NTree
|
|
117
|
+
data={props.depts}
|
|
118
|
+
keyField="value"
|
|
119
|
+
labelField="name"
|
|
120
|
+
defaultExpandAll={props.defaultExpandAll}
|
|
121
|
+
checkable={props.multiple}
|
|
122
|
+
selectable={!props.multiple}
|
|
123
|
+
multiple={false}
|
|
124
|
+
blockLine
|
|
125
|
+
checkOnClick
|
|
126
|
+
pattern={pattern}
|
|
127
|
+
filter={(pattern, it) => it.label.includes(pattern) || it.value.includes(pattern)}
|
|
128
|
+
checkedKeys={props.multiple ? value : undefined}
|
|
129
|
+
selectedKeys={props.multiple ? undefined : value}
|
|
130
|
+
onUpdateCheckedKeys={(checkedKeys) => {
|
|
131
|
+
if (props.max && checkedKeys?.length > props.max) return
|
|
132
|
+
onUpdateValue(checkedKeys)
|
|
133
|
+
}}
|
|
134
|
+
onUpdateSelectedKeys={(selectedKeys) => {
|
|
135
|
+
onUpdateValue(selectedKeys)
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let valueSet = value ? valuesMap.get(value) : new Set()
|
|
142
|
+
if (value && !valueSet) {
|
|
143
|
+
valueSet = new Set(value)
|
|
144
|
+
valuesMap.set(value, valueSet)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (current.value === false) {
|
|
148
|
+
return <NSpin show />
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let list = current.value || userArray.value
|
|
152
|
+
|
|
153
|
+
pattern = pattern?.trim()
|
|
154
|
+
if (pattern) {
|
|
155
|
+
list = list?.filter(it => it.label.includes(pattern) || it.value.includes(pattern))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const depths = depth.value
|
|
159
|
+
return (
|
|
160
|
+
<>
|
|
161
|
+
<div style="margin: 12px 16px; display: flex; justify-content: space-between; align-items: center">
|
|
162
|
+
{
|
|
163
|
+
depths.length > 0
|
|
164
|
+
? (
|
|
165
|
+
<>
|
|
166
|
+
<span style="display: flex; align-items: center">
|
|
167
|
+
{depths.length >= 2 ? depths.at(-2).label : t('common.all')}
|
|
168
|
+
<span style="padding: 0 4px">
|
|
169
|
+
<IRight />
|
|
170
|
+
</span>
|
|
171
|
+
{depths.at(-1).label}
|
|
172
|
+
</span>
|
|
173
|
+
<NButton
|
|
174
|
+
text
|
|
175
|
+
type="warning"
|
|
176
|
+
onClick={() => {
|
|
177
|
+
depths.pop()
|
|
178
|
+
current.value = depths.length > 0 ? false : undefined
|
|
179
|
+
if (depths.length > 0) {
|
|
180
|
+
loadChildren(depths.at(-1))
|
|
181
|
+
} else {
|
|
182
|
+
for (const u of users2.value) {
|
|
183
|
+
u.disabled = false
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
<NIcon>
|
|
189
|
+
<ILeft />
|
|
190
|
+
</NIcon>
|
|
191
|
+
{t('common.back')}
|
|
192
|
+
</NButton>
|
|
193
|
+
</>
|
|
194
|
+
)
|
|
195
|
+
: (
|
|
196
|
+
<span>{t('common.all')}</span>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
{list?.length
|
|
202
|
+
? (
|
|
203
|
+
<NList showDivider={false} style="padding: 0 16px">
|
|
204
|
+
{list.map((it) => {
|
|
205
|
+
return (
|
|
206
|
+
<NListItem key={it.type + '_' + it.value} style="padding: 6px 0">
|
|
207
|
+
{it.type === 'user'
|
|
208
|
+
? (
|
|
209
|
+
props.multiple
|
|
210
|
+
? (
|
|
211
|
+
<NCheckbox
|
|
212
|
+
checked={valueSet.has(it.value) || false}
|
|
213
|
+
onUpdateChecked={(checked) => {
|
|
214
|
+
if (checked && props.max && value.length >= props.max) return
|
|
215
|
+
|
|
216
|
+
const values = [...(value || [])]
|
|
217
|
+
if (checked) {
|
|
218
|
+
values.push(it.value)
|
|
219
|
+
} else {
|
|
220
|
+
const i = values.indexOf(it.value)
|
|
221
|
+
values.splice(i, 1)
|
|
222
|
+
}
|
|
223
|
+
onUpdateValue(values)
|
|
224
|
+
}}
|
|
225
|
+
style="margin-left: 3px"
|
|
226
|
+
>
|
|
227
|
+
{renderUsers([it], {
|
|
228
|
+
max: 1,
|
|
229
|
+
size: 24,
|
|
230
|
+
placement: 'right',
|
|
231
|
+
})}
|
|
232
|
+
</NCheckbox>
|
|
233
|
+
)
|
|
234
|
+
: (
|
|
235
|
+
<NRadio
|
|
236
|
+
checked={valueSet.has(it.value) || false}
|
|
237
|
+
onUpdateChecked={(checked) => {
|
|
238
|
+
onUpdateValue(checked ? [it.value] : [])
|
|
239
|
+
}}
|
|
240
|
+
style="margin-left: 3px"
|
|
241
|
+
>
|
|
242
|
+
{renderUsers([it], {
|
|
243
|
+
max: 1,
|
|
244
|
+
size: 24,
|
|
245
|
+
placement: 'right',
|
|
246
|
+
})}
|
|
247
|
+
</NRadio>
|
|
248
|
+
)
|
|
249
|
+
)
|
|
250
|
+
: (
|
|
251
|
+
<div
|
|
252
|
+
onClick={() => {
|
|
253
|
+
current.value = false
|
|
254
|
+
depth.value.push(it)
|
|
255
|
+
loadChildren(it)
|
|
256
|
+
}}
|
|
257
|
+
style="cursor: pointer; display: flex; align-items: center; gap: 8px"
|
|
258
|
+
>
|
|
259
|
+
{it.type === 'dept'
|
|
260
|
+
? (
|
|
261
|
+
<NAvatar size={24} style="background-color: red">
|
|
262
|
+
<NIcon>
|
|
263
|
+
<IDept />
|
|
264
|
+
</NIcon>
|
|
265
|
+
</NAvatar>
|
|
266
|
+
)
|
|
267
|
+
: (
|
|
268
|
+
<NAvatar size={24} style="background-color: green">
|
|
269
|
+
<NIcon>
|
|
270
|
+
<IGroup />
|
|
271
|
+
</NIcon>
|
|
272
|
+
</NAvatar>
|
|
273
|
+
)}
|
|
274
|
+
<span style="flex: 1 1 auto">{it.label}</span>
|
|
275
|
+
<NIcon>
|
|
276
|
+
<IRight />
|
|
277
|
+
</NIcon>
|
|
278
|
+
</div>
|
|
279
|
+
)}
|
|
280
|
+
</NListItem>
|
|
281
|
+
)
|
|
282
|
+
})}
|
|
283
|
+
</NList>
|
|
284
|
+
)
|
|
285
|
+
: (
|
|
286
|
+
<NEmpty />
|
|
287
|
+
)}
|
|
288
|
+
</>
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const renderTargetListEmpty = () => {
|
|
293
|
+
return <NEmpty description={props.placeholder} />
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const renderTransfer = (props2, options, value, onUpdateValue, onUpdateValue2) => {
|
|
297
|
+
return (
|
|
298
|
+
<NTransfer
|
|
299
|
+
{...props2}
|
|
300
|
+
key={props.type}
|
|
301
|
+
options={options}
|
|
302
|
+
renderSourceList={({ onCheck, pattern }) => renderSourceList(value, onCheck, pattern)}
|
|
303
|
+
renderTargetList={
|
|
304
|
+
props.placeholder?.trim() && !props.value?.length ? renderTargetListEmpty : undefined
|
|
305
|
+
}
|
|
306
|
+
sourceFilterable={props.filterable}
|
|
307
|
+
size={props.size}
|
|
308
|
+
disabled={props.disabled || undefined}
|
|
309
|
+
value={value}
|
|
310
|
+
filter={(pattern, it) => it.label.includes(pattern) || it.value.includes(pattern)}
|
|
311
|
+
onUpdate:value={(v) => {
|
|
312
|
+
onUpdateValue?.(v)
|
|
313
|
+
}}
|
|
314
|
+
onUpdateValue={(v) => {
|
|
315
|
+
onUpdateValue2?.(v)
|
|
316
|
+
}}
|
|
317
|
+
/>
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const renderTag = ({ option, handleClose }) => {
|
|
322
|
+
return (
|
|
323
|
+
<NTag
|
|
324
|
+
type={props.type === 'user' ? 'primary' : 'info'}
|
|
325
|
+
closable
|
|
326
|
+
onMousedown={e => e.preventDefault()}
|
|
327
|
+
onClose={(e) => {
|
|
328
|
+
e.stopPropagation()
|
|
329
|
+
handleClose()
|
|
330
|
+
}}
|
|
331
|
+
>
|
|
332
|
+
{option.label}
|
|
333
|
+
</NTag>
|
|
334
|
+
)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const emitValue = (v, k = 'updateModelValue') => {
|
|
338
|
+
if (props.multiple) {
|
|
339
|
+
emit(k, v)
|
|
340
|
+
} else {
|
|
341
|
+
emit(k, v?.[0])
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const selectRef = ref()
|
|
346
|
+
let opened = false
|
|
347
|
+
const showDialog = () => {
|
|
348
|
+
if (opened) return
|
|
349
|
+
|
|
350
|
+
opened = true
|
|
351
|
+
const valueRef = shallowRef([...(valueArray.value || [])])
|
|
352
|
+
$dialog({
|
|
353
|
+
showIcon: false,
|
|
354
|
+
title: props.placeholder,
|
|
355
|
+
style: {
|
|
356
|
+
width: '700px',
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
content: () => {
|
|
360
|
+
const options = props.type === 'user' ? users2.value : deptArray.value
|
|
361
|
+
return (
|
|
362
|
+
<div style={{ height: '550px' }}>
|
|
363
|
+
{renderTransfer(
|
|
364
|
+
{ style: { height: '100%' } },
|
|
365
|
+
options,
|
|
366
|
+
valueRef.value,
|
|
367
|
+
v => (valueRef.value = v),
|
|
368
|
+
)}
|
|
369
|
+
</div>
|
|
370
|
+
)
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
onOk() {
|
|
374
|
+
emitValue(valueRef.value, 'update:modelValue')
|
|
375
|
+
emitValue(valueRef.value, 'updateModelValue')
|
|
376
|
+
},
|
|
377
|
+
onAfterLeave() {
|
|
378
|
+
nextTick(() => {
|
|
379
|
+
selectRef.value?.blur()
|
|
380
|
+
opened = false
|
|
381
|
+
})
|
|
382
|
+
},
|
|
383
|
+
})
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const selectSlots = {
|
|
387
|
+
arrow: () => {
|
|
388
|
+
return <NIcon>{props.type === 'user' ? <IGroup /> : <IDept />}</NIcon>
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
return () => {
|
|
392
|
+
const options = props.type === 'user' ? users2.value : deptArray.value
|
|
393
|
+
|
|
394
|
+
if (props.selectType === 'dropdown' && props.type === 'dept') {
|
|
395
|
+
return (
|
|
396
|
+
<NTreeSelect
|
|
397
|
+
options={options}
|
|
398
|
+
keyField="value"
|
|
399
|
+
defaultExpandAll={props.defaultExpandAll}
|
|
400
|
+
checkable={props.multiple}
|
|
401
|
+
multiple={props.multiple}
|
|
402
|
+
filter={(pattern, it) => it.label.includes(pattern) || it.value.includes(pattern)}
|
|
403
|
+
value={props.value}
|
|
404
|
+
onUpdateValue={(v) => {
|
|
405
|
+
if (props.multiple && props.max && v?.length > props.max) return
|
|
406
|
+
emit('updateModelValue', v)
|
|
407
|
+
}}
|
|
408
|
+
onUpdate:value={(v) => {
|
|
409
|
+
if (props.multiple && props.max && v?.length > props.max) return
|
|
410
|
+
emit('update:modelValue', v)
|
|
411
|
+
}}
|
|
412
|
+
>
|
|
413
|
+
{selectSlots}
|
|
414
|
+
</NTreeSelect>
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (props.selectType === 'transfer') {
|
|
419
|
+
return renderTransfer(
|
|
420
|
+
attrs,
|
|
421
|
+
options,
|
|
422
|
+
valueArray.value,
|
|
423
|
+
v => emitValue(v, 'update:modelValue'),
|
|
424
|
+
v => emitValue(v, 'updateModelValue'),
|
|
425
|
+
)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const isDropdown = props.selectType === 'dropdown'
|
|
429
|
+
|
|
430
|
+
return (
|
|
431
|
+
<NSelect
|
|
432
|
+
{...attrs}
|
|
433
|
+
key={props.type}
|
|
434
|
+
ref={selectRef}
|
|
435
|
+
show={isDropdown ? undefined : false}
|
|
436
|
+
filterable={isDropdown ? props.filterable : false}
|
|
437
|
+
options={options}
|
|
438
|
+
multiple={props.multiple}
|
|
439
|
+
size={props.size}
|
|
440
|
+
placeholder={props.placeholder}
|
|
441
|
+
disabled={props.disabled || undefined}
|
|
442
|
+
value={props.value}
|
|
443
|
+
renderTag={props.multiple ? renderTag : undefined}
|
|
444
|
+
onFocus={isDropdown ? undefined : showDialog}
|
|
445
|
+
onUpdateValue={(v) => {
|
|
446
|
+
emit('updateModelValue', v)
|
|
447
|
+
}}
|
|
448
|
+
onUpdate:value={(v) => {
|
|
449
|
+
emit('update:modelValue', v)
|
|
450
|
+
}}
|
|
451
|
+
>
|
|
452
|
+
{selectSlots}
|
|
453
|
+
</NSelect>
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
function renderUser(user, showName, { placement, size }) {
|
|
460
|
+
const name = user.nickname.split(' ').at(-1)
|
|
461
|
+
let text = name
|
|
462
|
+
|
|
463
|
+
if (/^[\u4E00-\u9FA5]+$/.test(name)) {
|
|
464
|
+
// 全中文
|
|
465
|
+
const l = name.length
|
|
466
|
+
text = l >= 3 ? name.slice(-2) : name
|
|
467
|
+
} else {
|
|
468
|
+
if (name.length > 4) {
|
|
469
|
+
text = (
|
|
470
|
+
<NIcon>
|
|
471
|
+
<IAccount />
|
|
472
|
+
</NIcon>
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return (
|
|
477
|
+
<NPopover key={user.username} raw placement={placement}>
|
|
478
|
+
{{
|
|
479
|
+
default: () => {
|
|
480
|
+
return (
|
|
481
|
+
<NCard style="width: 200px" size="small">
|
|
482
|
+
<NH4>{user.nickname}</NH4>
|
|
483
|
+
<span>{user.username}</span>
|
|
484
|
+
</NCard>
|
|
485
|
+
)
|
|
486
|
+
},
|
|
487
|
+
trigger: () => {
|
|
488
|
+
const avatar = (
|
|
489
|
+
<NAvatar
|
|
490
|
+
color="var(--color-primary)"
|
|
491
|
+
round
|
|
492
|
+
size={size}
|
|
493
|
+
style={showName ? { position: 'absolute', bottom: -(size - 20) / 2 + 'px' } : ''}
|
|
494
|
+
>
|
|
495
|
+
{text}
|
|
496
|
+
</NAvatar>
|
|
497
|
+
)
|
|
498
|
+
return showName
|
|
499
|
+
? (
|
|
500
|
+
<div
|
|
501
|
+
style={
|
|
502
|
+
showName
|
|
503
|
+
? {
|
|
504
|
+
display: 'inline-block',
|
|
505
|
+
minWidth: size + 'px',
|
|
506
|
+
height: size + 'px',
|
|
507
|
+
}
|
|
508
|
+
: ''
|
|
509
|
+
}
|
|
510
|
+
>
|
|
511
|
+
{avatar}
|
|
512
|
+
|
|
513
|
+
{showName
|
|
514
|
+
? (
|
|
515
|
+
<span style={{ marginLeft: size + 6 + 'px' }}>{user.nickname}</span>
|
|
516
|
+
)
|
|
517
|
+
: undefined}
|
|
518
|
+
</div>
|
|
519
|
+
)
|
|
520
|
+
: (
|
|
521
|
+
avatar
|
|
522
|
+
)
|
|
523
|
+
},
|
|
524
|
+
}}
|
|
525
|
+
</NPopover>
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export function renderUsers(users, options = {}) {
|
|
530
|
+
options.size ||= 24
|
|
531
|
+
options.max ||= 4
|
|
532
|
+
const { max, size } = options
|
|
533
|
+
if (users.length <= 1) {
|
|
534
|
+
return <span style="position: relative">{users.map(u => renderUser(u, true, options))}</span>
|
|
535
|
+
}
|
|
536
|
+
return (
|
|
537
|
+
<span style={{ display: 'inline-block', height: size + 'px' }}>
|
|
538
|
+
<NAvatarGroup options={users} size={size} max={max || 4} style="top: -2px">
|
|
539
|
+
{{
|
|
540
|
+
avatar: ({ option }) => {
|
|
541
|
+
return renderUser(option, false, options)
|
|
542
|
+
},
|
|
543
|
+
rest: ({ options, rest }) => {
|
|
544
|
+
return (
|
|
545
|
+
<NDropdown
|
|
546
|
+
options={options}
|
|
547
|
+
keyField="username"
|
|
548
|
+
labelField="nickname"
|
|
549
|
+
renderOption={({ option }) => renderUser(option, false, options)}
|
|
550
|
+
>
|
|
551
|
+
<NAvatar>
|
|
552
|
+
+
|
|
553
|
+
{rest}
|
|
554
|
+
</NAvatar>
|
|
555
|
+
</NDropdown>
|
|
556
|
+
)
|
|
557
|
+
},
|
|
558
|
+
}}
|
|
559
|
+
</NAvatarGroup>
|
|
560
|
+
</span>
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export const DtDeptRender = /* @__PURE__ */ defineComponent({
|
|
565
|
+
name: 'DeptRender',
|
|
566
|
+
props: {
|
|
567
|
+
value: [String, Array],
|
|
568
|
+
multiple: Boolean,
|
|
569
|
+
getDeptsByCode: Function,
|
|
570
|
+
},
|
|
571
|
+
setup(props) {
|
|
572
|
+
const depts = ref([])
|
|
573
|
+
const map = {}
|
|
574
|
+
watch([() => props.value, () => props.multiple],
|
|
575
|
+
([value, multiple]) => {
|
|
576
|
+
depts.value = []
|
|
577
|
+
const deptcodes = value ? (multiple ? (Array.isArray(value) ? value : value.trim() ? value.trim().split(',') : []) : [value]) : []
|
|
578
|
+
|
|
579
|
+
const deptcodes1 = []
|
|
580
|
+
for (const [i, code] of deptcodes.entries()) {
|
|
581
|
+
if (!map[code]) {
|
|
582
|
+
const d = reactive({ code, name: code })
|
|
583
|
+
map[code] = d
|
|
584
|
+
deptcodes1.push(code)
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
depts.value[i] = map[code]
|
|
588
|
+
}
|
|
589
|
+
if (deptcodes1.length > 0) {
|
|
590
|
+
props.getDeptsByCode(deptcodes1).then((data) => {
|
|
591
|
+
for (const it of data) {
|
|
592
|
+
Object.assign(map[it.code], it)
|
|
593
|
+
}
|
|
594
|
+
})
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
{ immediate: true },
|
|
598
|
+
)
|
|
599
|
+
return () => depts.value.map(dept => <NTag key={dept.code}>{dept.name}</NTag>)
|
|
600
|
+
},
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
export const DtUserRender = /* @__PURE__ */ defineComponent({
|
|
604
|
+
name: 'UserRender',
|
|
605
|
+
props: {
|
|
606
|
+
value: [String, Array],
|
|
607
|
+
multiple: Boolean,
|
|
608
|
+
max: Number,
|
|
609
|
+
size: Number,
|
|
610
|
+
placement: String,
|
|
611
|
+
getUsersByUsername: Function,
|
|
612
|
+
},
|
|
613
|
+
setup(props) {
|
|
614
|
+
const users = ref([])
|
|
615
|
+
const map = {}
|
|
616
|
+
watch([() => props.value, () => props.multiple],
|
|
617
|
+
([value, multiple]) => {
|
|
618
|
+
users.value = []
|
|
619
|
+
const usernames = value ? (multiple ? (Array.isArray(value) ? value : value.trim() ? value.trim().split(',') : []) : [value]) : []
|
|
620
|
+
|
|
621
|
+
const usernames1 = []
|
|
622
|
+
for (const [i, code] of usernames.entries()) {
|
|
623
|
+
if (!map[code]) {
|
|
624
|
+
const d = reactive({ code, name: code })
|
|
625
|
+
map[code] = d
|
|
626
|
+
usernames1.push(code)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
users.value[i] = map[code]
|
|
630
|
+
}
|
|
631
|
+
if (usernames1.length > 0) {
|
|
632
|
+
props.getUsersByUsername(usernames1).then((data) => {
|
|
633
|
+
for (const it of data) {
|
|
634
|
+
Object.assign(map[it.code], it)
|
|
635
|
+
}
|
|
636
|
+
})
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
{ immediate: true },
|
|
640
|
+
)
|
|
641
|
+
return () => renderUsers(users.value, props)
|
|
642
|
+
},
|
|
643
|
+
})
|