@owocow/saber-ui 0.0.4 → 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,
@@ -4,13 +4,6 @@ export interface ApiResponse<T = unknown> {
4
4
  msg: string;
5
5
  data: T;
6
6
  }
7
- /** rows、total 位于响应顶层的列表响应。 */
8
- export interface ListResponse<T = unknown> {
9
- code: number;
10
- msg: string;
11
- rows: T[];
12
- total: number;
13
- }
14
7
  /** 通用分页请求参数。 */
15
8
  export interface PageParams {
16
9
  pageNum?: number;
@@ -1,3 +1,3 @@
1
1
  export type { EnableStatus, Id, Option, PartialNullable, VisibleStatus, YesNo, } from './common';
2
- export type { ApiResponse, CommonSearchParams, ListResponse, PageData, PageParams, SortOrder, } from './api';
2
+ export type { ApiResponse, CommonSearchParams, PageData, PageParams, SortOrder, } from './api';
3
3
  export type { AuthUserInfo, CaptchaCode, LoginForm, LoginTenant, LoginTenantItem, LoginToken, PwdLoginForm, RegisterForm, SocialLoginForm, } from './auth';
@@ -1,7 +1,12 @@
1
- import { ApiResponse, ListResponse } from '../types/api';
2
- export type { ApiResponse, ListResponse } from '../types/api';
3
- /** @deprecated 请使用 ListResponse。 */
4
- export type ListResult<T = unknown> = ListResponse<T>;
1
+ import { ApiResponse, PageData } from '../types/api';
2
+ export type { ApiResponse, PageData } from '../types/api';
3
+ /**
4
+ * 分页列表响应。
5
+ *
6
+ * 后端分页接口统一返回 `{ code, msg, data: { rows, total } }`,
7
+ * rows/total 位于 `ApiResponse.data` 内。
8
+ */
9
+ export type ListResult<T = unknown> = ApiResponse<PageData<T>>;
5
10
  export interface HttpConfig {
6
11
  /** API 基础路径,如 `/api` */
7
12
  baseURL: string;
@@ -36,7 +41,7 @@ export declare function setupHttp(config: HttpConfig): void;
36
41
  export declare function request<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
37
42
  export declare const http: {
38
43
  get<T = unknown, P extends object = object>(url: string, params?: P, withToken?: boolean): Promise<ApiResponse<T>>;
39
- list<T = unknown, P extends object = object>(url: string, params?: P, withToken?: boolean): Promise<ListResponse<T>>;
44
+ list<T = unknown, P extends object = object>(url: string, params?: P, withToken?: boolean): Promise<ListResult<T>>;
40
45
  post<T = unknown, D extends object = object>(url: string, data?: D, withToken?: boolean, encrypt?: boolean): Promise<ApiResponse<T>>;
41
46
  put<T = unknown, D extends object = object>(url: string, data?: D, withToken?: boolean, encrypt?: boolean): Promise<ApiResponse<T>>;
42
47
  patch<T = unknown, D extends object = object>(url: string, data?: D, withToken?: boolean, encrypt?: boolean): Promise<ApiResponse<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owocow/saber-ui",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Saber application foundation for Vue 3 projects built on Nuxt UI",
5
5
  "type": "module",
6
6
  "sideEffects": false,