@owocow/saber-ui 0.0.3 → 0.0.5

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.
@@ -27,7 +27,7 @@ export interface TableConfig<A extends ApiFn, T = any> {
27
27
  apiParams?: Partial<ApiParams<A>>;
28
28
  /** 转换已经附带 _index 的行数据。 */
29
29
  transformer?: (rows: TableDataWithIndex<T>[]) => any[];
30
- /** 自定义响应归一化;默认兼容顶层与 data 内的 rows/total */
30
+ /** 自定义响应归一化;默认解析 `data.rows / data.total`。 */
31
31
  responseAdapter?: (response: Awaited<ReturnType<A>>) => NormalizedTableResponse<T>;
32
32
  /** 获取并转换数据后的回调。 */
33
33
  onFetched?: (data: any[]) => MaybePromise<void>;
@@ -1,78 +1,78 @@
1
- import { reactive as y, ref as N, watch as z, computed as R } from "vue";
2
- import { klona as h } from "klona/json";
1
+ import { reactive as z, ref as N, watch as h, computed as R } from "vue";
2
+ import { klona as b } from "klona/json";
3
3
  import { useBoolean as C } from "./use-boolean.mjs";
4
4
  import { useLoading as D } from "./use-loading.mjs";
5
- function I(a) {
6
- const r = Array.isArray(a == null ? void 0 : a.rows) ? a : a == null ? void 0 : a.data;
5
+ function I(n) {
6
+ const e = n == null ? void 0 : n.data;
7
7
  return {
8
- rows: Array.isArray(r == null ? void 0 : r.rows) ? r.rows : [],
9
- total: Number((r == null ? void 0 : r.total) ?? 0)
8
+ rows: Array.isArray(e == null ? void 0 : e.rows) ? e.rows : [],
9
+ total: Number((e == null ? void 0 : e.total) ?? 0)
10
10
  };
11
11
  }
12
- function H(a) {
13
- const { loading: r, startLoading: d, endLoading: g } = D(), { bool: b, setBool: w } = C(), { apiFn: A, apiParams: f, transformer: p, responseAdapter: P, immediate: j = !0, paginConfig: O } = a, i = y(h({ ...f })), S = N([]), { pageSizes: k, pageSize: v, disabled: x = !1 } = O || {}, t = y({
14
- pageSizes: k || [10, 20, 50, 100],
15
- pageSize: v || 10,
12
+ function H(n) {
13
+ const { loading: e, startLoading: d, endLoading: g } = D(), { bool: y, setBool: w } = C(), { apiFn: j, apiParams: f, transformer: p, responseAdapter: P, immediate: O = !0, paginConfig: k } = n, s = z(b({ ...f })), S = N([]), { pageSizes: v, pageSize: x, disabled: A = !1 } = k || {}, t = z({
14
+ pageSizes: v || [10, 20, 50, 100],
15
+ pageSize: x || 10,
16
16
  currentPage: 1,
17
17
  total: 0
18
18
  });
19
19
  let u = !1;
20
- z(
20
+ h(
21
21
  () => t.currentPage,
22
22
  () => {
23
- u || s();
23
+ u || i();
24
24
  },
25
25
  { flush: "sync" }
26
- ), z(
26
+ ), h(
27
27
  () => t.pageSize,
28
28
  () => {
29
- u = !0, t.currentPage = 1, u = !1, s();
29
+ u = !0, t.currentPage = 1, u = !1, i();
30
30
  },
31
31
  { flush: "sync" }
32
32
  );
33
- function E(e) {
33
+ function E(a) {
34
34
  const o = t.currentPage || 1, c = t.pageSize > 0 ? t.pageSize : 10;
35
- return e.map((m, n) => ({
35
+ return a.map((m, r) => ({
36
36
  ...m,
37
- _index: (o - 1) * c + n + 1
37
+ _index: (o - 1) * c + r + 1
38
38
  }));
39
39
  }
40
- async function s() {
41
- var e;
40
+ async function i() {
41
+ var a;
42
42
  d();
43
43
  try {
44
- const o = T(i), c = await A(o), m = P ? P(c) : I(c), n = E(m.rows), l = p ? p(n) : n;
45
- return t.total = m.total, S.value = l, w(l.length === 0), await ((e = a.onFetched) == null ? void 0 : e.call(a, l)), l;
44
+ const o = T(s), c = await j(o), m = P ? P(c) : I(c), r = E(m.rows), l = p ? p(r) : r;
45
+ return t.total = m.total, S.value = l, w(l.length === 0), await ((a = n.onFetched) == null ? void 0 : a.call(n, l)), l;
46
46
  } finally {
47
47
  g();
48
48
  }
49
49
  }
50
50
  function L() {
51
- return x ? {} : {
51
+ return A ? {} : {
52
52
  pageNum: t.currentPage,
53
53
  pageSize: t.pageSize
54
54
  };
55
55
  }
56
- function T(e) {
57
- const o = {}, c = { ...L(), ...e };
58
- return Object.entries(c).forEach(([m, n]) => {
59
- n != null && n !== "" && (o[m] = n);
56
+ function T(a) {
57
+ const o = {}, c = { ...L(), ...a };
58
+ return Object.entries(c).forEach(([m, r]) => {
59
+ r != null && r !== "" && (o[m] = r);
60
60
  }), o;
61
61
  }
62
- function B(e) {
63
- return Object.assign(i, e), s();
62
+ function B(a) {
63
+ return Object.assign(s, a), i();
64
64
  }
65
65
  function F() {
66
66
  u = !0, t.currentPage = 1, u = !1;
67
- const e = h({ ...f });
68
- return Object.keys(i).forEach((o) => delete i[o]), Object.assign(i, e), s();
67
+ const a = b({ ...f });
68
+ return Object.keys(s).forEach((o) => delete s[o]), Object.assign(s, a), i();
69
69
  }
70
- return j && s(), {
71
- loading: r,
72
- empty: b,
70
+ return O && i(), {
71
+ loading: e,
72
+ empty: y,
73
73
  data: S,
74
- getData: s,
75
- params: i,
74
+ getData: i,
75
+ params: s,
76
76
  updateSearchParams: B,
77
77
  resetSearchParams: F,
78
78
  pagination: t,