@blueking/bk-user-selector 0.0.4 → 0.0.6

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,7 +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
+ :exact-search-key="exactSearchKey"
61
61
  @change="handleUserChange"
62
62
  />
63
63
 
@@ -67,7 +67,7 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
67
67
  :api-base-url="apiBaseUrl"
68
68
  :tenant-id="tenantId"
69
69
  :current-user-id="currentUserId"
70
- :exact-key="exactKey"
70
+ :exact-search-key="exactSearchKey"
71
71
  :multiple="true"
72
72
  :draggable="true"
73
73
  @change="handleUsersChange"
@@ -84,7 +84,7 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
84
84
  // 当前用户ID
85
85
  const currentUserId = ref('admin');
86
86
  // 精确查找key
87
- const exactKey = ref('bk_username');
87
+ const exactSearchKey = ref('bk_username');
88
88
  // 单选选中值
89
89
  const selectedUser = ref('');
90
90
  // 多选选中值
@@ -116,7 +116,7 @@ import '@blueking/bk-user-selector/vue2/vue2.css';
116
116
  | draggable | 是否可拖拽(仅多选模式有效) | Boolean | false |
117
117
  | apiBaseUrl | API 基础 URL | String | '' |
118
118
  | tenantId | 租户 ID | String | '' |
119
- | exactKey | 精确查找key,可选值为 bk_username、login_name、full_name, 多个以逗号分隔 | String | 'bk_username' |
119
+ | exactSearchKey | 精确查找key,可选值为 bk_username、login_name、full_name, 多个以逗号分隔 | String | 'bk_username' |
120
120
  | currentUserId | 当前用户ID(用于快速选择"我") | String | '' |
121
121
 
122
122
  ### 事件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/bk-user-selector",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "蓝鲸用户选择器",
5
5
  "license": "MIT",
6
6
  "author": "Tencent BlueKing",
@@ -23,10 +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
+ * @param exactSearchKey - 精确查找key
27
27
  * @returns 查找到的用户列表Promise
28
28
  */
29
- export declare const lookupUsers: (apiBaseUrl?: string, tenantId?: string, exactKey?: string, users?: string[]) => Promise<User[]>;
29
+ export declare const lookupUsers: (apiBaseUrl?: string, tenantId?: string, exactSearchKey?: string, users?: string[]) => Promise<User[]>;
30
30
  /**
31
31
  * 将API返回的用户数据格式化为组件所需格式
32
32
  * @param users - API返回的用户列表
@@ -59,7 +59,7 @@ declare const _default: import("vue").DefineComponent<{
59
59
  /**
60
60
  * 精确查找key
61
61
  */
