@blueking/bk-user-selector 0.0.29-beta.1 → 0.0.29-beta.10

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.
@@ -1,4 +1,4 @@
1
- import { shallowRef, watchEffect, unref, onScopeDispose, ref, onBeforeMount, defineComponent, openBlock, createElementBlock, normalizeClass, withModifiers, createCommentVNode, h, computed, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, Fragment, renderList, watch, nextTick, onMounted, withDirectives, isRef, vModelText, createTextVNode } from "vue";
1
+ import { unref, ref, onBeforeMount, defineComponent, openBlock, createElementBlock, normalizeClass, withModifiers, createCommentVNode, h, computed, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, Fragment, renderList, renderSlot, watch, nextTick, onMounted, withDirectives, isRef, vModelText, createTextVNode } from "vue";
2
2
  import { Popover, Loading, Tag, clickoutside, provideGlobalConfig } from "bkui-vue";
3
3
  const generateCallbackName = () => {
4
4
  const timestamp = Date.now();
@@ -8,10 +8,15 @@ const generateCallbackName = () => {
8
8
  const jsonpRequest = (requestUrl, options = {}) => {
9
9
  return new Promise((resolve, reject) => {
10
10
  const url = unref(requestUrl);
11
- const { timeout = 1e3 * 60 * 2, params } = options;
11
+ const { timeout = 1e3 * 60 * 2, params, withCredentials = true } = options;
12
12
  const callbackName = generateCallbackName();
13
13
  const script = document.createElement("script");
14
14
  let timeoutId;
15
+ if (withCredentials) {
16
+ script.crossOrigin = "use-credentials";
17
+ } else {
18
+ script.crossOrigin = "anonymous";
19
+ }
15
20
  const cleanup = () => {
16
21
  if (timeoutId) {
17
22
  clearTimeout(timeoutId);
@@ -25,7 +30,7 @@ const jsonpRequest = (requestUrl, options = {}) => {
25
30
  };
26
31
  window[callbackName] = (data) => {
27
32
  cleanup();
28
- resolve(data);
33
+ resolve(data.data || data);
29
34
  };
30
35
  timeoutId = setTimeout(() => {
31
36
  cleanup();
@@ -41,48 +46,6 @@ const jsonpRequest = (requestUrl, options = {}) => {
41
46
  document.head.appendChild(script);
42
47
  });
43
48
  };
44
- const useJSONP = (url, options = {}) => {
45
- const data = shallowRef(null);
46
- const loading = shallowRef(false);
47
- const error = shallowRef(null);
48
- let abortFlag = false;
49
- const executeRequest = async (requestUrl) => {
50
- if (!requestUrl) return;
51
- loading.value = true;
52
- error.value = null;
53
- abortFlag = false;
54
- try {
55
- const result = await jsonpRequest(requestUrl, options);
56
- if (!abortFlag) {
57
- data.value = result;
58
- }
59
- } catch (err) {
60
- if (!abortFlag) {
61
- const errorObj = err instanceof Error ? err : new Error(String(err));
62
- error.value = errorObj;
63
- }
64
- } finally {
65
- if (!abortFlag) {
66
- loading.value = false;
67
- }
68
- }
69
- };
70
- const stopWatcher = watchEffect(() => {
71
- executeRequest(unref(url));
72
- });
73
- onScopeDispose(() => {
74
- abortFlag = true;
75
- stopWatcher();
76
- });
77
- return {
78
- data,
79
- loading,
80
- error,
81
- refetch: () => {
82
- executeRequest(unref(url));
83
- }
84
- };
85
- };
86
49
  const getTenants = async (apiBaseUrl, tenantId) => {
87
50
  if (!apiBaseUrl || !tenantId) {
88
51
  console.warn("获取租户信息需要提供有效的apiBaseUrl和租户ID");
@@ -109,7 +72,7 @@ const getTenants = async (apiBaseUrl, tenantId) => {
109
72
  };
110
73
  const searchUsers = async (params) => {
111
74
  const { apiBaseUrl, tenantId, keyword, enableMultiTenantMode = true } = params;
112
- if (enableMultiTenantMode) {
75
+ if (!enableMultiTenantMode) {
113
76
  const userList = await getUserList(apiBaseUrl, {
114
77
  keyword,
115
78
  pageSize: 100,
@@ -145,13 +108,13 @@ const searchUsers = async (params) => {
145
108
  const lookupUsers = async (params) => {
146
109
  const { apiBaseUrl, tenantId, exactSearchKey = "bk_username", usersList = [], enableMultiTenantMode = true } = params;
147
110
  const users = usersList.filter((user) => user).map((user) => user.trim());
148
- if (enableMultiTenantMode) {
111
+ if (!enableMultiTenantMode) {
149
112
  const userList = await getUserList(apiBaseUrl, {
150
113
  userIds: users
151
114
  }).catch(() => {
152
115
  return [];
153
116
  });
154
- return userList;
117
+ return users.map((user) => userList.find((u) => u.username === user)).filter(Boolean);
155
118
  }
156
119
  if (users.length === 0 || !apiBaseUrl || !tenantId) {
157
120
  console.warn("批量查找用户需要提供有效的apiBaseUrl、租户ID和至少一个用户名");
@@ -176,18 +139,26 @@ const lookupUsers = async (params) => {
176
139
  return [];
177
140
  }
178
141
  };
179
- const formatUsers = (users) => {
142
+ const formatUsers = (users, enableMultiTenantMode = true) => {
180
143
  if (!users || !Array.isArray(users)) return [];
144
+ if (!enableMultiTenantMode) {
145
+ return users.map((user) => ({
146
+ ...user,
147
+ id: user.username,
148
+ name: `${user.display_name}(${user.username})`,
149
+ tenantId: user.owner_tenant_id
150
+ }));
151
+ }
181
152
  return users.map((user) => ({
182
- id: user.bk_username || user.username,
153
+ id: user.bk_username,
183
154
  name: user.display_name,
184
155
  tenantId: user.owner_tenant_id,
185
156
  ...user
186
157
  }));
187
158
  };
188
159
  const getUserList = async (url, params) => {
189
- const { userIds, keyword, pageSize, page, appCode } = params;
190
- const { data: userList } = await useJSONP(url, {
160
+ const { userIds, keyword, pageSize = 20, page, appCode } = params;
161
+ const data = await jsonpRequest(url, {
191
162
  params: {
192
163
  exact_lookups: (userIds == null ? void 0 : userIds.join(",")) || void 0,
193
164
  fuzzy_lookups: keyword || void 0,
@@ -196,9 +167,9 @@ const getUserList = async (url, params) => {
196
167
  app_code: appCode || "bk-magicbox"
197
168
  }
198
169
  });
199
- return userList.value || [];
170
+ return (data == null ? void 0 : data.results) || [];
200
171
  };
201
- const useTenantData = (apiBaseUrl, tenantId) => {
172
+ const useTenantData = (apiBaseUrl, tenantId, enableMultiTenantMode = true) => {
202
173
  const tenants = ref({});
203
174
  const loading = ref(false);
204
175
  const fetchTenants = async () => {
@@ -223,7 +194,9 @@ const useTenantData = (apiBaseUrl, tenantId) => {
223
194
  }
224
195
  };
225
196
  onBeforeMount(() => {
226
- fetchTenants();
197
+ if (enableMultiTenantMode) {
198
+ fetchTenants();
199
+ }
227
200
  });
228
201
  return {
229
202
  tenants,
@@ -3029,7 +3002,7 @@ const calculateVisibleTags = (container, items, containerWidth) => {
3029
3002
  }
3030
3003
  return Math.max(1, visibleCount);
3031
3004
  };
3032
- const useUserSearch = (apiBaseUrl, tenantId) => {
3005
+ const useUserSearch = (apiBaseUrl, tenantId, enableMultiTenantMode = true) => {
3033
3006
  const searchResults = ref([]);
3034
3007
  const loading = ref(false);
3035
3008
  const searchQuery = ref("");
@@ -3038,7 +3011,7 @@ const useUserSearch = (apiBaseUrl, tenantId) => {
3038
3011
  searchResults.value = [];
3039
3012
  return;
3040
3013
  }
3041
- if (!apiBaseUrl || !tenantId) {
3014
+ if (enableMultiTenantMode && (!apiBaseUrl || !tenantId)) {
3042
3015
  console.warn("执行用户搜索需要提供有效的API基础URL和租户ID");
3043
3016
  return;
3044
3017
  }
@@ -3048,9 +3021,9 @@ const useUserSearch = (apiBaseUrl, tenantId) => {
3048
3021
  apiBaseUrl,
3049
3022
  tenantId,
3050
3023
  keyword,
3051
- enableMultiTenantMode: true
3024
+ enableMultiTenantMode
3052
3025
  });
3053
- searchResults.value = formatUsers(results);
3026
+ searchResults.value = formatUsers(results, enableMultiTenantMode);
3054
3027
  } catch (error) {
3055
3028
  console.error("用户搜索失败:", error);
3056
3029
  searchResults.value = [];
@@ -3392,13 +3365,16 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3392
3365
  /* STABLE */
3393
3366
  }, 8, ["loading"])
3394
3367
  ]),
3395
- _: 1
3396
- /* STABLE */
3368
+ default: withCtx(() => [
3369
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
3370
+ ]),
3371
+ _: 3
3372
+ /* FORWARDED */
3397
3373
  }, 8, ["is-show", "offset", "width"]);
3398
3374
  };
3399
3375
  }
3400
3376
  });
3401
- const SelectionPopover = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-a4132257"]]);
3377
+ const SelectionPopover = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-6380faf5"]]);
3402
3378
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
3403
3379
  ...{
3404
3380
  name: "UserTag"
@@ -3482,7 +3458,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3482
3458
  searchQuery,
3483
3459
  // clearSearch,
3484
3460
  handleSearchInput
3485
- } = useUserSearch(props.apiBaseUrl, props.tenantId);
3461
+ } = useUserSearch(props.apiBaseUrl, props.tenantId, props.enableMultiTenantMode);
3486
3462
  const containerRef = ref(null);
3487
3463
  const tagsContainerRef = ref(null);
3488
3464
  const sortableContainerRef = ref(null);
@@ -3500,7 +3476,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3500
3476
  return searchResults.value.filter((user) => !props.selectedUsers.some((selectedUser) => selectedUser.id === user.id)).filter((user) => !props.excludeUserIds.includes(user.id));
3501
3477
  });
3502
3478
  const userGroupFilter = computed(() => {
3503
- return props.userGroup.filter((group) => !props.selectedUsers.some((user) => user.id === group.id) && !group.hidden);
3479
+ return props.userGroup.filter((group) => {
3480
+ var _a, _b;
3481
+ const filtered = !props.selectedUsers.some((user) => user.id === group.id) && !group.hidden;
3482
+ if (filtered) {
3483
+ return ((_a = group.id) == null ? void 0 : _a.includes(searchQuery.value)) || ((_b = group.name) == null ? void 0 : _b.includes(searchQuery.value));
3484
+ }
3485
+ return false;
3486
+ });
3504
3487
  });
3505
3488
  const initSortable = () => {
3506
3489
  if (!props.draggable || !sortableContainerRef.value) return;
@@ -3609,7 +3592,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3609
3592
  usersList: [props.currentUserId],
3610
3593
  enableMultiTenantMode: props.enableMultiTenantMode
3611
3594
  });
3612
- const formattedUsers = formatUsers(result);
3595
+ const formattedUsers = formatUsers(result, props.enableMultiTenantMode);
3613
3596
  if (formattedUsers.length > 0) {
3614
3597
  if (!props.selectedUsers.some((item) => item.id === formattedUsers[0].id)) {
3615
3598
  emit("update:selectedUsers", [...props.selectedUsers, formattedUsers[0]]);
@@ -3637,7 +3620,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3637
3620
  usersList: users,
3638
3621
  enableMultiTenantMode: props.enableMultiTenantMode
3639
3622
  });
3640
- const formattedUsers = formatUsers(result);
3623
+ const formattedUsers = formatUsers(result, props.enableMultiTenantMode);
3641
3624
  if (formattedUsers.length > 0) {
3642
3625
  const updatedUsers = [...props.selectedUsers, ...formattedUsers];
3643
3626
  emit("update:selectedUsers", updatedUsers);
@@ -3740,210 +3723,215 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3740
3723
  class: normalizeClass(["multiple-selector", { "is-disabled": _ctx.disabled }])
3741
3724
  },
3742
3725
  [
3743
- createCommentVNode(" 聚焦状态 - 可编辑模式 "),
3744
- isFocused.value ? (openBlock(), createElementBlock(
3745
- "div",
3746
- {
3747
- key: 0,
3748
- ref_key: "tagsContainerRef",
3749
- ref: tagsContainerRef,
3750
- class: "tags-container focused",
3751
- onClick: withModifiers(handleContainerClick, ["stop"])
3752
- },
3753
- [
3754
- createCommentVNode(" 用户标签列表 "),
3755
- createElementVNode(
3726
+ createCommentVNode(" 下拉选项列表 "),
3727
+ createVNode(SelectionPopover, {
3728
+ "container-width": containerRef.value ? containerRef.value.offsetWidth : "auto",
3729
+ "cross-axis-offset": crossAxisOffset.value,
3730
+ "empty-text": _ctx.emptyText,
3731
+ "is-show": showDropdown.value,
3732
+ loading: unref(searchLoading),
3733
+ options: options.value,
3734
+ "render-list-item": _ctx.renderListItem,
3735
+ "search-query": unref(searchQuery),
3736
+ "tenant-id": _ctx.tenantId,
3737
+ tenants: _ctx.tenants,
3738
+ "user-group": userGroupFilter.value,
3739
+ "user-group-name": _ctx.userGroupName,
3740
+ onClickOutside: handleClickOutside,
3741
+ onSelectUser: addUser
3742
+ }, {
3743
+ default: withCtx(() => [
3744
+ createCommentVNode(" 聚焦状态 - 可编辑模式 "),
3745
+ isFocused.value ? (openBlock(), createElementBlock(
3756
3746
  "div",
3757
3747
  {
3758
- ref_key: "sortableContainerRef",
3759
- ref: sortableContainerRef,
3760
- class: "tag-list"
3748
+ key: 0,
3749
+ ref_key: "tagsContainerRef",
3750
+ ref: tagsContainerRef,
3751
+ class: "tags-container focused",
3752
+ onClick: withModifiers(handleContainerClick, ["stop"])
3761
3753
  },
3762
3754
  [
3763
- (openBlock(true), createElementBlock(
3764
- Fragment,
3765
- null,
3766
- renderList(_ctx.selectedUsers, (user, index) => {
3767
- return openBlock(), createElementBlock("div", {
3768
- class: "tag-wrapper",
3769
- key: user.id,
3770
- onClick: withModifiers(($event) => handleTagClick(index), ["stop"])
3771
- }, [
3772
- createVNode(UserTag, {
3773
- active: index === activeTagIndex.value,
3774
- "current-tenant-id": _ctx.tenantId,
3775
- draggable: _ctx.draggable,
3776
- "render-tag": _ctx.renderTag,
3777
- tenants: _ctx.tenants,
3778
- user,
3779
- onClick: ($event) => handleTagClick(index),
3780
- onClose: ($event) => removeUser(user)
3781
- }, null, 8, ["active", "current-tenant-id", "draggable", "render-tag", "tenants", "user", "onClick", "onClose"]),
3782
- createCommentVNode(" 在当前激活标签后插入输入框 "),
3783
- index === activeTagIndex.value && activeTagIndex.value !== _ctx.selectedUsers.length - 1 ? withDirectives((openBlock(), createElementBlock(
3784
- "input",
3785
- {
3786
- key: 0,
3787
- ref_for: true,
3788
- ref_key: "inlineInputRef",
3789
- ref: inlineInputRef,
3790
- class: "search-input inline",
3791
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(searchQuery) ? searchQuery.value = $event : null),
3792
- onFocus: handleInputFocus,
3793
- onInput: handleInput,
3794
- onKeydown: handleKeyDown,
3795
- onPaste: handlePaste
3796
- },
3797
- null,
3798
- 544
3799
- /* NEED_HYDRATION, NEED_PATCH */
3800
- )), [
3801
- [vModelText, unref(searchQuery)]
3802
- ]) : createCommentVNode("v-if", true)
3803
- ], 8, _hoisted_1$1);
3804
- }),
3805
- 128
3806
- /* KEYED_FRAGMENT */
3807
- )),
3808
- createCommentVNode(" 最后一个输入框 "),
3809
- activeTagIndex.value === -1 || activeTagIndex.value === _ctx.selectedUsers.length - 1 ? withDirectives((openBlock(), createElementBlock("input", {
3810
- key: 0,
3811
- ref_key: "lastInputRef",
3812
- ref: lastInputRef,
3813
- class: "search-input last",
3814
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(searchQuery) ? searchQuery.value = $event : null),
3815
- placeholder: !_ctx.selectedUsers.length ? _ctx.placeholder : "",
3816
- onFocus: handleInputFocus,
3817
- onInput: handleInput,
3818
- onKeydown: handleKeyDown,
3819
- onPaste: handlePaste
3820
- }, null, 40, _hoisted_2$1)), [
3821
- [vModelText, unref(searchQuery)]
3822
- ]) : createCommentVNode("v-if", true),
3823
- createCommentVNode(' ""标签 '),
3824
- createVNode(MeTag, {
3825
- "current-user-id": _ctx.currentUserId,
3826
- "is-disabled": !!_ctx.currentUserId && _ctx.selectedUsers.some((user) => user.id === _ctx.currentUserId),
3827
- onClick: addCurrentUser
3828
- }, null, 8, ["current-user-id", "is-disabled"])
3755
+ createCommentVNode(" 用户标签列表 "),
3756
+ createElementVNode(
3757
+ "div",
3758
+ {
3759
+ ref_key: "sortableContainerRef",
3760
+ ref: sortableContainerRef,
3761
+ class: "tag-list"
3762
+ },
3763
+ [
3764
+ (openBlock(true), createElementBlock(
3765
+ Fragment,
3766
+ null,
3767
+ renderList(_ctx.selectedUsers, (user, index) => {
3768
+ return openBlock(), createElementBlock("div", {
3769
+ class: "tag-wrapper",
3770
+ key: user.id,
3771
+ onClick: withModifiers(($event) => handleTagClick(index), ["stop"])
3772
+ }, [
3773
+ createVNode(UserTag, {
3774
+ active: index === activeTagIndex.value,
3775
+ "current-tenant-id": _ctx.tenantId,
3776
+ draggable: _ctx.draggable,
3777
+ "render-tag": _ctx.renderTag,
3778
+ tenants: _ctx.tenants,
3779
+ user,
3780
+ onClick: ($event) => handleTagClick(index),
3781
+ onClose: ($event) => removeUser(user)
3782
+ }, null, 8, ["active", "current-tenant-id", "draggable", "render-tag", "tenants", "user", "onClick", "onClose"]),
3783
+ createCommentVNode(" 在当前激活标签后插入输入框 "),
3784
+ index === activeTagIndex.value && activeTagIndex.value !== _ctx.selectedUsers.length - 1 ? withDirectives((openBlock(), createElementBlock(
3785
+ "input",
3786
+ {
3787
+ key: 0,
3788
+ ref_for: true,
3789
+ ref_key: "inlineInputRef",
3790
+ ref: inlineInputRef,
3791
+ class: "search-input inline",
3792
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(searchQuery) ? searchQuery.value = $event : null),
3793
+ onFocus: handleInputFocus,
3794
+ onInput: handleInput,
3795
+ onKeydown: handleKeyDown,
3796
+ onPaste: handlePaste
3797
+ },
3798
+ null,
3799
+ 544
3800
+ /* NEED_HYDRATION, NEED_PATCH */
3801
+ )), [
3802
+ [vModelText, unref(searchQuery)]
3803
+ ]) : createCommentVNode("v-if", true)
3804
+ ], 8, _hoisted_1$1);
3805
+ }),
3806
+ 128
3807
+ /* KEYED_FRAGMENT */
3808
+ )),
3809
+ createCommentVNode(" 最后一个输入框 "),
3810
+ activeTagIndex.value === -1 || activeTagIndex.value === _ctx.selectedUsers.length - 1 ? withDirectives((openBlock(), createElementBlock("input", {
3811
+ key: 0,
3812
+ ref_key: "lastInputRef",
3813
+ ref: lastInputRef,
3814
+ class: "search-input last",
3815
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(searchQuery) ? searchQuery.value = $event : null),
3816
+ placeholder: !_ctx.selectedUsers.length ? _ctx.placeholder : "",
3817
+ onFocus: handleInputFocus,
3818
+ onInput: handleInput,
3819
+ onKeydown: handleKeyDown,
3820
+ onPaste: handlePaste
3821
+ }, null, 40, _hoisted_2$1)), [
3822
+ [vModelText, unref(searchQuery)]
3823
+ ]) : createCommentVNode("v-if", true),
3824
+ createCommentVNode(' "我"标签 '),
3825
+ createVNode(MeTag, {
3826
+ "current-user-id": _ctx.currentUserId,
3827
+ "is-disabled": !!_ctx.currentUserId && _ctx.selectedUsers.some((user) => user.id === _ctx.currentUserId),
3828
+ onClick: addCurrentUser
3829
+ }, null, 8, ["current-user-id", "is-disabled"])
3830
+ ],
3831
+ 512
3832
+ /* NEED_PATCH */
3833
+ )
3829
3834
  ],
3830
3835
  512
3831
3836
  /* NEED_PATCH */
3832
- )
3833
- ],
3834
- 512
3835
- /* NEED_PATCH */
3836
- )) : (openBlock(), createElementBlock(
3837
- Fragment,
3838
- { key: 1 },
3839
- [
3840
- createCommentVNode(" 未聚焦状态 - 只读展示模式 "),
3841
- createElementVNode(
3842
- "div",
3843
- {
3844
- ref_key: "collapsedContainerRef",
3845
- ref: collapsedContainerRef,
3846
- class: "tags-container collapsed",
3847
- onClick: withModifiers(handleFocus, ["stop"])
3848
- },
3837
+ )) : (openBlock(), createElementBlock(
3838
+ Fragment,
3839
+ { key: 1 },
3849
3840
  [
3850
- (openBlock(true), createElementBlock(
3851
- Fragment,
3852
- null,
3853
- renderList(visibleUsers.value, (user) => {
3854
- return openBlock(), createBlock(UserTag, {
3855
- "current-tenant-id": _ctx.tenantId,
3856
- key: user.id,
3857
- "render-tag": _ctx.renderTag,
3858
- "show-tenant": true,
3859
- tenants: _ctx.tenants,
3860
- user,
3861
- onClick: handleFocus,
3862
- onClose: ($event) => removeUser(user)
3863
- }, null, 8, ["current-tenant-id", "render-tag", "tenants", "user", "onClose"]);
3864
- }),
3865
- 128
3866
- /* KEYED_FRAGMENT */
3867
- )),
3868
- createCommentVNode(" 显示折叠标签数量 "),
3869
- hiddenCount.value > 0 ? (openBlock(), createBlock(unref(Popover), {
3870
- key: 0,
3871
- placement: "top"
3872
- }, {
3873
- content: withCtx(() => [
3841
+ createCommentVNode(" 未聚焦状态 - 只读展示模式 "),
3842
+ createElementVNode(
3843
+ "div",
3844
+ {
3845
+ ref_key: "collapsedContainerRef",
3846
+ ref: collapsedContainerRef,
3847
+ class: "tags-container collapsed",
3848
+ onClick: withModifiers(handleFocus, ["stop"])
3849
+ },
3850
+ [
3874
3851
  (openBlock(true), createElementBlock(
3875
3852
  Fragment,
3876
3853
  null,
3877
- renderList(_ctx.selectedUsers.slice(visibleUsers.value.length), (user) => {
3878
- return openBlock(), createBlock(unref(UserRender), {
3854
+ renderList(visibleUsers.value, (user) => {
3855
+ return openBlock(), createBlock(UserTag, {
3856
+ "current-tenant-id": _ctx.tenantId,
3879
3857
  key: user.id,
3880
- "tenant-id": _ctx.tenantId,
3858
+ "render-tag": _ctx.renderTag,
3859
+ "show-tenant": true,
3881
3860
  tenants: _ctx.tenants,
3882
- user
3883
- }, null, 8, ["tenant-id", "tenants", "user"]);
3861
+ user,
3862
+ onClick: handleFocus,
3863
+ onClose: ($event) => removeUser(user)
3864
+ }, null, 8, ["current-tenant-id", "render-tag", "tenants", "user", "onClose"]);
3884
3865
  }),
3885
3866
  128
3886
3867
  /* KEYED_FRAGMENT */
3887
- ))
3888
- ]),
3889
- default: withCtx(() => [
3890
- createVNode(unref(Tag), null, {
3868
+ )),
3869
+ createCommentVNode(" 显示折叠标签数量 "),
3870
+ hiddenCount.value > 0 ? (openBlock(), createBlock(unref(Popover), {
3871
+ key: 0,
3872
+ placement: "top"
3873
+ }, {
3874
+ content: withCtx(() => [
3875
+ (openBlock(true), createElementBlock(
3876
+ Fragment,
3877
+ null,
3878
+ renderList(_ctx.selectedUsers.slice(visibleUsers.value.length), (user) => {
3879
+ return openBlock(), createBlock(unref(UserRender), {
3880
+ key: user.id,
3881
+ "tenant-id": _ctx.tenantId,
3882
+ tenants: _ctx.tenants,
3883
+ user
3884
+ }, null, 8, ["tenant-id", "tenants", "user"]);
3885
+ }),
3886
+ 128
3887
+ /* KEYED_FRAGMENT */
3888
+ ))
3889
+ ]),
3891
3890
  default: withCtx(() => [
3892
- createTextVNode(
3893
- " +" + toDisplayString(hiddenCount.value),
3894
- 1
3895
- /* TEXT */
3896
- )
3891
+ createVNode(unref(Tag), null, {
3892
+ default: withCtx(() => [
3893
+ createTextVNode(
3894
+ " +" + toDisplayString(hiddenCount.value),
3895
+ 1
3896
+ /* TEXT */
3897
+ )
3898
+ ]),
3899
+ _: 1
3900
+ /* STABLE */
3901
+ })
3897
3902
  ]),
3898
3903
  _: 1
3899
3904
  /* STABLE */
3900
- })
3901
- ]),
3902
- _: 1
3903
- /* STABLE */
3904
- })) : createCommentVNode("v-if", true),
3905
- createCommentVNode(" 搜索输入框 "),
3906
- withDirectives(createElementVNode("input", {
3907
- ref_key: "collapsedInputRef",
3908
- ref: collapsedInputRef,
3909
- class: "search-input collapsed",
3910
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(searchQuery) ? searchQuery.value = $event : null),
3911
- placeholder: !_ctx.selectedUsers.length ? _ctx.placeholder : "",
3912
- onFocus: handleFocus
3913
- }, null, 40, _hoisted_3), [
3914
- [vModelText, unref(searchQuery)]
3915
- ]),
3916
- createCommentVNode(' 未聚焦状态下的"我"标签 '),
3917
- createVNode(MeTag, {
3918
- "current-user-id": _ctx.currentUserId,
3919
- "is-disabled": !!_ctx.currentUserId && _ctx.selectedUsers.some((user) => user[props.exactSearchKey] === _ctx.currentUserId),
3920
- onClick: addCurrentUser
3921
- }, null, 8, ["current-user-id", "is-disabled"])
3905
+ })) : createCommentVNode("v-if", true),
3906
+ createCommentVNode(" 搜索输入框 "),
3907
+ withDirectives(createElementVNode("input", {
3908
+ ref_key: "collapsedInputRef",
3909
+ ref: collapsedInputRef,
3910
+ class: "search-input collapsed",
3911
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(searchQuery) ? searchQuery.value = $event : null),
3912
+ placeholder: !_ctx.selectedUsers.length ? _ctx.placeholder : "",
3913
+ onFocus: handleFocus
3914
+ }, null, 40, _hoisted_3), [
3915
+ [vModelText, unref(searchQuery)]
3916
+ ]),
3917
+ createCommentVNode(' 未聚焦状态下的"我"标签 '),
3918
+ createVNode(MeTag, {
3919
+ "current-user-id": _ctx.currentUserId,
3920
+ "is-disabled": !!_ctx.currentUserId && _ctx.selectedUsers.some((user) => user[props.exactSearchKey] === _ctx.currentUserId),
3921
+ onClick: addCurrentUser
3922
+ }, null, 8, ["current-user-id", "is-disabled"])
3923
+ ],
3924
+ 512
3925
+ /* NEED_PATCH */
3926
+ )
3922
3927
  ],
3923
- 512
3924
- /* NEED_PATCH */
3925
- )
3926
- ],
3927
- 2112
3928
- /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
3929
- )),
3930
- createCommentVNode(" 下拉选项列表 "),
3931
- createVNode(SelectionPopover, {
3932
- "container-width": containerRef.value ? containerRef.value.offsetWidth : "auto",
3933
- "cross-axis-offset": crossAxisOffset.value,
3934
- "empty-text": _ctx.emptyText,
3935
- "is-show": showDropdown.value,
3936
- loading: unref(searchLoading),
3937
- options: options.value,
3938
- "render-list-item": _ctx.renderListItem,
3939
- "search-query": unref(searchQuery),
3940
- "tenant-id": _ctx.tenantId,
3941
- tenants: _ctx.tenants,
3942
- "user-group": userGroupFilter.value,
3943
- "user-group-name": _ctx.userGroupName,
3944
- onClickOutside: handleClickOutside,
3945
- onSelectUser: addUser
3946
- }, null, 8, ["container-width", "cross-axis-offset", "empty-text", "is-show", "loading", "options", "render-list-item", "search-query", "tenant-id", "tenants", "user-group", "user-group-name"])
3928
+ 2112
3929
+ /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
3930
+ ))
3931
+ ]),
3932
+ _: 1
3933
+ /* STABLE */
3934
+ }, 8, ["container-width", "cross-axis-offset", "empty-text", "is-show", "loading", "options", "render-list-item", "search-query", "tenant-id", "tenants", "user-group", "user-group-name"])
3947
3935
  ],
3948
3936
  2
3949
3937
  /* CLASS */
@@ -3951,7 +3939,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3951
3939
  };
3952
3940
  }
3953
3941
  });
3954
- const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-bebe517d"]]);
3942
+ const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-69acfacb"]]);
3955
3943
  const _hoisted_1 = { class: "input-container" };
3956
3944
  const _hoisted_2 = ["placeholder"];
3957
3945
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
@@ -3988,7 +3976,14 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3988
3976
  const searchQuery = ref("");
3989
3977
  const showDropdown = ref(false);
3990
3978
  const userGroupFilter = computed(() => {
3991
- return props.userGroup.filter((group) => group.id !== selectedUser.value && !group.hidden);
3979
+ return props.userGroup.filter((group) => {
3980
+ var _a, _b;
3981
+ const filtered = group.id !== selectedUser.value && !group.hidden;
3982
+ if (filtered) {
3983
+ return ((_a = group.id) == null ? void 0 : _a.includes(searchQuery.value)) || ((_b = group.name) == null ? void 0 : _b.includes(searchQuery.value));
3984
+ }
3985
+ return false;
3986
+ });
3992
3987
  });
3993
3988
  const selectedUserInfo = computed(() => {
3994
3989
  const userGroup = (props.userGroup || []).map((group) => ({
@@ -4012,7 +4007,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4012
4007
  usersList: [props.modelValue],
4013
4008
  enableMultiTenantMode: props.enableMultiTenantMode
4014
4009
  });
4015
- options.value = formatUsers(result).filter((user) => !props.excludeUserIds.includes(user.id));
4010
+ options.value = formatUsers(result, props.enableMultiTenantMode).filter(
4011
+ (user) => !props.excludeUserIds.includes(user.id)
4012
+ );
4016
4013
  if (props.userGroup.length > 0) {
4017
4014
  const groupResult = props.userGroup.filter((group) => group.id == props.modelValue);
4018
4015
  options.value = groupResult.map((group) => ({
@@ -4043,7 +4040,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4043
4040
  usersList: [props.currentUserId],
4044
4041
  enableMultiTenantMode: props.enableMultiTenantMode
4045
4042
  });
4046
- const formattedResults = formatUsers(result);
4043
+ const formattedResults = formatUsers(result, props.enableMultiTenantMode);
4047
4044
  if (formattedResults.length > 0) {
4048
4045
  options.value = formattedResults.filter((user) => !props.excludeUserIds.includes(user.id));
4049
4046
  addUser(formattedResults[0]);
@@ -4065,7 +4062,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4065
4062
  keyword,
4066
4063
  enableMultiTenantMode: props.enableMultiTenantMode
4067
4064
  });
4068
- options.value = formatUsers(result).filter((user) => !selectedUser.value || user.id !== selectedUser.value).filter((user) => !props.excludeUserIds.includes(user.id));
4065
+ options.value = formatUsers(result, props.enableMultiTenantMode).filter((user) => !selectedUser.value || user.id !== selectedUser.value).filter((user) => !props.excludeUserIds.includes(user.id));
4069
4066
  } catch (error) {
4070
4067
  console.error("获取用户列表失败:", error);
4071
4068
  options.value = [];
@@ -4112,39 +4109,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4112
4109
  class: normalizeClass(["single-selector", { "is-disabled": _ctx.disabled }])
4113
4110
  },
4114
4111
  [
4115
- createCommentVNode(" 输入框 "),
4116
- createElementVNode("div", _hoisted_1, [
4117
- createCommentVNode(" 用户标签显示 "),
4118
- selectedUserInfo.value ? (openBlock(), createElementBlock("div", {
4119
- key: 0,
4120
- onClick: withModifiers(removeSelectedUser, ["stop"])
4121
- }, [
4122
- createVNode(UserTag, {
4123
- "current-tenant-id": _ctx.tenantId,
4124
- "render-tag": _ctx.renderTag,
4125
- tenants: _ctx.tenants,
4126
- user: selectedUserInfo.value,
4127
- onClose: removeSelectedUser
4128
- }, null, 8, ["current-tenant-id", "render-tag", "tenants", "user"])
4129
- ])) : createCommentVNode("v-if", true),
4130
- withDirectives(createElementVNode("input", {
4131
- ref_key: "inputRef",
4132
- ref: inputRef,
4133
- class: "search-input",
4134
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchQuery.value = $event),
4135
- placeholder: selectedUserInfo.value ? "" : _ctx.placeholder,
4136
- onFocus: handleInputFocus,
4137
- onInput: handleInput
4138
- }, null, 40, _hoisted_2), [
4139
- [vModelText, searchQuery.value]
4140
- ]),
4141
- createCommentVNode(' "我"标签 '),
4142
- createVNode(MeTag, {
4143
- "current-user-id": _ctx.currentUserId,
4144
- "is-disabled": !!_ctx.currentUserId && !!selectedUserInfo.value && selectedUserInfo.value[_ctx.exactSearchKey] === _ctx.currentUserId,
4145
- onClick: addCurrentUser
4146
- }, null, 8, ["current-user-id", "is-disabled"])
4147
- ]),
4148
4112
  createCommentVNode(" 使用新的公共下拉选项组件 "),
4149
4113
  createVNode(SelectionPopover, {
4150
4114
  "container-width": containerRef.value ? containerRef.value.offsetWidth : "auto",
@@ -4159,7 +4123,45 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4159
4123
  "user-group": userGroupFilter.value,
4160
4124
  "user-group-name": _ctx.userGroupName,
4161
4125
  onSelectUser: addUser
4162
- }, null, 8, ["container-width", "empty-text", "is-show", "loading", "options", "render-list-item", "search-query", "tenant-id", "tenants", "user-group", "user-group-name"])
4126
+ }, {
4127
+ default: withCtx(() => [
4128
+ createCommentVNode(" 输入框 "),
4129
+ createElementVNode("div", _hoisted_1, [
4130
+ createCommentVNode(" 用户标签显示 "),
4131
+ selectedUserInfo.value ? (openBlock(), createElementBlock("div", {
4132
+ key: 0,
4133
+ onClick: withModifiers(removeSelectedUser, ["stop"])
4134
+ }, [
4135
+ createVNode(UserTag, {
4136
+ "current-tenant-id": _ctx.tenantId,
4137
+ "render-tag": _ctx.renderTag,
4138
+ tenants: _ctx.tenants,
4139
+ user: selectedUserInfo.value,
4140
+ onClose: removeSelectedUser
4141
+ }, null, 8, ["current-tenant-id", "render-tag", "tenants", "user"])
4142
+ ])) : createCommentVNode("v-if", true),
4143
+ withDirectives(createElementVNode("input", {
4144
+ ref_key: "inputRef",
4145
+ ref: inputRef,
4146
+ class: "search-input",
4147
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchQuery.value = $event),
4148
+ placeholder: selectedUserInfo.value ? "" : _ctx.placeholder,
4149
+ onFocus: handleInputFocus,
4150
+ onInput: handleInput
4151
+ }, null, 40, _hoisted_2), [
4152
+ [vModelText, searchQuery.value]
4153
+ ]),
4154
+ createCommentVNode(' "我"标签 '),
4155
+ createVNode(MeTag, {
4156
+ "current-user-id": _ctx.currentUserId,
4157
+ "is-disabled": !!_ctx.currentUserId && !!selectedUserInfo.value && selectedUserInfo.value[_ctx.exactSearchKey] === _ctx.currentUserId,
4158
+ onClick: addCurrentUser
4159
+ }, null, 8, ["current-user-id", "is-disabled"])
4160
+ ])
4161
+ ]),
4162
+ _: 1
4163
+ /* STABLE */
4164
+ }, 8, ["container-width", "empty-text", "is-show", "loading", "options", "render-list-item", "search-query", "tenant-id", "tenants", "user-group", "user-group-name"])
4163
4165
  ],
