@blueking/bk-user-selector 0.0.2-beta.1 → 0.0.4

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 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
- ### 在 Vue 3 中使用
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,8 @@ export default {
49
56
  v-model="selectedUser"
50
57
  :api-base-url="apiBaseUrl"
51
58
  :tenant-id="tenantId"
59
+ :current-user-id="currentUserId"
60
+ :exact-key="exactKey"
52
61
  @change="handleUserChange"
53
62
  />
54
63
 
@@ -57,6 +66,8 @@ export default {
57
66
  v-model="selectedUsers"
58
67
  :api-base-url="apiBaseUrl"
59
68
  :tenant-id="tenantId"
69
+ :current-user-id="currentUserId"
70
+ :exact-key="exactKey"
60
71
  :multiple="true"
61
72
  :draggable="true"
62
73
  @change="handleUsersChange"
@@ -64,26 +75,30 @@ export default {
64
75
  </template>
65
76
 
66
77
  <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 selectedUser = ref('');
75
- // 多选选中值
76
- const selectedUsers = ref([]);
77
-
78
- // 处理单选模式下的值变化
79
- const handleUserChange = (user) => {
80
- console.log('Selected user:', user);
81
- };
82
-
83
- // 处理多选模式下的值变化
84
- const handleUsersChange = (users) => {
85
- console.log('Selected users:', users);
86
- };
78
+ import { ref } from 'vue';
79
+
80
+ // API 基础路径
81
+ const apiBaseUrl = ref('https://api.example.com');
82
+ // 租户 ID
83
+ const tenantId = ref('default');
84
+ // 当前用户ID
85
+ const currentUserId = ref('admin');
86
+ // 精确查找key
87
+ const exactKey = ref('bk_username');
88
+ // 单选选中值
89
+ const selectedUser = ref('');
90
+ // 多选选中值
91
+ const selectedUsers = ref([]);
92
+
93
+ // 处理单选模式下的值变化
94
+ const handleUserChange = user => {
95
+ console.log('Selected user:', user);
96
+ };
97
+
98
+ // 处理多选模式下的值变化
99
+ const handleUsersChange = users => {
100
+ console.log('Selected users:', users);
101
+ };
87
102
  </script>
88
103
  ```
89
104
 
@@ -91,23 +106,35 @@ const handleUsersChange = (users) => {
91
106
 
92
107
  ### 属性
93
108
 
94
- | 参数 | 说明 | 类型 | 默认值 |
95
- |------|------|------|--------|
96
- | modelValue / v-model | 绑定值,单选为字符串,多选为数组 | String / Array | '' / [] |
97
- | label | 文本标签 | String | '人员选择' |
98
- | required | 是否必填 | Boolean | false |
99
- | placeholder | 占位文本 | String | '请输入人员名称搜索' |
100
- | multiple | 是否多选 | Boolean | false |
101
- | draggable | 是否可拖拽(仅多选模式有效) | Boolean | false |
102
- | apiBaseUrl | API 基础 URL | String | '' |
103
- | tenantId | 租户 ID | String | '' |
109
+ | 参数 | 说明 | 类型 | 默认值 |
110
+ | -------------------- | ----------------------------------------------------------------------- | -------------- | -------------------- |
111
+ | modelValue / v-model | 绑定值,单选为字符串,多选为数组 | String / Array | '' / [] |
112
+ | label | 文本标签 | String | '人员选择' |
113
+ | required | 是否必填 | Boolean | false |
114
+ | placeholder | 占位文本 | String | '请输入人员名称搜索' |
115
+ | multiple | 是否多选 | Boolean | false |
116
+ | draggable | 是否可拖拽(仅多选模式有效) | Boolean | false |
117
+ | apiBaseUrl | API 基础 URL | String | '' |
118
+ | tenantId | 租户 ID | String | '' |
119
+ | exactKey | 精确查找key,可选值为 bk_username、login_name、full_name, 多个以逗号分隔 | String | 'bk_username' |
120
+ | currentUserId | 当前用户ID(用于快速选择"我") | String | '' |
104
121
 
105
122
  ### 事件
106
123
 
107
- | 事件名称 | 说明 | 回调参数 |
108
- |---------|------|----------|
109
- | update:modelValue | 绑定值变化时触发 | 变化后的值 |
110
- | change | 选中值变化时触发 | 变化后的用户信息 |
124
+ | 事件名称 | 说明 | 回调参数 |
125
+ | ----------------- | ---------------- | ---------------- |
126
+ | update:modelValue | 绑定值变化时触发 | 变化后的值 |
127
+ | change | 选中值变化时触发 | 变化后的用户信息 |
128
+
129
+ ## 功能说明
130
+
131
+ ### 快速选择"我"
132
+
133
+ 当设置了`currentUserId`属性后,组件会在输入框右侧显示一个"我"的标签。点击该标签可以快速选择当前用户,无需手动搜索。
134
+
135
+ - 在单选模式下,点击"我"会直接选中当前用户
136
+ - 在多选模式下,点击"我"会将当前用户添加到已选列表中(如果尚未选择)
137
+ - 当当前用户已被选中时,"我"标签会显示为灰色且不可点击
111
138
 
112
139
  ## 开发
113
140
 
@@ -124,4 +151,4 @@ npm run build
124
151
 
125
152
  ## 许可证
126
153
 
127
- MIT
154
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/bk-user-selector",
3
- "version": "0.0.2-beta.1",
3
+ "version": "0.0.4",
4
4
  "description": "蓝鲸用户选择器",
5
5
  "license": "MIT",
6
6
  "author": "Tencent BlueKing",
@@ -17,15 +17,16 @@ 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: string, tenantId: string, keyword?: string) => Promise<User[]>;
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
+ * @param exactKey - 精确查找key
26
27
  * @returns 查找到的用户列表Promise
27
28
  */
28
- export declare const lookupUsers: (apiBaseUrl: string, tenantId: string, users?: string[]) => Promise<User[]>;
29
+ export declare const lookupUsers: (apiBaseUrl?: string, tenantId?: string, exactKey?: string, users?: string[]) => Promise<User[]>;
29
30
  /**
30
31
  * 将API返回的用户数据格式化为组件所需格式
31
32
  * @param users - API返回的用户列表
@@ -42,6 +42,27 @@ 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
+ };
59
+ /**
60
+ * 精确查找key
61
+ */
62
+ exactKey: {
63
+ type: StringConstructor;
64
+ default: string;
65
+ };
45
66
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
46
67
  "update:selectedUsers": (...args: any[]) => void;
47
68
  "add-user": (...args: any[]) => void;
@@ -89,16 +110,40 @@ declare const _default: import("vue").DefineComponent<{
89
110
  type: () => FormattedUser[];
90
111
  default: () => never[];
91
112
  };
113
+ /**
114
+ * 租户信息映射
115
+ */
116
+ tenants: {
117
+ type: () => Record<string, string>;
118
+ default: () => {};
119
+ };
120
+ /**
121
+ * 当前用户ID
122
+ */
123
+ currentUserId: {
124
+ type: StringConstructor;
125
+ default: string;
126
+ };
127
+ /**
128
+ * 精确查找key
129
+ */
130
+ exactKey: {
131
+ type: StringConstructor;
132
+ default: string;
133
+ };
92
134
  }>> & {
93
135
  "onUpdate:selectedUsers"?: ((...args: any[]) => any) | undefined;
94
136
  "onAdd-user"?: ((...args: any[]) => any) | undefined;
95
137
  "onRemove-user"?: ((...args: any[]) => any) | undefined;
96
138
  }, {
139
+ tenants: Record<string, string>;
140
+ draggable: boolean;
97
141
  modelValue: unknown[];
98
142
  placeholder: string;
99
143
  apiBaseUrl: string;
100
144
  tenantId: string;
101
- draggable: boolean;
102
145
  selectedUsers: FormattedUser[];
146
+ currentUserId: string;
147
+ exactKey: string;
103
148
  }, {}>;
104
149
  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,37 @@
1
1
  import { UserSelectorProps } from '../types';
2
2
  declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<UserSelectorProps>, {
3
- label: string;
4
- required: boolean;
3
+ apiBaseUrl: string;
4
+ tenantId: string;
5
5
  placeholder: string;
6
6
  modelValue: string;
7
7
  draggable: boolean;
8
8
  multiple: boolean;
9
- apiBaseUrl: string;
10
- tenantId: string;
9
+ currentUserId: string;
10
+ exactKey: string;
11
11
  }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
- "update:modelValue": (...args: any[]) => void;
13
12
  change: (...args: any[]) => void;
13
+ "update:modelValue": (...args: any[]) => void;
14
14
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<UserSelectorProps>, {
15
- label: string;
16
- required: boolean;
15
+ apiBaseUrl: string;
16
+ tenantId: string;
17
17
  placeholder: string;
18
18
  modelValue: string;
19
19
  draggable: boolean;
20
20
  multiple: boolean;
21
- apiBaseUrl: string;
22
- tenantId: string;
21
+ currentUserId: string;
22
+ exactKey: string;
23
23
  }>>> & {
24
- "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
25
24
  onChange?: ((...args: any[]) => any) | undefined;
25
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
26
26
  }, {
27
+ draggable: boolean;
27
28
  modelValue: string | string[];
28
29
  placeholder: string;
29
30
  apiBaseUrl: string;
30
31
  tenantId: string;
32
+ currentUserId: string;
33
+ exactKey: string;
31
34
  multiple: boolean;
32
- required: boolean;
33
- label: string;
34
- draggable: boolean;
35
35
  }, {}>;
36
36
  export default _default;
37
37
  type __VLS_WithDefaults<P, D> = {
@@ -2,7 +2,7 @@
2
2
  * 租户数据处理 Hook
3
3
  * @module hooks/useTenantData
4
4
  */
5
- import { Ref } from 'vue';
5
+ import { type Ref } from 'vue';
6
6
  /**
7
7
  * 使用租户数据的Hook
8
8
  * @param apiBaseUrl - API基础URL
@@ -2,8 +2,8 @@
2
2
  * 用户搜索 Hook
3
3
  * @module hooks/useUserSearch
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
@@ -19,7 +19,7 @@ export interface User {
19
19
  */
20
20
  full_name: string;
21
21
  /**
22
- * 登录名
22
+ * 登录名, 对应内网企微英文名
23
23
  */
24
24
  login_name: string;
25
25
  /**
@@ -62,13 +62,13 @@ export interface Tenant {
62
62
  */
63
63
  export interface UserSelectorProps {
64
64
  /**
65
- * 文本标签
65
+ * 接口基础URL
66
66
  */
67
- label?: string;
67
+ apiBaseUrl: string;
68
68
  /**
69
- * 是否必填
69
+ * 租户ID
70
70
  */
71
- required?: boolean;
71
+ tenantId: string;
72
72
  /**
73
73
  * 占位文字
74
74
  */
@@ -86,13 +86,13 @@ export interface UserSelectorProps {
86
86
  */
87
87
  multiple?: boolean;
88
88
  /**
89
- * 接口基础URL
89
+ * 本人ID
90
90
  */
91
- apiBaseUrl?: string;
91
+ currentUserId?: string;
92
92
  /**
93
- * 租户ID
93
+ * 精确查找key, 默认是 bk_username, 可选值为 bk_username、login_name、full_name, 多个以逗号分隔
94
94
  */
95
- tenantId?: string;
95
+ exactKey?: string;
96
96
  }
97
97
  /**
98
98
  * 单选模式属性
@@ -117,5 +117,13 @@ export interface SingleSelectorProps {
117
117
  /**
118
118
  * 租户信息映射
119
119
  */
120
- tenants?: Record<string, string>;
120
+ tenants: Record<string, string>;
121
+ /**
122
+ * 本人ID
123
+ */
124
+ currentUserId?: string;
125
+ /**
126
+ * 精确查找key
127
+ */
128
+ exactKey?: string;
121
129
  }
@@ -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> | HTMLElement[], containerWidth: number) => number;
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
- declare const _default: any;
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';