@dazhicheng/ui 1.6.17 → 1.6.19

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,8 +1,9 @@
1
1
  import { ref as b, watchEffect as j, unref as q, computed as B } from "vue";
2
2
  import { useRoute as H } from "vue-router";
3
3
  import { useOwnerRoutePath as I } from "./useOwnerRoutePath.js";
4
+ import { clearUserListCache as U } from "./userListCache.js";
4
5
  import { GEO_LEVEL_CODES as M, canDeriveGeoLevel as x, deriveRegionLevelOptionsFromGeoSource as Y, resolveHighestGeoLevelCode as A, isGeoLevelCode as L, CODE_REGISTRY as k } from "./basicDataCodes.js";
5
- const u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
6
+ const u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
6
7
  function C(r) {
7
8
  return Array.isArray(r) ? r : [];
8
9
  }
@@ -20,27 +21,27 @@ function S(r) {
20
21
  if (!c) return r;
21
22
  const a = r[c];
22
23
  if (!Array.isArray(a)) return r;
23
- const l = { ...r };
24
+ const d = { ...r };
24
25
  let o = !1;
25
26
  return M.forEach((f) => {
26
- x(c, f) && (D(l, f) || (l[f] = Y(a, f), o = !0));
27
- }), o ? l : r;
27
+ x(c, f) && (D(d, f) || (d[f] = Y(a, f), o = !0));
28
+ }), o ? d : r;
28
29
  }
29
30
  function N(r, c) {
30
- const a = F(c), l = r.filter(L), o = a || A(l) || void 0;
31
+ const a = F(c), d = r.filter(L), o = a || A(d) || void 0;
31
32
  return o ? r.filter((f) => L(f) ? !(x(o, f) || f === o && D(c, o)) : !0) : r;
32
33
  }