62
- exactKey: {
62
+ exactSearchKey: {
63
63
  type: StringConstructor;
64
64
  default: string;
65
65
  };
@@ -127,7 +127,7 @@ declare const _default: import("vue").DefineComponent<{
127
127
  /**
128
128
  * 精确查找key
129
129
  */
130
- exactKey: {
130
+ exactSearchKey: {
131
131
  type: StringConstructor;
132
132
  default: string;
133
133
  };
@@ -136,14 +136,14 @@ declare const _default: import("vue").DefineComponent<{
136
136
  "onAdd-user"?: ((...args: any[]) => any) | undefined;
137
137
  "onRemove-user"?: ((...args: any[]) => any) | undefined;
138
138
  }, {
139
+ tenantId: string;
139
140
  tenants: Record<string, string>;
140
141
  draggable: boolean;
141
142
  modelValue: unknown[];
142
143
  placeholder: string;
143
144
  apiBaseUrl: string;
144
- tenantId: string;
145
145
  selectedUsers: FormattedUser[];
146
146
  currentUserId: string;
147
- exactKey: string;
147
+ exactSearchKey: string;
148
148
  }, {}>;
149
149
  export default _default;
@@ -7,7 +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
+ exactSearchKey: string;
11
11
  }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
12
  change: (...args: any[]) => void;
13
13
  "update:modelValue": (...args: any[]) => void;
@@ -19,18 +19,18 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
19
19
  draggable: boolean;
20
20
  multiple: boolean;
21
21
  currentUserId: string;
22
- exactKey: string;
22
+ exactSearchKey: string;
23
23
  }>>> & {
24
24
  onChange?: ((...args: any[]) => any) | undefined;
25
25
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
26
26
  }, {
27
+ tenantId: string;
27
28
  draggable: boolean;
28
29
  modelValue: string | string[];
29
30
  placeholder: string;
30
31
  apiBaseUrl: string;
31
- tenantId: string;
32
32
  currentUserId: string;
33
- exactKey: string;
33
+ exactSearchKey: string;
34
34
  multiple: boolean;
35
35
  }, {}>;
36
36
  export default _default;
@@ -42,7 +42,11 @@ export interface FormattedUser {
42
42
  /**
43
43
  * 租户ID
44
44
  */
45
- tenantId?: string;
45
+ tenantId: string;
46
+ /**
47
+ * 其他属性
48
+ */
49
+ [key: string]: string;
46
50
  }
47
51
  /**
48
52
  * 租户信息
@@ -92,7 +96,7 @@ export interface UserSelectorProps {
92
96
  /**
93
97
  * 精确查找key, 默认是 bk_username, 可选值为 bk_username、login_name、full_name, 多个以逗号分隔
94
98
  */
95
- exactKey?: string;
99
+ exactSearchKey?: string;
96
100
  }
97
101
  /**
98
102
  * 单选模式属性
@@ -125,5 +129,5 @@ export interface SingleSelectorProps {
125
129
  /**
126
130
  * 精确查找key
127
131
  */
128
- exactKey?: string;
132
+ exactSearchKey: string;
129
133
  }
@@ -48,13 +48,13 @@ const searchUsers = async (apiBaseUrl = "", tenantId = "", keyword = "") => {
48
48
  return [];
49
49
  }
50
50
  };
