sy-page-sdk 0.1.0
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 +444 -0
- package/dist/chunk-R77DYKUJ.js +1034 -0
- package/dist/index.cjs +1060 -0
- package/dist/index.d.cts +729 -0
- package/dist/index.d.ts +729 -0
- package/dist/index.js +6 -0
- package/dist/react/index.cjs +1383 -0
- package/dist/react/index.d.cts +77 -0
- package/dist/react/index.d.ts +77 -0
- package/dist/react/index.js +307 -0
- package/package.json +40 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { PageContext, PageUserInfo, PageUserType, PageApiResponse, ViewPermissionSummary, ViewOperationPermission, ViewFieldPermissionValue, PageMessageApi, PageModalApi, PageNavigationApi, PageRouteInfo, PageSdk } from '../index.cjs';
|
|
3
|
+
export { ApiPermissionListParams, ApproveTaskParams, AssignPermissionsParams, AssignRolesParams, BatchAddUsersToRoleParams, BatchSendNotificationByTypeParams, ChangeUserRoleParams, CreateApiPermissionParams, CreateFormPermissionGroupDto, CreatePagePermissionGroupDto, CreateRoleParams, CreateUiPermissionParams, CreateUserParams, DataManagementConfigParams, DataManagementFilterState, DataPermissionConditionDto, DataPermissionDto, DataPermissionRuleDto, FieldPermissionDto, FormAdvancedSearchParams, FormChangeRecordParams, FormCreateParams, FormExportParams, FormGetDetailParams, FormImportParams, FormPermissionGroup, FormRemoveParams, FormSearchParams, FormUpdateParams, GetProcessInstanceParams, GetUserRolesParams, ImportExportRecordDownloadParams, ImportExportRecordQuery, InstanceStatus, NotificationChannel, NotificationMessageRecord, PageApiPermissionRecord, PageAppInfo, PageBinaryResponse, PageBridgeApi, PageDataManagementConfig, PageDataSourceDescriptor, PageDepartmentInfo, PageHttpMethod, PageInfo, PageListResult, PageOffsetListResult, PagePermissionGroup, PagePermissionInfo, PageQueryValue, PageRequestOptions, PageRoleRecord, PageScope, PageSdkError, PageSdkMeta, PageTransportDownloadPayload, PageTransportRequestPayload, PageUiPermissionRecord, PageUiPermissionType, PageUserRecord, ProcessApproveAction, QueryFormPermissionGroupDto, QueryPagePermissionGroupDto, RoleListParams, RoleUsersParams, SaveDataManagementConfigParams, SearchComponentName, SearchExpression, SearchFieldKey, SearchGroup, SearchLogic, SearchOperator, SearchRule, SearchSortItem, SearchSystemField, SendNotificationByTypeParams, SendNotificationResult, SubFormRule, SwitchAppRoleParams, SwitchPlatformRoleParams, TerminateProcessInstanceParams, TriggerCallbackTaskParams, UiPermissionListParams, UpdateApiPermissionParams, UpdateFormPermissionGroupDto, UpdatePagePermissionGroupDto, UpdateRoleParams, UpdateUiPermissionParams, UpdateUserParams, UserListParams, UserMenuPermissionsResponse, ValidateUserParams, createPageSdk } from '../index.cjs';
|
|
4
|
+
|
|
5
|
+
declare const createReactPage: (AppComponent: React.ComponentType) => {
|
|
6
|
+
mount: (el: HTMLElement, context: PageContext) => void;
|
|
7
|
+
update: (el: HTMLElement, context: PageContext) => void;
|
|
8
|
+
unmount: () => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
interface PageProviderProps {
|
|
12
|
+
context: PageContext;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare const PageProvider: React.FC<PageProviderProps>;
|
|
16
|
+
|
|
17
|
+
interface CurrentUserState {
|
|
18
|
+
user: PageUserInfo & {
|
|
19
|
+
userType: PageUserType;
|
|
20
|
+
isGuest: boolean;
|
|
21
|
+
};
|
|
22
|
+
isGuest: boolean;
|
|
23
|
+
isInternalUser: boolean;
|
|
24
|
+
displayName: string;
|
|
25
|
+
primaryDepartment: NonNullable<PageUserInfo["departments"]>[number] | null;
|
|
26
|
+
}
|
|
27
|
+
declare const useCurrentUser: () => CurrentUserState;
|
|
28
|
+
|
|
29
|
+
interface UseDataSourceOptions<TResult = unknown, TData = TResult, TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
30
|
+
params?: TParams;
|
|
31
|
+
immediate?: boolean;
|
|
32
|
+
transform?: (result: TResult, response: PageApiResponse<TResult>) => TData;
|
|
33
|
+
}
|
|
34
|
+
interface UseDataSourceResult<TResult = unknown, TData = TResult, TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
35
|
+
response: PageApiResponse<TResult> | null;
|
|
36
|
+
result: TResult | null;
|
|
37
|
+
data: TData | null;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: Error | null;
|
|
40
|
+
refresh: (params?: TParams) => Promise<PageApiResponse<TResult> | null>;
|
|
41
|
+
run: (params?: TParams) => Promise<PageApiResponse<TResult> | null>;
|
|
42
|
+
setResponse: Dispatch<SetStateAction<PageApiResponse<TResult> | null>>;
|
|
43
|
+
setResult: Dispatch<SetStateAction<TResult | null>>;
|
|
44
|
+
setData: Dispatch<SetStateAction<TData | null>>;
|
|
45
|
+
}
|
|
46
|
+
declare const useDataSource: <TResult = unknown, TData = TResult, TParams extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: UseDataSourceOptions<TResult, TData, TParams>) => UseDataSourceResult<TResult, TData, TParams>;
|
|
47
|
+
|
|
48
|
+
interface UseFormViewPermissionsOptions {
|
|
49
|
+
appType?: string;
|
|
50
|
+
immediate?: boolean;
|
|
51
|
+
}
|
|
52
|
+
interface UseFormViewPermissionsState {
|
|
53
|
+
summary: ViewPermissionSummary;
|
|
54
|
+
response: PageApiResponse<ViewPermissionSummary> | null;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
error: Error | null;
|
|
57
|
+
refresh: () => Promise<PageApiResponse<ViewPermissionSummary> | null>;
|
|
58
|
+
can: (operation: ViewOperationPermission) => boolean;
|
|
59
|
+
getFieldPermission: (fieldName: string) => ViewFieldPermissionValue | null;
|
|
60
|
+
}
|
|
61
|
+
declare const useFormViewPermissions: (formUuid: string, options?: UseFormViewPermissionsOptions) => UseFormViewPermissionsState;
|
|
62
|
+
|
|
63
|
+
declare const useMessage: () => PageMessageApi;
|
|
64
|
+
|
|
65
|
+
declare const useModal: () => PageModalApi;
|
|
66
|
+
|
|
67
|
+
declare const useNavigation: () => PageNavigationApi;
|
|
68
|
+
|
|
69
|
+
declare const usePageContext: () => PageContext;
|
|
70
|
+
|
|
71
|
+
declare const usePageProps: <T extends object = Record<string, unknown>>() => T;
|
|
72
|
+
|
|
73
|
+
declare const usePageRoute: () => PageRouteInfo;
|
|
74
|
+
|
|
75
|
+
declare const usePageSdk: () => PageSdk;
|
|
76
|
+
|
|
77
|
+
export { PageApiResponse, PageContext, PageMessageApi, PageModalApi, PageNavigationApi, PageProvider, PageRouteInfo, PageSdk, PageUserInfo, PageUserType, ViewFieldPermissionValue, ViewOperationPermission, ViewPermissionSummary, createReactPage, useCurrentUser, useDataSource, useFormViewPermissions, useMessage, useModal, useNavigation, usePageContext, usePageProps, usePageRoute, usePageSdk };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { PageContext, PageUserInfo, PageUserType, PageApiResponse, ViewPermissionSummary, ViewOperationPermission, ViewFieldPermissionValue, PageMessageApi, PageModalApi, PageNavigationApi, PageRouteInfo, PageSdk } from '../index.js';
|
|
3
|
+
export { ApiPermissionListParams, ApproveTaskParams, AssignPermissionsParams, AssignRolesParams, BatchAddUsersToRoleParams, BatchSendNotificationByTypeParams, ChangeUserRoleParams, CreateApiPermissionParams, CreateFormPermissionGroupDto, CreatePagePermissionGroupDto, CreateRoleParams, CreateUiPermissionParams, CreateUserParams, DataManagementConfigParams, DataManagementFilterState, DataPermissionConditionDto, DataPermissionDto, DataPermissionRuleDto, FieldPermissionDto, FormAdvancedSearchParams, FormChangeRecordParams, FormCreateParams, FormExportParams, FormGetDetailParams, FormImportParams, FormPermissionGroup, FormRemoveParams, FormSearchParams, FormUpdateParams, GetProcessInstanceParams, GetUserRolesParams, ImportExportRecordDownloadParams, ImportExportRecordQuery, InstanceStatus, NotificationChannel, NotificationMessageRecord, PageApiPermissionRecord, PageAppInfo, PageBinaryResponse, PageBridgeApi, PageDataManagementConfig, PageDataSourceDescriptor, PageDepartmentInfo, PageHttpMethod, PageInfo, PageListResult, PageOffsetListResult, PagePermissionGroup, PagePermissionInfo, PageQueryValue, PageRequestOptions, PageRoleRecord, PageScope, PageSdkError, PageSdkMeta, PageTransportDownloadPayload, PageTransportRequestPayload, PageUiPermissionRecord, PageUiPermissionType, PageUserRecord, ProcessApproveAction, QueryFormPermissionGroupDto, QueryPagePermissionGroupDto, RoleListParams, RoleUsersParams, SaveDataManagementConfigParams, SearchComponentName, SearchExpression, SearchFieldKey, SearchGroup, SearchLogic, SearchOperator, SearchRule, SearchSortItem, SearchSystemField, SendNotificationByTypeParams, SendNotificationResult, SubFormRule, SwitchAppRoleParams, SwitchPlatformRoleParams, TerminateProcessInstanceParams, TriggerCallbackTaskParams, UiPermissionListParams, UpdateApiPermissionParams, UpdateFormPermissionGroupDto, UpdatePagePermissionGroupDto, UpdateRoleParams, UpdateUiPermissionParams, UpdateUserParams, UserListParams, UserMenuPermissionsResponse, ValidateUserParams, createPageSdk } from '../index.js';
|
|
4
|
+
|
|
5
|
+
declare const createReactPage: (AppComponent: React.ComponentType) => {
|
|
6
|
+
mount: (el: HTMLElement, context: PageContext) => void;
|
|
7
|
+
update: (el: HTMLElement, context: PageContext) => void;
|
|
8
|
+
unmount: () => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
interface PageProviderProps {
|
|
12
|
+
context: PageContext;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare const PageProvider: React.FC<PageProviderProps>;
|
|
16
|
+
|
|
17
|
+
interface CurrentUserState {
|
|
18
|
+
user: PageUserInfo & {
|
|
19
|
+
userType: PageUserType;
|
|
20
|
+
isGuest: boolean;
|
|
21
|
+
};
|
|
22
|
+
isGuest: boolean;
|
|
23
|
+
isInternalUser: boolean;
|
|
24
|
+
displayName: string;
|
|
25
|
+
primaryDepartment: NonNullable<PageUserInfo["departments"]>[number] | null;
|
|
26
|
+
}
|
|
27
|
+
declare const useCurrentUser: () => CurrentUserState;
|
|
28
|
+
|
|
29
|
+
interface UseDataSourceOptions<TResult = unknown, TData = TResult, TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
30
|
+
params?: TParams;
|
|
31
|
+
immediate?: boolean;
|
|
32
|
+
transform?: (result: TResult, response: PageApiResponse<TResult>) => TData;
|
|
33
|
+
}
|
|
34
|
+
interface UseDataSourceResult<TResult = unknown, TData = TResult, TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
35
|
+
response: PageApiResponse<TResult> | null;
|
|
36
|
+
result: TResult | null;
|
|
37
|
+
data: TData | null;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: Error | null;
|
|
40
|
+
refresh: (params?: TParams) => Promise<PageApiResponse<TResult> | null>;
|
|
41
|
+
run: (params?: TParams) => Promise<PageApiResponse<TResult> | null>;
|
|
42
|
+
setResponse: Dispatch<SetStateAction<PageApiResponse<TResult> | null>>;
|
|
43
|
+
setResult: Dispatch<SetStateAction<TResult | null>>;
|
|
44
|
+
setData: Dispatch<SetStateAction<TData | null>>;
|
|
45
|
+
}
|
|
46
|
+
declare const useDataSource: <TResult = unknown, TData = TResult, TParams extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: UseDataSourceOptions<TResult, TData, TParams>) => UseDataSourceResult<TResult, TData, TParams>;
|
|
47
|
+
|
|
48
|
+
interface UseFormViewPermissionsOptions {
|
|
49
|
+
appType?: string;
|
|
50
|
+
immediate?: boolean;
|
|
51
|
+
}
|
|
52
|
+
interface UseFormViewPermissionsState {
|
|
53
|
+
summary: ViewPermissionSummary;
|
|
54
|
+
response: PageApiResponse<ViewPermissionSummary> | null;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
error: Error | null;
|
|
57
|
+
refresh: () => Promise<PageApiResponse<ViewPermissionSummary> | null>;
|
|
58
|
+
can: (operation: ViewOperationPermission) => boolean;
|
|
59
|
+
getFieldPermission: (fieldName: string) => ViewFieldPermissionValue | null;
|
|
60
|
+
}
|
|
61
|
+
declare const useFormViewPermissions: (formUuid: string, options?: UseFormViewPermissionsOptions) => UseFormViewPermissionsState;
|
|
62
|
+
|
|
63
|
+
declare const useMessage: () => PageMessageApi;
|
|
64
|
+
|
|
65
|
+
declare const useModal: () => PageModalApi;
|
|
66
|
+
|
|
67
|
+
declare const useNavigation: () => PageNavigationApi;
|
|
68
|
+
|
|
69
|
+
declare const usePageContext: () => PageContext;
|
|
70
|
+
|
|
71
|
+
declare const usePageProps: <T extends object = Record<string, unknown>>() => T;
|
|
72
|
+
|
|
73
|
+
declare const usePageRoute: () => PageRouteInfo;
|
|
74
|
+
|
|
75
|
+
declare const usePageSdk: () => PageSdk;
|
|
76
|
+
|
|
77
|
+
export { PageApiResponse, PageContext, PageMessageApi, PageModalApi, PageNavigationApi, PageProvider, PageRouteInfo, PageSdk, PageUserInfo, PageUserType, ViewFieldPermissionValue, ViewOperationPermission, ViewPermissionSummary, createReactPage, useCurrentUser, useDataSource, useFormViewPermissions, useMessage, useModal, useNavigation, usePageContext, usePageProps, usePageRoute, usePageSdk };
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPageSdk
|
|
3
|
+
} from "../chunk-R77DYKUJ.js";
|
|
4
|
+
|
|
5
|
+
// src/react/createReactPage.tsx
|
|
6
|
+
import { StyleProvider } from "@ant-design/cssinjs";
|
|
7
|
+
import { App as AntdApp, ConfigProvider } from "antd";
|
|
8
|
+
import zhCN from "antd/locale/zh_CN";
|
|
9
|
+
import { createRoot } from "react-dom/client";
|
|
10
|
+
|
|
11
|
+
// src/react/provider.tsx
|
|
12
|
+
import { useMemo } from "react";
|
|
13
|
+
|
|
14
|
+
// src/react/store.ts
|
|
15
|
+
import { createContext, useContext } from "react";
|
|
16
|
+
var ReactPageContext = createContext(null);
|
|
17
|
+
var usePageSdkStore = () => {
|
|
18
|
+
const store = useContext(ReactPageContext);
|
|
19
|
+
if (!store) {
|
|
20
|
+
throw new Error("usePageSdkStore \u5FC5\u987B\u5728 PageProvider \u5185\u4F7F\u7528");
|
|
21
|
+
}
|
|
22
|
+
return store;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/react/provider.tsx
|
|
26
|
+
import { jsx } from "react/jsx-runtime";
|
|
27
|
+
var PageProvider = ({
|
|
28
|
+
context,
|
|
29
|
+
children
|
|
30
|
+
}) => {
|
|
31
|
+
const value = useMemo(
|
|
32
|
+
() => ({
|
|
33
|
+
context,
|
|
34
|
+
sdk: createPageSdk(context)
|
|
35
|
+
}),
|
|
36
|
+
[context]
|
|
37
|
+
);
|
|
38
|
+
return /* @__PURE__ */ jsx(ReactPageContext.Provider, { value, children });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/react/createReactPage.tsx
|
|
42
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
43
|
+
var createRuntimeRoot = (el) => {
|
|
44
|
+
return createRoot(el);
|
|
45
|
+
};
|
|
46
|
+
var getStyleContainer = (el) => {
|
|
47
|
+
const rootNode = el.getRootNode?.();
|
|
48
|
+
if (typeof ShadowRoot !== "undefined" && rootNode instanceof ShadowRoot) {
|
|
49
|
+
return rootNode;
|
|
50
|
+
}
|
|
51
|
+
return document.head;
|
|
52
|
+
};
|
|
53
|
+
var createReactPage = (AppComponent) => {
|
|
54
|
+
let root = null;
|
|
55
|
+
let currentContainer = null;
|
|
56
|
+
const render = (el, context) => {
|
|
57
|
+
if (!root || currentContainer !== el) {
|
|
58
|
+
root?.unmount();
|
|
59
|
+
root = createRuntimeRoot(el);
|
|
60
|
+
currentContainer = el;
|
|
61
|
+
}
|
|
62
|
+
root.render(
|
|
63
|
+
/* @__PURE__ */ jsx2(StyleProvider, { layer: true, container: getStyleContainer(el), children: /* @__PURE__ */ jsx2(ConfigProvider, { locale: zhCN, theme: { cssVar: {} }, children: /* @__PURE__ */ jsx2(AntdApp, { children: /* @__PURE__ */ jsx2(PageProvider, { context, children: /* @__PURE__ */ jsx2(AppComponent, {}) }) }) }) })
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
mount: (el, context) => {
|
|
68
|
+
render(el, context);
|
|
69
|
+
},
|
|
70
|
+
update: (el, context) => {
|
|
71
|
+
render(el, context);
|
|
72
|
+
},
|
|
73
|
+
unmount: () => {
|
|
74
|
+
root?.unmount();
|
|
75
|
+
root = null;
|
|
76
|
+
currentContainer = null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/react/hooks/useCurrentUser.ts
|
|
82
|
+
import { useMemo as useMemo2 } from "react";
|
|
83
|
+
|
|
84
|
+
// src/react/hooks/usePageContext.ts
|
|
85
|
+
var usePageContext = () => {
|
|
86
|
+
return usePageSdkStore().context;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/react/hooks/useCurrentUser.ts
|
|
90
|
+
var useCurrentUser = () => {
|
|
91
|
+
const { user } = usePageContext();
|
|
92
|
+
return useMemo2(() => {
|
|
93
|
+
const userType = user.userType === "guest" || user.isGuest ? "guest" : "normal";
|
|
94
|
+
const isGuest = userType === "guest";
|
|
95
|
+
return {
|
|
96
|
+
user: {
|
|
97
|
+
...user,
|
|
98
|
+
isGuest,
|
|
99
|
+
userType
|
|
100
|
+
},
|
|
101
|
+
isGuest,
|
|
102
|
+
isInternalUser: !isGuest,
|
|
103
|
+
displayName: user.name || user.username || user.id,
|
|
104
|
+
primaryDepartment: user.departments?.[0] || null
|
|
105
|
+
};
|
|
106
|
+
}, [user]);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/react/hooks/useDataSource.ts
|
|
110
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
111
|
+
|
|
112
|
+
// src/react/hooks/usePageSdk.ts
|
|
113
|
+
var usePageSdk = () => {
|
|
114
|
+
return usePageSdkStore().sdk;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/react/hooks/useDataSource.ts
|
|
118
|
+
var createParamsSignature = (value) => {
|
|
119
|
+
try {
|
|
120
|
+
return JSON.stringify(value || {});
|
|
121
|
+
} catch {
|
|
122
|
+
return "";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var useDataSource = (name, options = {}) => {
|
|
126
|
+
const sdk = usePageSdk();
|
|
127
|
+
const { params, immediate = true, transform } = options;
|
|
128
|
+
const paramsRef = useRef(params);
|
|
129
|
+
const transformRef = useRef(transform);
|
|
130
|
+
const paramsSignature = createParamsSignature(params);
|
|
131
|
+
const [response, setResponse] = useState(
|
|
132
|
+
null
|
|
133
|
+
);
|
|
134
|
+
const [result, setResult] = useState(null);
|
|
135
|
+
const [data, setData] = useState(null);
|
|
136
|
+
const [loading, setLoading] = useState(false);
|
|
137
|
+
const [error, setError] = useState(null);
|
|
138
|
+
paramsRef.current = params;
|
|
139
|
+
transformRef.current = transform;
|
|
140
|
+
const run = useCallback(
|
|
141
|
+
async (overrideParams) => {
|
|
142
|
+
setLoading(true);
|
|
143
|
+
setError(null);
|
|
144
|
+
try {
|
|
145
|
+
const response2 = await sdk.dataSource.run(
|
|
146
|
+
name,
|
|
147
|
+
overrideParams || paramsRef.current || {}
|
|
148
|
+
);
|
|
149
|
+
setResponse(response2);
|
|
150
|
+
setResult(response2.result);
|
|
151
|
+
const activeTransform = transformRef.current;
|
|
152
|
+
const nextData = activeTransform ? activeTransform(response2.result, response2) : response2.result ?? null;
|
|
153
|
+
setData(nextData);
|
|
154
|
+
return response2;
|
|
155
|
+
} catch (runtimeError) {
|
|
156
|
+
const nextError = runtimeError instanceof Error ? runtimeError : new Error(String(runtimeError));
|
|
157
|
+
setError(nextError);
|
|
158
|
+
setResponse(null);
|
|
159
|
+
setResult(null);
|
|
160
|
+
return null;
|
|
161
|
+
} finally {
|
|
162
|
+
setLoading(false);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
[name, sdk.dataSource]
|
|
166
|
+
);
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (!immediate) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
void run();
|
|
172
|
+
}, [immediate, paramsSignature, run]);
|
|
173
|
+
return {
|
|
174
|
+
response,
|
|
175
|
+
result,
|
|
176
|
+
data,
|
|
177
|
+
loading,
|
|
178
|
+
error,
|
|
179
|
+
refresh: run,
|
|
180
|
+
run,
|
|
181
|
+
setResponse,
|
|
182
|
+
setResult,
|
|
183
|
+
setData
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/react/hooks/useFormViewPermissions.ts
|
|
188
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo3, useState as useState2 } from "react";
|
|
189
|
+
var EMPTY_SUMMARY = {
|
|
190
|
+
fieldPermissions: {},
|
|
191
|
+
operations: []
|
|
192
|
+
};
|
|
193
|
+
var toError = (error) => {
|
|
194
|
+
if (error instanceof Error) {
|
|
195
|
+
return error;
|
|
196
|
+
}
|
|
197
|
+
if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
|
|
198
|
+
return new Error(error.message);
|
|
199
|
+
}
|
|
200
|
+
return new Error(String(error || "\u83B7\u53D6\u67E5\u770B\u6001\u6743\u9650\u5931\u8D25"));
|
|
201
|
+
};
|
|
202
|
+
var useFormViewPermissions = (formUuid, options = {}) => {
|
|
203
|
+
const sdk = usePageSdk();
|
|
204
|
+
const [summary, setSummary] = useState2(EMPTY_SUMMARY);
|
|
205
|
+
const [response, setResponse] = useState2(null);
|
|
206
|
+
const [loading, setLoading] = useState2(false);
|
|
207
|
+
const [error, setError] = useState2(null);
|
|
208
|
+
const immediate = options.immediate ?? true;
|
|
209
|
+
const refresh = useCallback2(async () => {
|
|
210
|
+
const normalizedFormUuid = String(formUuid || "").trim();
|
|
211
|
+
if (!normalizedFormUuid) {
|
|
212
|
+
setSummary(EMPTY_SUMMARY);
|
|
213
|
+
setResponse(null);
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
setLoading(true);
|
|
217
|
+
setError(null);
|
|
218
|
+
try {
|
|
219
|
+
const nextResponse = await sdk.permission.formGroup.getViewPermissionSummary({
|
|
220
|
+
appType: options.appType,
|
|
221
|
+
formUuid: normalizedFormUuid
|
|
222
|
+
});
|
|
223
|
+
const nextSummary = nextResponse.result || EMPTY_SUMMARY;
|
|
224
|
+
setResponse(nextResponse);
|
|
225
|
+
setSummary({
|
|
226
|
+
fieldPermissions: nextSummary.fieldPermissions || {},
|
|
227
|
+
operations: nextSummary.operations || []
|
|
228
|
+
});
|
|
229
|
+
return nextResponse;
|
|
230
|
+
} catch (requestError) {
|
|
231
|
+
const nextError = toError(requestError);
|
|
232
|
+
setError(nextError);
|
|
233
|
+
setResponse(null);
|
|
234
|
+
setSummary(EMPTY_SUMMARY);
|
|
235
|
+
return null;
|
|
236
|
+
} finally {
|
|
237
|
+
setLoading(false);
|
|
238
|
+
}
|
|
239
|
+
}, [formUuid, options.appType, sdk]);
|
|
240
|
+
useEffect2(() => {
|
|
241
|
+
if (!immediate) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
void refresh();
|
|
245
|
+
}, [immediate, refresh]);
|
|
246
|
+
const operationSet = useMemo3(
|
|
247
|
+
() => new Set(summary.operations),
|
|
248
|
+
[summary.operations]
|
|
249
|
+
);
|
|
250
|
+
const can = useCallback2(
|
|
251
|
+
(operation) => operationSet.has(operation),
|
|
252
|
+
[operationSet]
|
|
253
|
+
);
|
|
254
|
+
const getFieldPermission = useCallback2(
|
|
255
|
+
(fieldName) => summary.fieldPermissions[fieldName] || null,
|
|
256
|
+
[summary.fieldPermissions]
|
|
257
|
+
);
|
|
258
|
+
return {
|
|
259
|
+
summary,
|
|
260
|
+
response,
|
|
261
|
+
loading,
|
|
262
|
+
error,
|
|
263
|
+
refresh,
|
|
264
|
+
can,
|
|
265
|
+
getFieldPermission
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// src/react/hooks/useMessage.ts
|
|
270
|
+
var useMessage = () => {
|
|
271
|
+
return usePageContext().ui.message;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// src/react/hooks/useModal.ts
|
|
275
|
+
var useModal = () => {
|
|
276
|
+
return usePageContext().ui.modal;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/react/hooks/useNavigation.ts
|
|
280
|
+
var useNavigation = () => {
|
|
281
|
+
return usePageContext().navigation;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// src/react/hooks/usePageProps.ts
|
|
285
|
+
var usePageProps = () => {
|
|
286
|
+
return usePageContext().page.props;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/react/hooks/usePageRoute.ts
|
|
290
|
+
var usePageRoute = () => {
|
|
291
|
+
return usePageContext().route;
|
|
292
|
+
};
|
|
293
|
+
export {
|
|
294
|
+
PageProvider,
|
|
295
|
+
createPageSdk,
|
|
296
|
+
createReactPage,
|
|
297
|
+
useCurrentUser,
|
|
298
|
+
useDataSource,
|
|
299
|
+
useFormViewPermissions,
|
|
300
|
+
useMessage,
|
|
301
|
+
useModal,
|
|
302
|
+
useNavigation,
|
|
303
|
+
usePageContext,
|
|
304
|
+
usePageProps,
|
|
305
|
+
usePageRoute,
|
|
306
|
+
usePageSdk
|
|
307
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sy-page-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Custom code page SDK for sy lowcode platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./dist/react/index.d.ts",
|
|
17
|
+
"import": "./dist/react/index.js",
|
|
18
|
+
"require": "./dist/react/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"package.json",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts src/react/index.ts --format esm,cjs --dts --clean --out-dir dist --tsconfig tsconfig.build.json",
|
|
28
|
+
"prepublishOnly": "pnpm build"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@ant-design/cssinjs": ">=1",
|
|
32
|
+
"antd": ">=5",
|
|
33
|
+
"react": ">=18",
|
|
34
|
+
"react-dom": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.3.0",
|
|
38
|
+
"typescript": "^5.7.0"
|
|
39
|
+
}
|
|
40
|
+
}
|