33
- function $(r) {
34
- const c = H(), a = I(), l = b({});
34
+ function ee(r) {
35
+ const c = H(), a = I(), d = b({});
35
36
  function o(t = {}) {
36
- l.value = r.codes.reduce(
37
+ d.value = r.codes.reduce(
37
38
  (e, n) => (e[n] = C(t[n]), e),
38
39
  {}
39
40
  );
40
41
  }
41
42
  o();
42
43
  function f(t) {
43
- u.delete(t), y.delete(t);
44
+ u.delete(t), m.delete(t);
44
45
  }
45
46
  function _(t) {
46
47
  const e = g.get(t) || /* @__PURE__ */ new Set(), n = e.size;
@@ -50,11 +51,11 @@ function $(r) {
50
51
  o(u.get(t));
51
52
  }
52
53
  function P(t) {
53
- const e = y.get(t);
54
+ const e = m.get(t);
54
55
  if (e) return e;
55
56
  const n = Promise.resolve().then(() => E());
56
- return y.set(t, n), n.finally(() => {
57
- y.get(t) === n && y.delete(t);
57
+ return m.set(t, n), n.finally(() => {
58
+ m.get(t) === n && m.delete(t);
58
59
  }), n;
59
60
  }
60
61
  async function T(t) {
@@ -69,9 +70,9 @@ function $(r) {
69
70
  return [i, []];
70
71
  }
71
72
  })
72
- )).reduce((i, d, h) => {
73
+ )).reduce((i, l, h) => {
73
74
  const w = t[h];
74
- return d.status === "fulfilled" ? i[d.value[0]] = C(d.value[1]) : i[w] = [], i;
75
+ return l.status === "fulfilled" ? i[l.value[0]] = C(l.value[1]) : i[w] = [], i;
75
76
  }, {});
76
77
  }
77
78
  async function E(t = !1) {
@@ -86,8 +87,8 @@ function $(r) {
86
87
  for (; ; ) {
87
88
  const s = S(u.get(e) || {});
88
89
  s !== (u.get(e) || {}) && u.set(e, s);
89
- const i = [...g.get(e) || r.codes], d = t ? i : i.filter((p) => !D(s, p));
90
- if (t = !1, !d.length) {
90
+ const i = [...g.get(e) || r.codes], l = t ? i : i.filter((p) => !D(s, p));
91
+ if (t = !1, !l.length) {
91
92
  o(s);
92
93
  return;
93
94
  }
@@ -98,17 +99,17 @@ function $(r) {
98
99
  continue;
99
100
  } catch {
100
101
  }
101
- const w = N(d, s);
102
+ const w = N(l, s);
102
103
  if (!w.length) {
103
104
  const p = S(s);
104
105
  u.set(e, p), o(p);
105
106
  return;
106
107
  }
107
- const G = T(w), R = (m.get(e) || 0) + 1;
108
- m.set(e, R), O.set(e, G);
108
+ const G = T(w), R = (y.get(e) || 0) + 1;
109
+ y.set(e, R), O.set(e, G);
109
110
  try {
110
111
  const p = await G;
111
- if (m.get(e) !== R)
112
+ if (y.get(e) !== R)
112
113
  continue;
113
114
  let v = {
114
115
  ...u.get(e) || {},
@@ -116,17 +117,17 @@ function $(r) {
116
117
  };
117
118
  v = S(v), u.set(e, v), o(v);
118
119
  } finally {
119
- m.get(e) === R && O.delete(e);
120
+ y.get(e) === R && O.delete(e);
120
121
  }
121
122
  }
122
123
  } catch {
123
- const n = [...g.get(e) || r.codes], s = J(n), d = { ...u.get(e) || {}, ...s };
124
- u.set(e, d), o(d);
124
+ const n = [...g.get(e) || r.codes], s = J(n), l = { ...u.get(e) || {}, ...s };
125
+ u.set(e, l), o(l);
125
126
  }
126
127
  }
127
128
  async function V() {
128
129
  const t = a, e = new Set(g.get(t) || r.codes);
129
- O.clear(), y.clear(), u.clear(), g.clear(), m.clear(), g.set(t, e), f(t), await E(!0);
130
+ O.clear(), m.clear(), u.clear(), g.clear(), y.clear(), U(), g.set(t, e), f(t), await E(!0);
130
131
  }
131
132
  return j(() => {
132
133
  const t = q(r.dataSource);
@@ -137,7 +138,7 @@ function $(r) {
137
138
  }), _(a), P(a).then(() => z(a)), {
138
139
  dataSource: B(() => {
139
140
  const t = r.codes.reduce(
140
- (e, n) => (e[n] = C(l.value[n]), e),
141
+ (e, n) => (e[n] = C(d.value[n]), e),
141
142
  {}
142
143
  );
143
144
  return new Proxy(t, {
@@ -153,5 +154,5 @@ function $(r) {
153
154
  };
154
155
  }
155
156
  export {
156
- $ as useBasicDataOptions
157
+ ee as useBasicDataOptions
157
158
  };
@@ -1,9 +1,8 @@
1
- import { queryDataPermissionDetailDataTypeContext as _, pageUser as j } from "../api/dataTypeContext.js";
2
- import { ref as k, watchEffect as B, unref as b, computed as F } from "vue";
3
- import { useOwnerRoutePath as W } from "./useOwnerRoutePath.js";
4
- const c = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map();
5
- let v, p;
6
- const G = "all", H = { label: "全部", value: G }, U = /* @__PURE__ */ new WeakMap(), J = {
1
+ import { queryDataPermissionDetailDataTypeContext as E } from "../api/dataTypeContext.js";
2
+ import { fetchUserListOnce as V, clearUserListCache as _ } from "./userListCache.js";
3
+ import { ref as j, watchEffect as k, unref as R, computed as B } from "vue";
4
+ import { useOwnerRoutePath as F } from "./useOwnerRoutePath.js";
5
+ const o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), W = "all", G = { label: "全部", value: W }, T = /* @__PURE__ */ new WeakMap(), H = {
7
6
  platformId: ["platformName", "platformId"],
8
7
  shopId: ["shopName", "shopId"],
9
8
  purchasePlaceId: ["purchasePlaceName", "purchasePlaceCode"],
@@ -11,130 +10,114 @@ const G = "all", H = { label: "全部", value: G }, U = /* @__PURE__ */ new Weak
11
10
  lockUserId: ["userName", "userId"],
12
11
  userId: ["fullName", "id"]
13
12
  };
14
- async function Q() {
15
- if (v) return v;
16
- if (p) return p;
17
- p = j({ pageNo: 1, pageSize: 9999 }).then((n) => {
18
- const s = n.records || [];
19
- return v = s, s;
20
- });
21
- try {
22
- return await p;
23
- } finally {
24
- p = void 0;
25
- }
26
- }
27
- function X(n, s = []) {
28
- const g = U.get(s) || /* @__PURE__ */ new Map(), u = g.get(n);
29
- if (u) return u.slice();
30
- const [S, q] = J[n], P = s.map((m) => {
31
- const l = n === "purchasePlaceId" ? m.purchaseInfo || {} : m;
13
+ function J(n, a = []) {
14
+ const h = T.get(a) || /* @__PURE__ */ new Map(), c = h.get(n);
15
+ if (c) return c.slice();
16
+ const [D, v] = H[n], C = a.map((p) => {
17
+ const u = n === "purchasePlaceId" ? p.purchaseInfo || {} : p;
32
18
  return {
33
- ...m,
34
- label: l == null ? void 0 : l[S],
35
- value: l == null ? void 0 : l[q]
19
+ ...p,
20
+ label: u == null ? void 0 : u[D],
21
+ value: u == null ? void 0 : u[v]
36
22
  };
37
23
  });
38
- return g.set(n, P), U.set(s, g), P.slice();
24
+ return h.set(n, C), T.set(a, h), C.slice();
39
25
  }
40
- function ee(n) {
41
- const s = W(), g = k({});
42
- function u(t = {}) {
43
- g.value = n.codes.reduce(
44
- (e, r) => (e[r] = X(r, t[r]), e),
26
+ function K(n) {
27
+ const a = F(), h = j({});
28
+ function c(t = {}) {
29
+ h.value = n.codes.reduce(
30
+ (e, r) => (e[r] = J(r, t[r]), e),
45
31
  {}
46
32
  );
47
33
  }
48
- function S(t) {
34
+ function D(t) {
49
35
  var e;
50
36
  return typeof n.showAll == "boolean" ? n.showAll : ((e = n.showAll) == null ? void 0 : e[t]) ?? !1;
51
37
  }
52
- function q() {
53
- I.clear(), h.clear(), c.clear(), f.clear(), w.clear(), v = void 0, p = void 0;
38
+ function v() {
39
+ y.clear(), f.clear(), o.clear(), i.clear(), w.clear(), _();
54
40
  }
55
- function P(t) {
56
- c.delete(t), f.delete(t), h.delete(t);
41
+ function C(t) {
42
+ o.delete(t), i.delete(t), f.delete(t);
57
43
  }
58
- function m(t) {
59
- const e = f.get(t) || /* @__PURE__ */ new Set(), r = e.size;
60
- n.codes.forEach((o) => e.add(o)), f.set(t, e), e.size !== r && (h.delete(t), M(t));
44
+ function p(t) {
45
+ const e = i.get(t) || /* @__PURE__ */ new Set(), r = e.size;
46
+ n.codes.forEach((d) => e.add(d)), i.set(t, e), e.size !== r && (f.delete(t), A(t));
61
47
  }
62
- async function l(t = !1) {
63
- const e = s, r = b(n.dataSource);
48
+ async function u(t = !1) {
49
+ const e = a, r = R(n.dataSource);
64
50
  if (r) {
65
- const i = { ...c.get(e) || {}, ...r };
66
- c.set(e, i), u(i);
51
+ c({ ...o.get(e) || {}, ...r });
67
52
  return;
68
53
  }
69
- const o = c.get(e) || {}, O = [...f.get(e) || n.codes];
70
- let C = t ? O : O.filter((a) => !Object.prototype.hasOwnProperty.call(o, a));
71
- if (!C.length) {
72
- u(o);
54
+ const d = o.get(e) || {}, S = [...i.get(e) || n.codes];
55
+ let m = t ? S : S.filter((s) => !Object.prototype.hasOwnProperty.call(d, s));
56
+ if (!m.length) {
57
+ c(d);
73
58
  return;
74
59
  }
75
- const R = t ? void 0 : I.get(e);
76
- if (R) {
77
- const a = await R, d = { ...c.get(e) || {}, ...a };
78
- if (c.set(e, d), C = O.filter((y) => !Object.prototype.hasOwnProperty.call(d, y)), !C.length) {
79
- u(d);
60
+ const L = t ? void 0 : y.get(e);
61
+ if (L) {
62
+ const s = await L, l = { ...o.get(e) || {}, ...s };
63
+ if (o.set(e, l), m = S.filter((g) => !Object.prototype.hasOwnProperty.call(l, g)), !m.length) {
64
+ c(l);
80
65
  return;
81
66
  }
82
67
  }
83
- const x = C.filter((a) => a !== "userId"), V = C.includes("userId"), L = Promise.allSettled([
84
- x.length ? _({ dataTypeName: x }).then(
85
- (a) => a
68
+ const M = m.filter((s) => s !== "userId"), z = m.includes("userId"), N = Promise.allSettled([
69
+ M.length ? E({ dataTypeName: M }).then(
70
+ (s) => s
86
71
  ) : Promise.resolve([]),
87
- V ? Q() : Promise.resolve(void 0)
88
- ]).then(([a, i]) => {
89
- const d = a.status === "fulfilled" ? a.value : [], y = i.status === "fulfilled" ? i.value : void 0;
72
+ z ? V() : Promise.resolve(void 0)
73
+ ]).then(([s, P]) => {
74
+ const l = s.status === "fulfilled" ? s.value : [], g = P.status === "fulfilled" ? P.value : void 0;
90
75
  return {
91
- ...y ? { userId: y } : {},
92
- ...d.reduce((A, D) => {
93
- const T = D == null ? void 0 : D.dataTypeCode;
94
- return T && (A[T] = D.originalItems || []), A;
76
+ ...g != null && g.length ? { userId: g } : {},
77
+ ...l.reduce((q, I) => {
78
+ const x = I == null ? void 0 : I.dataTypeCode;
79
+ return x && (q[x] = I.originalItems || []), q;
95
80
  }, {})
96
81
  };
97
- }), N = (w.get(e) || 0) + 1;
98
- w.set(e, N), I.set(e, L);
82
+ }), O = (w.get(e) || 0) + 1;
83
+ w.set(e, O), y.set(e, N);
99
84
  try {
100
- const a = await L;
101
- if (w.get(e) !== N) return;
102
- const d = { ...c.get(e) || {}, ...a };
103
- c.set(e, d), u(d);
85
+ const s = await N;
86
+ if (w.get(e) !== O) return;
87
+ const l = { ...o.get(e) || {}, ...s };
88
+ o.set(e, l), c(l);
104
89
  } finally {
105
- w.get(e) === N && I.delete(e);
90
+ w.get(e) === O && y.delete(e);
106
91
  }
107
92
  }
108
- async function z() {
109
- const t = s, e = new Set(f.get(t) || n.codes);
110
- q(), f.set(t, e), P(t), await l(!0);
93
+ async function b() {
94
+ const t = a, e = new Set(i.get(t) || n.codes);
95
+ v(), i.set(t, e), C(t), await u(!0);
111
96
  }
112
- function M(t) {
113
- const e = h.get(t);
97
+ function A(t) {
98
+ const e = f.get(t);
114
99
  if (e) return e;
115
- const r = Promise.resolve().then(() => l());
116
- return h.set(t, r), r.finally(() => {
117
- h.get(t) === r && h.delete(t);
100
+ const r = Promise.resolve().then(() => u());
101
+ return f.set(t, r), r.finally(() => {
102
+ f.get(t) === r && f.delete(t);
118
103
  }), r;
119
104
  }
120
- B(() => {
121
- const t = b(n.dataSource);
122
- if (!t) return;
123
- const e = s, o = { ...c.get(e) || {}, ...t };
124
- c.set(e, o), u(o);
105
+ k(() => {
106
+ const t = R(n.dataSource);
107
+ t && c({ ...o.get(a) || {}, ...t });
125
108
  });
126
- function E(t) {
127
- u(c.get(t));
109
+ function U(t) {
110
+ c(o.get(t));
128
111
  }
129
- return m(s), M(s).then(() => E(s)), {
112
+ return p(a), A(a).then(() => U(a)), {
130
113
  /**
131
114
  * 数据源
132
115
  */
133
- dataSource: F(() => {
116
+ dataSource: B(() => {
134
117
  const t = n.codes.reduce(
135
118
  (e, r) => {
136
- const o = g.value[r] || [];
137
- return e[r] = S(r) ? [H, ...o] : o, e;
119
+ const d = h.value[r] || [];
120
+ return e[r] = D(r) ? [G, ...d] : d, e;
138
121
  },
139
122
  {}
140
123
  );
@@ -150,9 +133,9 @@ function ee(n) {
150
133
  /**
151
134
  * @description 清空所有缓存,重新请求
152
135
  */
153
- reload: z
136
+ reload: b
154
137
  };
155
138
  }
156
139
  export {
157
- ee as useDataPermissionOptions
140
+ K as useDataPermissionOptions
158
141
  };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 取全量用户列表,整个应用只请求一次
3
+ *
4
+ * `useDataPermissionOptions` 的 `userId` 和 `useBasicDataOptions` 的 `USER` 都要这份数据。
5
+ * 两边各自缓存会把 `/iam/user/page` 打两遍,所以请求收敛到这里,label value 的映射仍由各自负责。
6
+ *
7
+ * 空结果和请求失败都不写缓存、不留在途引用,下次调用可以重新请求
8
+ * @returns 用户原始记录列表
9
+ */
10
+ export declare function fetchUserListOnce(): Promise<IamAPI.UserDTO[]>;
11
+ /** 清空用户列表缓存,供各 hook 的 reload 使用 */
12
+ export declare function clearUserListCache(): void;
@@ -0,0 +1,17 @@
1
+ import { pageUser as t } from "../api/dataTypeContext.js";
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) || [];
6
+ return n.length ? r = n : e = void 0, n;
7
+ }), e.catch(() => {
8
+ e = void 0;
9
+ }), e);
10
+ }
11
+ function s() {
12
+ r = void 0, e = void 0;
13
+ }
14
+ export {
15
+ s as clearUserListCache,
16
+ c as fetchUserListOnce
17
+ };