@_tc/template-core 0.0.1-bate.37 → 0.0.1-bate.38
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/cjs/bundler/utils.js +1 -1
- package/cjs/packages/core/index.js +1 -1
- package/cjs/packages/core/loader/config.js +4 -2
- package/cjs/packages/core/loader/controller.js +2 -3
- package/cjs/packages/core/loader/extend.js +1 -2
- package/cjs/packages/core/loader/middleware.js +2 -3
- package/cjs/packages/core/loader/model.js +7 -3
- package/cjs/packages/core/loader/router-schema.js +4 -2
- package/cjs/packages/core/loader/router.js +10 -6
- package/cjs/packages/core/loader/service.js +2 -2
- package/cjs/packages/utils/runFileFn.js +46 -1
- package/esm/bundler/utils.js +1 -1
- package/esm/packages/core/index.js +1 -2
- package/esm/packages/core/loader/config.js +4 -3
- package/esm/packages/core/loader/controller.js +2 -4
- package/esm/packages/core/loader/extend.js +1 -3
- package/esm/packages/core/loader/middleware.js +2 -4
- package/esm/packages/core/loader/model.js +7 -4
- package/esm/packages/core/loader/router-schema.js +4 -3
- package/esm/packages/core/loader/router.js +10 -7
- package/esm/packages/core/loader/service.js +2 -3
- package/esm/packages/utils/runFileFn.js +47 -1
- package/fe/frontend/dash/Dashboard.js +11 -1
- package/fe/frontend/dash/dash.entry.js +19 -1
- package/fe/frontend/main.js +2 -0
- package/fe/frontend/widgets/common/CRUD/CRUD.js +1 -0
- package/fe/frontend/widgets/common/importComponent.js +1 -0
- package/fe/frontend/widgets/common/language.js +1 -0
- package/fe/frontend/widgets/common/menu.d.ts +12 -0
- package/fe/frontend/widgets/common/menu.js +21 -0
- package/fe/frontend/widgets/common/request.d.ts +3 -0
- package/fe/frontend/widgets/common/request.js +6 -0
- package/fe/frontend/widgets/components/BasePage/HeaderView.js +3 -1
- package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/PopFrom.js +15 -0
- package/fe/frontend/widgets/defaultPages/Schema/components/SchemaSearch/index.js +5 -0
- package/fe/frontend/widgets/defaultPages/Schema/components/SchemaTable/index.js +13 -1
- package/fe/frontend/widgets/defaultPages/Schema/data/eventInfo.js +4 -4
- package/fe/frontend/widgets/defaultPages/Schema/index.js +7 -0
- package/fe/frontend/widgets/defaultPages/Schema/schemaType.d.ts +9 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.d.ts +19 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.js +4 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.d.ts +14 -0
- package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.js +2 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/schemaConversion.js +43 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/validator.d.ts +3 -0
- package/fe/frontend/widgets/defaultPages/Schema/utils/validator.js +5 -0
- package/fe/frontend/widgets/defaultPages/SidebarSlotPage/SidebarSlotContainer.js +7 -0
- package/fe/frontend/widgets/defaultPages/SidebarSlotPage/index.js +1 -0
- package/fe/frontend/widgets/defaultPages/SlotPage/index.js +2 -0
- package/fe/frontend/widgets/hooks/useCurrentMenuData.d.ts +8 -0
- package/fe/frontend/widgets/hooks/useCurrentMenuData.js +8 -0
- package/fe/frontend/widgets/store/mode.d.ts +3 -0
- package/fe/frontend/widgets/store/mode.js +1 -0
- package/fe/model/types/data/button.d.ts +9 -0
- package/fe/model/types/data/button.js +15 -0
- package/fe/model/types/data/component.d.ts +24 -0
- package/fe/model/types/data/component.js +10 -0
- package/fe/model/types/data/fetchInfo.d.ts +12 -0
- package/fe/model/types/data/schema.d.ts +51 -0
- package/fe/model/types/menuType.d.ts +29 -0
- package/fe/model/types/model.d.ts +13 -0
- package/fe/packages/common/i18n/default.d.ts +5 -0
- package/fe/packages/common/i18n/default.js +5 -0
- package/fe/packages/common/i18n/en-US.d.ts +5 -0
- package/fe/packages/common/i18n/en-US.js +5 -0
- package/fe/packages/common/i18n/index.d.ts +24 -0
- package/fe/packages/common/i18n/index.js +31 -0
- package/fe/packages/common/i18n/types.d.ts +24 -0
- package/fe/packages/ui/react/components/Button/Button.d.ts +33 -0
- package/fe/packages/ui/react/components/Button/Button.js +3 -0
- package/fe/packages/ui/react/components/Button/SumbitButton.d.ts +4 -0
- package/fe/packages/ui/react/components/Button/SumbitButton.js +4 -0
- package/fe/packages/ui/react/components/ConfirmDialog/ConfirmDialog.d.ts +8 -0
- package/fe/packages/ui/react/components/DataTable/index.d.ts +19 -0
- package/fe/packages/ui/react/components/DataTable/index.js +4 -0
- package/fe/packages/ui/react/components/Date/Calendar.d.ts +13 -0
- package/fe/packages/ui/react/components/Date/Calendar.js +10 -1
- package/fe/packages/ui/react/components/Date/Date.d.ts +11 -0
- package/fe/packages/ui/react/components/Date/Date.js +19 -0
- package/fe/packages/ui/react/components/Date/LocaleContext.d.ts +4 -0
- package/fe/packages/ui/react/components/Date/LocaleContext.js +4 -0
- package/fe/packages/ui/react/components/Date/LocaleProvider.d.ts +11 -0
- package/fe/packages/ui/react/components/Date/LocaleProvider.js +11 -0
- package/fe/packages/ui/react/components/Date/TimePicker.js +1 -0
- package/fe/packages/ui/react/components/Date/dateLocaleStore.d.ts +6 -0
- package/fe/packages/ui/react/components/Date/locales.d.ts +19 -0
- package/fe/packages/ui/react/components/Date/locales.js +9 -0
- package/fe/packages/ui/react/components/Drawer/Drawer.d.ts +6 -0
- package/fe/packages/ui/react/components/Dropdown/Dropdown.d.ts +1 -0
- package/fe/packages/ui/react/components/Form/Form.d.ts +6 -0
- package/fe/packages/ui/react/components/Form/FormItem.d.ts +21 -0
- package/fe/packages/ui/react/components/Form/FormItem.js +8 -1
- package/fe/packages/ui/react/components/Form/SchemaForm/data.js +1 -0
- package/fe/packages/ui/react/components/Form/SchemaForm/index.d.ts +93 -0
- package/fe/packages/ui/react/components/Form/SchemaForm/index.js +5 -1
- package/fe/packages/ui/react/components/ImagePreview/ImagePreview.js +8 -0
- package/fe/packages/ui/react/components/ImagePreview/PreviewImage.d.ts +3 -0
- package/fe/packages/ui/react/components/Input/Input.d.ts +22 -0
- package/fe/packages/ui/react/components/Input/Input.js +3 -0
- package/fe/packages/ui/react/components/InputNumber/InputNumber.d.ts +2 -0
- package/fe/packages/ui/react/components/Label/Label.d.ts +29 -0
- package/fe/packages/ui/react/components/Label/Label.js +2 -0
- package/fe/packages/ui/react/components/Menu/Menu.js +4 -0
- package/fe/packages/ui/react/components/Menu/SubMenu.d.ts +7 -0
- package/fe/packages/ui/react/components/Menu/SubMenu.js +46 -1
- package/fe/packages/ui/react/components/Menu/menuTypes.d.ts +1 -0
- package/fe/packages/ui/react/components/Message/Message.d.ts +7 -0
- package/fe/packages/ui/react/components/Message/Message.js +3 -0
- package/fe/packages/ui/react/components/Message/MessageManager.js +8 -0
- package/fe/packages/ui/react/components/Modal/Modal.d.ts +6 -0
- package/fe/packages/ui/react/components/Modal/Modal.js +1 -0
- package/fe/packages/ui/react/components/Modal/ModalManager.d.ts +12 -0
- package/fe/packages/ui/react/components/Modal/ModalManager.js +4 -1
- package/fe/packages/ui/react/components/Overlay/Overlay.d.ts +3 -0
- package/fe/packages/ui/react/components/Pagination/Pagination.d.ts +7 -0
- package/fe/packages/ui/react/components/Pagination/Pagination.js +8 -1
- package/fe/packages/ui/react/components/Popup/Popup.js +14 -2
- package/fe/packages/ui/react/components/Search/Search.d.ts +3 -0
- package/fe/packages/ui/react/components/Select/Select.d.ts +5 -0
- package/fe/packages/ui/react/components/Select/Select.js +4 -0
- package/fe/packages/ui/react/components/Skeleton/Skeleton.d.ts +15 -0
- package/fe/packages/ui/react/components/Skeleton/Skeleton.js +1 -1
- package/fe/packages/ui/react/components/TableSearch/TableSearch.d.ts +37 -0
- package/fe/packages/ui/react/components/TableSearch/TableSearch.js +4 -1
- package/fe/packages/ui/react/components/Textarea/Textarea.d.ts +46 -0
- package/fe/packages/ui/react/components/Textarea/Textarea.js +1 -0
- package/fe/packages/ui/react/components/Tooltip/Tooltip.d.ts +16 -0
- package/fe/packages/ui/react/components/Tooltip/Tooltip.js +8 -0
- package/fe/packages/ui/react/components/TreeSelect/TreeSelect.d.ts +6 -0
- package/fe/packages/ui/react/components/TreeSelect/TreeSelect.js +6 -0
- package/fe/packages/ui/react/components/Upload/Upload.d.ts +27 -0
- package/fe/packages/ui/react/components/breadcrumb/breadcrumb.js +9 -0
- package/fe/packages/ui/react/components/hooks/useDropdownPositioning.d.ts +6 -0
- package/fe/packages/ui/react/components/hooks/useDropdownPositioning.js +14 -0
- package/fe/packages/ui/react/components/hooks/useInputController.d.ts +3 -0
- package/fe/packages/ui/react/components/hooks/useInputController.js +7 -0
- package/fe/packages/ui/react/components/testPage/MenuTestPage.js +3 -0
- package/fe/packages/ui/react/components/testPage/index.js +26 -0
- package/fe/packages/ui/react/hooks/useExecuteOnce.d.ts +19 -1
- package/fe/packages/ui/react/hooks/useExecuteOnce.js +22 -1
- package/fe/packages/ui/react/hooks/useRefState.d.ts +12 -0
- package/fe/packages/ui/react/hooks/useRefState.js +1 -0
- package/fe/packages/ui/react/hooks/useWatch.d.ts +8 -0
- package/fe/packages/ui/react/i18n/I18nProvider.d.ts +18 -0
- package/fe/packages/ui/react/i18n/useI18n.d.ts +4 -0
- package/fe/packages/ui/react/i18n/useI18n.js +4 -0
- package/fe/packages/ui/react/index.js +2 -0
- package/fe/packages/ui/react/lib/export.d.ts +44 -0
- package/fe/packages/ui/react/lib/export.js +40 -0
- package/fe/packages/ui/react/lib/utils.d.ts +24 -0
- package/fe/packages/ui/react/lib/utils.js +25 -0
- package/fe/packages/ui/react/stores/breadcrumb.js +2 -0
- package/model/index.d.ts +2 -0
- package/model/types/data/button.d.ts +32 -0
- package/model/types/data/component.d.ts +61 -0
- package/model/types/data/fetchInfo.d.ts +20 -0
- package/model/types/data/schema.d.ts +98 -0
- package/model/types/data/search.d.ts +7 -0
- package/model/types/index.d.ts +2 -0
- package/model/types/menuType.d.ts +73 -0
- package/model/types/model.d.ts +33 -0
- package/model/types/test.d.ts +2 -0
- package/package.json +10 -7
- package/types/packages/utils/runFileFn.d.ts +5 -3
|
@@ -16,15 +16,27 @@ const baseRoutes = [
|
|
|
16
16
|
path: `/testPage`,
|
|
17
17
|
component: renderImportComponent(import('../testPage')),
|
|
18
18
|
},
|
|
19
|
+
//
|
|
19
20
|
{
|
|
20
21
|
path: `todo`,
|
|
21
22
|
component: renderImportComponent(import('../widgets/defaultPages/Todo')),
|
|
22
23
|
},
|
|
24
|
+
// sidebarRoutes 追加在这
|
|
25
|
+
// {
|
|
26
|
+
// path: "/iframe",
|
|
27
|
+
// component: renderImportComponent(import("../defaultPages/Iframe")),
|
|
28
|
+
// },
|
|
29
|
+
// {
|
|
30
|
+
// path: "/schema",
|
|
31
|
+
// component: renderImportComponent(import("../defaultPages/Schema")),
|
|
32
|
+
// },
|
|
33
|
+
// 插入自定义路由
|
|
23
34
|
],
|
|
24
35
|
},
|
|
25
36
|
];
|
|
26
37
|
const sidebarRoutes = [
|
|
27
38
|
{
|
|
39
|
+
// path: `/:${QK.k}/:${QK.sk}`,
|
|
28
40
|
path: `/:${QK.k}/*`,
|
|
29
41
|
component: renderImportComponent(import('../widgets/defaultPages/SidebarSlotPage')),
|
|
30
42
|
children: [
|
|
@@ -36,6 +48,11 @@ const sidebarRoutes = [
|
|
|
36
48
|
path: `:${QK.sk}`,
|
|
37
49
|
component: renderImportComponent(import('../widgets/defaultPages/SlotPage')),
|
|
38
50
|
},
|
|
51
|
+
// {
|
|
52
|
+
// path: "schema",
|
|
53
|
+
// component: renderImportComponent(import("../defaultPages/Schema")),
|
|
54
|
+
// },
|
|
55
|
+
// 插入自定义路由
|
|
39
56
|
],
|
|
40
57
|
},
|
|
41
58
|
{
|
|
@@ -54,7 +71,8 @@ const sidebarRoutes = [
|
|
|
54
71
|
},
|
|
55
72
|
];
|
|
56
73
|
const getDefaultPageRoutes = () => {
|
|
57
|
-
baseRoutes[0]
|
|
74
|
+
// getBusinessRoutes(baseRoutes, sidebarRoutes[0]?.childrens ?? []);
|
|
75
|
+
baseRoutes[0]?.children?.push(...sidebarRoutes);
|
|
58
76
|
return [...baseRoutes];
|
|
59
77
|
};
|
|
60
78
|
initApp(({ children }) => _jsx("div", { className: "dash", children: children }), {
|
package/fe/frontend/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { lazy, Suspense } from 'react';
|
|
3
3
|
export const renderImportComponent = (c, fallback) => {
|
|
4
4
|
const Component = lazy(() => c);
|
|
5
|
+
// TODO 加上页面级 loading
|
|
5
6
|
const showFallback = typeof fallback !== 'undefined' ? fallback : 'loading';
|
|
6
7
|
return (_jsx(Suspense, { fallback: showFallback, children: _jsx(Component, {}) }));
|
|
7
8
|
};
|
|
@@ -9,9 +9,21 @@ type MenuItem = {
|
|
|
9
9
|
}>;
|
|
10
10
|
};
|
|
11
11
|
export declare const enum QK {
|
|
12
|
+
/**
|
|
13
|
+
* project key
|
|
14
|
+
*/
|
|
12
15
|
pk = "projk",
|
|
16
|
+
/**
|
|
17
|
+
* key topMenu key
|
|
18
|
+
*/
|
|
13
19
|
k = "key",
|
|
20
|
+
/**
|
|
21
|
+
* sidebar key leftMenu key
|
|
22
|
+
*/
|
|
14
23
|
sk = "sidek",
|
|
24
|
+
/**
|
|
25
|
+
* 自定义 页面的key
|
|
26
|
+
*/
|
|
15
27
|
ck = "custk"
|
|
16
28
|
}
|
|
17
29
|
export declare const leftSidebarBasePath = "_sidebar_";
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { modeStore } from "../../widgets/store/mode";
|
|
2
2
|
export var QK;
|
|
3
3
|
(function (QK) {
|
|
4
|
+
/**
|
|
5
|
+
* project key
|
|
6
|
+
*/
|
|
4
7
|
QK["pk"] = "projk";
|
|
8
|
+
/**
|
|
9
|
+
* key topMenu key
|
|
10
|
+
*/
|
|
5
11
|
QK["k"] = "key";
|
|
12
|
+
/**
|
|
13
|
+
* sidebar key leftMenu key
|
|
14
|
+
*/
|
|
6
15
|
QK["sk"] = "sidek";
|
|
16
|
+
/**
|
|
17
|
+
* 自定义 页面的key
|
|
18
|
+
*/
|
|
7
19
|
QK["ck"] = "custk";
|
|
8
20
|
})(QK || (QK = {}));
|
|
9
21
|
export const leftSidebarBasePath = "_sidebar_";
|
|
@@ -40,9 +52,11 @@ const generateMenuItem = (item) => {
|
|
|
40
52
|
let path = `/${item.key}`;
|
|
41
53
|
let search = new URLSearchParams(query).toString();
|
|
42
54
|
if (item.moduleType === "sidebar") {
|
|
55
|
+
// query[QK.sk] = item.sidebarConfig.menu[0].key;
|
|
43
56
|
const sfMenu = findMenuItem(item.sidebarConfig.menu, item.sidebarConfig.menu[0].key);
|
|
44
57
|
path += `${sfMenu.path.pathname}`;
|
|
45
58
|
search = sfMenu.path.search ?? "";
|
|
59
|
+
// path += `/pending`;
|
|
46
60
|
}
|
|
47
61
|
data = {
|
|
48
62
|
...item,
|
|
@@ -61,6 +75,13 @@ const generateMenuItem = (item) => {
|
|
|
61
75
|
export const findMenuItem = (menuData, key) => {
|
|
62
76
|
let data = undefined;
|
|
63
77
|
const useFirstAvailableMenu = typeof key === "undefined";
|
|
78
|
+
/**
|
|
79
|
+
* url query 分为
|
|
80
|
+
*
|
|
81
|
+
* projk 为项目key
|
|
82
|
+
* key 当前选择的top菜单key
|
|
83
|
+
* sidek 为侧边栏选中的key
|
|
84
|
+
*/
|
|
64
85
|
for (const item of menuData) {
|
|
65
86
|
if (item.menuType === "module") {
|
|
66
87
|
if (useFirstAvailableMenu || item.key === key) {
|
|
@@ -16,6 +16,9 @@ export interface BaseResponse<T> {
|
|
|
16
16
|
code: number;
|
|
17
17
|
message: string;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* GET/DELETE 不发送 body;统一把 data 转到 params。
|
|
21
|
+
* */
|
|
19
22
|
export declare function get<T = unknown, D = unknown>(url: string, data?: D, config?: RequestConfig<D>): Promise<ResponseConfig<BaseResponse<T>, D>>;
|
|
20
23
|
export declare function post<T = unknown, D = unknown>(url: string, data?: D, config?: RequestConfig<D>): Promise<ResponseConfig<BaseResponse<T>, D>>;
|
|
21
24
|
export declare function put<T = unknown, D = unknown>(url: string, data?: D, config?: RequestConfig<D>): Promise<ResponseConfig<BaseResponse<T>, D>>;
|
|
@@ -24,6 +24,7 @@ const removeBaseurlFromURL = (config) => {
|
|
|
24
24
|
const pathname = requestURL.pathname.slice(basePath.length) || '/';
|
|
25
25
|
config.url = `${pathname}${requestURL.search}${requestURL.hash}`;
|
|
26
26
|
};
|
|
27
|
+
// ---- Request Interceptors ----
|
|
27
28
|
api.interceptors.request.use(async (config) => {
|
|
28
29
|
removeBaseurlFromURL(config);
|
|
29
30
|
const token = await getAuthToken();
|
|
@@ -47,6 +48,7 @@ api.interceptors.request.use((config) => {
|
|
|
47
48
|
console.debug(`[API] ${config.method?.toUpperCase()} ${config.url}`);
|
|
48
49
|
return config;
|
|
49
50
|
});
|
|
51
|
+
// ---- Response Interceptors ----
|
|
50
52
|
api.interceptors.response.use((res) => res, async (err) => {
|
|
51
53
|
const axiosErr = err;
|
|
52
54
|
if (axiosErr.response?.status === 401) {
|
|
@@ -62,6 +64,7 @@ api.interceptors.response.use((res) => res, async (err) => {
|
|
|
62
64
|
});
|
|
63
65
|
return Promise.reject(err);
|
|
64
66
|
});
|
|
67
|
+
// ---- Helpers ----
|
|
65
68
|
function extractErrorMessage(err) {
|
|
66
69
|
if (!(err instanceof Error))
|
|
67
70
|
return 'Unknown error';
|
|
@@ -82,6 +85,9 @@ function extractErrorMessage(err) {
|
|
|
82
85
|
return 'Request timed out';
|
|
83
86
|
return 'Network error';
|
|
84
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* GET/DELETE 不发送 body;统一把 data 转到 params。
|
|
90
|
+
* */
|
|
85
91
|
export function get(url, data, config) {
|
|
86
92
|
const hasDataParams = data !== undefined && data !== null && typeof data === 'object';
|
|
87
93
|
const getConfig = hasDataParams
|
|
@@ -9,6 +9,8 @@ const headerThemeStyle = {
|
|
|
9
9
|
};
|
|
10
10
|
const HeaderView = (props) => {
|
|
11
11
|
const { title, menu, userArea, children } = props ?? defaultProps;
|
|
12
|
-
return (_jsxs("div", { className: "header-view", style: headerThemeStyle, children: [_jsxs("header", { className: cn("header flex h-16 items-center border-b",
|
|
12
|
+
return (_jsxs("div", { className: "header-view", style: headerThemeStyle, children: [_jsxs("header", { className: cn("header flex h-16 items-center border-b",
|
|
13
|
+
// "border-[hsl(var(--theme-bg)/0.14)] bg-(--header-bg) text-(--header-fg)",
|
|
14
|
+
"shadow-[0_10px_30px_var(--header-shadow)]"), children: [_jsx("div", { className: "brand flex w-60 items-center border-r border-[hsl(var(--theme-bg)/0.14)] px-6 text-base font-semibold tracking-[0.02em] text-(--header-fg)", children: title ?? defaultTitle }), _jsx("div", { className: "top-menu flex flex-1 items-center px-6 text-(--header-fg)", children: menu }), _jsx("div", { className: "user-area flex items-center justify-end border-l border-[hsl(var(--theme-bg)/0.14)] px-6 text-(--header-fg)", children: userArea })] }), children] }));
|
|
13
15
|
};
|
|
14
16
|
export default HeaderView;
|
|
@@ -62,6 +62,16 @@ const PopForm = memo((props) => {
|
|
|
62
62
|
const { schema, config, api } = useComConfig({ comName: props.comName });
|
|
63
63
|
const formRef = useRef(null);
|
|
64
64
|
const [loading, setLoading] = useState(false);
|
|
65
|
+
/**
|
|
66
|
+
* 1. 生成 schemas
|
|
67
|
+
* 2. 根据config 获取相关展示内容、请求数据
|
|
68
|
+
* 3. 支持 create、edit
|
|
69
|
+
*
|
|
70
|
+
*
|
|
71
|
+
* 交互结束时 通知上层 清除show component
|
|
72
|
+
*
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
65
75
|
const schemas = useMemo(() => {
|
|
66
76
|
return generateSchemas(schema);
|
|
67
77
|
}, [schema]);
|
|
@@ -73,6 +83,9 @@ const PopForm = memo((props) => {
|
|
|
73
83
|
};
|
|
74
84
|
const defaultValue = useMemo(() => generateDefaultValue(schema, props.data), [schema, props.data]);
|
|
75
85
|
useExecuteOnce(async () => {
|
|
86
|
+
/**
|
|
87
|
+
* 编辑弹窗需要 获取一下数据
|
|
88
|
+
*/
|
|
76
89
|
if (props.comName === 'editForm' && 'fetchKey' in config) {
|
|
77
90
|
const { fetchKey } = config;
|
|
78
91
|
const params = {
|
|
@@ -87,6 +100,7 @@ const PopForm = memo((props) => {
|
|
|
87
100
|
}, { executionPhase: 'mount' });
|
|
88
101
|
const handleSubmit = useCallback(async (v) => {
|
|
89
102
|
setSubmitting(true);
|
|
103
|
+
// 逻辑处理
|
|
90
104
|
let fetchFn = put;
|
|
91
105
|
if (props.comName === 'createForm') {
|
|
92
106
|
fetchFn = post;
|
|
@@ -94,6 +108,7 @@ const PopForm = memo((props) => {
|
|
|
94
108
|
try {
|
|
95
109
|
const res = await handlingRequestErrors(fetchFn(api, v));
|
|
96
110
|
if (res.data.code === 0) {
|
|
111
|
+
// 通知
|
|
97
112
|
schemaEventBus.getState().emitCom({
|
|
98
113
|
type: merge(eventsInfo.closeCom, eventsInfo.initTable, props.comName === 'createForm' ? eventsInfo.resetSearch : eventsInfo.none),
|
|
99
114
|
});
|
|
@@ -7,6 +7,10 @@ import { memo, useState } from 'react';
|
|
|
7
7
|
import { schemaEventBus } from '../../stores/schemaEventBus';
|
|
8
8
|
import { useSchemaStore } from '../../stores/schemaStore';
|
|
9
9
|
const generateSchemas = (config) => {
|
|
10
|
+
// TODO ? 是否需要缓存
|
|
11
|
+
// const { comSchemaCache } = schemaStore.getState()
|
|
12
|
+
// if (comSchemaCache.has(schemaKey)) {
|
|
13
|
+
// }
|
|
10
14
|
const keys = Object.keys(config);
|
|
11
15
|
const schemas = [];
|
|
12
16
|
let defaultValue = undefined;
|
|
@@ -31,6 +35,7 @@ const generateSchemas = (config) => {
|
|
|
31
35
|
return { schemas, defaultValue };
|
|
32
36
|
};
|
|
33
37
|
const SchemaSearch = memo(() => {
|
|
38
|
+
// 暂时没有 config
|
|
34
39
|
const schema = useSchemaStore((s) => s.searchSchema);
|
|
35
40
|
const [schemas, setSchemas] = useState([]);
|
|
36
41
|
const [defaultValue, setSchemaDefaultValue] = useState(undefined);
|
|
@@ -21,11 +21,14 @@ const generateColumns = (config) => {
|
|
|
21
21
|
keys.forEach((k) => {
|
|
22
22
|
const fieldInfo = config[k];
|
|
23
23
|
if (fieldInfo?.option) {
|
|
24
|
-
const {
|
|
24
|
+
const {
|
|
25
|
+
// comType = 'input', default: defaultFieldValue,
|
|
26
|
+
...fieldProps } = fieldInfo.option;
|
|
25
27
|
columns.push({
|
|
26
28
|
title: getText(fieldInfo.label),
|
|
27
29
|
key: k,
|
|
28
30
|
...fieldProps,
|
|
31
|
+
// fieldProps,
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
34
|
});
|
|
@@ -36,12 +39,15 @@ const generateRowActions = (btnConfigs, rowData, api) => {
|
|
|
36
39
|
const { eventKey, eventOption } = btnConfig;
|
|
37
40
|
switch (eventKey) {
|
|
38
41
|
case 'callComponent':
|
|
42
|
+
// 与 schemaPage通信
|
|
39
43
|
const { emitTable } = schemaEventBus.getState();
|
|
40
44
|
emitTable({ ...rowData, comName: eventOption.comName });
|
|
41
45
|
break;
|
|
42
46
|
case 'remove':
|
|
47
|
+
// 调用api
|
|
43
48
|
if (api) {
|
|
44
49
|
const apiParams = Object.entries(eventOption.params).reduce((o, [k, v]) => {
|
|
50
|
+
// 使用当前行的某个数据
|
|
45
51
|
if (('' + v).includes(VALUE_KEY)) {
|
|
46
52
|
const valueKey = ('' + v).split(VALUE_KEY)[1];
|
|
47
53
|
o[k] = rowData[valueKey];
|
|
@@ -114,15 +120,19 @@ const SchemaTable = memo(({ ref }) => {
|
|
|
114
120
|
const actionColumn = [];
|
|
115
121
|
if (params.config) {
|
|
116
122
|
const { rowButtons, headerButtons } = params.config;
|
|
123
|
+
// 处理row交互
|
|
117
124
|
if (rowButtons) {
|
|
118
125
|
actionColumn.push({
|
|
119
126
|
key: 'action',
|
|
120
127
|
title: getText('操作'),
|
|
121
128
|
actions: (_value, _record, index) => [
|
|
122
129
|
...generateRowActions(rowButtons, _record, params.api),
|
|
130
|
+
// { key: `text-${index}`, label: 'text' },
|
|
131
|
+
// { key: `link-${index}`, label: 'link' },
|
|
123
132
|
],
|
|
124
133
|
});
|
|
125
134
|
}
|
|
135
|
+
// 处理page 交互
|
|
126
136
|
setHandleBtn(headerButtons?.map((c) => {
|
|
127
137
|
const { label, eventKey, eventOption, ...props } = c;
|
|
128
138
|
return {
|
|
@@ -132,10 +142,12 @@ const SchemaTable = memo(({ ref }) => {
|
|
|
132
142
|
schemaEventBus.getState().emitTable(eventOption);
|
|
133
143
|
}
|
|
134
144
|
else {
|
|
145
|
+
// 不存在这种用法
|
|
135
146
|
}
|
|
136
147
|
},
|
|
137
148
|
...props,
|
|
138
149
|
};
|
|
150
|
+
// }
|
|
139
151
|
}) ?? []);
|
|
140
152
|
}
|
|
141
153
|
uColumns(contextColumns.concat(actionColumn));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const eventsInfo = {
|
|
2
|
-
none: 0b00000000000000,
|
|
3
|
-
closeCom: 0b00000000000001,
|
|
4
|
-
initTable: 0b00000000000010,
|
|
5
|
-
resetSearch: 0b00000000000010,
|
|
2
|
+
none: /** */ 0b00000000000000,
|
|
3
|
+
closeCom: /** */ 0b00000000000001,
|
|
4
|
+
initTable: /** */ 0b00000000000010,
|
|
5
|
+
resetSearch: /** */ 0b00000000000010,
|
|
6
6
|
};
|
|
@@ -27,6 +27,9 @@ const Schema = memo(() => {
|
|
|
27
27
|
setShowCompoentKey(comName);
|
|
28
28
|
}, []);
|
|
29
29
|
const comDone = useCallback(({ type }) => {
|
|
30
|
+
/**
|
|
31
|
+
* 解析出需要执行的操作
|
|
32
|
+
*/
|
|
30
33
|
if (isAllowed(type, eventsInfo.closeCom)) {
|
|
31
34
|
setShowCompoentKey(undefined);
|
|
32
35
|
setComProps(undefined);
|
|
@@ -38,11 +41,15 @@ const Schema = memo(() => {
|
|
|
38
41
|
}
|
|
39
42
|
}, []);
|
|
40
43
|
useInit(() => {
|
|
44
|
+
// schema数据分离
|
|
41
45
|
schemaConversion(menu.schemaConfig, menu.key);
|
|
42
46
|
});
|
|
43
47
|
useExecuteOnce(() => {
|
|
48
|
+
// 关联search
|
|
44
49
|
schemaEventBus.getState().subscribeSearch(onSearch);
|
|
50
|
+
// 订阅组件消息
|
|
45
51
|
schemaEventBus.getState().subscribeCom(comDone);
|
|
52
|
+
// 关联table
|
|
46
53
|
schemaEventBus.getState().subscribeTable(callCom);
|
|
47
54
|
}, { executionPhase: executionPhaseType.mount });
|
|
48
55
|
useExecuteOnce(() => {
|
|
@@ -13,7 +13,13 @@ export type NonOptionKey = {
|
|
|
13
13
|
}[AllFieldKeys];
|
|
14
14
|
export type StoreSchemaType = UsedConfigSchema<BaseOption<FieldType[`${AllOptionsPreNames}${SuffixKey}`]>>;
|
|
15
15
|
export type NamedSchemaType<N extends `${AllOptionsPreNames}${SuffixKey}`> = UsedConfigSchema<BaseOption<FieldType[N]>>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取具体名称的 components options 配置
|
|
18
|
+
*/
|
|
16
19
|
export type NamedComOption<N extends CallComNames> = ComponentType<ComponentConfig>[N];
|
|
20
|
+
/**
|
|
21
|
+
* 获取具名 组件配置
|
|
22
|
+
*/
|
|
17
23
|
export type NamedComponentConfig<N extends CallComNames> = ComponentConfig[N];
|
|
18
24
|
type ComponentC<C extends ComponentConfig> = {
|
|
19
25
|
[K in keyof C]: {
|
|
@@ -33,6 +39,9 @@ export declare const enum ComEventType {
|
|
|
33
39
|
close = 0
|
|
34
40
|
}
|
|
35
41
|
export type SchemaComEventInfo = {
|
|
42
|
+
/**
|
|
43
|
+
* 操作权限合集
|
|
44
|
+
*/
|
|
36
45
|
type: number;
|
|
37
46
|
};
|
|
38
47
|
export type CallComponent<T> = {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { SchemaComEventInfo, SchemaDefaultValue, SchemaTableEmitData } from '../schemaType';
|
|
2
|
+
/**
|
|
3
|
+
* 消费方 subscribeSearch(fn)
|
|
4
|
+
* unSubscribeSearch(fn)
|
|
5
|
+
*
|
|
6
|
+
* 通知方 emitSearch (value)
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
2
9
|
type WatchFn<V = SchemaDefaultValue | undefined> = (value: V) => void;
|
|
3
10
|
declare const enum SubscribeEnum {
|
|
4
11
|
search = "search",
|
|
@@ -7,13 +14,25 @@ declare const enum SubscribeEnum {
|
|
|
7
14
|
}
|
|
8
15
|
interface SchemaEventBusStore {
|
|
9
16
|
readonly Subscribers: Map<WatchFn, SubscribeEnum>;
|
|
17
|
+
/**
|
|
18
|
+
* 订阅 Search 变化
|
|
19
|
+
*/
|
|
10
20
|
subscribeSearch: (fn: WatchFn) => void;
|
|
11
21
|
unSubscribeSearch: (fn: WatchFn) => void;
|
|
12
22
|
emitSearch: (v: SchemaDefaultValue | undefined) => void;
|
|
23
|
+
/**
|
|
24
|
+
* 订阅 Table 变化
|
|
25
|
+
*/
|
|
13
26
|
subscribeTable: (fn: WatchFn<SchemaTableEmitData>) => void;
|
|
14
27
|
unSubscribeTable: (fn: WatchFn<SchemaTableEmitData>) => void;
|
|
15
28
|
emitTable: (v: SchemaTableEmitData) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 通用 call
|
|
31
|
+
*/
|
|
16
32
|
emitCall: (v: SchemaDefaultValue | undefined, type: SubscribeEnum) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 订阅组件变化
|
|
35
|
+
*/
|
|
17
36
|
subscribeCom: (fn: WatchFn<SchemaComEventInfo>) => void;
|
|
18
37
|
unSubscribeCom: (fn: WatchFn<SchemaComEventInfo>) => void;
|
|
19
38
|
emitCom: (v: SchemaComEventInfo) => void;
|
|
@@ -9,6 +9,7 @@ var SubscribeEnum;
|
|
|
9
9
|
export const schemaEventBus = createStore((set, get) => {
|
|
10
10
|
return {
|
|
11
11
|
Subscribers: new Map(),
|
|
12
|
+
// com
|
|
12
13
|
subscribeCom(fn) {
|
|
13
14
|
get().Subscribers.set(fn, SubscribeEnum.com);
|
|
14
15
|
},
|
|
@@ -24,6 +25,7 @@ export const schemaEventBus = createStore((set, get) => {
|
|
|
24
25
|
emitCom(v) {
|
|
25
26
|
get().emitCall(v, SubscribeEnum.com);
|
|
26
27
|
},
|
|
28
|
+
// table
|
|
27
29
|
subscribeTable(fn) {
|
|
28
30
|
get().Subscribers.set(fn, SubscribeEnum.table);
|
|
29
31
|
},
|
|
@@ -47,6 +49,7 @@ export const schemaEventBus = createStore((set, get) => {
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
},
|
|
52
|
+
// search
|
|
50
53
|
subscribeSearch(fn) {
|
|
51
54
|
get().Subscribers.set(fn, SubscribeEnum.search);
|
|
52
55
|
},
|
|
@@ -62,5 +65,6 @@ export const schemaEventBus = createStore((set, get) => {
|
|
|
62
65
|
emitSearch(v) {
|
|
63
66
|
get().emitCall(v, SubscribeEnum.search);
|
|
64
67
|
},
|
|
68
|
+
//
|
|
65
69
|
};
|
|
66
70
|
});
|
|
@@ -15,14 +15,28 @@ interface ComSchemaCache {
|
|
|
15
15
|
}
|
|
16
16
|
interface SchemaStoreState extends Partial<FunctionalData> {
|
|
17
17
|
readonly schemaStoreAvailable: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 页面schema 配置
|
|
20
|
+
*/
|
|
18
21
|
readonly schemaCache: LRUCache<FunctionalData>;
|
|
22
|
+
/**
|
|
23
|
+
* 组件schema缓存配置
|
|
24
|
+
*/
|
|
19
25
|
readonly comSchemaCache: LRUCache<ComSchemaCache>;
|
|
20
26
|
}
|
|
21
27
|
interface SchemaStoreActions {
|
|
22
28
|
setSchemaState: (data: Partial<MOmit<SchemaStoreState, 'schemaStoreAvailable' | 'schemaCache'>>) => void;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* 更新 key schema 缓存
|
|
32
|
+
*/
|
|
23
33
|
updateSchemaCache: (data: FunctionalData & {
|
|
24
34
|
schemaKey: string;
|
|
25
35
|
}) => void;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* 更新 组件 配置
|
|
39
|
+
*/
|
|
26
40
|
updateComSchemaCache: (data: ComSchemaCache & {
|
|
27
41
|
schemaKey: string;
|
|
28
42
|
}) => void;
|
|
@@ -11,11 +11,13 @@ export const schemaStore = createStore((set, get) => ({
|
|
|
11
11
|
set({ schemaStoreAvailable: !!get().api });
|
|
12
12
|
},
|
|
13
13
|
updateSchemaCache: (data) => {
|
|
14
|
+
// 直接设置值
|
|
14
15
|
const { schemaKey, ...params } = data;
|
|
15
16
|
const { schemaCache } = get();
|
|
16
17
|
schemaCache.set(schemaKey, params);
|
|
17
18
|
},
|
|
18
19
|
updateComSchemaCache: (data) => {
|
|
20
|
+
// 直接设置值
|
|
19
21
|
const { schemaKey, ...params } = data;
|
|
20
22
|
const { comSchemaCache } = get();
|
|
21
23
|
comSchemaCache.set(schemaKey, params);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { suffixKey } from '../data';
|
|
2
2
|
import { schemaStore } from '../stores/schemaStore';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* 构建出需要optios + 其他字段
|
|
6
|
+
*/
|
|
3
7
|
const buildSchema = (schema, fieldType) => {
|
|
4
8
|
if (!schema.properties)
|
|
5
9
|
return;
|
|
@@ -12,11 +16,14 @@ const buildSchema = (schema, fieldType) => {
|
|
|
12
16
|
const fieldInfo = schema.properties[key];
|
|
13
17
|
const fieldKeys = Object.keys(fieldInfo);
|
|
14
18
|
temSchema.properties[key] = fieldKeys.reduce((o, fieldKey) => {
|
|
19
|
+
// 为xxxoption
|
|
15
20
|
if (fieldKey.indexOf(suffixKey) !== -1) {
|
|
21
|
+
// 需要的option
|
|
16
22
|
if (fieldKey === `${fieldType}${suffixKey}`) {
|
|
17
23
|
o['option'] = fieldInfo[fieldKey];
|
|
18
24
|
}
|
|
19
25
|
}
|
|
26
|
+
// 其余属性
|
|
20
27
|
else {
|
|
21
28
|
;
|
|
22
29
|
o[fieldKey] = fieldInfo[fieldKey];
|
|
@@ -26,21 +33,57 @@ const buildSchema = (schema, fieldType) => {
|
|
|
26
33
|
}
|
|
27
34
|
return temSchema;
|
|
28
35
|
};
|
|
36
|
+
// properties 构建
|
|
37
|
+
// const buildSchema = (data: FieldType, fieldType: AllOptionsPreNames) => {
|
|
38
|
+
// console.log(data);
|
|
39
|
+
// const keys = Object.keys(data) as (keyof FieldType)[];
|
|
40
|
+
// type TargetOptionKey = `${typeof fieldType}${typeof suffixKey}`;
|
|
41
|
+
// type NewState = Partial<{
|
|
42
|
+
// [K in NonOptionKey]: FieldType[K];
|
|
43
|
+
// }> & {
|
|
44
|
+
// option?: FieldType[TargetOptionKey];
|
|
45
|
+
// };
|
|
46
|
+
// const newData = produce<NewState>(data, (temData) => {
|
|
47
|
+
// const newState: NewState = {
|
|
48
|
+
// option: undefined,
|
|
49
|
+
// } as unknown as NewState;
|
|
50
|
+
// keys.forEach((k) => {
|
|
51
|
+
// // 是 Option
|
|
52
|
+
// if (k.indexOf(suffixKey) !== -1) {
|
|
53
|
+
// // 需要的options
|
|
54
|
+
// if (k === (`${fieldType}${suffixKey}` as const)) {
|
|
55
|
+
// newState["option"] = (temData as FieldType)[k];
|
|
56
|
+
// }
|
|
57
|
+
// } else {
|
|
58
|
+
// (newState as any)[k] = (temData as FieldType)[
|
|
59
|
+
// k
|
|
60
|
+
// ] as NewState[keyof NewState];
|
|
61
|
+
// }
|
|
62
|
+
// });
|
|
63
|
+
// return newState;
|
|
64
|
+
// });
|
|
65
|
+
// return newData;
|
|
66
|
+
// };
|
|
29
67
|
export const schemaConversion = (schema, schemaKey) => {
|
|
68
|
+
// 存在缓存直接跳过
|
|
30
69
|
const { schemaCache, setSchemaState } = schemaStore.getState();
|
|
31
70
|
if (schemaCache.has(schemaKey)) {
|
|
71
|
+
// 应用缓存
|
|
32
72
|
setSchemaState({
|
|
33
73
|
...schemaCache.get(schemaKey),
|
|
34
74
|
});
|
|
35
75
|
return;
|
|
36
76
|
}
|
|
37
77
|
const { api, schema: schemaMetadata = {}, componentConfig, tableConfig, searchConfig } = schema;
|
|
78
|
+
// 整个schema 进行移动
|
|
38
79
|
const tableSchema = buildSchema(JSON.parse(JSON.stringify(schemaMetadata)), 'table');
|
|
39
80
|
const searchSchema = buildSchema(JSON.parse(JSON.stringify(schemaMetadata)), 'search');
|
|
40
81
|
let components = {};
|
|
82
|
+
// page components
|
|
41
83
|
if (componentConfig) {
|
|
42
84
|
const componentKeys = Object.keys(componentConfig ?? {});
|
|
43
85
|
components = componentKeys.reduce((o, comKey) => {
|
|
86
|
+
// 获取组件的 schema
|
|
44
87
|
const comSchema = buildSchema(JSON.parse(JSON.stringify(schemaMetadata)), comKey);
|
|
45
88
|
o[comKey] = {
|
|
46
89
|
schema: comSchema,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Ajv } from 'ajv';
|
|
2
2
|
export declare const ajvInstance: Ajv;
|
|
3
|
+
/**
|
|
4
|
+
* 创建验证器
|
|
5
|
+
*/
|
|
3
6
|
export declare function createAjvValidator(schema: object): (rule: object, value: unknown, callback: (errors?: string[]) => void) => void;
|
|
4
7
|
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Ajv } from 'ajv';
|
|
2
|
+
// 初始化 AJV (全局复用)
|
|
2
3
|
export const ajvInstance = new Ajv({ allErrors: true, verbose: true, strict: false });
|
|
4
|
+
/**
|
|
5
|
+
* 创建验证器
|
|
6
|
+
*/
|
|
3
7
|
export function createAjvValidator(schema) {
|
|
4
8
|
const validate = ajvInstance.compile(schema);
|
|
5
9
|
return (rule, value, callback) => {
|
|
@@ -13,6 +17,7 @@ export function createAjvValidator(schema) {
|
|
|
13
17
|
}
|
|
14
18
|
};
|
|
15
19
|
}
|
|
20
|
+
// 格式化错误信息
|
|
16
21
|
function formatError(error) {
|
|
17
22
|
const path = error.instancePath.replace(/^\//, '') || 'value';
|
|
18
23
|
switch (error.keyword) {
|
|
@@ -10,7 +10,12 @@ const SidebarSlotContainer = (props) => {
|
|
|
10
10
|
const params = useRouterParams();
|
|
11
11
|
const [SK, uSK] = useState(params[QK.sk]);
|
|
12
12
|
const nav = useNavigate();
|
|
13
|
+
// menu 初始化选中
|
|
13
14
|
useEffect(() => {
|
|
15
|
+
/**
|
|
16
|
+
* 如果没有 sidebar key 说明当前是 自定义路由
|
|
17
|
+
* 则需要获取 query 中的 ck 来查找 menuinfo
|
|
18
|
+
*/
|
|
14
19
|
if (!params[QK.sk]) {
|
|
15
20
|
if (params[QK.ck]) {
|
|
16
21
|
const m = findMenuItem(rawMenuData, params[QK.ck]);
|
|
@@ -19,6 +24,8 @@ const SidebarSlotContainer = (props) => {
|
|
|
19
24
|
return;
|
|
20
25
|
}
|
|
21
26
|
}
|
|
27
|
+
// 运行到这 说明
|
|
28
|
+
// 异常路径
|
|
22
29
|
logPageNotFound();
|
|
23
30
|
}
|
|
24
31
|
}, [rawMenuData, params]);
|
|
@@ -7,6 +7,7 @@ import { useParams } from "react-router-dom";
|
|
|
7
7
|
import SidebarSlotContainer from "./SidebarSlotContainer";
|
|
8
8
|
const SidebarSlotPage = () => {
|
|
9
9
|
const params = useParams();
|
|
10
|
+
// top left 从当前路由中获取到 sidebarConfig中的数据
|
|
10
11
|
const { menu: parentMenuInfo } = useCurrentMenuData();
|
|
11
12
|
const prefixPath = useMemo(() => `/${params[QK.k]}`, [params[QK.k]]);
|
|
12
13
|
const menuItem = generateMenuItemData(parentMenuInfo?.sidebarConfig?.menu ?? []);
|