@blueking/bk-user-selector 0.0.3 → 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
@@ -57,6 +57,7 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
57
57
  :api-base-url="apiBaseUrl"
58
58
  :tenant-id="tenantId"
59
59
  :current-user-id="currentUserId"
60
+ :exact-key="exactKey"
60
61
  @change="handleUserChange"
61
62
  />
62
63
 
@@ -66,6 +67,7 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
66
67
  :api-base-url="apiBaseUrl"
67
68
  :tenant-id="tenantId"
68
69
  :current-user-id="currentUserId"
70
+ :exact-key="exactKey"
69
71
  :multiple="true"
70
72
  :draggable="true"
71
73
  @change="handleUsersChange"
@@ -80,7 +82,9 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
80
82
  // 租户 ID
81
83
  const tenantId = ref('default');
82
84
  // 当前用户ID
83
- const currentUserId = ref('admin');
85
+ const currentUserId = ref('admin');
86
+ // 精确查找key
87
+ const exactKey = ref('bk_username');
84
88
  // 单选选中值
85
89
  const selectedUser = ref('');
86
90
  // 多选选中值
@@ -102,17 +106,18 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
102
106
 
103
107
  ### 属性
104
108
 
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 | '' |
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 | '' |
116
121
 
117
122
  ### 事件
118
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/bk-user-selector",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "蓝鲸用户选择器",
5
5
  "license": "MIT",
6
6
  "author": "Tencent BlueKing",
@@ -23,9 +23,10 @@ export declare const searchUsers: (apiBaseUrl?: string, tenantId?: string, keywo
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返回的用户列表
@@ -56,6 +56,13 @@ declare const _default: import("vue").DefineComponent<{
56
56
  type: StringConstructor;
57
57
  default: string;
58
58
  };
59
+ /**
60
+ * 精确查找key
61
+ */
62
+ exactKey: {
63
+ type: StringConstructor;
64
+ default: string;
65
+ };
59
66
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
60
67
  "update:selectedUsers": (...args: any[]) => void;
61
68
  "add-user": (...args: any[]) => void;
@@ -117,6 +124,13 @@ declare const _default: import("vue").DefineComponent<{
117
124
  type: StringConstructor;
118
125
  default: string;
119
126
  };
127
+ /**
128
+ * 精确查找key
129
+ */
130
+ exactKey: {
131
+ type: StringConstructor;
132
+ default: string;
133
+ };
120
134
  }>> & {
121
135
  "onUpdate:selectedUsers"?: ((...args: any[]) => any) | undefined;
122
136
  "onAdd-user"?: ((...args: any[]) => any) | undefined;
@@ -130,5 +144,6 @@ declare const _default: import("vue").DefineComponent<{
130
144
  tenantId: string;
131
145
  selectedUsers: FormattedUser[];
132
146
  currentUserId: string;
147
+ exactKey: string;
133
148
  }, {}>;
134
149
  export default _default;
@@ -7,6 +7,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
7
7
  draggable: boolean;
8
8
  multiple: boolean;
9
9
  currentUserId: string;
10
+ exactKey: string;
10
11
  }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
12
  change: (...args: any[]) => void;
12
13
  "update:modelValue": (...args: any[]) => void;
@@ -18,6 +19,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
18
19
  draggable: boolean;
19
20
  multiple: boolean;
20
21
  currentUserId: string;
22
+ exactKey: string;
21
23
  }>>> & {
22
24
  onChange?: ((...args: any[]) => any) | undefined;
23
25
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
@@ -28,6 +30,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
28
30
  apiBaseUrl: string;
29
31
  tenantId: string;
30
32
  currentUserId: string;
33
+ exactKey: string;
31
34
  multiple: boolean;
32
35
  }, {}>;
33
36
  export default _default;
@@ -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
  /**
@@ -89,6 +89,10 @@ export interface UserSelectorProps {
89
89
  * 本人ID
90
90
  */
91
91
  currentUserId?: string;