4164
4166
  2
4165
4167
  /* CLASS */
@@ -4169,7 +4171,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4169
4171
  };
4170
4172
  }
4171
4173
  });
4172
- const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-67f2ee6a"]]);
4174
+ const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d52d578d"]]);
4173
4175
  const _sfc_main = /* @__PURE__ */ defineComponent({
4174
4176
  ...{
4175
4177
  name: "BkUserSelector"
@@ -4191,7 +4193,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4191
4193
  renderListItem: {},
4192
4194
  renderTag: {},
4193
4195
  excludeUserIds: { default: () => [] },
4194
- enableMultiTenantMode: { type: Boolean, default: false }
4196
+ enableMultiTenantMode: { type: Boolean, default: true }
4195
4197
  },
4196
4198
  emits: ["update:modelValue", "change"],
4197
4199
  setup(__props, { emit: __emit }) {
@@ -4200,7 +4202,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4200
4202
  });
4201
4203
  const props = __props;
4202
4204
  const emit = __emit;
4203
- const { tenants = {} } = useTenantData(props.apiBaseUrl, props.tenantId);
4205
+ const { tenants = {} } = useTenantData(props.apiBaseUrl, props.tenantId, props.enableMultiTenantMode);
4204
4206
  const selectedUsers = ref([]);
4205
4207
  const selectedUser = ref(props.multiple ? "" : props.modelValue);
4206
4208
  const selectedUserIds = computed(() => {
@@ -4227,7 +4229,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4227
4229
  usersList: ids,
4228
4230
  enableMultiTenantMode: props.enableMultiTenantMode
4229
4231
  });
4230
- selectedUsers.value = [...selected, ...formatUsers(result)];
4232
+ const selectedList = [...selected, ...formatUsers(result, props.enableMultiTenantMode)];
4233
+ selectedUsers.value = ids.map((id) => selectedList.find((user) => user.id === id)).filter(Boolean);
4231
4234
  } catch (error) {
4232
4235
  console.error("获取选中用户信息失败:", error);
4233
4236
  }
@@ -4334,7 +4337,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4334
4337
  };
4335
4338
  }
4336
4339
  });
4337
- const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-30b84150"]]);
4340
+ const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-02466e5e"]]);
4338
4341
  export {
4339
4342
  BkUserSelector,
4340
4343
  BkUserSelector as default