@basestone/hooks 1.3.6
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/README.md +69 -0
- package/dist/design-hooks.es.prod.d.ts +209 -0
- package/dist/design-hooks.es.prod.js +296 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# design-hooks
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 安装
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
pnpm add @base-stone/hooks
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### useTableList 使用
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
const { tableProps, reload } = useTableList<ListItemData>({
|
|
19
|
+
queryFn: getCooperateList,
|
|
20
|
+
params: {
|
|
21
|
+
orderField: 'createDate',
|
|
22
|
+
orderType: 'DESC',
|
|
23
|
+
taskStatuses: taskStatusesArr,
|
|
24
|
+
scope: scopeType
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
<Table rowKey="id" scroll={{ x: 'max-content' }} columns={columns} {...tableProps} />
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### useCreateModal 使用
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
const { editModal, infoModal, memberModal, toggle } = useCreateModal(['edit', 'member', 'info'])
|
|
38
|
+
|
|
39
|
+
toggle(type, data)
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### useSelectOptions 使用
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
const { sceneOptions, sceneMap } = useSelectOptions<string, 'scene'>({
|
|
49
|
+
queryFn: getRecruitSceneList,
|
|
50
|
+
dataKey: 'scene',
|
|
51
|
+
fieldNames: { label: 'recruitTypeName', value: 'recruitEncrypt' }
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### useRequestQuery 使用
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
const { settlementInfo, refresh } = useRequestQuery<ListItemData, 'settlementInfo'>({
|
|
61
|
+
queryFn: getSettlementInfo,
|
|
62
|
+
dataKey: 'settlementInfo',
|
|
63
|
+
dataType: 'Object',
|
|
64
|
+
params: {
|
|
65
|
+
taskId
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
```
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Key } from 'react';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { TablePaginationConfig } from 'antd/es/table/interface';
|
|
5
|
+
import { TableProps as TableProps_2 } from 'antd';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 配置全局表格参数
|
|
9
|
+
* @param config
|
|
10
|
+
*/
|
|
11
|
+
export declare function configureTableOption(config: GlobalTableConfig): void;
|
|
12
|
+
|
|
13
|
+
declare type DataType = 'Array' | 'Object';
|
|
14
|
+
|
|
15
|
+
export declare interface DrawerProps {
|
|
16
|
+
size: number | 'default' | 'large';
|
|
17
|
+
title: string | ReactElement;
|
|
18
|
+
open: boolean;
|
|
19
|
+
maskClosable: boolean;
|
|
20
|
+
destroyOnHidden: boolean;
|
|
21
|
+
placement: Placement;
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare interface FormSubmitResult {
|
|
26
|
+
loading: boolean;
|
|
27
|
+
submit: (number?: unknown) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare interface GlobalTableConfig {
|
|
31
|
+
sortField: string[];
|
|
32
|
+
sortOrder: string[];
|
|
33
|
+
pageSize: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare type MapData<K extends string | number = string | number> = Map<K, string | number | undefined>;
|
|
37
|
+
|
|
38
|
+
declare interface ModalConfig<T = Record<string, any>> {
|
|
39
|
+
width: number;
|
|
40
|
+
title: string | ReactElement | ((data: T) => string | ReactElement);
|
|
41
|
+
maskClosable?: boolean;
|
|
42
|
+
centered?: boolean;
|
|
43
|
+
destroyOnHidden?: boolean;
|
|
44
|
+
placement?: Placement;
|
|
45
|
+
onClose?: () => void;
|
|
46
|
+
onCancel?: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare type ModalInstance<T = any> = {
|
|
50
|
+
visible: boolean;
|
|
51
|
+
data: T;
|
|
52
|
+
modalProps: ModalProps;
|
|
53
|
+
drawerProps: DrawerProps;
|
|
54
|
+
toggle: (data?: T) => void;
|
|
55
|
+
open: (data?: T) => void;
|
|
56
|
+
close: () => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export declare interface ModalProps {
|
|
60
|
+
width: number;
|
|
61
|
+
title: string | ReactElement;
|
|
62
|
+
open: boolean;
|
|
63
|
+
maskClosable?: boolean;
|
|
64
|
+
centered?: boolean;
|
|
65
|
+
destroyOnHidden?: boolean;
|
|
66
|
+
onCancel: () => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare type noop = (this: any, ...args: any[]) => any;
|
|
70
|
+
|
|
71
|
+
declare type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
|
|
72
|
+
|
|
73
|
+
declare type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
74
|
+
|
|
75
|
+
declare interface QueryOptions<K extends string, T = Record<string, any>> {
|
|
76
|
+
queryFn: (data: QueryParamsData_2) => Promise<QueryResponse_2<T>>;
|
|
77
|
+
params?: Record<string, any> | undefined;
|
|
78
|
+
dataType: DataType;
|
|
79
|
+
dataKey: K;
|
|
80
|
+
transform?: (data: unknown) => T;
|
|
81
|
+
initialValue?: Record<string, any> | Record<string, any>[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare interface QueryParamsData {
|
|
85
|
+
pageNo: number;
|
|
86
|
+
pageSize: number;
|
|
87
|
+
orderType?: string;
|
|
88
|
+
orderField?: string;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare type QueryParamsData_2 = Record<string, any>;
|
|
93
|
+
|
|
94
|
+
declare interface QueryResponse {
|
|
95
|
+
status: string;
|
|
96
|
+
data: Record<string, any>[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare interface QueryResponse_2<T> {
|
|
100
|
+
status: string;
|
|
101
|
+
data: T;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare type QueryResult<K extends string, T = Record<string, any>> = {
|
|
105
|
+
loading: boolean;
|
|
106
|
+
refresh: (params?: Record<string, any> | undefined) => void;
|
|
107
|
+
} & {
|
|
108
|
+
[P in K]?: T;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
declare interface RequestFn {
|
|
112
|
+
(val?: unknown): Promise<{
|
|
113
|
+
status: string;
|
|
114
|
+
info: string;
|
|
115
|
+
}>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare interface SelectConfig<K extends string> {
|
|
119
|
+
queryFn: (data: Record<string, any>) => Promise<QueryResponse>;
|
|
120
|
+
params?: Record<string, any>;
|
|
121
|
+
dataKey: K;
|
|
122
|
+
transform?: (data: unknown) => Record<string, any>[];
|
|
123
|
+
fieldNames: {
|
|
124
|
+
label: string;
|
|
125
|
+
value: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare type SelectOption<V extends string | number = string | number> = {
|
|
130
|
+
label: string;
|
|
131
|
+
value: V;
|
|
132
|
+
data?: Record<string, unknown>;
|
|
133
|
+
[key: string]: any;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
declare type SelectOptionsResult<K extends string, V extends string | number = string | number> = Readonly<{
|
|
137
|
+
loading: boolean;
|
|
138
|
+
refresh: () => void;
|
|
139
|
+
} & {
|
|
140
|
+
[P in `${K}Options`]: (SelectOption<V> & Record<string, any>)[];
|
|
141
|
+
} & {
|
|
142
|
+
[P in `${K}Map`]?: MapData<V>;
|
|
143
|
+
}>;
|
|
144
|
+
|
|
145
|
+
declare interface SuccessFn {
|
|
146
|
+
(data: Record<string, any>): void;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare interface TableOptions<T, P = Record<string, any>> {
|
|
150
|
+
queryFn: (data: QueryParamsData) => Promise<TableResponse<T>>;
|
|
151
|
+
params?: P;
|
|
152
|
+
transform?: (result: TableResponse<T>['data']) => TableResponse<T>['data'];
|
|
153
|
+
rowSelection?: boolean;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export declare interface TableProps<T> {
|
|
157
|
+
bordered: boolean;
|
|
158
|
+
size: 'middle';
|
|
159
|
+
sticky: boolean;
|
|
160
|
+
rowSelection: TableProps_2<T>['rowSelection'] | undefined;
|
|
161
|
+
pagination: TablePaginationConfig;
|
|
162
|
+
loading: boolean;
|
|
163
|
+
dataSource: T[];
|
|
164
|
+
onChange: TableProps_2<T>['onChange'];
|
|
165
|
+
locale: {
|
|
166
|
+
emptyText: string | ReactNode;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
declare interface TableResponse<T> {
|
|
171
|
+
status: string;
|
|
172
|
+
data: {
|
|
173
|
+
list: T[];
|
|
174
|
+
totalCount: number;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare interface TableResult<T> {
|
|
179
|
+
/** 查询参数 */
|
|
180
|
+
queryParams: QueryParamsData;
|
|
181
|
+
/** 执行查询方法 */
|
|
182
|
+
search: (params?: Record<string, any>) => void;
|
|
183
|
+
refresh: (params?: Record<string, any>) => void;
|
|
184
|
+
reset: (params?: Record<string, any>) => void;
|
|
185
|
+
/** 选中的行 keys */
|
|
186
|
+
selectedRowKeys: Key[];
|
|
187
|
+
/** 表格属性 */
|
|
188
|
+
tableProps: TableProps<T>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export declare function useCreateModal<const T extends Record<string, ModalConfig>>(configs: T): {
|
|
192
|
+
[K in keyof T as `${string & K}Modal`]: ModalInstance;
|
|
193
|
+
} & {
|
|
194
|
+
open: (type: keyof T, data?: any) => void;
|
|
195
|
+
close: (type: keyof T) => void;
|
|
196
|
+
toggle: (type: keyof T, data?: any) => void;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
|
|
200
|
+
|
|
201
|
+
export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
|
|
202
|
+
|
|
203
|
+
export declare function useRequestQuery<T = Record<string, any> | Record<string, any>[] | undefined, const K extends string = string>({ queryFn, params, dataType, dataKey, initialValue, transform }: QueryOptions<K, T>): QueryResult<K, T>;
|
|
204
|
+
|
|
205
|
+
export declare function useSelectOptions<V extends string | number = string | number, const K extends string = string>({ queryFn, params, dataKey, fieldNames, transform }: SelectConfig<K>): SelectOptionsResult<K, V>;
|
|
206
|
+
|
|
207
|
+
export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, params: initParams, transform, rowSelection }: TableOptions<T>): TableResult<T>;
|
|
208
|
+
|
|
209
|
+
export { }
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { useRef as j, useMemo as V, useState as h, useEffectEvent as A, useEffect as T, useId as W, useCallback as X } from "react";
|
|
2
|
+
import { Empty as J, App as K } from "antd";
|
|
3
|
+
import { create as ee } from "zustand";
|
|
4
|
+
var _ = { exports: {} }, C = {};
|
|
5
|
+
var H;
|
|
6
|
+
function te() {
|
|
7
|
+
if (H) return C;
|
|
8
|
+
H = 1;
|
|
9
|
+
var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
10
|
+
function o(t, s, n) {
|
|
11
|
+
var p = null;
|
|
12
|
+
if (n !== void 0 && (p = "" + n), s.key !== void 0 && (p = "" + s.key), "key" in s) {
|
|
13
|
+
n = {};
|
|
14
|
+
for (var c in s)
|
|
15
|
+
c !== "key" && (n[c] = s[c]);
|
|
16
|
+
} else n = s;
|
|
17
|
+
return s = n.ref, {
|
|
18
|
+
$$typeof: r,
|
|
19
|
+
type: t,
|
|
20
|
+
key: p,
|
|
21
|
+
ref: s !== void 0 ? s : null,
|
|
22
|
+
props: n
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return C.Fragment = a, C.jsx = o, C.jsxs = o, C;
|
|
26
|
+
}
|
|
27
|
+
var I;
|
|
28
|
+
function se() {
|
|
29
|
+
return I || (I = 1, _.exports = te()), _.exports;
|
|
30
|
+
}
|
|
31
|
+
var ae = se();
|
|
32
|
+
function y(r) {
|
|
33
|
+
const a = j(r);
|
|
34
|
+
a.current = V(() => r, [r]);
|
|
35
|
+
const o = j(void 0);
|
|
36
|
+
return o.current || (o.current = function(...t) {
|
|
37
|
+
return a.current.apply(this, t);
|
|
38
|
+
}), o.current;
|
|
39
|
+
}
|
|
40
|
+
const w = {
|
|
41
|
+
sortField: ["orderType", "orderField"],
|
|
42
|
+
sortOrder: ["ASC", "DESC"],
|
|
43
|
+
pageSize: 10
|
|
44
|
+
};
|
|
45
|
+
function ie(r) {
|
|
46
|
+
Object.keys(r).forEach((a) => {
|
|
47
|
+
w[a] = r[a];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function ce({
|
|
51
|
+
queryFn: r,
|
|
52
|
+
params: a,
|
|
53
|
+
transform: o,
|
|
54
|
+
rowSelection: t
|
|
55
|
+
}) {
|
|
56
|
+
const s = w.pageSize, [n, p] = h({
|
|
57
|
+
pagination: {
|
|
58
|
+
showSizeChanger: !0,
|
|
59
|
+
showQuickJumper: !0,
|
|
60
|
+
total: 0,
|
|
61
|
+
pageSize: s,
|
|
62
|
+
current: 1
|
|
63
|
+
},
|
|
64
|
+
list: [],
|
|
65
|
+
queryParams: {
|
|
66
|
+
pageNo: 1,
|
|
67
|
+
pageSize: s,
|
|
68
|
+
...a
|
|
69
|
+
}
|
|
70
|
+
}), { pagination: c, list: f, queryParams: e } = n, { pageNo: l, pageSize: d } = e, [i, m] = h(!0), [g, M] = h([]), R = V(() => {
|
|
71
|
+
if (t)
|
|
72
|
+
return {
|
|
73
|
+
selectedRowKeys: g,
|
|
74
|
+
onChange: (u) => M(u)
|
|
75
|
+
};
|
|
76
|
+
}, [t, g]), b = y(
|
|
77
|
+
(u) => `共 ${u} 条记录 第 ${l}/${Math.ceil(u / d)} 页 `
|
|
78
|
+
), v = async (u) => {
|
|
79
|
+
const { pageNo: L } = u;
|
|
80
|
+
m(!0);
|
|
81
|
+
const E = { ...a, pageSize: d, ...u };
|
|
82
|
+
u.pageNo === void 0 && (E.pageNo = 1), u.pageSize === void 0 && (E.pageSize = d);
|
|
83
|
+
const { data: D } = await r(E), N = o ? o(D) : D, { list: O = [], totalCount: F = 0 } = N || {};
|
|
84
|
+
t && M([]), p({
|
|
85
|
+
list: O,
|
|
86
|
+
queryParams: E,
|
|
87
|
+
pagination: {
|
|
88
|
+
...c,
|
|
89
|
+
current: L,
|
|
90
|
+
pageSize: E.pageSize,
|
|
91
|
+
total: F
|
|
92
|
+
}
|
|
93
|
+
}), m(!1);
|
|
94
|
+
}, P = A(() => {
|
|
95
|
+
v({ ...e, pageNo: 1 });
|
|
96
|
+
}), x = (u) => {
|
|
97
|
+
v({ ...e, ...u, pageNo: 1 });
|
|
98
|
+
}, k = (u) => {
|
|
99
|
+
v({ ...e, ...u });
|
|
100
|
+
}, S = (u) => {
|
|
101
|
+
v({ ...u, pageSize: d, pageNo: 1 });
|
|
102
|
+
}, z = (u, L, E, D) => {
|
|
103
|
+
const { action: N } = D;
|
|
104
|
+
if (["paginate", "sort"].includes(N)) {
|
|
105
|
+
const { current: O, pageSize: F } = u, { field: G, order: q } = E, [Q, Y] = w.sortField, [Z, B] = w.sortOrder, U = {
|
|
106
|
+
...e,
|
|
107
|
+
[Q]: q ? q === "ascend" ? Z : B : void 0,
|
|
108
|
+
[Y]: G,
|
|
109
|
+
pageNo: O,
|
|
110
|
+
pageSize: F
|
|
111
|
+
};
|
|
112
|
+
v(U);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return T(() => {
|
|
116
|
+
P();
|
|
117
|
+
}, []), {
|
|
118
|
+
queryParams: e,
|
|
119
|
+
search: y(x),
|
|
120
|
+
refresh: y(k),
|
|
121
|
+
reset: y(S),
|
|
122
|
+
selectedRowKeys: g,
|
|
123
|
+
tableProps: {
|
|
124
|
+
bordered: !0,
|
|
125
|
+
size: "middle",
|
|
126
|
+
sticky: !0,
|
|
127
|
+
rowSelection: R,
|
|
128
|
+
loading: i,
|
|
129
|
+
dataSource: f,
|
|
130
|
+
pagination: { ...c, showTotal: b },
|
|
131
|
+
onChange: y(z),
|
|
132
|
+
locale: {
|
|
133
|
+
emptyText: i ? "" : /* @__PURE__ */ ae.jsx(J, { image: J.PRESENTED_IMAGE_SIMPLE })
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const $ = ee((r) => ({
|
|
139
|
+
modals: {},
|
|
140
|
+
toggleModal: (a, o) => r((t) => {
|
|
141
|
+
const n = t.modals[a]?.visible || !1;
|
|
142
|
+
return {
|
|
143
|
+
modals: {
|
|
144
|
+
...t.modals,
|
|
145
|
+
[a]: {
|
|
146
|
+
visible: !n,
|
|
147
|
+
data: n ? {} : o || {}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}),
|
|
152
|
+
setModal: (a, o, t) => r((s) => ({
|
|
153
|
+
modals: {
|
|
154
|
+
...s.modals,
|
|
155
|
+
[a]: {
|
|
156
|
+
visible: o,
|
|
157
|
+
data: o ? t || {} : {}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
})),
|
|
161
|
+
clearModals: (a) => r((o) => {
|
|
162
|
+
const t = { ...o.modals };
|
|
163
|
+
return a.forEach((s) => {
|
|
164
|
+
delete t[s];
|
|
165
|
+
}), { modals: t };
|
|
166
|
+
})
|
|
167
|
+
}));
|
|
168
|
+
function le(r) {
|
|
169
|
+
const a = $((e) => e.modals), o = $((e) => e.toggleModal), t = $((e) => e.setModal), s = $((e) => e.clearModals), n = W(), p = j([]), c = Object.keys(r);
|
|
170
|
+
T(() => (p.current = c.map(
|
|
171
|
+
(e) => `${n}-${e}`
|
|
172
|
+
), () => {
|
|
173
|
+
s(p.current);
|
|
174
|
+
}), []);
|
|
175
|
+
const f = {};
|
|
176
|
+
return c.forEach((e) => {
|
|
177
|
+
const l = `${n}-${e}`, d = a[l] ?? { visible: !1, data: {} }, i = r[e], m = typeof i.title == "function" ? i.title(d.data) : i.title;
|
|
178
|
+
f[`${e}Modal`] = {
|
|
179
|
+
visible: d.visible,
|
|
180
|
+
data: d.data,
|
|
181
|
+
modalProps: {
|
|
182
|
+
width: i.width,
|
|
183
|
+
title: m,
|
|
184
|
+
open: d.visible,
|
|
185
|
+
maskClosable: i.maskClosable ?? !1,
|
|
186
|
+
centered: i.centered ?? !0,
|
|
187
|
+
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
188
|
+
onCancel: i.onCancel ?? (() => t(l, !1))
|
|
189
|
+
},
|
|
190
|
+
drawerProps: {
|
|
191
|
+
size: i.width,
|
|
192
|
+
title: m,
|
|
193
|
+
open: d.visible,
|
|
194
|
+
maskClosable: i.maskClosable ?? !0,
|
|
195
|
+
destroyOnHidden: i.destroyOnHidden ?? !0,
|
|
196
|
+
placement: i.placement ?? "right",
|
|
197
|
+
onClose: i.onClose ?? (() => t(l, !1))
|
|
198
|
+
},
|
|
199
|
+
toggle: (g) => o(l, g),
|
|
200
|
+
open: (g) => t(l, !0, g),
|
|
201
|
+
close: () => t(l, !1)
|
|
202
|
+
};
|
|
203
|
+
}), f.toggle = (e, l) => {
|
|
204
|
+
o(`${n}-${e}`, l);
|
|
205
|
+
}, f.open = (e, l) => {
|
|
206
|
+
t(`${n}-${e}`, !0, l);
|
|
207
|
+
}, f.close = (e) => {
|
|
208
|
+
t(`${n}-${e}`, !1);
|
|
209
|
+
}, f;
|
|
210
|
+
}
|
|
211
|
+
function ue({ queryFn: r, params: a, dataKey: o, fieldNames: t, transform: s }) {
|
|
212
|
+
const [n, p] = h({
|
|
213
|
+
list: [],
|
|
214
|
+
mapData: /* @__PURE__ */ new Map()
|
|
215
|
+
}), [c, f] = h(!1), e = async () => {
|
|
216
|
+
f(!0);
|
|
217
|
+
const { data: g, status: M } = await r(a);
|
|
218
|
+
if (M === "success") {
|
|
219
|
+
const b = (s ? s(g) : g) || [], { label: v, value: P } = t, x = /* @__PURE__ */ new Map([]), k = b.map((S) => {
|
|
220
|
+
const z = S[P];
|
|
221
|
+
return x.set(z, S[v]), {
|
|
222
|
+
label: S[v],
|
|
223
|
+
value: z,
|
|
224
|
+
data: S
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
p((S) => ({ ...S, list: k, mapData: x }));
|
|
228
|
+
}
|
|
229
|
+
f(!1);
|
|
230
|
+
}, l = A(e), d = y(() => {
|
|
231
|
+
e();
|
|
232
|
+
});
|
|
233
|
+
T(() => {
|
|
234
|
+
l();
|
|
235
|
+
}, []);
|
|
236
|
+
const { list: i, mapData: m } = n;
|
|
237
|
+
return {
|
|
238
|
+
loading: c,
|
|
239
|
+
refresh: d,
|
|
240
|
+
[`${o}Options`]: i,
|
|
241
|
+
[`${o}Map`]: m
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function de(r, a) {
|
|
245
|
+
const [o, t] = h(!1), { message: s } = K.useApp(), n = X(async (p) => {
|
|
246
|
+
try {
|
|
247
|
+
t(!0);
|
|
248
|
+
const c = await r(p), { status: f, info: e } = c;
|
|
249
|
+
f == "success" && (a(c), s.success(e));
|
|
250
|
+
} catch {
|
|
251
|
+
}
|
|
252
|
+
t(!1);
|
|
253
|
+
}, [r, a, s]);
|
|
254
|
+
return {
|
|
255
|
+
loading: o,
|
|
256
|
+
submit: n
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function pe({
|
|
260
|
+
queryFn: r,
|
|
261
|
+
params: a,
|
|
262
|
+
dataType: o,
|
|
263
|
+
dataKey: t,
|
|
264
|
+
initialValue: s,
|
|
265
|
+
transform: n
|
|
266
|
+
}) {
|
|
267
|
+
const p = s || (o === "Array" ? [] : /* @__PURE__ */ Object.create({})), [c, f] = h(p), [e, l] = h(!1), d = async (g) => {
|
|
268
|
+
l(!0);
|
|
269
|
+
const { data: M, status: R } = await r(g ?? a);
|
|
270
|
+
if (R === "success") {
|
|
271
|
+
const b = n ? n(M) : M;
|
|
272
|
+
f(b);
|
|
273
|
+
}
|
|
274
|
+
l(!1);
|
|
275
|
+
}, i = A(d);
|
|
276
|
+
T(() => {
|
|
277
|
+
i();
|
|
278
|
+
}, []);
|
|
279
|
+
const m = y((g) => {
|
|
280
|
+
d(g);
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
[t]: c,
|
|
284
|
+
loading: e,
|
|
285
|
+
refresh: m
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
export {
|
|
289
|
+
ie as configureTableOption,
|
|
290
|
+
le as useCreateModal,
|
|
291
|
+
de as useFormSubmit,
|
|
292
|
+
y as useMemoizedFn,
|
|
293
|
+
pe as useRequestQuery,
|
|
294
|
+
ue as useSelectOptions,
|
|
295
|
+
ce as useTableList
|
|
296
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@basestone/hooks",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "1.3.6",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "leafront",
|
|
7
|
+
"email": "leafront@126.com"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/base-stone/hooks.git"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/design-hooks.es.prod.js",
|
|
22
|
+
"module": "./dist/design-hooks.es.prod.js",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/design-hooks.es.prod.js",
|
|
26
|
+
"types": "./dist/design-hooks.es.prod.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/base-stone/design-hooks",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build:prod": "tsc && vite build",
|
|
33
|
+
"build:publish": "npm run build:prod && npm publish",
|
|
34
|
+
"eslint": "eslint ./src --fix",
|
|
35
|
+
"prettier": "prettier --write \"./src/**/*.{tsx,ts}\"",
|
|
36
|
+
"lint:js": "npm run eslint && npm run prettier"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^9.39.2",
|
|
40
|
+
"@types/node": "^25.0.10",
|
|
41
|
+
"@types/react": "^19.2.9",
|
|
42
|
+
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
43
|
+
"classnames": "^2.5.1",
|
|
44
|
+
"eslint": "^9.39.2",
|
|
45
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
46
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
47
|
+
"eslint-plugin-react-refresh": "^0.4.26",
|
|
48
|
+
"prettier": "^3.8.1",
|
|
49
|
+
"rollup-plugin-shell": "^1.0.9",
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"typescript-eslint": "^8.54.0",
|
|
52
|
+
"vite": "^7.3.1",
|
|
53
|
+
"vite-plugin-dts": "^4.5.4"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"antd": "^6.2.2",
|
|
57
|
+
"react": "^19.2.4",
|
|
58
|
+
"zustand": "^5.0.10"
|
|
59
|
+
}
|
|
60
|
+
}
|