@jari-ace/element-plus-component 0.1.10 → 0.2.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/README.md +1 -18
- package/dist/components/form/JaForm.vue.d.ts +0 -3
- package/dist/components/form/JaForm.vue.d.ts.map +1 -1
- package/dist/components/form/JaForm.vue.js +68 -22
- package/dist/components/form/JaForm.vue.js.map +1 -1
- package/dist/components/formItem/JaFormItem.vue.d.ts +0 -4
- package/dist/components/formItem/JaFormItem.vue.d.ts.map +1 -1
- package/dist/components/formItem/JaFormItem.vue.js +8 -26
- package/dist/components/formItem/JaFormItem.vue.js.map +1 -1
- package/dist/components/userPicker/src/UserPicker.vue.d.ts +17 -0
- package/dist/components/userPicker/src/UserPicker.vue.d.ts.map +1 -1
- package/dist/components/userPicker/src/UserPicker.vue.js +15 -0
- package/dist/components/userPicker/src/UserPicker.vue.js.map +1 -1
- package/dist/components/userSelectDialog/src/userSelectDialog.vue.d.ts +17 -0
- package/dist/components/userSelectDialog/src/userSelectDialog.vue.d.ts.map +1 -1
- package/dist/components/userSelectDialog/src/userSelectDialog.vue.js +15 -0
- package/dist/components/userSelectDialog/src/userSelectDialog.vue.js.map +1 -1
- package/dist/hooks/useBackendValidations.js +0 -1
- package/dist/hooks/useBackendValidations.js.map +1 -1
- package/dist/hooks/useClassificationLevels.d.ts +21 -0
- package/dist/hooks/useClassificationLevels.d.ts.map +1 -0
- package/dist/hooks/useClassificationLevels.js +55 -0
- package/dist/hooks/useClassificationLevels.js.map +1 -0
- package/dist/hooks/useUserRefQuery.d.ts +6 -0
- package/dist/hooks/useUserRefQuery.d.ts.map +1 -1
- package/dist/hooks/useUserRefQuery.js +4 -0
- package/dist/hooks/useUserRefQuery.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/lib/index.css +1 -1
- package/lib/index.js +1808 -1774
- package/lib/index.umd.cjs +2 -2
- package/package.json +61 -61
- package/packages/components/autoComplete/JaAutoComplete.vue +47 -47
- package/packages/components/autoComplete/index.ts +5 -5
- package/packages/components/avatar/JaAvatar.vue +126 -126
- package/packages/components/avatar/avatarToken.ts +11 -11
- package/packages/components/avatar/defaultImg.ts +14 -14
- package/packages/components/avatar/index.ts +7 -7
- package/packages/components/button/JaButton.vue +51 -51
- package/packages/components/button/index.ts +4 -4
- package/packages/components/channelPicker/index.ts +7 -7
- package/packages/components/channelPicker/src/ChannelPicker.vue +43 -43
- package/packages/components/channelPicker/src/JaChannelPicker.vue +42 -42
- package/packages/components/checkbox/JaCheckbox.vue +73 -73
- package/packages/components/checkbox/index.ts +4 -4
- package/packages/components/checkboxGroup/JaCheckboxGroup.vue +45 -45
- package/packages/components/checkboxGroup/index.ts +4 -4
- package/packages/components/customGroupTree/index.ts +10 -10
- package/packages/components/customGroupTree/src/customGroupTree.vue +91 -91
- package/packages/components/datePicker/JaDatePicker.vue +52 -52
- package/packages/components/datePicker/index.ts +4 -4
- package/packages/components/departmentPicker/index.ts +4 -4
- package/packages/components/departmentPicker/src/DepartmentPicker.vue +107 -107
- package/packages/components/departmentPicker/src/consts.ts +2 -2
- package/packages/components/departmentTree/index.ts +10 -10
- package/packages/components/departmentTree/src/departmentTree.vue +135 -135
- package/packages/components/dropdownButton/JaDropdownButton.vue +59 -59
- package/packages/components/dropdownButton/index.ts +4 -4
- package/packages/components/enumList/EnumListInput.vue +107 -107
- package/packages/components/enumList/JaEnumList.vue +39 -39
- package/packages/components/enumList/index.ts +7 -7
- package/packages/components/enumPicker/index.ts +5 -5
- package/packages/components/enumPicker/src/EnumPicker.vue +103 -103
- package/packages/components/form/JaForm.vue +186 -146
- package/packages/components/form/index.ts +5 -5
- package/packages/components/form/types.ts +4 -4
- package/packages/components/formItem/JaFormItem.vue +68 -87
- package/packages/components/formItem/index.ts +4 -4
- package/packages/components/index.ts +34 -34
- package/packages/components/input/JaInput.vue +143 -143
- package/packages/components/input/index.ts +4 -4
- package/packages/components/inputI18n/I18nBundleEditor.vue +76 -76
- package/packages/components/inputI18n/InputI18n.vue +146 -146
- package/packages/components/inputI18n/JaInputI18n.vue +50 -50
- package/packages/components/inputI18n/index.ts +8 -8
- package/packages/components/inputNumber/JaInputNumber.vue +98 -98
- package/packages/components/inputNumber/index.ts +4 -4
- package/packages/components/mapItemList/JaMapItemList.vue +35 -35
- package/packages/components/mapItemList/MapItemListInput.vue +191 -191
- package/packages/components/mapItemList/index.ts +7 -7
- package/packages/components/numberList/JaNumberList.vue +36 -36
- package/packages/components/numberList/NumberListInput.vue +111 -111
- package/packages/components/numberList/index.ts +7 -7
- package/packages/components/properyPicker/JaPropertyPicker.vue +38 -38
- package/packages/components/properyPicker/PropertyPicker.vue +314 -314
- package/packages/components/properyPicker/index.ts +7 -7
- package/packages/components/radioGroup/JaRadioGroup.vue +50 -50
- package/packages/components/radioGroup/index.ts +4 -4
- package/packages/components/rolePicker/RoleEditor.vue +129 -129
- package/packages/components/rolePicker/RolePicker.vue +44 -44
- package/packages/components/rolePicker/RolePickerRaw.vue +56 -56
- package/packages/components/rolePicker/baseRolePicker.vue +87 -87
- package/packages/components/rolePicker/index.ts +10 -10
- package/packages/components/scrollbar/Scrollbar.vue +89 -89
- package/packages/components/scrollbar/index.ts +5 -5
- package/packages/components/scrollbar/utils.ts +17 -17
- package/packages/components/select/JaSelect.vue +48 -48
- package/packages/components/select/index.ts +4 -4
- package/packages/components/stringList/JaStringList.vue +36 -36
- package/packages/components/stringList/StringListInput.vue +96 -96
- package/packages/components/stringList/index.ts +7 -7
- package/packages/components/switch/JaSwitch.vue +50 -50
- package/packages/components/switch/index.ts +4 -4
- package/packages/components/timePicker/JaTimePicker.vue +52 -52
- package/packages/components/timePicker/index.ts +5 -5
- package/packages/components/tip/index.ts +4 -4
- package/packages/components/tip/src/AceTip.vue +43 -43
- package/packages/components/upload/index.ts +6 -6
- package/packages/components/upload/src/Upload.vue +25 -25
- package/packages/components/upload/src/type.ts +3 -3
- package/packages/components/userGroupPicker/index.ts +4 -4
- package/packages/components/userGroupPicker/src/UserGroupPicker.vue +94 -94
- package/packages/components/userGroupTree/index.ts +10 -10
- package/packages/components/userGroupTree/src/userGroupTree.vue +149 -149
- package/packages/components/userPicker/index.ts +10 -10
- package/packages/components/userPicker/src/CustomGroupManager.vue +189 -189
- package/packages/components/userPicker/src/JaUserList.vue +283 -283
- package/packages/components/userPicker/src/JaUserPicker.vue +37 -37
- package/packages/components/userPicker/src/UserPicker.vue +376 -368
- package/packages/components/userSelectDialog/index.ts +6 -6
- package/packages/components/userSelectDialog/src/userSelectDialog.vue +462 -455
- package/packages/components/userTag/UserInfoTag.vue +397 -397
- package/packages/components/userTag/index.ts +6 -6
- package/packages/components/userTag/sharedAxios.ts +8 -8
- package/packages/directives/auth/index.ts +41 -41
- package/packages/directives/autofocus/index.ts +29 -29
- package/packages/directives/index.ts +10 -10
- package/packages/directives/shortcut/index.ts +192 -192
- package/packages/hooks/useAppInstances.ts +34 -34
- package/packages/hooks/useBackendValidations.ts +81 -81
- package/packages/hooks/useBridage.ts +157 -157
- package/packages/hooks/useClassificationLevels.ts +62 -0
- package/packages/hooks/useDateTimeShortCuts.ts +65 -65
- package/packages/hooks/useRealms.ts +28 -28
- package/packages/hooks/useTreeData.ts +45 -45
- package/packages/hooks/useUserRefQuery.ts +232 -224
- package/packages/index.ts +24 -22
- package/packages/list.json +7 -7
- package/packages/types/custom.d.ts +13 -13
- package/packages/types/window.d.ts +16 -16
- package/packages/utils/install.ts +43 -43
- package/packages/utils/objectUtils.ts +31 -31
- package/theme-style/fonts/iconfont.json +5196 -5196
- package/theme-style/index.scss +10 -10
- package/theme-style/styles/element-plus-var.scss +1419 -1419
- package/theme-style/styles/iconfont.css +2979 -2979
- package/theme-style/styles/theme-var.scss +72 -72
- package/theme-style/styles/transition.scss +122 -122
- package/dist/utils/formUtils.d.ts +0 -7
- package/dist/utils/formUtils.d.ts.map +0 -1
- package/dist/utils/formUtils.js +0 -54
- package/dist/utils/formUtils.js.map +0 -1
- package/packages/utils/formUtils.ts +0 -57
|
@@ -1,283 +1,283 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
|
|
3
|
-
import {ElEmpty, ElIcon, ElScrollbar, vLoading} from "element-plus";
|
|
4
|
-
import {Check} from "@element-plus/icons-vue";
|
|
5
|
-
import {JaUserInfoTag} from "../../userTag";
|
|
6
|
-
import {computed, nextTick, onUnmounted, ref, watch} from "vue";
|
|
7
|
-
import type {UserReference} from "@jari-ace/app-bolts";
|
|
8
|
-
import throttle from "lodash-es/throttle";
|
|
9
|
-
|
|
10
|
-
const props = defineProps<{
|
|
11
|
-
emptyText: string,
|
|
12
|
-
multiple?: boolean,
|
|
13
|
-
total: number,
|
|
14
|
-
pageSize: number,
|
|
15
|
-
height?: number | string,
|
|
16
|
-
loading: boolean,
|
|
17
|
-
users: UserReference[]
|
|
18
|
-
}>();
|
|
19
|
-
const activeIndex = ref(0);
|
|
20
|
-
const scrollbar = ref<InstanceType<typeof ElScrollbar>>();
|
|
21
|
-
const tolerance = 1;
|
|
22
|
-
const isDragSelecting = ref(false);
|
|
23
|
-
const selectedUsers = defineModel<UserReference[] | UserReference | null>({
|
|
24
|
-
required: true
|
|
25
|
-
});
|
|
26
|
-
const page = defineModel<number>("page", {
|
|
27
|
-
required: true
|
|
28
|
-
})
|
|
29
|
-
const emits = defineEmits(["arrowKeyDown", "itemClicked"]);
|
|
30
|
-
const handleScroll = () => {
|
|
31
|
-
const scrollElement = scrollbar.value?.wrapRef;
|
|
32
|
-
if (scrollElement) {
|
|
33
|
-
const isBottom = scrollElement.scrollHeight - scrollElement.scrollTop
|
|
34
|
-
<= scrollElement.clientHeight + tolerance;
|
|
35
|
-
|
|
36
|
-
if (isBottom) {
|
|
37
|
-
if (page.value < props.total / props.pageSize) {
|
|
38
|
-
page.value++;
|
|
39
|
-
}
|
|
40
|
-
// 在这里执行事件方法
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const throttleScroll = throttle(handleScroll, 200);
|
|
45
|
-
|
|
46
|
-
function switchUserSelect(u: UserReference) {
|
|
47
|
-
if (props.multiple) {
|
|
48
|
-
if (!Array.isArray(selectedUsers.value)) {
|
|
49
|
-
throw new Error("UserPicker组件设置为多选模式(multiple)时,v-model必须绑定UserReference数组")
|
|
50
|
-
}
|
|
51
|
-
const index = selectedUsers.value.findIndex(su => su.id == u.id);
|
|
52
|
-
if (index < 0) {
|
|
53
|
-
selectedUsers.value.push(u);
|
|
54
|
-
} else {
|
|
55
|
-
selectedUsers.value.splice(index, 1);
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
selectedUsers.value = u;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let clickedUser: UserReference;
|
|
63
|
-
|
|
64
|
-
function onMouseDown(u: UserReference) {
|
|
65
|
-
switchUserSelect(u)
|
|
66
|
-
isDragSelecting.value = true;
|
|
67
|
-
clickedUser = u;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function onMouseUp() {
|
|
71
|
-
isDragSelecting.value = false;
|
|
72
|
-
emits("itemClicked", clickedUser);
|
|
73
|
-
clickedUser = undefined;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function onMouseEnter(u: UserReference) {
|
|
77
|
-
if (isDragSelecting.value) {
|
|
78
|
-
switchUserSelect(u);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function onInputArrowDown() {
|
|
83
|
-
if (activeIndex.value < props.users.length - 1) {
|
|
84
|
-
activeIndex.value++;
|
|
85
|
-
}
|
|
86
|
-
scrollToActive();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function onInputArrowUp() {
|
|
90
|
-
if (activeIndex.value > 0) {
|
|
91
|
-
activeIndex.value--;
|
|
92
|
-
}
|
|
93
|
-
scrollToActive();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const scrollToActive = () => {
|
|
97
|
-
nextTick(() => {
|
|
98
|
-
const scrollWrapper = scrollbar.value?.$refs.wrapRef as HTMLElement;
|
|
99
|
-
const activeItem = scrollWrapper?.querySelectorAll('li')[activeIndex.value] as HTMLElement;
|
|
100
|
-
if (activeItem && scrollWrapper) {
|
|
101
|
-
const itemTop = (
|
|
102
|
-
activeItem as HTMLElement
|
|
103
|
-
).offsetTop;
|
|
104
|
-
const itemBottom = activeItem.offsetTop + activeItem.offsetHeight;
|
|
105
|
-
const visibleTop = scrollWrapper.scrollTop;
|
|
106
|
-
const visibleBottom = scrollWrapper.scrollTop + scrollWrapper.clientHeight;
|
|
107
|
-
if (itemBottom > visibleBottom) {
|
|
108
|
-
scrollbar.value?.scrollTo(0,
|
|
109
|
-
itemBottom - scrollWrapper.clientHeight + activeItem.offsetHeight - 38);
|
|
110
|
-
} else if (itemTop < visibleTop) {
|
|
111
|
-
scrollbar.value?.scrollTo(0, itemTop);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const throttleDown = throttle(onInputArrowDown, 100);
|
|
118
|
-
const throttleUp = throttle(onInputArrowUp, 100);
|
|
119
|
-
|
|
120
|
-
function onMouseOver(event: MouseEvent, index: number) {
|
|
121
|
-
activeIndex.value = index
|
|
122
|
-
isDragSelecting.value = event.buttons > 0;
|
|
123
|
-
if (isDragSelecting.value) {
|
|
124
|
-
const scrollWrapper = scrollbar.value?.$refs.wrapRef as HTMLElement;
|
|
125
|
-
const activeItem = event.target as HTMLElement;
|
|
126
|
-
if (activeItem && scrollWrapper) {
|
|
127
|
-
const itemTop = (
|
|
128
|
-
activeItem as HTMLElement
|
|
129
|
-
).offsetTop;
|
|
130
|
-
const itemBottom = activeItem.offsetTop + activeItem.offsetHeight;
|
|
131
|
-
const visibleTop = scrollWrapper.scrollTop;
|
|
132
|
-
const visibleBottom = scrollWrapper.scrollTop + scrollWrapper.clientHeight;
|
|
133
|
-
if (itemBottom + 20 > visibleBottom) {
|
|
134
|
-
throttleDown();
|
|
135
|
-
} else if (itemTop < visibleTop + 20) {
|
|
136
|
-
throttleUp();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function userSelected(u: UserReference) {
|
|
143
|
-
return selectedForBinding.value.some(su => su.id === u.id);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const userTagTheme = (u: UserReference) => {
|
|
147
|
-
if (selectedForBinding.value.some(su => su.id === u.id)) {
|
|
148
|
-
return "autumnOrange"
|
|
149
|
-
} else {
|
|
150
|
-
return "skyGray"
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const selectedForBinding = computed(() => {
|
|
155
|
-
if (props.multiple && Array.isArray(selectedUsers.value)) {
|
|
156
|
-
return selectedUsers.value;
|
|
157
|
-
} else if (!props.multiple && !Array.isArray(selectedUsers.value)) {
|
|
158
|
-
if (selectedUsers.value) {
|
|
159
|
-
return [selectedUsers.value as UserReference];
|
|
160
|
-
} else {
|
|
161
|
-
return [] as UserReference[];
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
throw new Error("UserPicker组件设置为多选模式(multiple)时,v-model必须绑定UserReference数组")
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
function getUserItemClass(index: number) {
|
|
169
|
-
return index === activeIndex.value ? "active" : "";
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const listLoading = computed(() => props.loading && props.users.length == 0);
|
|
173
|
-
|
|
174
|
-
defineExpose({
|
|
175
|
-
scrollUp() {
|
|
176
|
-
onInputArrowUp();
|
|
177
|
-
},
|
|
178
|
-
scrollDown() {
|
|
179
|
-
onInputArrowDown();
|
|
180
|
-
},
|
|
181
|
-
activeIndex
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
watch(() => props.users, () => {
|
|
185
|
-
activeIndex.value = 0;
|
|
186
|
-
}, {
|
|
187
|
-
deep: false
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
onUnmounted(() => {
|
|
191
|
-
throttleDown.cancel()
|
|
192
|
-
throttleUp.cancel()
|
|
193
|
-
throttleScroll.cancel()
|
|
194
|
-
})
|
|
195
|
-
</script>
|
|
196
|
-
|
|
197
|
-
<template>
|
|
198
|
-
<div class="ja-user-list">
|
|
199
|
-
<el-scrollbar :height="height" ref="scrollbar" always
|
|
200
|
-
@scroll="throttleScroll" v-loading="listLoading">
|
|
201
|
-
<ul v-if="users.length > 0"
|
|
202
|
-
@mouseup="onMouseUp">
|
|
203
|
-
<li v-for="(u, index) in users" :key="u.id"
|
|
204
|
-
:class="getUserItemClass(index)"
|
|
205
|
-
@mouseenter="isDragSelecting && onMouseEnter(u)"
|
|
206
|
-
@mousedown="onMouseDown(u)"
|
|
207
|
-
@mouseover="onMouseOver($event, index)">
|
|
208
|
-
<el-icon color="#0D6A9F">
|
|
209
|
-
<Check v-if="userSelected(u)"/>
|
|
210
|
-
</el-icon>
|
|
211
|
-
<ja-user-info-tag :user-id="u.id" :full-name="u.fullName"
|
|
212
|
-
:has-avatar="u.hasAvatar"
|
|
213
|
-
placement="left-start"
|
|
214
|
-
:theme="userTagTheme(u)"></ja-user-info-tag>
|
|
215
|
-
</li>
|
|
216
|
-
</ul>
|
|
217
|
-
<el-empty v-else
|
|
218
|
-
:description="emptyText"></el-empty>
|
|
219
|
-
</el-scrollbar>
|
|
220
|
-
<div class="page-indicator"
|
|
221
|
-
v-if="users.length > 0">
|
|
222
|
-
<div class="nb-spinner" v-show="loading"></div>
|
|
223
|
-
已加载
|
|
224
|
-
{{ page }}
|
|
225
|
-
/{{ Math.ceil(total / pageSize) }}页
|
|
226
|
-
</div>
|
|
227
|
-
</div>
|
|
228
|
-
</template>
|
|
229
|
-
|
|
230
|
-
<style scoped lang="scss">
|
|
231
|
-
.ja-user-list {
|
|
232
|
-
user-select: none;
|
|
233
|
-
position: relative;
|
|
234
|
-
overflow: hidden;
|
|
235
|
-
|
|
236
|
-
ul {
|
|
237
|
-
padding: 0;
|
|
238
|
-
margin: 0;
|
|
239
|
-
|
|
240
|
-
li {
|
|
241
|
-
height: 38px;
|
|
242
|
-
display: flex;
|
|
243
|
-
align-items: center;
|
|
244
|
-
gap: 4px;
|
|
245
|
-
|
|
246
|
-
&.active {
|
|
247
|
-
background-color: var(--el-color-primary-light-9);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
.page-indicator {
|
|
253
|
-
position: absolute;
|
|
254
|
-
right: 20px;
|
|
255
|
-
bottom: 12px;
|
|
256
|
-
color: var(--el-color-info-light-5);
|
|
257
|
-
display: flex;
|
|
258
|
-
align-items: center;
|
|
259
|
-
gap: 4px;
|
|
260
|
-
|
|
261
|
-
.nb-spinner {
|
|
262
|
-
width: 16px;
|
|
263
|
-
height: 16px;
|
|
264
|
-
border-radius: 50%;
|
|
265
|
-
background-color: transparent;
|
|
266
|
-
display: inline-block;
|
|
267
|
-
border: 2px solid #ccc;
|
|
268
|
-
border-top-color: #009688;
|
|
269
|
-
animation: 1s spin linear infinite;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
@keyframes spin {
|
|
273
|
-
from {
|
|
274
|
-
transform: rotate(0deg);
|
|
275
|
-
}
|
|
276
|
-
to {
|
|
277
|
-
transform: rotate(360deg);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
|
|
3
|
+
import {ElEmpty, ElIcon, ElScrollbar, vLoading} from "element-plus";
|
|
4
|
+
import {Check} from "@element-plus/icons-vue";
|
|
5
|
+
import {JaUserInfoTag} from "../../userTag";
|
|
6
|
+
import {computed, nextTick, onUnmounted, ref, watch} from "vue";
|
|
7
|
+
import type {UserReference} from "@jari-ace/app-bolts";
|
|
8
|
+
import throttle from "lodash-es/throttle";
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
emptyText: string,
|
|
12
|
+
multiple?: boolean,
|
|
13
|
+
total: number,
|
|
14
|
+
pageSize: number,
|
|
15
|
+
height?: number | string,
|
|
16
|
+
loading: boolean,
|
|
17
|
+
users: UserReference[]
|
|
18
|
+
}>();
|
|
19
|
+
const activeIndex = ref(0);
|
|
20
|
+
const scrollbar = ref<InstanceType<typeof ElScrollbar>>();
|
|
21
|
+
const tolerance = 1;
|
|
22
|
+
const isDragSelecting = ref(false);
|
|
23
|
+
const selectedUsers = defineModel<UserReference[] | UserReference | null>({
|
|
24
|
+
required: true
|
|
25
|
+
});
|
|
26
|
+
const page = defineModel<number>("page", {
|
|
27
|
+
required: true
|
|
28
|
+
})
|
|
29
|
+
const emits = defineEmits(["arrowKeyDown", "itemClicked"]);
|
|
30
|
+
const handleScroll = () => {
|
|
31
|
+
const scrollElement = scrollbar.value?.wrapRef;
|
|
32
|
+
if (scrollElement) {
|
|
33
|
+
const isBottom = scrollElement.scrollHeight - scrollElement.scrollTop
|
|
34
|
+
<= scrollElement.clientHeight + tolerance;
|
|
35
|
+
|
|
36
|
+
if (isBottom) {
|
|
37
|
+
if (page.value < props.total / props.pageSize) {
|
|
38
|
+
page.value++;
|
|
39
|
+
}
|
|
40
|
+
// 在这里执行事件方法
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const throttleScroll = throttle(handleScroll, 200);
|
|
45
|
+
|
|
46
|
+
function switchUserSelect(u: UserReference) {
|
|
47
|
+
if (props.multiple) {
|
|
48
|
+
if (!Array.isArray(selectedUsers.value)) {
|
|
49
|
+
throw new Error("UserPicker组件设置为多选模式(multiple)时,v-model必须绑定UserReference数组")
|
|
50
|
+
}
|
|
51
|
+
const index = selectedUsers.value.findIndex(su => su.id == u.id);
|
|
52
|
+
if (index < 0) {
|
|
53
|
+
selectedUsers.value.push(u);
|
|
54
|
+
} else {
|
|
55
|
+
selectedUsers.value.splice(index, 1);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
selectedUsers.value = u;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let clickedUser: UserReference;
|
|
63
|
+
|
|
64
|
+
function onMouseDown(u: UserReference) {
|
|
65
|
+
switchUserSelect(u)
|
|
66
|
+
isDragSelecting.value = true;
|
|
67
|
+
clickedUser = u;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function onMouseUp() {
|
|
71
|
+
isDragSelecting.value = false;
|
|
72
|
+
emits("itemClicked", clickedUser);
|
|
73
|
+
clickedUser = undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function onMouseEnter(u: UserReference) {
|
|
77
|
+
if (isDragSelecting.value) {
|
|
78
|
+
switchUserSelect(u);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function onInputArrowDown() {
|
|
83
|
+
if (activeIndex.value < props.users.length - 1) {
|
|
84
|
+
activeIndex.value++;
|
|
85
|
+
}
|
|
86
|
+
scrollToActive();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function onInputArrowUp() {
|
|
90
|
+
if (activeIndex.value > 0) {
|
|
91
|
+
activeIndex.value--;
|
|
92
|
+
}
|
|
93
|
+
scrollToActive();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const scrollToActive = () => {
|
|
97
|
+
nextTick(() => {
|
|
98
|
+
const scrollWrapper = scrollbar.value?.$refs.wrapRef as HTMLElement;
|
|
99
|
+
const activeItem = scrollWrapper?.querySelectorAll('li')[activeIndex.value] as HTMLElement;
|
|
100
|
+
if (activeItem && scrollWrapper) {
|
|
101
|
+
const itemTop = (
|
|
102
|
+
activeItem as HTMLElement
|
|
103
|
+
).offsetTop;
|
|
104
|
+
const itemBottom = activeItem.offsetTop + activeItem.offsetHeight;
|
|
105
|
+
const visibleTop = scrollWrapper.scrollTop;
|
|
106
|
+
const visibleBottom = scrollWrapper.scrollTop + scrollWrapper.clientHeight;
|
|
107
|
+
if (itemBottom > visibleBottom) {
|
|
108
|
+
scrollbar.value?.scrollTo(0,
|
|
109
|
+
itemBottom - scrollWrapper.clientHeight + activeItem.offsetHeight - 38);
|
|
110
|
+
} else if (itemTop < visibleTop) {
|
|
111
|
+
scrollbar.value?.scrollTo(0, itemTop);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const throttleDown = throttle(onInputArrowDown, 100);
|
|
118
|
+
const throttleUp = throttle(onInputArrowUp, 100);
|
|
119
|
+
|
|
120
|
+
function onMouseOver(event: MouseEvent, index: number) {
|
|
121
|
+
activeIndex.value = index
|
|
122
|
+
isDragSelecting.value = event.buttons > 0;
|
|
123
|
+
if (isDragSelecting.value) {
|
|
124
|
+
const scrollWrapper = scrollbar.value?.$refs.wrapRef as HTMLElement;
|
|
125
|
+
const activeItem = event.target as HTMLElement;
|
|
126
|
+
if (activeItem && scrollWrapper) {
|
|
127
|
+
const itemTop = (
|
|
128
|
+
activeItem as HTMLElement
|
|
129
|
+
).offsetTop;
|
|
130
|
+
const itemBottom = activeItem.offsetTop + activeItem.offsetHeight;
|
|
131
|
+
const visibleTop = scrollWrapper.scrollTop;
|
|
132
|
+
const visibleBottom = scrollWrapper.scrollTop + scrollWrapper.clientHeight;
|
|
133
|
+
if (itemBottom + 20 > visibleBottom) {
|
|
134
|
+
throttleDown();
|
|
135
|
+
} else if (itemTop < visibleTop + 20) {
|
|
136
|
+
throttleUp();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function userSelected(u: UserReference) {
|
|
143
|
+
return selectedForBinding.value.some(su => su.id === u.id);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const userTagTheme = (u: UserReference) => {
|
|
147
|
+
if (selectedForBinding.value.some(su => su.id === u.id)) {
|
|
148
|
+
return "autumnOrange"
|
|
149
|
+
} else {
|
|
150
|
+
return "skyGray"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const selectedForBinding = computed(() => {
|
|
155
|
+
if (props.multiple && Array.isArray(selectedUsers.value)) {
|
|
156
|
+
return selectedUsers.value;
|
|
157
|
+
} else if (!props.multiple && !Array.isArray(selectedUsers.value)) {
|
|
158
|
+
if (selectedUsers.value) {
|
|
159
|
+
return [selectedUsers.value as UserReference];
|
|
160
|
+
} else {
|
|
161
|
+
return [] as UserReference[];
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
throw new Error("UserPicker组件设置为多选模式(multiple)时,v-model必须绑定UserReference数组")
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
function getUserItemClass(index: number) {
|
|
169
|
+
return index === activeIndex.value ? "active" : "";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const listLoading = computed(() => props.loading && props.users.length == 0);
|
|
173
|
+
|
|
174
|
+
defineExpose({
|
|
175
|
+
scrollUp() {
|
|
176
|
+
onInputArrowUp();
|
|
177
|
+
},
|
|
178
|
+
scrollDown() {
|
|
179
|
+
onInputArrowDown();
|
|
180
|
+
},
|
|
181
|
+
activeIndex
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
watch(() => props.users, () => {
|
|
185
|
+
activeIndex.value = 0;
|
|
186
|
+
}, {
|
|
187
|
+
deep: false
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
onUnmounted(() => {
|
|
191
|
+
throttleDown.cancel()
|
|
192
|
+
throttleUp.cancel()
|
|
193
|
+
throttleScroll.cancel()
|
|
194
|
+
})
|
|
195
|
+
</script>
|
|
196
|
+
|
|
197
|
+
<template>
|
|
198
|
+
<div class="ja-user-list">
|
|
199
|
+
<el-scrollbar :height="height" ref="scrollbar" always
|
|
200
|
+
@scroll="throttleScroll" v-loading="listLoading">
|
|
201
|
+
<ul v-if="users.length > 0"
|
|
202
|
+
@mouseup="onMouseUp">
|
|
203
|
+
<li v-for="(u, index) in users" :key="u.id"
|
|
204
|
+
:class="getUserItemClass(index)"
|
|
205
|
+
@mouseenter="isDragSelecting && onMouseEnter(u)"
|
|
206
|
+
@mousedown="onMouseDown(u)"
|
|
207
|
+
@mouseover="onMouseOver($event, index)">
|
|
208
|
+
<el-icon color="#0D6A9F">
|
|
209
|
+
<Check v-if="userSelected(u)"/>
|
|
210
|
+
</el-icon>
|
|
211
|
+
<ja-user-info-tag :user-id="u.id" :full-name="u.fullName"
|
|
212
|
+
:has-avatar="u.hasAvatar"
|
|
213
|
+
placement="left-start"
|
|
214
|
+
:theme="userTagTheme(u)"></ja-user-info-tag>
|
|
215
|
+
</li>
|
|
216
|
+
</ul>
|
|
217
|
+
<el-empty v-else
|
|
218
|
+
:description="emptyText"></el-empty>
|
|
219
|
+
</el-scrollbar>
|
|
220
|
+
<div class="page-indicator"
|
|
221
|
+
v-if="users.length > 0">
|
|
222
|
+
<div class="nb-spinner" v-show="loading"></div>
|
|
223
|
+
已加载
|
|
224
|
+
{{ page }}
|
|
225
|
+
/{{ Math.ceil(total / pageSize) }}页
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
</template>
|
|
229
|
+
|
|
230
|
+
<style scoped lang="scss">
|
|
231
|
+
.ja-user-list {
|
|
232
|
+
user-select: none;
|
|
233
|
+
position: relative;
|
|
234
|
+
overflow: hidden;
|
|
235
|
+
|
|
236
|
+
ul {
|
|
237
|
+
padding: 0;
|
|
238
|
+
margin: 0;
|
|
239
|
+
|
|
240
|
+
li {
|
|
241
|
+
height: 38px;
|
|
242
|
+
display: flex;
|
|
243
|
+
align-items: center;
|
|
244
|
+
gap: 4px;
|
|
245
|
+
|
|
246
|
+
&.active {
|
|
247
|
+
background-color: var(--el-color-primary-light-9);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.page-indicator {
|
|
253
|
+
position: absolute;
|
|
254
|
+
right: 20px;
|
|
255
|
+
bottom: 12px;
|
|
256
|
+
color: var(--el-color-info-light-5);
|
|
257
|
+
display: flex;
|
|
258
|
+
align-items: center;
|
|
259
|
+
gap: 4px;
|
|
260
|
+
|
|
261
|
+
.nb-spinner {
|
|
262
|
+
width: 16px;
|
|
263
|
+
height: 16px;
|
|
264
|
+
border-radius: 50%;
|
|
265
|
+
background-color: transparent;
|
|
266
|
+
display: inline-block;
|
|
267
|
+
border: 2px solid #ccc;
|
|
268
|
+
border-top-color: #009688;
|
|
269
|
+
animation: 1s spin linear infinite;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@keyframes spin {
|
|
273
|
+
from {
|
|
274
|
+
transform: rotate(0deg);
|
|
275
|
+
}
|
|
276
|
+
to {
|
|
277
|
+
transform: rotate(360deg);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
</style>
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import UserPicker from "./UserPicker.vue";
|
|
3
|
-
import {inject, watch, ref} from "vue";
|
|
4
|
-
import {getValue, setValue} from "../../../utils/objectUtils";
|
|
5
|
-
import type {ValidationInstance} from "../../../hooks/useBackendValidations";
|
|
6
|
-
import type {UserReference} from "@jari-ace/app-bolts";
|
|
7
|
-
|
|
8
|
-
const model = inject('aceFormModel') as Record<string, never>
|
|
9
|
-
const prop = inject('aceFormItemProp') as string
|
|
10
|
-
const validator = inject('aceFormValidator') as ValidationInstance
|
|
11
|
-
const emit = defineEmits<{
|
|
12
|
-
change: [value: UserReference[]]
|
|
13
|
-
}>()
|
|
14
|
-
|
|
15
|
-
function onChange(value: UserReference[]) {
|
|
16
|
-
validator.removeFieldError(prop)
|
|
17
|
-
setValue(model.formData, prop, mv.value);
|
|
18
|
-
emit('change', value)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const mv = ref(getValue(model.formData, prop) as UserReference[] ?? []);
|
|
22
|
-
watch(() => model.formData, () => {
|
|
23
|
-
mv.value = getValue(model.formData, prop) as UserReference[] ?? []
|
|
24
|
-
}, {
|
|
25
|
-
deep: true
|
|
26
|
-
})
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<template>
|
|
30
|
-
<user-picker v-model="mv"
|
|
31
|
-
@change="onChange"
|
|
32
|
-
v-bind="$attrs"/>
|
|
33
|
-
</template>
|
|
34
|
-
|
|
35
|
-
<style scoped lang="scss">
|
|
36
|
-
|
|
37
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UserPicker from "./UserPicker.vue";
|
|
3
|
+
import {inject, watch, ref} from "vue";
|
|
4
|
+
import {getValue, setValue} from "../../../utils/objectUtils";
|
|
5
|
+
import type {ValidationInstance} from "../../../hooks/useBackendValidations";
|
|
6
|
+
import type {UserReference} from "@jari-ace/app-bolts";
|
|
7
|
+
|
|
8
|
+
const model = inject('aceFormModel') as Record<string, never>
|
|
9
|
+
const prop = inject('aceFormItemProp') as string
|
|
10
|
+
const validator = inject('aceFormValidator') as ValidationInstance
|
|
11
|
+
const emit = defineEmits<{
|
|
12
|
+
change: [value: UserReference[]]
|
|
13
|
+
}>()
|
|
14
|
+
|
|
15
|
+
function onChange(value: UserReference[]) {
|
|
16
|
+
validator.removeFieldError(prop)
|
|
17
|
+
setValue(model.formData, prop, mv.value);
|
|
18
|
+
emit('change', value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const mv = ref(getValue(model.formData, prop) as UserReference[] ?? []);
|
|
22
|
+
watch(() => model.formData, () => {
|
|
23
|
+
mv.value = getValue(model.formData, prop) as UserReference[] ?? []
|
|
24
|
+
}, {
|
|
25
|
+
deep: true
|
|
26
|
+
})
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<user-picker v-model="mv"
|
|
31
|
+
@change="onChange"
|
|
32
|
+
v-bind="$attrs"/>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<style scoped lang="scss">
|
|
36
|
+
|
|
37
|
+
</style>
|