diff --git a/nodemon.json b/nodemon.json index 51695bfc2..8652250f2 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,6 +1,6 @@ { "watch": ["packages/", ".env"], - "ignore": ["packages/app"], + "ignore": ["packages/app", "packages/client"], "ext": "ts", "exec": "ts-node -r dotenv/config ./packages/api/src/index.ts" } \ No newline at end of file diff --git a/packages/app/src/pages/index.tsx b/packages/app/src/pages/index.tsx index 71da229f0..4cbe7d211 100644 --- a/packages/app/src/pages/index.tsx +++ b/packages/app/src/pages/index.tsx @@ -1,21 +1,60 @@ -import React, { useEffect } from 'react'; +import 'antd/dist/antd.css' +import { useRequest } from 'ahooks'; import { Spin } from 'antd'; +import React, { useMemo } from 'react'; import { - RouteSwitch, - useGlobalAction, - loadBlocks, - loadTemplates, - templates, + MemoryRouter as Router, +} from 'react-router-dom'; +import { + createRouteSwitch, + AdminLayout, + AuthLayout, + RouteSchemaRenderer, } from '@nocobase/client'; +import { UseRequestProvider } from 'ahooks'; +import { extend } from 'umi-request'; -loadBlocks(); -loadTemplates(); +const request = extend({ + prefix: 'http://localhost:23003/api/', + timeout: 1000, +}); + +// console.log = () => {} + +const RouteSwitch = createRouteSwitch({ + components: { + AdminLayout, + AuthLayout, + RouteSchemaRenderer, + }, +}); + +const App = () => { + const { data, loading } = useRequest('routes:getAccessible', { + formatResult: (result) => result?.data, + }); + + if (loading) { + return + } + + return ( +
+ {/* */} + + {/* */} +
+ ); +}; export default function IndexPage() { - const { data, loading } = useGlobalAction('routes:getAccessible'); - console.log({ data }); - if (loading) { - return ; - } - return ; + return ( + request(service), + }} + > + + + ); } diff --git a/packages/client/src/components/admin-layout/datatable.tsx b/packages/client/src/components/admin-layout/datatable.tsx index feaa9ded2..e04eddf51 100644 --- a/packages/client/src/components/admin-layout/datatable.tsx +++ b/packages/client/src/components/admin-layout/datatable.tsx @@ -1,4 +1,4 @@ -import { SchemaRenderer } from '@nocobase/client/lib'; +import { SchemaRenderer } from '../../'; import React from 'react'; export default () => { diff --git a/packages/client/src/components/admin-layout/index.tsx b/packages/client/src/components/admin-layout/index.tsx index 693142055..c320081b1 100644 --- a/packages/client/src/components/admin-layout/index.tsx +++ b/packages/client/src/components/admin-layout/index.tsx @@ -92,7 +92,7 @@ function LayoutWithMenu({ schema }) { theme={'light'} width={200} > - + {activeKey && } diff --git a/packages/client/src/components/schema-renderer/index.tsx b/packages/client/src/components/schema-renderer/index.tsx index 4c95a686a..a036bc7f9 100644 --- a/packages/client/src/components/schema-renderer/index.tsx +++ b/packages/client/src/components/schema-renderer/index.tsx @@ -19,9 +19,10 @@ import { useMemo } from 'react'; import { CodeOutlined } from '@ant-design/icons'; import Editor from '@monaco-editor/react'; -import { ArrayCollapse, ArrayTable, FormLayout, FormItem as FormilyFormItem } from '@formily/antd'; +import { ArrayCollapse, FormLayout, FormItem as FormilyFormItem } from '@formily/antd'; import { Space, Card, Modal, Spin } from 'antd'; +import { ArrayTable } from '../../schemas/array-table'; import { Action } from '../../schemas/action'; import { AddNew } from '../../schemas/add-new'; import { Cascader } from '../../schemas/cascader'; diff --git a/packages/client/src/schemas/add-new/index.tsx b/packages/client/src/schemas/add-new/index.tsx index 7f463ec1c..9416ee1d3 100644 --- a/packages/client/src/schemas/add-new/index.tsx +++ b/packages/client/src/schemas/add-new/index.tsx @@ -727,58 +727,61 @@ AddNew.FormItem = observer((props: any) => { - {options.map((option) => ( - - {option.children.map((item) => ( - { - setVisible(false); - const values = await FormDialog(`新增字段`, () => { - return ( - - - - ); - }).open({ - initialValues: { - ...item.default, - key: uid(), - name: `f_${uid()}`, - }, - }); - await createCollectionField(resource.name, values); - await refresh(); - let data: ISchema = cloneDeep(values.uiSchema); - data['name'] = values.name; - data['referenceKey'] = data['key']; - data['key'] = uid(); - if (isGridBlock(schema)) { - path.pop(); - path.pop(); - data = generateGridBlock(data); - } else if (isGrid(schema)) { - data = generateGridBlock(data); - } - if (data) { - let s; - if (isGrid(schema)) { - s = appendChild(data, [...path]); - } else if (defaultAction === 'insertAfter') { - s = insertAfter(data, [...path]); - } else { - s = insertBefore(data, [...path]); - } - await createSchema(s); - } - }} - > - {item.title} - - ))} - - ))} + {options.map( + (option) => + option.children.length > 0 && ( + + {option.children.map((item) => ( + { + setVisible(false); + const values = await FormDialog(`新增字段`, () => { + return ( + + + + ); + }).open({ + initialValues: { + ...item.default, + key: uid(), + name: `f_${uid()}`, + }, + }); + await createCollectionField(resource.name, values); + await refresh(); + let data: ISchema = cloneDeep(values.uiSchema); + data['name'] = values.name; + data['referenceKey'] = data['key']; + data['key'] = uid(); + if (isGridBlock(schema)) { + path.pop(); + path.pop(); + data = generateGridBlock(data); + } else if (isGrid(schema)) { + data = generateGridBlock(data); + } + if (data) { + let s; + if (isGrid(schema)) { + s = appendChild(data, [...path]); + } else if (defaultAction === 'insertAfter') { + s = insertAfter(data, [...path]); + } else { + s = insertBefore(data, [...path]); + } + await createSchema(s); + } + }} + > + {item.title} + + ))} + + ), + )} {/* */} { + if (isValid(defaultValue)) return defaultValue; + if (Array.isArray(schema?.items)) + return getDefaultValue(defaultValue, schema.items[0]); + if (schema?.items?.type === 'array') return []; + if (schema?.items?.type === 'boolean') return true; + if (schema?.items?.type === 'date') return ''; + if (schema?.items?.type === 'datetime') return ''; + if (schema?.items?.type === 'number') return 0; + if (schema?.items?.type === 'object') return {}; + if (schema?.items?.type === 'string') return ''; + return null; +}; + +ArrayTable.Addition = (props: any) => { + const { randomValue } = props; + const self = useField(); + const array = Table.useArray(); + const prefixCls = usePrefixCls('formily-array-base'); + if (!array) return null; + if (array.field?.pattern !== 'editable') return null; + return ( + + ); +}; + +export default ArrayTable; diff --git a/packages/client/src/schemas/database-field/index.tsx b/packages/client/src/schemas/database-field/index.tsx index 72636f041..67aa9524c 100644 --- a/packages/client/src/schemas/database-field/index.tsx +++ b/packages/client/src/schemas/database-field/index.tsx @@ -39,7 +39,11 @@ import Modal from 'antd/lib/modal/Modal'; import { clone, cloneDeep, get } from 'lodash'; import { useEffect } from 'react'; import { useRequest } from 'ahooks'; -import { createOrUpdateCollection, deleteCollection, useCollectionContext } from '..'; +import { + createOrUpdateCollection, + deleteCollection, + useCollectionContext, +} from '..'; export const DatabaseCollection = observer((props) => { const field = useField(); @@ -84,6 +88,10 @@ export const DatabaseCollection = observer((props) => {