51
- const lookupUsers = async (apiBaseUrl = "", tenantId = "", exactKey = "bk_username", users = []) => {
51
+ const lookupUsers = async (apiBaseUrl = "", tenantId = "", exactSearchKey = "bk_username", users = []) => {
52
52
  if (users.length === 0 || !apiBaseUrl || !tenantId) {
53
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=${exactKey}`;
57
+ const url = `${apiBaseUrl}/api/v3/open-web/tenant/users/-/lookup/?lookups=${users.join(",")}&lookup_fields=${exactSearchKey}`;
58
58
  const response = await fetch(url, {
59
59
  method: "GET",
60
60
  headers: {
@@ -77,7 +77,8 @@ const formatUsers = (users) => {
77
77
  return users.map((user) => ({
78
78
  id: user.bk_username,
79
79
  name: user.display_name,
80
- tenantId: user.owner_tenant_id
80
+ tenantId: user.owner_tenant_id,
81
+ ...user
81
82
  }));
82
83
  };
83
84
  const useTenantData = (apiBaseUrl, tenantId) => {
@@ -16780,7 +16781,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16780
16781
  /**
16781
16782
  * 精确查找key
16782
16783
  */
16783
- exactKey: {
16784
+ exactSearchKey: {
16784
16785
  type: String,
16785
16786
  default: "bk_username"
16786
16787
  }
@@ -16898,7 +16899,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16898
16899
  const addCurrentUser = async () => {
16899
16900
  if (!props2.currentUserId || props2.selectedUsers.some((user) => user.id === props2.currentUserId)) return;
16900
16901
  try {
16901
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, [props2.currentUserId]);
16902
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactSearchKey, [props2.currentUserId]);
16902
16903
  const formattedUsers = formatUsers(result);
16903
16904
  if (formattedUsers.length > 0) {
16904
16905
  if (!props2.selectedUsers.some((item) => item.id === formattedUsers[0].id)) {
@@ -16919,7 +16920,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16919
16920
  if (pastedText.trim()) {
16920
16921
  try {
16921
16922
  const users = pastedText.trim().split(/[,,;\n\s]+/).filter(Boolean);
16922
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, users);
16923
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactSearchKey, users);
16923
16924
  const formattedUsers = formatUsers(result);
16924
16925
  if (formattedUsers.length > 0) {
16925
16926
  const updatedUsers = [...props2.selectedUsers, ...formattedUsers];
@@ -17096,16 +17097,17 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
17096
17097
  [vModelText, unref(searchQuery)]
17097
17098
  ]) : createCommentVNode("v-if", true),
17098
17099
  createCommentVNode(' "我"标签 '),
17099
- createElementVNode(
17100
+ __props.currentUserId ? (openBlock(), createElementBlock(
17100
17101
  "div",
17101
17102
  {
17103
+ key: 1,
17102
17104
  class: normalizeClass(["me-tag", { disabled: __props.currentUserId && __props.selectedUsers.some((user) => user.id === __props.currentUserId) }]),
17103
17105
  onClick: _cache[2] || (_cache[2] = withModifiers(($event) => addCurrentUser(), ["stop"]))
17104
17106
  },
17105
17107
  " 我 ",
17106
17108
  2
17107
17109
  /* CLASS */
17108
- )
17110
+ )) : createCommentVNode("v-if", true)
17109
17111
  ],
17110
17112
  512
17111
17113
  /* NEED_PATCH */
@@ -17171,16 +17173,17 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
17171
17173
  [vModelText, unref(searchQuery)]
17172
17174
  ]),
17173
17175
  createCommentVNode(' 未聚焦状态下的"我"标签 '),
17174
- createElementVNode(
17176
+ __props.currentUserId ? (openBlock(), createElementBlock(
17175
17177
  "div",
17176
17178
  {
17177
- class: normalizeClass(["me-tag", { disabled: __props.currentUserId && __props.selectedUsers.some((user) => user.id === __props.currentUserId) }]),
17179
+ key: 1,
17180
+ class: normalizeClass(["me-tag", { disabled: __props.currentUserId && __props.selectedUsers.some((user) => user[props2.exactSearchKey] === __props.currentUserId) }]),
17178
17181
  onClick: _cache[4] || (_cache[4] = withModifiers(($event) => addCurrentUser(), ["stop"]))
17179
17182
  },
17180
17183
  " 我 ",
17181
17184
  2
17182
17185
  /* CLASS */
17183
- )
17186
+ )) : createCommentVNode("v-if", true)
17184
17187
  ],
17185
17188
  512
17186
17189
  /* NEED_PATCH */
@@ -17257,8 +17260,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
17257
17260
  };
17258
17261
  }
17259
17262
  });
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);
17263
+ const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-50540b99"]]);
17264
+ const _withScopeId = (n2) => (pushScopeId("data-v-308925e9"), n2 = n2(), popScopeId(), n2);
17262
17265
  const _hoisted_1$1 = { class: "input-container" };
17263
17266
  const _hoisted_2 = {
17264
17267
  key: 0,
@@ -17293,7 +17296,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17293
17296
  tenantId: {},
17294
17297
  tenants: {},
17295
17298
  currentUserId: {},
17296
- exactKey: {}
17299
+ exactSearchKey: {}
17297
17300
  },
17298
17301
  emits: ["update:modelValue", "change"],
17299
17302
  setup(__props, { emit: __emit }) {
@@ -17313,7 +17316,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17313
17316
  if (typeof props2.modelValue === "string" && props2.modelValue) {
17314
17317
  try {
17315
17318
  isLoading.value = true;
17316
- const result = await lookupUsers(props2.apiBaseUrl || "", props2.tenantId || "", props2.exactKey, [
17319
+ const result = await lookupUsers(props2.apiBaseUrl || "", props2.tenantId || "", props2.exactSearchKey, [
17317
17320
  props2.modelValue
17318
17321
  ]);
17319
17322
  options.value = formatUsers(result);
@@ -17327,7 +17330,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17327
17330
  const addCurrentUser = async () => {
17328
17331
  if (!props2.currentUserId || selectedUser.value === props2.currentUserId) return;
17329
17332
  try {
17330
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, [props2.currentUserId]);
17333
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactSearchKey, [props2.currentUserId]);
17331
17334
  const formattedResults = formatUsers(result);
17332
17335
  if (formattedResults.length > 0) {
17333
17336
  options.value = formattedResults;
@@ -17382,6 +17385,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17382
17385
  emit("change", selectedUserInfo2 || null);
17383
17386
  });
17384
17387
  return (_ctx, _cache) => {
17388
+ var _a;
17385
17389
  return withDirectives((openBlock(), createElementBlock("div", {
17386
17390
  ref_key: "containerRef",
17387
17391
  ref: containerRef,
@@ -17402,7 +17406,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17402
17406
  1
17403
17407
  /* TEXT */
17404
17408
  ),
17405
- selectedUserInfo.value.tenantId !== props2.tenantId && selectedUserInfo.value.tenantId && _ctx.tenants[selectedUserInfo.value.tenantId] ? (openBlock(), createElementBlock(
17409
+ selectedUserInfo.value.tenantId !== _ctx.tenantId && selectedUserInfo.value.tenantId && _ctx.tenants[selectedUserInfo.value.tenantId] ? (openBlock(), createElementBlock(
17406
17410
  "span",
17407
17411
  _hoisted_2,
17408
17412
  "@" + toDisplayString(_ctx.tenants[selectedUserInfo.value.tenantId]),
@@ -17416,18 +17420,18 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17416
17420
  ref: inputRef,
17417
17421
  class: "search-input",
17418
17422
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchQuery.value = $event),
17419
- placeholder: selectedUserInfo.value ? "" : props2.placeholder,
17423
+ placeholder: selectedUserInfo.value ? "" : _ctx.placeholder,
17420
17424
  onFocus: handleInputFocus,
17421
17425
  onInput: handleInput
17422
17426
  }, null, 40, _hoisted_4), [
17423
17427
  [vModelText, searchQuery.value]
17424
17428
  ]),
17425
17429
  createCommentVNode(' "我"标签 '),
17426
- props2.currentUserId ? (openBlock(), createElementBlock(
17430
+ _ctx.currentUserId ? (openBlock(), createElementBlock(
17427
17431
  "div",
17428
17432
  {
17429
17433
  key: 1,
17430
- class: normalizeClass(["me-tag", { disabled: props2.currentUserId && selectedUser.value === props2.currentUserId }]),
17434
+ class: normalizeClass(["me-tag", { disabled: _ctx.currentUserId && ((_a = selectedUserInfo.value) == null ? void 0 : _a[_ctx.exactSearchKey]) === _ctx.currentUserId }]),
17431
17435
  onClick: _cache[1] || (_cache[1] = ($event) => addCurrentUser())
17432
17436
  },
17433
17437
  " 我 ",
@@ -17477,10 +17481,10 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17477
17481
  1
17478
17482
  /* TEXT */
17479
17483
  ),
17480
- user.tenantId !== props2.tenantId && user.tenantId && props2.tenants[user.tenantId] ? (openBlock(), createElementBlock(
17484
+ user.tenantId !== _ctx.tenantId && user.tenantId && _ctx.tenants[user.tenantId] ? (openBlock(), createElementBlock(
17481
17485
  "span",
17482
17486
  _hoisted_7,
17483
- "@" + toDisplayString(props2.tenants[user.tenantId]),
17487
+ "@" + toDisplayString(_ctx.tenants[user.tenantId]),
17484
17488
  1
17485
17489
  /* TEXT */
17486
17490
  )) : createCommentVNode("v-if", true)
@@ -17503,7 +17507,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17503
17507
  };
17504
17508
  }
17505
17509
  });
17506
- const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d17d0282"]]);
17510
+ const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-308925e9"]]);
17507
17511
  const _hoisted_1 = { class: "bk-user-selector" };
17508
17512
  const _sfc_main = /* @__PURE__ */ defineComponent({
17509
17513
  ...{
@@ -17518,7 +17522,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17518
17522
  draggable: { type: Boolean, default: false },
17519
17523
  multiple: { type: Boolean, default: false },
17520
17524
  currentUserId: { default: "" },
17521
- exactKey: { default: "" }
17525
+ exactSearchKey: { default: "" }
17522
17526
  },
17523
17527
  emits: ["update:modelValue", "change"],
17524
17528
  setup(__props, { emit: __emit }) {
@@ -17535,8 +17539,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17535
17539
  const ids = Array.isArray(props2.modelValue) ? props2.modelValue : [];
17536
17540
  if (ids.length > 0) {
17537
17541
  try {
17538
- console.log(props2.exactKey);
17539
- const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactKey, ids);
17542
+ console.log(props2.exactSearchKey);
17543
+ const result = await lookupUsers(props2.apiBaseUrl, props2.tenantId, props2.exactSearchKey, ids);
17540
17544
  selectedUsers.value = formatUsers(result);
17541
17545
  } catch (error3) {
17542
17546
  console.error("获取选中用户信息失败:", error3);
@@ -17574,12 +17578,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17574
17578
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectedUser.value = $event),
17575
17579
  "api-base-url": _ctx.apiBaseUrl,
17576
17580
  "current-user-id": _ctx.currentUserId,
17577
- "exact-key": _ctx.exactKey,
17581
+ "exact-search-key": _ctx.exactSearchKey,
17578
17582
  placeholder: _ctx.placeholder,
17579
17583
  "tenant-id": _ctx.tenantId,
17580
17584
  tenants: unref(tenants),
17581
17585
  onChange: handleUpdateUser
17582
- }, null, 8, ["modelValue", "api-base-url", "current-user-id", "exact-key", "placeholder", "tenant-id", "tenants"])) : (openBlock(), createElementBlock(
17586
+ }, null, 8, ["modelValue", "api-base-url", "current-user-id", "exact-search-key", "placeholder", "tenant-id", "tenants"])) : (openBlock(), createElementBlock(
17583
17587
  Fragment,
17584
17588
  { key: 1 },
17585
17589
  [
@@ -17590,13 +17594,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17590
17594
  "api-base-url": _ctx.apiBaseUrl,
17591
17595
  "current-user-id": _ctx.currentUserId,
17592
17596
  draggable: _ctx.draggable,
17593
- "exact-key": _ctx.exactKey,
17597
+ "exact-search-key": _ctx.exactSearchKey,
17594
17598
  placeholder: _ctx.placeholder,
17595
17599
  "selected-users": selectedUsers.value,
17596
17600
  "tenant-id": _ctx.tenantId,
17597
17601
  tenants: unref(tenants),
17598
17602
  "onUpdate:selectedUsers": handleUpdateSelectedUsers
17599
- }, null, 8, ["modelValue", "api-base-url", "current-user-id", "draggable", "exact-key", "placeholder", "selected-users", "tenant-id", "tenants"])
17603
+ }, null, 8, ["modelValue", "api-base-url", "current-user-id", "draggable", "exact-search-key", "placeholder", "selected-users", "tenant-id", "tenants"])
17600
17604
  ],
17601
17605
  2112
17602
17606
  /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
@@ -17605,7 +17609,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17605
17609
  };
17606
17610
  }
17607
17611
  });
17608
- const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ee509d86"]]);
17612
+ const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-fe084750"]]);
17609
17613
  const vue2 = {
17610
17614
  beforeDestroy() {
17611
17615
  var _a;