From 1dff47e8e418773099597ff54716097a8f63ecf0 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 28 Sep 2021 09:33:38 +0800 Subject: [PATCH] feat: add client provider --- packages/app/package.json | 21 ++- packages/app/src/{api => apis}/index.ts | 7 + .../{tsconfig.api.json => tsconfig.apis.json} | 4 +- packages/client/src/ClientSDK.ts | 19 +++ .../Permissions/MenuPermissionTable.tsx | 3 +- packages/client/src/constate/Client.tsx | 25 +++ packages/client/src/constate/index.tsx | 1 + packages/client/src/demos/RequestProvider.tsx | 39 ----- packages/client/src/demos/api/index.ts | 38 ----- .../src/demos/api/routes-getAccessible.ts | 35 ---- .../src/demos/api/ui-schemas-getTree/item1.ts | 157 ------------------ .../src/demos/api/ui-schemas-getTree/item2.ts | 31 ---- .../demos/api/ui-schemas-getTree/item22.ts | 63 ------- .../src/demos/api/ui-schemas-getTree/item3.ts | 139 ---------------- .../src/demos/api/ui-schemas-getTree/item4.ts | 17 -- .../src/demos/api/ui-schemas-getTree/item5.ts | 92 ---------- .../src/demos/api/ui-schemas-getTree/login.ts | 62 ------- .../src/demos/api/ui-schemas-getTree/menu.ts | 107 ------------ .../demos/api/ui-schemas-getTree/register.ts | 76 --------- packages/client/src/demos/demo1.tsx | 14 +- packages/client/src/index.tsx | 2 + packages/client/src/schemas/action/index.md | 7 +- .../client/src/schemas/select/demos/demo1.tsx | 5 +- .../client/src/schemas/table/demos/demo3.tsx | 13 +- 24 files changed, 90 insertions(+), 887 deletions(-) rename packages/app/src/{api => apis}/index.ts (90%) rename packages/app/{tsconfig.api.json => tsconfig.apis.json} (66%) create mode 100644 packages/client/src/ClientSDK.ts create mode 100644 packages/client/src/constate/Client.tsx delete mode 100644 packages/client/src/demos/RequestProvider.tsx delete mode 100644 packages/client/src/demos/api/index.ts delete mode 100644 packages/client/src/demos/api/routes-getAccessible.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/item1.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/item2.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/item22.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/item3.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/item4.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/item5.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/login.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/menu.ts delete mode 100644 packages/client/src/demos/api/ui-schemas-getTree/register.ts diff --git a/packages/app/package.json b/packages/app/package.json index 448eadc33..529e8ce4d 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -4,11 +4,10 @@ "scripts": { "start": "concurrently \"cd ../../ && npm run start-server\" \"umi dev\"", "start-client": "umi dev", - "start-server": "nodemon", + "start-server": "ts-node-dev -r dotenv/config --project tsconfig.apis.json ./src/apis/index.ts", "build": "npm run build-server && npm run build-client", "build-client": "umi build", - "nocobase": "cross-env TS_NODE_PROJECT=\"tsconfig.api.json\" ts-node ./src/api/index.ts", - "build-server": "rimraf -rf lib && tsc --project tsconfig.api.json", + "build-server": "rimraf -rf lib && tsc --project tsconfig.apis.json", "postinstall": "umi generate tmp", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "test": "umi-test", @@ -27,10 +26,20 @@ }, "dependencies": { "@nocobase/client": "^0.4.0-alpha.7", - "@nocobase/preset-nocobase": "^0.4.0-alpha.7", + "@nocobase/plugin-action-logs": "^0.4.0-alpha.7", + "@nocobase/plugin-automations": "^0.4.0-alpha.7", + "@nocobase/plugin-china-region": "^0.4.0-alpha.7", + "@nocobase/plugin-collections": "^0.4.0-alpha.7", + "@nocobase/plugin-file-manager": "^0.4.0-alpha.7", + "@nocobase/plugin-pages": "^0.4.0-alpha.7", + "@nocobase/plugin-permissions": "^0.4.0-alpha.7", + "@nocobase/plugin-ui-router": "^0.4.0-alpha.7", + "@nocobase/plugin-ui-schema": "^0.4.0-alpha.7", + "@nocobase/plugin-users": "^0.4.0-alpha.7", + "@nocobase/plugin-saas": "^0.4.0-alpha.7", + "@nocobase/server": "^0.4.0-alpha.7", "@umijs/preset-react": "1.x", "koa-mount": "^4.0.0", - "ts-node-dev": "^1.1.8", "umi": "^3.0.0" }, "devDependencies": { @@ -40,11 +49,11 @@ "concurrently": "^5.3.0", "cross-env": "^7.0.3", "mockjs": "^1.1.0", - "nodemon": "^2.0.12", "prettier": "^2.2.0", "react": "17.x", "react-dom": "17.x", "ts-node": "^10.2.1", + "ts-node-dev": "^1.1.8", "yorkie": "^2.0.0" } } diff --git a/packages/app/src/api/index.ts b/packages/app/src/apis/index.ts similarity index 90% rename from packages/app/src/api/index.ts rename to packages/app/src/apis/index.ts index 58e06fe30..b9a25ae69 100644 --- a/packages/app/src/api/index.ts +++ b/packages/app/src/apis/index.ts @@ -1,4 +1,10 @@ import Server from '@nocobase/server'; +import dotenv from 'dotenv'; +import path from 'path'; + +dotenv.config({ + path: path.resolve(__dirname, '../../../../.env'), +}); const start = Date.now(); @@ -35,6 +41,7 @@ const api = new Server({ }); const plugins = [ + '@nocobase/plugin-saas', '@nocobase/plugin-collections', '@nocobase/plugin-ui-router', '@nocobase/plugin-ui-schema', diff --git a/packages/app/tsconfig.api.json b/packages/app/tsconfig.apis.json similarity index 66% rename from packages/app/tsconfig.api.json rename to packages/app/tsconfig.apis.json index 4b14009ec..980bc92f5 100644 --- a/packages/app/tsconfig.api.json +++ b/packages/app/tsconfig.apis.json @@ -1,9 +1,9 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "outDir": "./lib/api" + "outDir": "./lib/apis" }, "include": [ - "src/api", + "src/apis", ] } \ No newline at end of file diff --git a/packages/client/src/ClientSDK.ts b/packages/client/src/ClientSDK.ts new file mode 100644 index 000000000..755d5d2bb --- /dev/null +++ b/packages/client/src/ClientSDK.ts @@ -0,0 +1,19 @@ +import { RequestMethod, RequestOptionsInit } from 'umi-request'; + +export class ClientSDK { + options: any; + + constructor(options) { + this.options = options; + } + + request(url: string, options?: RequestOptionsInit): RequestMethod { + return this.options.request(url, options); + } + + resource(name) { + + } +} + +export default ClientSDK; diff --git a/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx b/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx index afd0d9d1e..9bf94a1e2 100644 --- a/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx +++ b/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { observer } from '@formily/react'; import { Table, Checkbox, Spin } from 'antd'; import { useRequest } from 'ahooks'; -import { request } from '../../../schemas'; import { Resource } from '../../../resource'; import { useContext } from 'react'; import { RoleContext } from '.'; @@ -23,7 +22,7 @@ export const MenuPermissionTable = observer((props) => { const [allUiSchemaKyes, setAllUiSchemaKyes] = useState([]); const [uiSchemaKyes, setUiSchemaKeys] = useState([]); const { data, loading } = useRequest( - () => request('ui_schemas:getMenuItems'), + 'ui_schemas:getMenuItems', { formatResult: (data) => data?.data, onSuccess(data) { diff --git a/packages/client/src/constate/Client.tsx b/packages/client/src/constate/Client.tsx new file mode 100644 index 000000000..c1a6ec828 --- /dev/null +++ b/packages/client/src/constate/Client.tsx @@ -0,0 +1,25 @@ +import React, { createContext, useContext } from 'react'; +import { UseRequestProvider } from 'ahooks'; + +const ClientContext = createContext({ + client: null, +}); + +export function ClientProvider(props) { + const { client } = props; + return ( + + client.request(service), + }} + > + {props.children} + + + ); +} + +export function useClient() { + return useContext(ClientContext); +} diff --git a/packages/client/src/constate/index.tsx b/packages/client/src/constate/index.tsx index 8ab5bbd88..08bb03048 100644 --- a/packages/client/src/constate/index.tsx +++ b/packages/client/src/constate/index.tsx @@ -2,3 +2,4 @@ export * from './Collections'; export * from './DesignableSwitch'; export * from './DisplayedMap'; export * from './PageTitle'; +export * from './Client'; diff --git a/packages/client/src/demos/RequestProvider.tsx b/packages/client/src/demos/RequestProvider.tsx deleted file mode 100644 index 307fb08ee..000000000 --- a/packages/client/src/demos/RequestProvider.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useRequest } from 'ahooks'; -import { Spin } from 'antd'; -import React, { useMemo } from 'react'; -import { MemoryRouter as Router } from 'react-router-dom'; -import { - createRouteSwitch, - RouteRedirectProps, - AdminLayout, - AuthLayout, - RouteSchemaRenderer, -} from '../'; -import { UseRequestProvider } from 'ahooks'; -import { extend } from 'umi-request'; - -const request = extend({ - prefix: process.env.API_URL, - timeout: 30000, -}); - -request.use(async (ctx, next) => { - const { headers } = ctx.req.options as any; - const token = localStorage.getItem('NOCOBASE_TOKEN'); - if (token) { - headers['Authorization'] = `Bearer ${token}`; - } - await next(); -}); - -export const RequestProvider = (props) => { - return ( - request(service), - }} - > - {props.children} - - ); -}; diff --git a/packages/client/src/demos/api/index.ts b/packages/client/src/demos/api/index.ts deleted file mode 100644 index c73f53e15..000000000 --- a/packages/client/src/demos/api/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -const api = { - '/api/routes:getAccessible': require('./routes-getAccessible').default, - // '/api/blocks:getSchema/login': require('./blocks-getSchema/login').default, - // '/api/blocks:getSchema/register': require('./blocks-getSchema/register').default, - // '/api/blocks:getSchema/item1': require('./blocks-getSchema/item1').default, - // '/api/blocks:getSchema/item2': require('./blocks-getSchema/item2').default, - // '/api/blocks:getSchema/item22': require('./blocks-getSchema/item22').default, - // '/api/blocks:getSchema/item3': require('./blocks-getSchema/item3').default, - // '/api/blocks:getSchema/item4': require('./blocks-getSchema/item4').default, - // '/api/blocks:getSchema/item5': require('./blocks-getSchema/item5').default, - // '/api/blocks:getSchema/menu': require('./blocks-getSchema/menu').default, - '/api/ui-schemas:getTree/login': require('./ui-schemas-getTree/login').default, - '/api/ui-schemas:getTree/register': require('./ui-schemas-getTree/register').default, - '/api/ui-schemas:getTree/menu': require('./ui-schemas-getTree/menu').default, -} - -export function request(service) { - let url = null; - if (typeof service === 'string') { - url = service; - } else if (typeof service === 'object' && service.url) { - url = service.url; - } - - console.log('request.url', url) - - return new Promise((resolve, reject) => { - setTimeout(() => { - if (api[url]) { - resolve({ - data: api[url], - }) - } else { - resolve({ data: {} }); - } - }, 100) - }) -} \ No newline at end of file diff --git a/packages/client/src/demos/api/routes-getAccessible.ts b/packages/client/src/demos/api/routes-getAccessible.ts deleted file mode 100644 index 9fd1bb7f7..000000000 --- a/packages/client/src/demos/api/routes-getAccessible.ts +++ /dev/null @@ -1,35 +0,0 @@ -export default [ - { - type: 'redirect', - from: '/', - to: '/admin', - exact: true, - }, - { - type: 'route', - path: '/admin/:name(.+)?', - component: 'AdminLayout', - title: `后台`, - uiSchemaKey: 'qqzzjakwkwl', - }, - { - type: 'route', - component: 'AuthLayout', - children: [ - { - type: 'route', - path: '/login', - component: 'RouteSchemaRenderer', - title: `登录`, - uiSchemaKey: 'dtf9j0b8p9u', - }, - { - type: 'route', - path: '/register', - component: 'RouteSchemaRenderer', - title: `注册`, - uiSchemaKey: '46qlxqam3xk', - }, - ], - }, -]; diff --git a/packages/client/src/demos/api/ui-schemas-getTree/item1.ts b/packages/client/src/demos/api/ui-schemas-getTree/item1.ts deleted file mode 100644 index cfb8d780d..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/item1.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { ISchema } from '@formily/json-schema'; -import { uid } from '@formily/shared'; - -export default { - type: 'object', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'void', - 'x-decorator': 'BlockItem', - 'x-component': 'Form', - properties: { - [uid()]: { - type: 'void', - 'x-decorator': 'Card', - 'x-component': 'Grid', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段1', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段2', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - - [uid()]: { - type: 'string', - required: true, - title: '字段3', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段4', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段5', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, - }, - }, - }, - actions: { - type: 'void', - // 'x-decorator': 'Div', - 'x-component': 'Space', - properties: { - submit: { - type: 'void', - 'x-component': 'Action', - 'x-component-props': { - // block: true, - type: 'primary', - useAction: '{{ useLogin }}', - style: { - // width: '100%', - }, - }, - title: '提交', - }, - reset: { - type: 'void', - 'x-component': 'Action', - 'x-component-props': { - // block: true, - useAction: '{{ useLogin }}', - style: { - // width: '100%', - }, - }, - title: '重置', - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, -} as ISchema; diff --git a/packages/client/src/demos/api/ui-schemas-getTree/item2.ts b/packages/client/src/demos/api/ui-schemas-getTree/item2.ts deleted file mode 100644 index 84218c353..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/item2.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { ISchema } from '@formily/json-schema'; -import { uid } from '@formily/shared'; - -export default { - type: 'object', - properties: { - [uid()]: { - type: 'void', - 'x-decorator': 'Card', - 'x-component': 'Grid', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'AddNew.BlockItem', - }, - }, - }, - }, - }, - }, - }, - }, -} as ISchema; diff --git a/packages/client/src/demos/api/ui-schemas-getTree/item22.ts b/packages/client/src/demos/api/ui-schemas-getTree/item22.ts deleted file mode 100644 index 088287438..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/item22.ts +++ /dev/null @@ -1,63 +0,0 @@ -export default { - type: 'object', - properties: { - input: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Input', - 'x-component-props': { - placeholder: '邮箱或用户名', - style: { - // width: 240, - }, - }, - }, - textarea: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Password', - 'x-component-props': { - placeholder: '密码', - style: { - // width: 240, - }, - }, - }, - actions: { - type: 'void', - // 'x-decorator': 'Div', - 'x-component': 'Div', - properties: { - submit: { - type: 'void', - 'x-component': 'Action', - 'x-component-props': { - block: true, - type: 'primary', - useAction: '{{ useLogin }}', - style: { - width: '100%', - }, - }, - title: '登录', - }, - }, - }, - registerlink: { - type: 'void', - 'x-component': 'Div', - properties: { - link: { - type: 'void', - 'x-component': 'Action.Link', - 'x-component-props': { - to: '/register', - }, - title: '注册账号', - }, - }, - }, - }, -} \ No newline at end of file diff --git a/packages/client/src/demos/api/ui-schemas-getTree/item3.ts b/packages/client/src/demos/api/ui-schemas-getTree/item3.ts deleted file mode 100644 index dd2ca5683..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/item3.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { uid } from '@formily/shared'; - -const schema = { - type: 'object', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Form', - properties: { - [uid()]: { - type: 'void', - 'x-decorator': 'Card', - 'x-component': 'Grid', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段1', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段2', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - - [uid()]: { - type: 'string', - required: true, - title: '字段3', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段4', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, - }, - [uid()]: { - type: 'void', - 'x-component': 'Grid.Row', - properties: { - [uid()]: { - type: 'void', - 'x-component': 'Grid.Col', - properties: { - [uid()]: { - type: 'string', - required: true, - title: '字段5', - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, - }, - }, - }, - actions: { - type: 'void', - // 'x-decorator': 'Div', - 'x-component': 'Space', - properties: { - submit: { - type: 'void', - 'x-component': 'Action', - 'x-component-props': { - // block: true, - type: 'primary', - useAction: '{{ useLogin }}', - style: { - // width: '100%', - }, - }, - title: '提交', - }, - reset: { - type: 'void', - 'x-component': 'Action', - 'x-component-props': { - // block: true, - useAction: '{{ useLogin }}', - style: { - // width: '100%', - }, - }, - title: '重置', - }, - }, - }, - }, - }, - }, -}; - -export default schema; diff --git a/packages/client/src/demos/api/ui-schemas-getTree/item4.ts b/packages/client/src/demos/api/ui-schemas-getTree/item4.ts deleted file mode 100644 index 0ef8bb70e..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/item4.ts +++ /dev/null @@ -1,17 +0,0 @@ -export default { - type: 'object', - properties: { - input: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Input', - 'x-component-props': { - placeholder: '邮箱或用户名', - style: { - // width: 240, - }, - }, - }, - }, -} \ No newline at end of file diff --git a/packages/client/src/demos/api/ui-schemas-getTree/item5.ts b/packages/client/src/demos/api/ui-schemas-getTree/item5.ts deleted file mode 100644 index de67b77d5..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/item5.ts +++ /dev/null @@ -1,92 +0,0 @@ -export default { - name: 'arr', - type: 'array', - 'x-component': 'Table', - default: [{ field1: 'a', field2: 'b' }, { field1: 'a', field2: 'b' }], - 'x-component-props': {}, - properties: { - actionBar1: { - type: 'void', - 'x-component': 'Table.ActionBar', - properties: { - action1: { - type: 'object', - title: '按钮1', - 'x-component': 'Table.Action.Popover', - 'x-component-props': { - }, - properties: { - - }, - }, - action2: { - type: 'void', - title: '按钮2', - 'x-component': 'Table.Action.Button', - 'x-component-props': { - label: '按钮2', - }, - }, - }, - }, - actionBar2: { - type: 'void', - 'x-component': 'Table.ActionBar', - 'x-component-props': { - align: 'bottom', - }, - properties: { - pagination: { - type: 'void', - 'x-component': 'Table.Pagination', - 'x-component-props': { - defaultCurrent: 1, - total: 50, - }, - }, - }, - }, - details: { - type: 'void', - 'x-component': 'Table.Details', - properties: {}, - }, - col1: { - type: 'void', - title: '字段1', - 'x-component': 'Table.Column', - 'x-component-props': { - title: 'z1', - width: 100, - }, - properties: { - field1: { - type: 'string', - required: true, - 'x-decorator-props': { - feedbackLayout: 'popover', - }, - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - col2: { - type: 'void', - title: '字段2', - 'x-component': 'Table.Column', - properties: { - field2: { - type: 'string', - title: '字段2', - required: true, - 'x-decorator-props': { - feedbackLayout: 'popover', - }, - 'x-decorator': 'FormItem', - 'x-component': 'Input', - }, - }, - }, - }, -} \ No newline at end of file diff --git a/packages/client/src/demos/api/ui-schemas-getTree/login.ts b/packages/client/src/demos/api/ui-schemas-getTree/login.ts deleted file mode 100644 index b427552b5..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/login.ts +++ /dev/null @@ -1,62 +0,0 @@ -export default { - type: 'object', - properties: { - email: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Input', - 'x-component-props': { - placeholder: '邮箱或用户名', - style: { - // width: 240, - }, - }, - }, - password: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Password', - 'x-component-props': { - placeholder: '密码', - style: { - // width: 240, - }, - }, - }, - actions: { - type: 'void', - 'x-component': 'Div', - properties: { - submit: { - type: 'void', - 'x-component': 'Action', - 'x-component-props': { - block: true, - type: 'primary', - useAction: '{{ useLogin }}', - style: { - width: '100%', - }, - }, - title: '登录', - }, - }, - }, - registerlink: { - type: 'void', - 'x-component': 'Div', - properties: { - link: { - type: 'void', - 'x-component': 'Action.Link', - 'x-component-props': { - to: '/register', - }, - title: '注册账号', - }, - }, - }, - }, -}; diff --git a/packages/client/src/demos/api/ui-schemas-getTree/menu.ts b/packages/client/src/demos/api/ui-schemas-getTree/menu.ts deleted file mode 100644 index 068759f8b..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/menu.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { uid } from '@formily/shared'; - -export default { - type: 'void', - name: `menu_${uid()}`, - 'x-component': 'Menu', - 'x-designable-bar': 'Menu.DesignableBar', - 'x-component-props': { - mode: 'mix', - theme: 'dark', - defaultSelectedKeys: '{{ selectedKeys }}', - sideMenuRef: '{{ sideMenuRef }}', - onSelect: '{{ onSelect }}', - }, - properties: { - [uid()]: { - type: 'void', - title: `菜单2`, - 'x-component': 'Menu.Link', - 'x-component-props': { - icon: 'MailOutlined', - }, - }, - [uid()]: { - type: 'void', - title: `菜单22`, - 'x-component': 'Menu.Link', - 'x-component-props': { - icon: 'AppstoreOutlined', - // url: 'https://www.google.com', - }, - }, - [uid()]: { - type: 'void', - title: '菜单组1', - 'x-component': 'Menu.SubMenu', - 'x-component-props': { - icon: 'SettingOutlined', - }, - }, - [uid()]: { - type: 'void', - title: '菜单组2', - 'x-component': 'Menu.SubMenu', - 'x-component-props': { - icon: 'SettingOutlined', - }, - properties: { - [uid()]: { - type: 'void', - title: '菜单6', - 'x-component': 'Menu.SubMenu', - 'x-component-props': { - icon: 'AppstoreOutlined', - }, - properties: { - [uid()]: { - type: 'void', - title: '菜单9', - 'x-component': 'Menu.SubMenu', - properties: { - [uid()]: { - type: 'void', - title: `子菜单10`, - 'x-component': 'Menu.Link', - }, - [uid()]: { - type: 'void', - title: `子菜单11`, - 'x-component': 'Menu.Link', - }, - } - }, - [uid()]: { - type: 'void', - title: `子菜单7`, - 'x-component': 'Menu.Link', - }, - [uid()]: { - type: 'void', - title: `子菜单8`, - 'x-component': 'Menu.Link', - }, - } - }, - [uid()]: { - type: 'void', - title: `子菜单1`, - 'x-component': 'Menu.Link', - }, - [uid()]: { - type: 'void', - title: `子菜单2`, - 'x-component': 'Menu.Link', - }, - } - }, - [uid()]: { - type: 'void', - title: `菜单1`, - 'x-component': 'Menu.Link', - 'x-component-props': { - icon: 'SettingOutlined', - }, - }, - }, -} \ No newline at end of file diff --git a/packages/client/src/demos/api/ui-schemas-getTree/register.ts b/packages/client/src/demos/api/ui-schemas-getTree/register.ts deleted file mode 100644 index f7b427dd9..000000000 --- a/packages/client/src/demos/api/ui-schemas-getTree/register.ts +++ /dev/null @@ -1,76 +0,0 @@ -export default { - type: 'object', - properties: { - username: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Input', - 'x-component-props': { - placeholder: '用户名', - style: { - // width: 240, - }, - }, - }, - pwd1: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Password', - 'x-component-props': { - placeholder: '密码', - checkStrength: true, - style: { - // width: 240, - }, - }, - }, - pwd2: { - type: 'string', - required: true, - 'x-decorator': 'FormItem', - 'x-component': 'Password', - 'x-component-props': { - placeholder: '密码', - checkStrength: true, - style: { - // width: 240, - }, - }, - }, - actions: { - type: 'void', - 'x-component': 'Div', - properties: { - submit: { - type: 'void', - title: '注册', - 'x-component': 'Action', - 'x-component-props': { - block: true, - type: 'primary', - useAction: '{{ useRegister }}', - style: { - width: '100%', - }, - }, - }, - }, - }, - registerlink: { - type: 'void', - 'x-component': 'Div', - properties: { - link: { - type: 'void', - 'x-component': 'Action.Link', - 'x-component-props': { - to: '/login', - }, - title: '使用已有账号登录', - }, - }, - }, - }, -} diff --git a/packages/client/src/demos/demo1.tsx b/packages/client/src/demos/demo1.tsx index 2ff13d323..d9145e709 100644 --- a/packages/client/src/demos/demo1.tsx +++ b/packages/client/src/demos/demo1.tsx @@ -10,6 +10,8 @@ import { AdminLayout, AuthLayout, RouteSchemaRenderer, + ClientProvider, + ClientSDK } from '../'; import { UseRequestProvider } from 'ahooks'; import { extend } from 'umi-request'; @@ -28,6 +30,10 @@ request.use(async (ctx, next) => { await next(); }); +const client = new ClientSDK({ + request, +}); + console.log('process.env.API_URL', process.env.API_URL); // console.log = () => {} @@ -60,12 +66,8 @@ const App = () => { export default () => { return ( - request(service), - }} - > + - + ); } diff --git a/packages/client/src/index.tsx b/packages/client/src/index.tsx index e183ef860..abfca1cd8 100644 --- a/packages/client/src/index.tsx +++ b/packages/client/src/index.tsx @@ -3,3 +3,5 @@ export * from './components/admin-layout'; export * from './components/auth-layout'; export * from './components/route-schema-renderer'; export * from './schemas'; +export * from './constate'; +export * from './ClientSDK'; \ No newline at end of file diff --git a/packages/client/src/schemas/action/index.md b/packages/client/src/schemas/action/index.md index 7158456b6..33e1c41b0 100644 --- a/packages/client/src/schemas/action/index.md +++ b/packages/client/src/schemas/action/index.md @@ -2,10 +2,11 @@ title: Action - 操作 nav: title: 组件 - path: /schemas + path: /client group: - title: 组件 - path: /schemas + order: 1 + title: Schemas + path: /client/schemas --- # Action - 操作 diff --git a/packages/client/src/schemas/select/demos/demo1.tsx b/packages/client/src/schemas/select/demos/demo1.tsx index 101a87306..d54575fd3 100644 --- a/packages/client/src/schemas/select/demos/demo1.tsx +++ b/packages/client/src/schemas/select/demos/demo1.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { ISchema, SchemaRenderer } from '../../'; import { useSelect, useOptionTagValues } from '../'; import { uid } from '@formily/shared'; -import { RequestProvider } from '@nocobase/client/src/demos/RequestProvider'; import { CollectionsProvider } from '@nocobase/client/src/constate'; console.log({ useSelect }); @@ -194,13 +193,11 @@ const schema: ISchema = { export default () => { return ( - - + - ); }; diff --git a/packages/client/src/schemas/table/demos/demo3.tsx b/packages/client/src/schemas/table/demos/demo3.tsx index 7ba486237..50a639eb4 100644 --- a/packages/client/src/schemas/table/demos/demo3.tsx +++ b/packages/client/src/schemas/table/demos/demo3.tsx @@ -7,7 +7,6 @@ import { CollectionsProvider, DesignableSwitchProvider, } from '@nocobase/client/src/constate'; -import { RequestProvider } from '@nocobase/client/src/demos/RequestProvider'; const schema = { name: 'table1', @@ -222,13 +221,11 @@ const schema = { export default () => { return (
- - - - - - - + + + + +
); };