fix: uiSchemaTemplates:list 403

This commit is contained in:
chenos 2023-10-22 13:32:52 +08:00
parent 4eb6027189
commit f51c06e7b8

View File

@ -2,6 +2,7 @@ import { ISchema, useFieldSchema } from '@formily/react';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import React, { ReactNode, createContext, useContext, useMemo } from 'react'; import React, { ReactNode, createContext, useContext, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { useAPIClient, useRequest } from '../api-client'; import { useAPIClient, useRequest } from '../api-client';
import { Plugin } from '../application/Plugin'; import { Plugin } from '../application/Plugin';
import { useAppSpin } from '../application/hooks/useAppSpin'; import { useAppSpin } from '../application/hooks/useAppSpin';
@ -114,7 +115,7 @@ export const useSchemaTemplateManager = () => {
}; };
}; };
export const RemoteSchemaTemplateManagerProvider: React.FC<{ children?: ReactNode }> = (props) => { const Internal = (props) => {
const api = useAPIClient(); const api = useAPIClient();
const { render } = useAppSpin(); const { render } = useAppSpin();
const options = { const options = {
@ -125,6 +126,7 @@ export const RemoteSchemaTemplateManagerProvider: React.FC<{ children?: ReactNod
paginate: false, paginate: false,
}, },
}; };
const service = useRequest<{ const service = useRequest<{
data: any[]; data: any[];
}>(options); }>(options);
@ -144,6 +146,14 @@ export const RemoteSchemaTemplateManagerProvider: React.FC<{ children?: ReactNod
); );
}; };
export const RemoteSchemaTemplateManagerProvider: React.FC<{ children?: ReactNode }> = (props) => {
const location = useLocation();
if (location.pathname.startsWith('/admin')) {
return <Internal {...props} />;
}
return <>{props.children}</>;
};
export class RemoteSchemaTemplateManagerPlugin extends Plugin { export class RemoteSchemaTemplateManagerPlugin extends Plugin {
async load() { async load() {
this.addRoutes(); this.addRoutes();