feat: improve code
This commit is contained in:
parent
8a791f37aa
commit
01e5e1cbac
@ -63,7 +63,7 @@ const plugins = [
|
|||||||
'@nocobase/plugin-file-manager',
|
'@nocobase/plugin-file-manager',
|
||||||
'@nocobase/plugin-system-settings',
|
'@nocobase/plugin-system-settings',
|
||||||
'@nocobase/plugin-users',
|
'@nocobase/plugin-users',
|
||||||
'@nocobase/plugin-acl',
|
// '@nocobase/plugin-acl',
|
||||||
'@nocobase/plugin-china-region',
|
'@nocobase/plugin-china-region',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { APIClient } from '@nocobase/client';
|
import { APIClient } from '@nocobase/client';
|
||||||
import mock from './mock';
|
|
||||||
|
|
||||||
const apiClient = new APIClient({
|
const apiClient = new APIClient({
|
||||||
baseURL: `${location.protocol}//${location.host}/api/`,
|
baseURL: `http://localhost:3000/api/`,
|
||||||
});
|
});
|
||||||
|
|
||||||
mock(apiClient);
|
// mock(apiClient);
|
||||||
|
|
||||||
export default apiClient;
|
export default apiClient;
|
||||||
|
@ -47,7 +47,7 @@ const providers = [
|
|||||||
|
|
||||||
const App = compose(...providers)(() => {
|
const App = compose(...providers)(() => {
|
||||||
const { data, loading } = useRequest({
|
const { data, loading } = useRequest({
|
||||||
url: 'routes:getAccessible',
|
url: 'uiRoutes:getAccessible',
|
||||||
});
|
});
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Spin />;
|
return <Spin />;
|
||||||
|
@ -9,7 +9,7 @@ export default (apiClient: APIClient) => {
|
|||||||
data: { lang: 'en-US' },
|
data: { lang: 'en-US' },
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.onGet('/system_settings:get').reply(200, {
|
mock.onGet('/systemSettings:get/1').reply(200, {
|
||||||
data: {
|
data: {
|
||||||
title: 'NocoBase',
|
title: 'NocoBase',
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,7 @@ export default (apiClient: APIClient) => {
|
|||||||
data: { lang: 'en-US' },
|
data: { lang: 'en-US' },
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.onGet('/system_settings:get').reply(200, {
|
mock.onGet('/systemSettings:get/1').reply(200, {
|
||||||
data: {
|
data: {
|
||||||
title: 'NocoBase',
|
title: 'NocoBase',
|
||||||
},
|
},
|
||||||
@ -135,6 +135,33 @@ export default (apiClient: APIClient) => {
|
|||||||
return [200, response];
|
return [200, response];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mock.onGet(/\/ui_schemas\:getProperties\/(\w+)/).reply(function (config) {
|
||||||
|
// const name = config.url.split('/').pop();
|
||||||
|
// console.log(name);
|
||||||
|
// if (jsonSchema[name]) {
|
||||||
|
// return [200, { data: jsonSchema[name] }];
|
||||||
|
// }
|
||||||
|
const response = {
|
||||||
|
data: {
|
||||||
|
type: 'void',
|
||||||
|
name: uid(),
|
||||||
|
'x-uid': uid(),
|
||||||
|
'x-component': 'Page',
|
||||||
|
properties: {
|
||||||
|
[uid()]: {
|
||||||
|
type: 'void',
|
||||||
|
name: 'grid1',
|
||||||
|
'x-component': 'Grid',
|
||||||
|
'x-item-initializer': 'Grid.AddBlockItem',
|
||||||
|
'x-uid': uid(),
|
||||||
|
properties: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return [200, response];
|
||||||
|
});
|
||||||
|
|
||||||
mock.onGet('/routes:getAccessible').reply(200, {
|
mock.onGet('/routes:getAccessible').reply(200, {
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ export function AdminLayout(props: any) {
|
|||||||
<Layout>
|
<Layout>
|
||||||
<Layout.Sider style={{ display: 'none' }} theme={'light'} ref={sideMenuRef}></Layout.Sider>
|
<Layout.Sider style={{ display: 'none' }} theme={'light'} ref={sideMenuRef}></Layout.Sider>
|
||||||
<Layout.Content>
|
<Layout.Content>
|
||||||
<RemoteSchemaComponent uid={match.params.name} />
|
<RemoteSchemaComponent onlyRenderProperties uid={match.params.name} />
|
||||||
</Layout.Content>
|
</Layout.Content>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
@ -20,7 +20,7 @@ const useSideMenuRef = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return scope[scopeKey];
|
return scope[scopeKey];
|
||||||
}
|
};
|
||||||
|
|
||||||
export const Menu: ComposedMenu = observer((props) => {
|
export const Menu: ComposedMenu = observer((props) => {
|
||||||
let {
|
let {
|
||||||
@ -32,7 +32,6 @@ export const Menu: ComposedMenu = observer((props) => {
|
|||||||
defaultOpenKeys: dOpenKeys,
|
defaultOpenKeys: dOpenKeys,
|
||||||
...others
|
...others
|
||||||
} = props;
|
} = props;
|
||||||
console.log('defaultSelectedUid', defaultSelectedUid)
|
|
||||||
const schema = useFieldSchema();
|
const schema = useFieldSchema();
|
||||||
const sideMenuRef = useSideMenuRef();
|
const sideMenuRef = useSideMenuRef();
|
||||||
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState(() => {
|
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState(() => {
|
||||||
@ -52,8 +51,9 @@ export const Menu: ComposedMenu = observer((props) => {
|
|||||||
return dOpenKeys;
|
return dOpenKeys;
|
||||||
});
|
});
|
||||||
const [sideMenuSchema, setSideMenuSchema] = useState<Schema>(() => {
|
const [sideMenuSchema, setSideMenuSchema] = useState<Schema>(() => {
|
||||||
if (mode === 'mix' && defaultSelectedKeys[0]) {
|
const key = defaultSelectedKeys?.[0] || null;
|
||||||
const s = schema.properties?.[defaultSelectedKeys[0]];
|
if (mode === 'mix' && key) {
|
||||||
|
const s = schema.properties?.[key];
|
||||||
if (s['x-component'] === 'Menu.SubMenu') {
|
if (s['x-component'] === 'Menu.SubMenu') {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -12,25 +12,24 @@ export interface RemoteSchemaComponentProps {
|
|||||||
schemaTransform?: (schema: Schema) => Schema;
|
schemaTransform?: (schema: Schema) => Schema;
|
||||||
render?: any;
|
render?: any;
|
||||||
hidden?: any;
|
hidden?: any;
|
||||||
|
onlyRenderProperties?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultTransform = (s: Schema) => s;
|
const defaultTransform = (s: Schema) => s;
|
||||||
|
|
||||||
const RequestSchemaComponent: React.FC<RemoteSchemaComponentProps> = (props) => {
|
const RequestSchemaComponent: React.FC<RemoteSchemaComponentProps> = (props) => {
|
||||||
const { hidden, scope, uid, onSuccess, schemaTransform = defaultTransform } = props;
|
const { onlyRenderProperties, hidden, scope, uid, onSuccess, schemaTransform = defaultTransform } = props;
|
||||||
const { reset } = useSchemaComponentContext();
|
const { reset } = useSchemaComponentContext();
|
||||||
const { data, loading } = useRequest(
|
const conf = {
|
||||||
{
|
url: `/ui_schemas:${onlyRenderProperties ? 'getProperties' : 'getJsonSchema'}/${uid}`,
|
||||||
url: `/ui_schemas:getJsonSchema/${uid}`,
|
};
|
||||||
|
const { data, loading } = useRequest(conf, {
|
||||||
|
refreshDeps: [uid],
|
||||||
|
onSuccess(data) {
|
||||||
|
onSuccess && onSuccess(data);
|
||||||
|
reset && reset();
|
||||||
},
|
},
|
||||||
{
|
});
|
||||||
refreshDeps: [uid],
|
|
||||||
onSuccess(data) {
|
|
||||||
onSuccess && onSuccess(data);
|
|
||||||
reset && reset();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Spin />;
|
return <Spin />;
|
||||||
|
@ -11,11 +11,7 @@ export const useSystemSettings = () => {
|
|||||||
|
|
||||||
export const SystemSettingsProvider: React.FC = (props) => {
|
export const SystemSettingsProvider: React.FC = (props) => {
|
||||||
const result = useRequest({
|
const result = useRequest({
|
||||||
resource: 'system_settings',
|
url: 'systemSettings:get/1',
|
||||||
action: 'get',
|
|
||||||
params: {
|
|
||||||
filterByTk: 1,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (result.loading) {
|
if (result.loading) {
|
||||||
return <Spin />;
|
return <Spin />;
|
||||||
|
@ -16,7 +16,7 @@ const apiClient = new APIClient();
|
|||||||
|
|
||||||
const mock = new MockAdapter(apiClient.axios);
|
const mock = new MockAdapter(apiClient.axios);
|
||||||
|
|
||||||
mock.onGet('/system_settings:get').reply(200, {
|
mock.onGet('/systemSettings:get/1').reply(200, {
|
||||||
data: {
|
data: {
|
||||||
title: 'NocoBase',
|
title: 'NocoBase',
|
||||||
},
|
},
|
||||||
|
@ -45,6 +45,21 @@ export class UiRoutesStoragePlugin extends Plugin {
|
|||||||
title: 'Menu Item u7',
|
title: 'Menu Item u7',
|
||||||
'x-component': 'Menu.Item',
|
'x-component': 'Menu.Item',
|
||||||
'x-component-props': {},
|
'x-component-props': {},
|
||||||
|
properties: {
|
||||||
|
page1: {
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Page',
|
||||||
|
'x-async': true,
|
||||||
|
properties: {
|
||||||
|
grid1: {
|
||||||
|
type: 'void',
|
||||||
|
'x-component': 'Grid',
|
||||||
|
'x-item-initializer': 'Grid.AddBlockItem',
|
||||||
|
properties: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
item8: {
|
item8: {
|
||||||
type: 'void',
|
type: 'void',
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { MagicAttributeModel } from '@nocobase/database';
|
import { MagicAttributeModel } from '@nocobase/database';
|
||||||
import { Plugin } from '@nocobase/server';
|
import { Plugin } from '@nocobase/server';
|
||||||
|
import { uid } from '@nocobase/utils';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { uiSchemaActions } from './actions/ui-schema-action';
|
import { uiSchemaActions } from './actions/ui-schema-action';
|
||||||
import { UiSchemaModel } from './model';
|
import { UiSchemaModel } from './model';
|
||||||
@ -27,6 +28,9 @@ export class UiSchemaStoragePlugin extends Plugin {
|
|||||||
|
|
||||||
db.on('ui_schemas.beforeCreate', function setUid(model) {
|
db.on('ui_schemas.beforeCreate', function setUid(model) {
|
||||||
model.set('uid', model.get('x-uid'));
|
model.set('uid', model.get('x-uid'));
|
||||||
|
if (!model.get('name')) {
|
||||||
|
model.set('name', uid());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
db.on('ui_schemas.afterCreate', async function insertSchema(model, options) {
|
db.on('ui_schemas.afterCreate', async function insertSchema(model, options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user