92
+ /**
93
+ * 精确查找key, 默认是 bk_username, 可选值为 bk_username、login_name、full_name, 多个以逗号分隔
94
+ */
95
+ exactKey?: string;
92
96
  }
93
97
  /**
94
98
  * 单选模式属性
@@ -118,4 +122,8 @@ export interface SingleSelectorProps {
118
122
  * 本人ID
119
123
  */
120
124
  currentUserId?: string;
125
+ /**
126
+ * 精确查找key
127
+ */
128
+ exactKey?: string;
121
129
  }
@@ -2,7 +2,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_vue__ from "@blueking/bkui-library";
2
2
  import { ref, onBeforeMount, defineComponent, createBlock, openBlock, unref, withModifiers, normalizeClass, withCtx, createElementVNode, createElementBlock, createCommentVNode, toDisplayString, watch, nextTick, onMounted, withDirectives, createVNode, Fragment, renderList, isRef, vModelText, createTextVNode, computed, pushScopeId, popScopeId, createApp, h as h$1 } from "@blueking/bkui-library";
3
3
  const getTenants = async (apiBaseUrl, tenantId) => {
4
4
  if (!apiBaseUrl || !tenantId) {
5
- console.warn("获取租户信息需要提供有效的API基础URL和租户ID");
5
+ console.warn("获取租户信息需要提供有效的apiBaseUrl和租户ID");
6
6
  return [];
7
7
  }
8
8
  try {
@@ -26,7 +26,7 @@ const getTenants = async (apiBaseUrl, tenantId) => {
26
26
  };
27
27
  const searchUsers = async (apiBaseUrl = "", tenantId = "", keyword = "") => {
28
28
  if (!keyword || !apiBaseUrl || !tenantId) {
29
- console.warn("搜索用户需要提供有效的API基础URL、租户ID和关键词");
29
+ console.warn("搜索用户需要提供有效的apiBaseUrl、租户ID和关键词");
30
30
  return [];
31
31
  }
32
32
  try {
@@ -48,13 +48,13 @@ const searchUsers = async (apiBaseUrl = "", tenantId = "", keyword = "") => {
48
48
  return [];
49
49
  }
50
50
  };
51
- const lookupUsers = async (apiBaseUrl = "", tenantId = "", users = []) => {
51
+ const lookupUsers = async (apiBaseUrl = "", tenantId = "", exactKey = "bk_username", users = []) => {
52
52
  if (users.length === 0 || !apiBaseUrl || !tenantId) {
53
- console.warn("批量查找用户需要提供有效的API基础URL、租户ID和至少一个用户名");
53
+ console.warn("批量查找用户需要提供有效的apiBaseUrl、租户ID和至少一个用户名");
54
54
  return [];
55
55
  }
56
56
  try {
57
- const url = `${apiBaseUrl}/api/v3/open-web/tenant/users/-/lookup/?lookups=${users.join(",")}&lookup_fields=bk_username`;
57
+ const url = `${apiBaseUrl}/api/v3/open-web/tenant/users/-/lookup/?lookups=${users.join(",")}&lookup_fields=${exactKey}`;
58
58
  const response = await fetch(url, {
59
59
  method: "GET",
60
60
  headers: {
@@ -16776,6 +16776,13 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16776
16776
  currentUserId: {
16777
16777
  type: String,
16778
16778
  default: ""
16779
+ },
16780
+ /**
16781
+ * 精确查找key
16782
+ */
16783
+ exactKey: {
16784
+ type: String,
16785
+ default: "bk_username"
16779
16786
  }
16780
16787
  },
16781
16788
  emits: ["update:selectedUsers", "add-user", "remove-user"],
@@ -16816,7 +16823,6 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16816
16823
  const [movedUser] = updatedUsers.splice(oldIndex, 1);
16817
16824
  updatedUsers.splice(newIndex, 0, movedUser);
16818
16825
  emit("update:selectedUsers", updatedUsers);
16819
- activeTagIndex.value = newIndex;
16820
16826
  }
16821
16827
  });
16822
16828
  };
@@ -16892,7 +16898,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16892
16898
  const addCurrentUser = async () => {
16893
16899
  if (!props2.currentUserId || props2.selectedUsers.some((user) => user.id === props2.currentUserId)) return;
16894
16900
  try {
16895
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, [props2.currentUserId]);
16901
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, [props2.currentUserId]);
16896
16902
  const formattedUsers = formatUsers(result);
16897
16903
  if (formattedUsers.length > 0) {
16898
16904
  if (!props2.selectedUsers.some((item) => item.id === formattedUsers[0].id)) {
@@ -16913,7 +16919,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16913
16919
  if (pastedText.trim()) {
16914
16920
  try {
16915
16921
  const users = pastedText.trim().split(/[,,;\n\s]+/).filter(Boolean);
16916
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, users);
16922
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, users);
16917
16923
  const formattedUsers = formatUsers(result);
16918
16924
  if (formattedUsers.length > 0) {
16919
16925
  const updatedUsers = [...props2.selectedUsers, ...formattedUsers];
@@ -16943,8 +16949,16 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16943
16949
  const addUser = (user) => {
16944
16950
  if (!(user == null ? void 0 : user.id)) return;
16945
16951
  if (!props2.selectedUsers.some((item) => item.id === user.id)) {
16946
- const updatedUsers = [...props2.selectedUsers, user];
16947
- emit("update:selectedUsers", updatedUsers);
16952
+ if (activeTagIndex.value !== -1) {
16953
+ const updatedUsers = [
16954
+ ...props2.selectedUsers.slice(0, activeTagIndex.value + 1),
16955
+ user,
16956
+ ...props2.selectedUsers.slice(activeTagIndex.value + 1)
16957
+ ];
16958
+ emit("update:selectedUsers", updatedUsers);
16959
+ } else {
16960
+ emit("update:selectedUsers", [...props2.selectedUsers, user]);
16961
+ }
16948
16962
  emit("add-user", user);
16949
16963
  }
16950
16964
  searchQuery.value = "";
@@ -17243,8 +17257,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
17243
17257
  };
17244
17258
  }
17245
17259
  });
17246
- const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-0bc02f6f"]]);
17247
- const _withScopeId = (n2) => (pushScopeId("data-v-02788d3d"), n2 = n2(), popScopeId(), n2);
17260
+ const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-55945956"]]);
17261
+ const _withScopeId = (n2) => (pushScopeId("data-v-d17d0282"), n2 = n2(), popScopeId(), n2);
17248
17262
  const _hoisted_1$1 = { class: "input-container" };
17249
17263
  const _hoisted_2 = {
17250
17264
  key: 0,
@@ -17278,7 +17292,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17278
17292
  apiBaseUrl: {},
17279
17293
  tenantId: {},
17280
17294
  tenants: {},
17281
- currentUserId: {}
17295
+ currentUserId: {},
17296
+ exactKey: {}
17282
17297
  },
17283
17298
  emits: ["update:modelValue", "change"],
17284
17299
  setup(__props, { emit: __emit }) {
@@ -17298,7 +17313,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17298
17313
  if (typeof props2.modelValue === "string" && props2.modelValue) {
17299
17314
  try {
17300
17315
  isLoading.value = true;
17301
- const result = await lookupUsers(props2.apiBaseUrl || "", props2.tenantId || "", [props2.modelValue]);
17316
+ const result = await lookupUsers(props2.apiBaseUrl || "", props2.tenantId || "", props2.exactKey, [
17317
+ props2.modelValue
17318
+ ]);
17302
17319
  options.value = formatUsers(result);
17303
17320
  } catch (error3) {
17304
17321
  console.error("获取用户信息失败:", error3);
@@ -17310,7 +17327,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17310
17327
  const addCurrentUser = async () => {
17311
17328
  if (!props2.currentUserId || selectedUser.value === props2.currentUserId) return;
17312
17329
  try {
17313
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, [props2.currentUserId]);
17330
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, [props2.currentUserId]);
17314
17331
  const formattedResults = formatUsers(result);
17315
17332
  if (formattedResults.length > 0) {
17316
17333
  options.value = formattedResults;
@@ -17486,7 +17503,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17486
17503
  };
17487
17504
  }
17488
17505
  });
17489
- const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-02788d3d"]]);
17506
+ const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d17d0282"]]);
17490
17507
  const _hoisted_1 = { class: "bk-user-selector" };
17491
17508
  const _sfc_main = /* @__PURE__ */ defineComponent({
17492
17509
  ...{
@@ -17500,7 +17517,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17500
17517
  modelValue: { default: "" },
17501
17518
  draggable: { type: Boolean, default: false },
17502
17519
  multiple: { type: Boolean, default: false },
17503
- currentUserId: { default: "" }
17520
+ currentUserId: { default: "" },
17521
+ exactKey: { default: "" }
17504
17522
  },
17505
17523
  emits: ["update:modelValue", "change"],
17506
17524
  setup(__props, { emit: __emit }) {
@@ -17517,7 +17535,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17517
17535
  const ids = Array.isArray(props2.modelValue) ? props2.modelValue : [];
17518
17536
  if (ids.length > 0) {
17519
17537
  try {
17520
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, ids);
17538
+ console.log(props2.exactKey);
17539
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, ids);
17521
17540
  selectedUsers.value = formatUsers(result);
17522
17541
  } catch (error3) {
17523
17542
  console.error("获取选中用户信息失败:", error3);
@@ -17555,11 +17574,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17555
17574
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectedUser.value = $event),
17556
17575
  "api-base-url": _ctx.apiBaseUrl,
17557
17576
  "current-user-id": _ctx.currentUserId,
17577
+ "exact-key": _ctx.exactKey,
17558
17578
  placeholder: _ctx.placeholder,
17559
17579
  "tenant-id": _ctx.tenantId,
17560
17580
  tenants: unref(tenants),
17561
17581
  onChange: handleUpdateUser
17562
- }, null, 8, ["modelValue", "api-base-url", "current-user-id", "placeholder", "tenant-id", "tenants"])) : (openBlock(), createElementBlock(
17582
+ }, null, 8, ["modelValue", "api-base-url", "current-user-id", "exact-key", "placeholder", "tenant-id", "tenants"])) : (openBlock(), createElementBlock(
17563
17583
  Fragment,
17564
17584
  { key: 1 },
17565
17585
  [
@@ -17570,12 +17590,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17570
17590
  "api-base-url": _ctx.apiBaseUrl,
17571
17591
  "current-user-id": _ctx.currentUserId,
17572
17592
  draggable: _ctx.draggable,
17593
+ "exact-key": _ctx.exactKey,
17573
17594
  placeholder: _ctx.placeholder,
17574
17595
  "selected-users": selectedUsers.value,
17575
17596
  "tenant-id": _ctx.tenantId,
17576
17597
  tenants: unref(tenants),
17577
17598
  "onUpdate:selectedUsers": handleUpdateSelectedUsers
17578
- }, null, 8, ["modelValue", "api-base-url", "current-user-id", "draggable", "placeholder", "selected-users", "tenant-id", "tenants"])
17599
+ }, null, 8, ["modelValue", "api-base-url", "current-user-id", "draggable", "exact-key", "placeholder", "selected-users", "tenant-id", "tenants"])
17579
17600
  ],
17580
17601
  2112
17581
17602
  /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
@@ -17584,7 +17605,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17584
17605
  };
17585
17606
  }
17586
17607
  });
17587
- const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-bb73e41f"]]);
17608
+ const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ee509d86"]]);
17588
17609
  const vue2 = {
17589
17610
  beforeDestroy() {
17590
17611
  var _a;