@dazhicheng/ui 1.6.26 → 1.6.27

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,5 +1,6 @@
1
1
  import { getAllBasicAirline as O, getDictItemsByCodes as R, listChainByTypeAirportRegionLevel as A } from "../api/basicData.js";
2
- import { queryAllRoles as L, pageUser as I } from "../api/dataTypeContext.js";
2
+ import { queryAllRoles as L } from "../api/dataTypeContext.js";
3
+ import { fetchUserListOnce as I } from "./userListCache.js";
3
4
  import { secondaryDropdownListLossReason as T, primaryDropdownListLossReason as C } from "../api/lossReason.js";
4
5
  import { listAllSupplierPurchase as P, listAllValidSupplierManage as _, getAllConfigListSupplierConfigManage as h } from "../api/supplier.js";
5
6
  const o = {
@@ -56,7 +57,7 @@ const o = {
56
57
  REFUND: "退票",
57
58
  REBOOK: "改签"
58
59
  };
59
- function J(a, e) {
60
+ function Q(a, e) {
60
61
  if (!Array.isArray(a) || !a.length) return a || [];
61
62
  if (e === d.PINYIN || e === d.NONE) return a;
62
63
  const l = b[e];
@@ -77,7 +78,7 @@ function J(a, e) {
77
78
  n.get(i).children.push(u);
78
79
  }), s.map((u) => n.get(u));
79
80
  }
80
- function Q(a) {
81
+ function X(a) {
81
82
  const e = /* @__PURE__ */ new Map();
82
83
  return (Array.isArray(a) ? a : []).forEach((l) => {
83
84
  const n = l.purchaseInfo || l, s = (n == null ? void 0 : n.supplierSubType) ?? "其他";
@@ -89,7 +90,7 @@ function Q(a) {
89
90
  }, e.set(s, r)), r.children.push(l);
90
91
  }), Array.from(e.values());
91
92
  }
92
- function X(a, e) {
93
+ function Z(a, e) {
93
94
  return e || (a === o.CONTINENT ? d.NONE : a === o.AIRPORT || a === o.CITY ? d.COUNTRY : a === o.COUNTRY || a === o.REGION ? d.CONTINENT : a === o.LOSS_REASON ? d.BUSINESS_TYPE : a === o.LOSS_REASON_SECONDARY ? d.PRIMARY_REASON : a === o.SUPPLIER_CONFIG ? d.SUPPLIER_MANAGE_NAME : d.PINYIN);
94
95
  }
95
96
  const v = {
@@ -155,10 +156,10 @@ o.CONTINENT, o.REGION, o.COUNTRY, o.CITY;
155
156
  function N(a) {
156
157
  return U.includes(a);
157
158
  }
158
- function Z(a, e) {
159
+ function ee(a, e) {
159
160
  return !N(a) || !N(e) ? !1 : y[a] > y[e];
160
161
  }
161
- function ee(a, e) {
162
+ function ae(a, e) {
162
163
  if (!N(e)) return [];
163
164
  const { codeKey: l, nameKey: n } = F[e], s = /* @__PURE__ */ new Map();
164
165
  return (Array.isArray(a) ? a : []).forEach((r) => {
@@ -172,7 +173,7 @@ function ee(a, e) {
172
173
  });
173
174
  }), Array.from(s.values());
174
175
  }
175
- function ae(a) {
176
+ function re(a) {
176
177
  let e;
177
178
  for (const l of a)
178
179
  N(l) && (!e || y[l] > y[e]) && (e = l);
@@ -231,14 +232,14 @@ function S(a, e = D) {
231
232
  }
232
233
  };
233
234
  }
234
- function x(a = []) {
235
+ function m(a = []) {
235
236
  return (Array.isArray(a) ? a : []).filter((e) => (e == null ? void 0 : e.id) !== void 0 && (e == null ? void 0 : e.id) !== null).map((e) => ({
236
237
  ...e,
237
238
  label: e.fullName || e.username || String(e.id),
238
239
  value: e.id
239
240
  }));
240
241
  }
241
- function m(a = []) {
242
+ function x(a = []) {
242
243
  return (Array.isArray(a) ? a : []).filter((e) => (e == null ? void 0 : e.id) !== void 0 && (e == null ? void 0 : e.id) !== null).map((e) => ({
243
244
  ...e,
244
245
  label: e.roleName || e.roleCode || String(e.id),
@@ -293,7 +294,7 @@ function H(a = []) {
293
294
  }
294
295
  }));
295
296
  }
296
- const re = {
297
+ const le = {
297
298
  [o.AIRLINE]: {
298
299
  defaultFieldName: "airlineCodes",
299
300
  defaultLabel: "航司",
@@ -386,8 +387,8 @@ const re = {
386
387
  defaultShowAll: !1,
387
388
  async fetchOptions() {
388
389
  try {
389
- const a = await I({ pageNo: 1, pageSize: 9999 });
390
- return x((a == null ? void 0 : a.records) || []);
390
+ const a = await I();
391
+ return m(a);
391
392
  } catch {
392
393
  return [];
393
394
  }
@@ -402,7 +403,7 @@ const re = {
402
403
  async fetchOptions() {
403
404
  try {
404
405
  const a = await L();
405
- return m(a || []);
406
+ return x(a || []);
406
407
  } catch {
407
408
  return [];
408
409
  }
@@ -492,14 +493,14 @@ const re = {
492
493
  };
493
494
  export {
494
495
  o as CODES,
495
- re as CODE_REGISTRY,
496
+ le as CODE_REGISTRY,
496
497
  U as GEO_LEVEL_CODES,
497
498
  d as GROUP_BY,
498
- Z as canDeriveGeoLevel,
499
- ee as deriveRegionLevelOptionsFromGeoSource,
500
- J as groupBasicDataOptions,
501
- Q as groupPurchasePlaceOptions,
499
+ ee as canDeriveGeoLevel,
500
+ ae as deriveRegionLevelOptionsFromGeoSource,
501
+ Q as groupBasicDataOptions,
502
+ X as groupPurchasePlaceOptions,
502
503
  N as isGeoLevelCode,
503
- X as resolveDefaultGroupBy,
504
- ae as resolveHighestGeoLevelCode
504
+ Z as resolveDefaultGroupBy,
505
+ re as resolveHighestGeoLevelCode
505
506
  };
@@ -1,26 +1,39 @@
1
1
  import { MaybeRef, Ref } from 'vue';
2
- export type BudinessDataType = "platformId" | "shopId" | "purchasePlaceId" | "businessType" | "lockUserId" | "userId";
2
+ /** 数据权限维度的 code 标识,对应平台、店铺、采购地、业务类型、锁单人、用户 */
3
+ export type BusinessDataType = "platformId" | "shopId" | "purchasePlaceId" | "businessType" | "lockUserId" | "userId";
4
+ /** 下拉选项条目,label 和 value 由 toNormalizedOptions 从原始字段映射而来 */
3
5
  export type DataPermissionOptionItem = Record<string, any> & {
4
6
  label?: string;
5
7
  value?: string | number;
6
8
  };
7
- export type DataPermissionOptionsMap = Partial<Record<BudinessDataType, DataPermissionOptionItem[]>>;
8
- export interface UseBudinessDataOptions {
9
- codes: BudinessDataType[];
9
+ /** code 到选项列表的映射,Partial 因为不一定每个 code 都有数据 */
10
+ export type DataPermissionOptionsMap = Partial<Record<BusinessDataType, DataPermissionOptionItem[]>>;
11
+ /** useDataPermissionOptions 的入参 */
12
+ export interface UseBusinessDataOptions {
13
+ /** 需要获取的数据权限维度 */
14
+ codes: BusinessDataType[];
15
+ /** 外部数据源,传入后优先使用,不走接口请求,不回写共享缓存 */
10
16
  dataSource?: MaybeRef<DataPermissionOptionsMap | undefined>;
11
- showAll?: boolean | Partial<Record<BudinessDataType, boolean>>;
17
+ /** 是否在选项列表头部插入「全部」选项。传 boolean 对所有 code 生效,传对象可按 code 单独控制 */
18
+ showAll?: boolean | Partial<Record<BusinessDataType, boolean>>;
12
19
  }
13
20
  /**
21
+ * 获取当前用户的数据权限下拉选项(平台 / 店铺 / 采购地 / 业务类型 / 锁单人 / 用户)。
14
22
  *
23
+ * 同路由多个实例共享缓存,microtask 合并同 tick 请求,pending 去重跨 tick 请求。
24
+ * 返回的 dataSource 是只读 Proxy,访问未声明的 code 返回空数组,赋值会报错。
25
+ *
26
+ * @param options 配置项
27
+ * @returns dataSource — 响应式选项数据源;reload — 清空当前路由缓存并重新请求
15
28
  * @example
16
29
  * ```ts
17
30
  * const { dataSource } = useDataPermissionOptions({
18
- * codes:['userId','shopId]
19
- * })
20
- *
21
- * dataSource.value.userId
31
+ * codes: ["userId", "shopId"],
32
+ * });
33
+ * dataSource.value.userId // [{ label: "张三", value: 1 }, ...]
34
+ * ```
22
35
  */
23
- export declare function useDataPermissionOptions(options: UseBudinessDataOptions): {
24
- dataSource: Ref<Record<BudinessDataType, DataPermissionOptionItem[]>>;
36
+ export declare function useDataPermissionOptions(options: UseBusinessDataOptions): {
37
+ dataSource: Ref<Record<BusinessDataType, DataPermissionOptionItem[]>>;
25
38
  reload: () => Promise<void>;
26
39
  };
@@ -1,146 +1,103 @@
1
- import { queryDataPermissionDetailDataTypeContext as j } from "../api/dataTypeContext.js";
2
- import { fetchUserListOnce as k, clearUserListCache as B } from "./userListCache.js";
3
- import { ref as F, watchEffect as W, unref as U, computed as G } from "vue";
4
- import { useOwnerRoutePath as H } from "./useOwnerRoutePath.js";
5
- const u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), J = "all", Q = { label: "全部", value: J }, b = /* @__PURE__ */ new WeakMap(), X = {
1
+ import { queryDataPermissionDetailDataTypeContext as M } from "../api/dataTypeContext.js";
2
+ import { fetchUserListOnce as N, clearUserListCache as R } from "./userListCache.js";
3
+ import { computed as O, unref as S, ref as A } from "vue";
4
+ import { useOwnerRoutePath as D } from "./useOwnerRoutePath.js";
5
+ const F = { label: "全部", value: "all" }, T = {
6
6
  platformId: ["platformName", "platformId"],
7
7
  shopId: ["shopName", "shopId"],
8
8
  purchasePlaceId: ["purchasePlaceName", "purchasePlaceCode"],
9
9
  businessType: ["itemName", "itemCode"],
10
10
  lockUserId: ["userName", "userId"],
11
11
  userId: ["fullName", "id"]
12
- };
13
- function Y(n, a = []) {
14
- const i = b.get(a) || /* @__PURE__ */ new Map(), o = i.get(n);
15
- if (o) return o.slice();
16
- const [y, S] = X[n], m = a.map((h) => {
17
- const c = n === "purchasePlaceId" ? h.purchaseInfo || {} : h;
18
- return {
19
- ...h,
20
- label: c == null ? void 0 : c[y],
21
- value: c == null ? void 0 : c[S]
22
- };
12
+ }, f = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new WeakMap();
13
+ function v(e) {
14
+ let s = y.get(e);
15
+ return s || (s = A(0), y.set(e, s)), s;
16
+ }
17
+ function q(e) {
18
+ v(e).value++;
19
+ }
20
+ function x(e, s = []) {
21
+ let o = I.get(s);
22
+ o || (o = /* @__PURE__ */ new Map(), I.set(s, o));
23
+ const a = o.get(e);
24
+ if (a) return a.slice();
25
+ const [l, r] = T[e], c = s.map((t) => {
26
+ const n = e === "purchasePlaceId" ? t.purchaseInfo || {} : t;
27
+ return { ...t, label: n[l], value: n[r] };
23
28
  });
24
- return i.set(n, m), b.set(a, i), m.slice();
29
+ return o.set(e, c), c.slice();
25
30
  }
26
- function re(n) {
27
- const a = H(), i = F({});
28
- function o(t = {}) {
29
- i.value = n.codes.reduce(
30
- (e, r) => (e[r] = Y(r, t[r]), e),
31
- {}
32
- );
33
- }
34
- function y(t) {
35
- var e;
36
- return typeof n.showAll == "boolean" ? n.showAll : ((e = n.showAll) == null ? void 0 : e[t]) ?? !1;
37
- }
38
- function S() {
39
- p.clear(), f.clear(), u.clear(), d.clear(), I.clear(), B();
31
+ async function L(e) {
32
+ const s = e.filter((t) => t !== "userId"), o = e.includes("userId"), [a, l] = await Promise.allSettled([
33
+ s.length ? M({ dataTypeName: s }).then(
34
+ (t) => t
35
+ ) : Promise.resolve([]),
36
+ o ? N() : Promise.resolve(void 0)
37
+ ]), r = {};
38
+ if (a.status === "fulfilled") {
39
+ for (const t of s)
40
+ r[t] = [];
41
+ for (const t of a.value) {
42
+ const n = t == null ? void 0 : t.dataTypeCode;
43
+ n && (r[n] = t.originalItems || []);
44
+ }
40
45
  }
41
- function m(t) {
42
- u.delete(t), d.delete(t), f.delete(t);
46
+ const c = l.status === "fulfilled" ? l.value : void 0;
47
+ return c != null && c.length && (r.userId = c), r;
48
+ }
49
+ async function C(e, s = !1) {
50
+ const o = d.get(e);
51
+ o && await o;
52
+ const a = f.get(e) ?? {}, l = [...h.get(e) ?? []], r = s ? l : l.filter((n) => !Object.hasOwn(a, n));
53
+ if (!r.length) return;
54
+ const c = p.get(e) ?? 0, t = (async () => {
55
+ const n = await L(r);
56
+ if ((p.get(e) ?? 0) !== c) return;
57
+ const m = { ...f.get(e) ?? {}, ...n };
58
+ f.set(e, m), q(e);
59
+ })();
60
+ d.set(e, t);
61
+ try {
62
+ await t;
63
+ } finally {
64
+ d.get(e) === t && d.delete(e);
43
65
  }
44
- function h(t) {
45
- const e = d.get(t) || /* @__PURE__ */ new Set(), r = e.size;
46
- n.codes.forEach((l) => e.add(l)), d.set(t, e), e.size !== r && A(t);
66
+ }
67
+ function U(e) {
68
+ g.has(e) || (g.add(e), Promise.resolve().then(() => {
69
+ g.delete(e), C(e);
70
+ }));
71
+ }
72
+ function E(e) {
73
+ const s = D(), o = v(s), a = h.get(s) ?? /* @__PURE__ */ new Set();
74
+ e.codes.forEach((t) => a.add(t)), h.set(s, a), U(s);
75
+ function l(t) {
76
+ var n;
77
+ return typeof e.showAll == "boolean" ? e.showAll : ((n = e.showAll) == null ? void 0 : n[t]) ?? !1;
47
78
  }
48
- async function c(t = !1) {
49
- const e = a, r = U(n.dataSource);
50
- if (r) {
51
- o({ ...u.get(e) || {}, ...r });
52
- return;
79
+ const r = O(() => {
80
+ o.value;
81
+ const t = S(e.dataSource), n = f.get(s) ?? {}, w = t ? { ...n, ...t } : n, m = {};
82
+ for (const i of e.codes) {
83
+ const u = x(i, w[i]);
84
+ m[i] = l(i) ? [F, ...u] : u;
53
85
  }
54
- const l = /* @__PURE__ */ new Set(), V = 32;
55
- for (let L = 0; L < V; L++) {
56
- const v = u.get(e) || {}, M = [...d.get(e) || n.codes], g = t ? M : M.filter((s) => !Object.prototype.hasOwnProperty.call(v, s));
57
- if (t = !1, !g.length) {
58
- o(v);
59
- return;
60
- }
61
- const N = p.get(e);
62
- if (N) {
63
- await N;
64
- continue;
65
- }
66
- if (g.every((s) => l.has(s))) {
67
- o(v);
68
- return;
69
- }
70
- g.forEach((s) => l.add(s));
71
- const x = g.filter((s) => s !== "userId"), _ = g.includes("userId"), D = Promise.allSettled([
72
- x.length ? j({ dataTypeName: x }).then(
73
- (s) => s
74
- ) : Promise.resolve([]),
75
- _ ? k() : Promise.resolve(void 0)
76
- ]).then(([s, q]) => {
77
- const w = s.status === "fulfilled" ? s.value : [], C = q.status === "fulfilled" ? q.value : void 0;
78
- return {
79
- ...C != null && C.length ? { userId: C } : {},
80
- ...w.reduce((O, P) => {
81
- const T = P == null ? void 0 : P.dataTypeCode;
82
- return T && (O[T] = P.originalItems || []), O;
83
- }, {})
84
- };
85
- }), R = (I.get(e) || 0) + 1;
86
- I.set(e, R), p.set(e, D);
87
- try {
88
- const s = await D;
89
- if (I.get(e) !== R) continue;
90
- const w = { ...u.get(e) || {}, ...s };
91
- u.set(e, w), o(w);
92
- } finally {
93
- p.get(e) === D && p.delete(e);
86
+ return new Proxy(m, {
87
+ get(i, u, b) {
88
+ return typeof u == "symbol" ? Reflect.get(i, u, b) : i[u] ?? [];
89
+ },
90
+ set(i, u) {
91
+ return !0;
94
92
  }
95
- }
96
- o(u.get(e) || {});
97
- }
98
- async function E() {
99
- const t = a, e = new Set(d.get(t) || n.codes);
100
- S(), m(t), d.set(t, e), await c(!0);
101
- }
102
- function A(t) {
103
- const e = f.get(t);
104
- if (e) return e;
105
- const r = Promise.resolve().then(() => c());
106
- return f.set(t, r), r.finally(() => {
107
- f.get(t) === r && f.delete(t);
108
- }), r;
109
- }
110
- W(() => {
111
- const t = U(n.dataSource);
112
- t && o({ ...u.get(a) || {}, ...t });
93
+ });
113
94
  });
114
- function z(t) {
115
- o(u.get(t));
95
+ async function c() {
96
+ const t = (p.get(s) ?? 0) + 1;
97
+ p.set(s, t), f.delete(s), d.delete(s), R(), await C(s, !0);
116
98
  }
117
- return h(a), A(a).then(() => z(a)), {
118
- /**
119
- * 数据源
120
- */
121
- dataSource: G(() => {
122
- const t = n.codes.reduce(
123
- (e, r) => {
124
- const l = i.value[r] || [];
125
- return e[r] = y(r) ? [Q, ...l] : l, e;
126
- },
127
- {}
128
- );
129
- return new Proxy(t, {
130
- get(e, r) {
131
- return typeof r != "string" ? [] : t[r] || [];
132
- },
133
- set() {
134
- return !1;
135
- }
136
- });
137
- }),
138
- /**
139
- * @description 清空所有缓存,重新请求
140
- */
141
- reload: E
142
- };
99
+ return { dataSource: r, reload: c };
143
100
  }
144
101
  export {
145
- re as useDataPermissionOptions
102
+ E as useDataPermissionOptions
146
103
  };
@@ -1,8 +1,8 @@
1
1
  import { TtFormSchema } from '../components/tt-form';
2
2
  import { Recordable } from '../../../utils/src';
3
3
  import { MaybeRef, Ref } from 'vue';
4
- import { BudinessDataType, DataPermissionOptionsMap } from './useDataPermissionOptions';
5
- type DataType = Exclude<BudinessDataType, "userId">;
4
+ import { BusinessDataType, DataPermissionOptionsMap } from './useDataPermissionOptions';
5
+ type DataType = Exclude<BusinessDataType, "userId">;
6
6
  /**
7
7
  * 表单使用场景。
8
8
  *
@@ -89,7 +89,7 @@ export type SelectOption = Recordable & {
89
89
  * 返回值会包含每个 DataType 对应的 TtFormSchema,以及当前已归一化的下拉数据源。
90
90
  */
91
91
  type UseFormSchemasLinkResult = Record<DataType, TtFormSchema> & {
92
- dataSource: Ref<Record<BudinessDataType, SelectOption[]>>;
92
+ dataSource: Ref<Record<BusinessDataType, SelectOption[]>>;
93
93
  };
94
94
  type FormSchemasLinkBuilder = {
95
95
  /** 设置为查询筛选场景 */
@@ -99,7 +99,7 @@ type FormSchemasLinkBuilder = {
99
99
  /** 设置表单场景 */
100
100
  scene(scene: FormScene): FormSchemasLinkBuilder;
101
101
  /** 指定需要请求和构建的字段类型,默认包含全部 DataType */
102
- codes(codes: BudinessDataType[]): FormSchemasLinkBuilder;
102
+ codes(codes: BusinessDataType[]): FormSchemasLinkBuilder;
103
103
  /** 使用外部数据源,跳过内部接口请求 */
104
104
  dataSource(dataSource: MaybeRef<DataPermissionOptionsMap | undefined>): FormSchemasLinkBuilder;
105
105
  /** 覆盖单个字段配置 */
@@ -1,8 +1,8 @@
1
- import { pageUser as t } from "../api/dataTypeContext.js";
1
+ import { pageUser as o } from "../api/dataTypeContext.js";
2
2
  let r, e;
3
- function c() {
4
- return r != null && r.length ? Promise.resolve(r) : e || (e = t({ pageNo: 1, pageSize: 9999 }).then((i) => {
5
- const n = (i == null ? void 0 : i.records) || [];
3
+ function a() {
4
+ return r != null && r.length ? Promise.resolve(r) : e || (e = o({ pageNo: 1, pageSize: 9999 }).then((i) => {
5
+ const n = ((i == null ? void 0 : i.records) ?? (Array.isArray(i) ? i : [])) || [];
6
6
  return n.length ? r = n : e = void 0, n;
7
7
  }), e.catch(() => {
8
8
  e = void 0;
@@ -13,5 +13,5 @@ function s() {
13
13
  }
14
14
  export {
15
15
  s as clearUserListCache,
16
- c as fetchUserListOnce
16
+ a as fetchUserListOnce
17
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dazhicheng/ui",
3
- "version": "1.6.26",
3
+ "version": "1.6.27",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -69,8 +69,8 @@
69
69
  "vue-router": "^5.0.2",
70
70
  "vxe-pc-ui": "^4.14.15",
71
71
  "vxe-table": "^4.18.13",
72
- "@dazhicheng/utils": "1.3.53",
73
- "@dazhicheng/hooks": "1.4.56"
72
+ "@dazhicheng/hooks": "1.4.56",
73
+ "@dazhicheng/utils": "1.3.53"
74
74
  },
75
75
  "files": [
76
76
  "dist"