@blueking/bk-user-selector 0.0.2-beta.1 → 0.0.3
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 +60 -38
- package/package.json +1 -1
- package/typings/api/user.d.ts +3 -3
- package/typings/components/multiple-selector.vue.d.ts +31 -1
- package/typings/components/single-selector.vue.d.ts +2 -2
- package/typings/components/user-selector.vue.d.ts +10 -13
- package/typings/hooks/useTenantData.d.ts +1 -1
- package/typings/hooks/useUserSearch.d.ts +2 -2
- package/typings/hooks/useUserSelection.d.ts +2 -2
- package/typings/types/index.d.ts +11 -11
- package/typings/utils/common.d.ts +2 -2
- package/typings/vue2.d.ts +15 -1
- package/vue2/index.es.min.js +10434 -29768
- package/vue2/index.iife.min.js +8079 -27487
- package/vue2/index.umd.min.js +7138 -26472
- package/vue2/vue2.css +189 -1722
- package/vue3/index.es.min.js +3079 -2264
- package/vue3/index.iife.min.js +8521 -27853
- package/vue3/index.umd.min.js +3078 -2263
- package/vue3/vue3.css +148 -48
- package/typings/index.d.ts +0 -18
package/README.md
CHANGED
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
- 支持用户搜索功能
|
|
9
9
|
- 支持跨租户显示
|
|
10
10
|
- 支持拖拽排序(多选模式)
|
|
11
|
-
-
|
|
12
|
-
- 完全响应式设计
|
|
11
|
+
- 支持快速选择当前用户
|
|
13
12
|
|
|
14
13
|
## 安装
|
|
15
14
|
|
|
@@ -19,12 +18,13 @@ npm install @blueking/bk-user-selector
|
|
|
19
18
|
|
|
20
19
|
## 使用方法
|
|
21
20
|
|
|
22
|
-
### 在
|
|
21
|
+
### 在 Vue3 中使用
|
|
23
22
|
|
|
24
23
|
```javascript
|
|
25
24
|
// 全局注册
|
|
26
25
|
import { createApp } from 'vue';
|
|
27
26
|
import BkUserSelector from '@blueking/bk-user-selector';
|
|
27
|
+
import '@blueking/bk-user-selector/vue3/vue3.css';
|
|
28
28
|
|
|
29
29
|
const app = createApp(App);
|
|
30
30
|
app.use(BkUserSelector);
|
|
@@ -40,6 +40,13 @@ export default {
|
|
|
40
40
|
};
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
### 在 Vue2 中使用
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
import BkUserSelector from '@blueking/bk-user-selector/vue2';
|
|
47
|
+
import '@blueking/bk-user-selector/vue2/vue2.css';
|
|
48
|
+
```
|
|
49
|
+
|
|
43
50
|
### 基本用法
|
|
44
51
|
|
|
45
52
|
```vue
|
|
@@ -49,6 +56,7 @@ export default {
|
|
|
49
56
|
v-model="selectedUser"
|
|
50
57
|
:api-base-url="apiBaseUrl"
|
|
51
58
|
:tenant-id="tenantId"
|
|
59
|
+
:current-user-id="currentUserId"
|
|
52
60
|
@change="handleUserChange"
|
|
53
61
|
/>
|
|
54
62
|
|
|
@@ -57,6 +65,7 @@ export default {
|
|
|
57
65
|
v-model="selectedUsers"
|
|
58
66
|
:api-base-url="apiBaseUrl"
|
|
59
67
|
:tenant-id="tenantId"
|
|
68
|
+
:current-user-id="currentUserId"
|
|
60
69
|
:multiple="true"
|
|
61
70
|
:draggable="true"
|
|
62
71
|
@change="handleUsersChange"
|
|
@@ -64,26 +73,28 @@ export default {
|
|
|
64
73
|
</template>
|
|
65
74
|
|
|
66
75
|
<script setup>
|
|
67
|
-
import { ref } from 'vue';
|
|
68
|
-
|
|
69
|
-
// API 基础路径
|
|
70
|
-
const apiBaseUrl = ref('https://api.example.com');
|
|
71
|
-
// 租户 ID
|
|
72
|
-
const tenantId = ref('default');
|
|
73
|
-
//
|
|
74
|
-
const
|
|
75
|
-
//
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
import { ref } from 'vue';
|
|
77
|
+
|
|
78
|
+
// API 基础路径
|
|
79
|
+
const apiBaseUrl = ref('https://api.example.com');
|
|
80
|
+
// 租户 ID
|
|
81
|
+
const tenantId = ref('default');
|
|
82
|
+
// 当前用户ID
|
|
83
|
+
const currentUserId = ref('admin');
|
|
84
|
+
// 单选选中值
|
|
85
|
+
const selectedUser = ref('');
|
|
86
|
+
// 多选选中值
|
|
87
|
+
const selectedUsers = ref([]);
|
|
88
|
+
|
|
89
|
+
// 处理单选模式下的值变化
|
|
90
|
+
const handleUserChange = user => {
|
|
91
|
+
console.log('Selected user:', user);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// 处理多选模式下的值变化
|
|
95
|
+
const handleUsersChange = users => {
|
|
96
|
+
console.log('Selected users:', users);
|
|
97
|
+
};
|
|
87
98
|
</script>
|
|
88
99
|
```
|
|
89
100
|
|
|
@@ -91,23 +102,34 @@ const handleUsersChange = (users) => {
|
|
|
91
102
|
|
|
92
103
|
### 属性
|
|
93
104
|
|
|
94
|
-
| 参数
|
|
95
|
-
|
|
96
|
-
| modelValue / v-model | 绑定值,单选为字符串,多选为数组 | String / Array | '' / []
|
|
97
|
-
| label
|
|
98
|
-
| required
|
|
99
|
-
| placeholder
|
|
100
|
-
| multiple
|
|
101
|
-
| draggable
|
|
102
|
-
| apiBaseUrl
|
|
103
|
-
| tenantId
|
|
105
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
106
|
+
| -------------------- | -------------------------------- | -------------- | -------------------- |
|
|
107
|
+
| modelValue / v-model | 绑定值,单选为字符串,多选为数组 | String / Array | '' / [] |
|
|
108
|
+
| label | 文本标签 | String | '人员选择' |
|
|
109
|
+
| required | 是否必填 | Boolean | false |
|
|
110
|
+
| placeholder | 占位文本 | String | '请输入人员名称搜索' |
|
|
111
|
+
| multiple | 是否多选 | Boolean | false |
|
|
112
|
+
| draggable | 是否可拖拽(仅多选模式有效) | Boolean | false |
|
|
113
|
+
| apiBaseUrl | API 基础 URL | String | '' |
|
|
114
|
+
| tenantId | 租户 ID | String | '' |
|
|
115
|
+
| currentUserId | 当前用户ID(用于快速选择"我") | String | '' |
|
|
104
116
|
|
|
105
117
|
### 事件
|
|
106
118
|
|
|
107
|
-
| 事件名称
|
|
108
|
-
|
|
109
|
-
| update:modelValue | 绑定值变化时触发 | 变化后的值
|
|
110
|
-
| change
|
|
119
|
+
| 事件名称 | 说明 | 回调参数 |
|
|
120
|
+
| ----------------- | ---------------- | ---------------- |
|
|
121
|
+
| update:modelValue | 绑定值变化时触发 | 变化后的值 |
|
|
122
|
+
| change | 选中值变化时触发 | 变化后的用户信息 |
|
|
123
|
+
|
|
124
|
+
## 功能说明
|
|
125
|
+
|
|
126
|
+
### 快速选择"我"
|
|
127
|
+
|
|
128
|
+
当设置了`currentUserId`属性后,组件会在输入框右侧显示一个"我"的标签。点击该标签可以快速选择当前用户,无需手动搜索。
|
|
129
|
+
|
|
130
|
+
- 在单选模式下,点击"我"会直接选中当前用户
|
|
131
|
+
- 在多选模式下,点击"我"会将当前用户添加到已选列表中(如果尚未选择)
|
|
132
|
+
- 当当前用户已被选中时,"我"标签会显示为灰色且不可点击
|
|
111
133
|
|
|
112
134
|
## 开发
|
|
113
135
|
|
|
@@ -124,4 +146,4 @@ npm run build
|
|
|
124
146
|
|
|
125
147
|
## 许可证
|
|
126
148
|
|
|
127
|
-
MIT
|
|
149
|
+
MIT
|
package/package.json
CHANGED
package/typings/api/user.d.ts
CHANGED
|
@@ -17,15 +17,15 @@ export declare const getTenants: (apiBaseUrl: string, tenantId: string) => Promi
|
|
|
17
17
|
* @param keyword - 搜索关键词
|
|
18
18
|
* @returns 用户列表Promise
|
|
19
19
|
*/
|
|
20
|
-
export declare const searchUsers: (apiBaseUrl
|
|
20
|
+
export declare const searchUsers: (apiBaseUrl?: string, tenantId?: string, keyword?: string) => Promise<User[]>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* 批量精准查找用户
|
|
23
23
|
* @param apiBaseUrl - API基础URL
|
|
24
24
|
* @param tenantId - 租户ID
|
|
25
25
|
* @param users - 用户名列表
|
|
26
26
|
* @returns 查找到的用户列表Promise
|
|
27
27
|
*/
|
|
28
|
-
export declare const lookupUsers: (apiBaseUrl
|
|
28
|
+
export declare const lookupUsers: (apiBaseUrl?: string, tenantId?: string, users?: string[]) => Promise<User[]>;
|
|
29
29
|
/**
|
|
30
30
|
* 将API返回的用户数据格式化为组件所需格式
|
|
31
31
|
* @param users - API返回的用户列表
|
|
@@ -42,6 +42,20 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
42
42
|
type: () => FormattedUser[];
|
|
43
43
|
default: () => never[];
|
|
44
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* 租户信息映射
|
|
47
|
+
*/
|
|
48
|
+
tenants: {
|
|
49
|
+
type: () => Record<string, string>;
|
|
50
|
+
default: () => {};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* 当前用户ID
|
|
54
|
+
*/
|
|
55
|
+
currentUserId: {
|
|
56
|
+
type: StringConstructor;
|
|
57
|
+
default: string;
|
|
58
|
+
};
|
|
45
59
|
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
46
60
|
"update:selectedUsers": (...args: any[]) => void;
|
|
47
61
|
"add-user": (...args: any[]) => void;
|
|
@@ -89,16 +103,32 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
89
103
|
type: () => FormattedUser[];
|
|
90
104
|
default: () => never[];
|
|
91
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* 租户信息映射
|
|
108
|
+
*/
|
|
109
|
+
tenants: {
|
|
110
|
+
type: () => Record<string, string>;
|
|
111
|
+
default: () => {};
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* 当前用户ID
|
|
115
|
+
*/
|
|
116
|
+
currentUserId: {
|
|
117
|
+
type: StringConstructor;
|
|
118
|
+
default: string;
|
|
119
|
+
};
|
|
92
120
|
}>> & {
|
|
93
121
|
"onUpdate:selectedUsers"?: ((...args: any[]) => any) | undefined;
|
|
94
122
|
"onAdd-user"?: ((...args: any[]) => any) | undefined;
|
|
95
123
|
"onRemove-user"?: ((...args: any[]) => any) | undefined;
|
|
96
124
|
}, {
|
|
125
|
+
tenants: Record<string, string>;
|
|
126
|
+
draggable: boolean;
|
|
97
127
|
modelValue: unknown[];
|
|
98
128
|
placeholder: string;
|
|
99
129
|
apiBaseUrl: string;
|
|
100
130
|
tenantId: string;
|
|
101
|
-
draggable: boolean;
|
|
102
131
|
selectedUsers: FormattedUser[];
|
|
132
|
+
currentUserId: string;
|
|
103
133
|
}, {}>;
|
|
104
134
|
export default _default;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SingleSelectorProps } from '../types';
|
|
2
2
|
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<SingleSelectorProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
3
|
-
"update:modelValue": (...args: any[]) => void;
|
|
4
3
|
change: (...args: any[]) => void;
|
|
4
|
+
"update:modelValue": (...args: any[]) => void;
|
|
5
5
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<SingleSelectorProps>>> & {
|
|
6
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
7
6
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
7
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
8
8
|
}, {}, {}>;
|
|
9
9
|
export default _default;
|
|
10
10
|
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
import { UserSelectorProps } from '../types';
|
|
2
2
|
declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<UserSelectorProps>, {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
apiBaseUrl: string;
|
|
4
|
+
tenantId: string;
|
|
5
5
|
placeholder: string;
|
|
6
6
|
modelValue: string;
|
|
7
7
|
draggable: boolean;
|
|
8
8
|
multiple: boolean;
|
|
9
|
-
|
|
10
|
-
tenantId: string;
|
|
9
|
+
currentUserId: string;
|
|
11
10
|
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
12
|
-
"update:modelValue": (...args: any[]) => void;
|
|
13
11
|
change: (...args: any[]) => void;
|
|
12
|
+
"update:modelValue": (...args: any[]) => void;
|
|
14
13
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<UserSelectorProps>, {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
apiBaseUrl: string;
|
|
15
|
+
tenantId: string;
|
|
17
16
|
placeholder: string;
|
|
18
17
|
modelValue: string;
|
|
19
18
|
draggable: boolean;
|
|
20
19
|
multiple: boolean;
|
|
21
|
-
|
|
22
|
-
tenantId: string;
|
|
20
|
+
currentUserId: string;
|
|
23
21
|
}>>> & {
|
|
24
|
-
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
25
22
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
23
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
26
24
|
}, {
|
|
25
|
+
draggable: boolean;
|
|
27
26
|
modelValue: string | string[];
|
|
28
27
|
placeholder: string;
|
|
29
28
|
apiBaseUrl: string;
|
|
30
29
|
tenantId: string;
|
|
30
|
+
currentUserId: string;
|
|
31
31
|
multiple: boolean;
|
|
32
|
-
required: boolean;
|
|
33
|
-
label: string;
|
|
34
|
-
draggable: boolean;
|
|
35
32
|
}, {}>;
|
|
36
33
|
export default _default;
|
|
37
34
|
type __VLS_WithDefaults<P, D> = {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* 用户选择 Hook
|
|
3
3
|
* @module hooks/useUserSelection
|
|
4
4
|
*/
|
|
5
|
-
import { Ref } from 'vue';
|
|
6
|
-
import { FormattedUser } from '../types';
|
|
5
|
+
import { type Ref } from 'vue';
|
|
6
|
+
import { type FormattedUser } from '../types';
|
|
7
7
|
/**
|
|
8
8
|
* 使用用户选择的Hook
|
|
9
9
|
* @param apiBaseUrl - API基础URL
|
package/typings/types/index.d.ts
CHANGED
|
@@ -62,13 +62,13 @@ export interface Tenant {
|
|
|
62
62
|
*/
|
|
63
63
|
export interface UserSelectorProps {
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* 接口基础URL
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
apiBaseUrl: string;
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* 租户ID
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
tenantId: string;
|
|
72
72
|
/**
|
|
73
73
|
* 占位文字
|
|
74
74
|
*/
|
|
@@ -86,13 +86,9 @@ export interface UserSelectorProps {
|
|
|
86
86
|
*/
|
|
87
87
|
multiple?: boolean;
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
*/
|
|
91
|
-
apiBaseUrl?: string;
|
|
92
|
-
/**
|
|
93
|
-
* 租户ID
|
|
89
|
+
* 本人ID
|
|
94
90
|
*/
|
|
95
|
-
|
|
91
|
+
currentUserId?: string;
|
|
96
92
|
}
|
|
97
93
|
/**
|
|
98
94
|
* 单选模式属性
|
|
@@ -117,5 +113,9 @@ export interface SingleSelectorProps {
|
|
|
117
113
|
/**
|
|
118
114
|
* 租户信息映射
|
|
119
115
|
*/
|
|
120
|
-
tenants
|
|
116
|
+
tenants: Record<string, string>;
|
|
117
|
+
/**
|
|
118
|
+
* 本人ID
|
|
119
|
+
*/
|
|
120
|
+
currentUserId?: string;
|
|
121
121
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 通用工具函数
|
|
3
3
|
* @module utils/common
|
|
4
4
|
*/
|
|
5
|
-
import { FormattedUser } from '../types';
|
|
5
|
+
import { type FormattedUser } from '../types';
|
|
6
6
|
/**
|
|
7
7
|
* 防抖函数
|
|
8
8
|
* @param fn - 需要防抖的函数
|
|
@@ -17,7 +17,7 @@ export declare const debounce: <T extends (...args: any[]) => any>(fn: T, delay:
|
|
|
17
17
|
* @param containerWidth - 容器宽度
|
|
18
18
|
* @returns 可见项目数量
|
|
19
19
|
*/
|
|
20
|
-
export declare const calculateVisibleTags: (container: HTMLElement, items: NodeListOf<Element
|
|
20
|
+
export declare const calculateVisibleTags: (container: HTMLElement, items: HTMLElement[] | NodeListOf<Element>, containerWidth: number) => number;
|
|
21
21
|
/**
|
|
22
22
|
* 转换用户数组为Map结构,方便快速查找
|
|
23
23
|
* @param users - 用户列表
|
package/typings/vue2.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import BkUserSelector from './components/user-selector.vue';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
beforeDestroy(): void;
|
|
4
|
+
created(): void;
|
|
5
|
+
data(): {
|
|
6
|
+
app: null;
|
|
7
|
+
unWatchStack: never[];
|
|
8
|
+
};
|
|
9
|
+
mounted(): void;
|
|
10
|
+
name: string;
|
|
11
|
+
props: any;
|
|
12
|
+
render(createElement: any): any;
|
|
13
|
+
};
|
|
2
14
|
export default _default;
|
|
15
|
+
export { BkUserSelector };
|
|
16
|
+
export * from './types';
|