@blueking/bk-user-selector 0.0.29-beta.2 → 0.0.29-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/bk-user-selector",
3
- "version": "0.0.29-beta.2",
3
+ "version": "0.0.29-beta.4",
4
4
  "description": "蓝鲸用户选择器",
5
5
  "license": "MIT",
6
6
  "author": "Tencent BlueKing",
@@ -39,7 +39,7 @@ export declare const lookupUsers: (params: {
39
39
  * @param users - API返回的用户列表
40
40
  * @returns 格式化后的用户列表
41
41
  */
42
- export declare const formatUsers: (users: User[]) => FormattedUser[];
42
+ export declare const formatUsers: (users: User[], enableMultiTenantMode?: boolean) => FormattedUser[];
43
43
  /**
44
44
  * 获取用户列表 兼容旧版本的人员选择器
45
45
  * @param url 请求的 URL
@@ -4,6 +4,8 @@ export interface JSONPOptions {
4
4
  timeout?: number;
5
5
  /** 请求参数 */
6
6
  params?: Record<string, string | undefined>;
7
+ /** 是否携带凭证(cookie),默认为 true */
8
+ withCredentials?: boolean;
7
9
  }
8
10
  export interface JSONPResult<T> {
9
11
  /** 响应数据 */
@@ -10,7 +10,7 @@ import { type FormattedUser } from '../types';
10
10
  * @param tenantId - 租户ID
11
11
  * @returns 用户搜索相关状态和方法
12
12
  */
13
- export declare const useUserSearch: (apiBaseUrl: string, tenantId: string) => {
13
+ export declare const useUserSearch: (apiBaseUrl: string, tenantId: string, enableMultiTenantMode?: boolean) => {
14
14
  searchResults: Ref<FormattedUser[], FormattedUser[]>;
15
15
  loading: Ref<boolean, boolean>;
16
16
  searchQuery: Ref<string, string>;
@@ -1,5 +1,5 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_vue__ from "@blueking/bkui-library";
2
- import { shallowRef, watchEffect, unref, onScopeDispose, ref, onBeforeMount, defineComponent, openBlock, createElementBlock, normalizeClass, withModifiers, createCommentVNode, h as h$1, computed, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, Fragment, renderList, watch, nextTick, onMounted, withDirectives, isRef, vModelText, createTextVNode, createApp } from "@blueking/bkui-library";
2
+ import { unref, ref, onBeforeMount, defineComponent, openBlock, createElementBlock, normalizeClass, withModifiers, createCommentVNode, h as h$1, computed, createBlock, withCtx, createVNode, createElementVNode, toDisplayString, Fragment, renderList, watch, nextTick, onMounted, withDirectives, isRef, vModelText, createTextVNode, createApp } from "@blueking/bkui-library";
3
3
  var top = "top";
4
4
  var bottom = "bottom";
5
5
  var right = "right";
@@ -10678,10 +10678,15 @@ const generateCallbackName = () => {
10678
10678
  const jsonpRequest = (requestUrl, options = {}) => {
10679
10679
  return new Promise((resolve, reject) => {
10680
10680
  const url = unref(requestUrl);
10681
- const { timeout = 1e3 * 60 * 2, params } = options;
10681
+ const { timeout = 1e3 * 60 * 2, params, withCredentials = true } = options;
10682
10682
  const callbackName = generateCallbackName();
10683
10683
  const script = document.createElement("script");
10684
10684
  let timeoutId;
10685
+ if (withCredentials) {
10686
+ script.crossOrigin = "use-credentials";
10687
+ } else {
10688
+ script.crossOrigin = "anonymous";
10689
+ }
10685
10690
  const cleanup = () => {
10686
10691
  if (timeoutId) {
10687
10692
  clearTimeout(timeoutId);
@@ -10695,7 +10700,7 @@ const jsonpRequest = (requestUrl, options = {}) => {
10695
10700
  };
10696
10701
  window[callbackName] = (data2) => {
10697
10702
  cleanup();
10698
- resolve(data2);
10703
+ resolve(data2.data || data2);
10699
10704
  };
10700
10705
  timeoutId = setTimeout(() => {
10701
10706
  cleanup();
@@ -10711,48 +10716,6 @@ const jsonpRequest = (requestUrl, options = {}) => {
10711
10716
  document.head.appendChild(script);
10712
10717
  });
10713
10718
  };
10714
- const useJSONP = (url, options = {}) => {
10715
- const data2 = shallowRef(null);
10716
- const loading2 = shallowRef(false);
10717
- const error3 = shallowRef(null);
10718
- let abortFlag = false;
10719
- const executeRequest = async (requestUrl) => {
10720
- if (!requestUrl) return;
10721
- loading2.value = true;
10722
- error3.value = null;
10723
- abortFlag = false;
10724
- try {
10725
- const result = await jsonpRequest(requestUrl, options);
10726
- if (!abortFlag) {
10727
- data2.value = result;
10728
- }
10729
- } catch (err) {
10730
- if (!abortFlag) {
10731
- const errorObj = err instanceof Error ? err : new Error(String(err));
10732
- error3.value = errorObj;
10733
- }
10734
- } finally {
10735
- if (!abortFlag) {
10736
- loading2.value = false;
10737
- }
10738
- }
10739
- };
10740
- const stopWatcher = watchEffect(() => {
10741
- executeRequest(unref(url));
10742
- });
10743
- onScopeDispose(() => {
10744
- abortFlag = true;
10745
- stopWatcher();
10746
- });
10747
- return {
10748
- data: data2,
10749
- loading: loading2,
10750
- error: error3,
10751
- refetch: () => {
10752
- executeRequest(unref(url));
10753
- }
10754
- };
10755
- };
10756
10719
  const getTenants = async (apiBaseUrl, tenantId) => {
10757
10720
  if (!apiBaseUrl || !tenantId) {
10758
10721
  console.warn("获取租户信息需要提供有效的apiBaseUrl和租户ID");
@@ -10779,7 +10742,7 @@ const getTenants = async (apiBaseUrl, tenantId) => {
10779
10742
  };
10780
10743
  const searchUsers = async (params) => {
10781
10744
  const { apiBaseUrl, tenantId, keyword, enableMultiTenantMode = true } = params;
10782
- if (enableMultiTenantMode) {
10745
+ if (!enableMultiTenantMode) {
10783
10746
  const userList = await getUserList(apiBaseUrl, {
10784
10747
  keyword,
10785
10748
  pageSize: 100,
@@ -10815,7 +10778,7 @@ const searchUsers = async (params) => {
10815
10778
  const lookupUsers = async (params) => {
10816
10779
  const { apiBaseUrl, tenantId, exactSearchKey = "bk_username", usersList = [], enableMultiTenantMode = true } = params;
10817
10780
  const users = usersList.filter((user) => user).map((user) => user.trim());
10818
- if (enableMultiTenantMode) {
10781
+ if (!enableMultiTenantMode) {
10819
10782
  const userList = await getUserList(apiBaseUrl, {
10820
10783
  userIds: users
10821
10784
  }).catch(() => {
@@ -10846,18 +10809,26 @@ const lookupUsers = async (params) => {
10846
10809
  return [];
10847
10810
  }
10848
10811
  };
10849
- const formatUsers = (users) => {
10812
+ const formatUsers = (users, enableMultiTenantMode = true) => {
10850
10813
  if (!users || !Array.isArray(users)) return [];
10814
+ if (!enableMultiTenantMode) {
10815
+ return users.map((user) => ({
10816
+ ...user,
10817
+ id: user.username,
10818
+ name: `${user.display_name}(${user.username})`,
10819
+ tenantId: user.owner_tenant_id
10820
+ }));
10821
+ }
10851
10822
  return users.map((user) => ({
10852
- id: user.bk_username || user.username,
10823
+ id: user.bk_username,
10853
10824
  name: user.display_name,
10854
10825
  tenantId: user.owner_tenant_id,
10855
10826
  ...user
10856
10827
  }));
10857
10828
  };
10858
10829
  const getUserList = async (url, params) => {
10859
- const { userIds, keyword, pageSize, page, appCode } = params;
10860
- const { data: userList } = await useJSONP(url, {
10830
+ const { userIds, keyword, pageSize = 20, page, appCode } = params;
10831
+ const data2 = await jsonpRequest(url, {
10861
10832
  params: {
10862
10833
  exact_lookups: (userIds == null ? void 0 : userIds.join(",")) || void 0,
10863
10834
  fuzzy_lookups: keyword || void 0,
@@ -10866,7 +10837,7 @@ const getUserList = async (url, params) => {
10866
10837
  app_code: appCode || "bk-magicbox"
10867
10838
  }
10868
10839
  });
10869
- return userList.value || [];
10840
+ return (data2 == null ? void 0 : data2.results) || [];
10870
10841
  };
10871
10842
  const useTenantData = (apiBaseUrl, tenantId, enableMultiTenantMode = true) => {
10872
10843
  const tenants = ref({});
@@ -13697,7 +13668,7 @@ const calculateVisibleTags = (container, items, containerWidth) => {
13697
13668
  }
13698
13669
  return Math.max(1, visibleCount);
13699
13670
  };
13700
- const useUserSearch = (apiBaseUrl, tenantId) => {
13671
+ const useUserSearch = (apiBaseUrl, tenantId, enableMultiTenantMode = true) => {
13701
13672
  const searchResults = ref([]);
13702
13673
  const loading2 = ref(false);
13703
13674
  const searchQuery = ref("");
@@ -13716,9 +13687,9 @@ const useUserSearch = (apiBaseUrl, tenantId) => {
13716
13687
  apiBaseUrl,
13717
13688
  tenantId,
13718
13689
  keyword,
13719
- enableMultiTenantMode: true
13690
+ enableMultiTenantMode
13720
13691
  });
13721
- searchResults.value = formatUsers(results);
13692
+ searchResults.value = formatUsers(results, enableMultiTenantMode);
13722
13693
  } catch (error3) {
13723
13694
  console.error("用户搜索失败:", error3);
13724
13695
  searchResults.value = [];
@@ -14150,7 +14121,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
14150
14121
  searchQuery,
14151
14122
  // clearSearch,
14152
14123
  handleSearchInput
14153
- } = useUserSearch(props2.apiBaseUrl, props2.tenantId);
14124
+ } = useUserSearch(props2.apiBaseUrl, props2.tenantId, props2.enableMultiTenantMode);
14154
14125
  const containerRef = ref(null);
14155
14126
  const tagsContainerRef = ref(null);
14156
14127
  const sortableContainerRef = ref(null);
@@ -14277,7 +14248,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
14277
14248
  usersList: [props2.currentUserId],
14278
14249
  enableMultiTenantMode: props2.enableMultiTenantMode
14279
14250
  });
14280
- const formattedUsers = formatUsers(result);
14251
+ const formattedUsers = formatUsers(result, props2.enableMultiTenantMode);
14281
14252
  if (formattedUsers.length > 0) {
14282
14253
  if (!props2.selectedUsers.some((item) => item.id === formattedUsers[0].id)) {
14283
14254
  emit("update:selectedUsers", [...props2.selectedUsers, formattedUsers[0]]);
@@ -14305,7 +14276,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
14305
14276
  usersList: users,
14306
14277
  enableMultiTenantMode: props2.enableMultiTenantMode
14307
14278
  });
14308
- const formattedUsers = formatUsers(result);
14279
+ const formattedUsers = formatUsers(result, props2.enableMultiTenantMode);
14309
14280
  if (formattedUsers.length > 0) {
14310
14281
  const updatedUsers = [...props2.selectedUsers, ...formattedUsers];
14311
14282
  emit("update:selectedUsers", updatedUsers);
@@ -14619,7 +14590,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
14619
14590
  };
14620
14591
  }
14621
14592
  });
14622
- const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-bebe517d"]]);
14593
+ const MultipleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-7ff53892"]]);
14623
14594
  const _hoisted_1 = { class: "input-container" };
14624
14595
  const _hoisted_2 = ["placeholder"];
14625
14596
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
@@ -14680,7 +14651,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
14680
14651
  usersList: [props2.modelValue],
14681
14652
  enableMultiTenantMode: props2.enableMultiTenantMode
14682
14653
  });
14683
- options.value = formatUsers(result).filter((user) => !props2.excludeUserIds.includes(user.id));
14654
+ options.value = formatUsers(result, props2.enableMultiTenantMode).filter(
14655
+ (user) => !props2.excludeUserIds.includes(user.id)
14656
+ );
14684
14657
  if (props2.userGroup.length > 0) {
14685
14658
  const groupResult = props2.userGroup.filter((group) => group.id == props2.modelValue);
14686
14659
  options.value = groupResult.map((group) => ({
@@ -14711,7 +14684,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
14711
14684
  usersList: [props2.currentUserId],
14712
14685
  enableMultiTenantMode: props2.enableMultiTenantMode
14713
14686
  });
14714
- const formattedResults = formatUsers(result);
14687
+ const formattedResults = formatUsers(result, props2.enableMultiTenantMode);
14715
14688
  if (formattedResults.length > 0) {
14716
14689
  options.value = formattedResults.filter((user) => !props2.excludeUserIds.includes(user.id));
14717
14690
  addUser(formattedResults[0]);
@@ -14733,7 +14706,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
14733
14706
  keyword,
14734
14707
  enableMultiTenantMode: props2.enableMultiTenantMode
14735
14708
  });
14736
- options.value = formatUsers(result).filter((user) => !selectedUser.value || user.id !== selectedUser.value).filter((user) => !props2.excludeUserIds.includes(user.id));
14709
+ options.value = formatUsers(result, props2.enableMultiTenantMode).filter((user) => !selectedUser.value || user.id !== selectedUser.value).filter((user) => !props2.excludeUserIds.includes(user.id));
14737
14710
  } catch (error3) {
14738
14711
  console.error("获取用户列表失败:", error3);
14739
14712
  options.value = [];
@@ -14837,7 +14810,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
14837
14810
  };
14838
14811
  }
14839
14812
  });
14840
- const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-67f2ee6a"]]);
14813
+ const SingleSelector = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d56195a1"]]);
14841
14814
  const _sfc_main = /* @__PURE__ */ defineComponent({
14842
14815
  ...{
14843
14816
  name: "BkUserSelector"
@@ -14895,7 +14868,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
14895
14868
  usersList: ids,
14896
14869
  enableMultiTenantMode: props2.enableMultiTenantMode
14897
14870
  });
14898
- selectedUsers.value = [...selected, ...formatUsers(result)];
14871
+ selectedUsers.value = [...selected, ...formatUsers(result, props2.enableMultiTenantMode)];
14899
14872
  } catch (error3) {
14900
14873
  console.error("获取选中用户信息失败:", error3);
14901
14874
  }
@@ -15002,7 +14975,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
15002
14975
  };
15003
14976
  }
15004
14977
  });
15005
- const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-617ed278"]]);
14978
+ const BkUserSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-812cbe5a"]]);
15006
14979
  const vue2 = {
15007
14980
  model: {
15008
14981
  prop: "modelValue",