diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..0d4222f54 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +**/*.md +**/*.svg +**/*.ejs +**/*.html +package.json +.umi +.umi-production +.umi-test diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..94beb1484 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,11 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "printWidth": 80, + "overrides": [ + { + "files": ".prettierrc", + "options": { "parser": "json" } + } + ] +} diff --git a/packages/client/src/ClientSDK.ts b/packages/client/src/ClientSDK.ts index afaa33175..9ed0ff144 100644 --- a/packages/client/src/ClientSDK.ts +++ b/packages/client/src/ClientSDK.ts @@ -9,12 +9,10 @@ export class ClientSDK { request(url: string, options?: RequestOptionsInit): RequestMethod { console.log('this.options.request', this.options.request); - return this.options.request(url, options||{}); + return this.options.request(url, options || {}); } - resource(name) { - - } + resource(name) {} } export default ClientSDK; diff --git a/packages/client/src/ConfigProvider.tsx b/packages/client/src/ConfigProvider.tsx index 9e3467853..ce4fa1dd5 100644 --- a/packages/client/src/ConfigProvider.tsx +++ b/packages/client/src/ConfigProvider.tsx @@ -1,4 +1,4 @@ -import React, { createContext } from 'react' +import React, { createContext } from 'react'; // import { ConfigProvider as AntdConfigProvider } from 'antd'; // import enUS from 'antd/lib/locale/en_US'; // import zhCN from 'antd/lib/locale/zh_CN'; @@ -11,9 +11,5 @@ const ConfigContext = createContext(null); export function ConfigProvider(props: any) { const { client } = props; - return ( - - {props.children} - - ) -}; + return {props.children}; +} diff --git a/packages/client/src/components/Sortable/index.tsx b/packages/client/src/components/Sortable/index.tsx index 7aa995c14..dba2bf48e 100644 --- a/packages/client/src/components/Sortable/index.tsx +++ b/packages/client/src/components/Sortable/index.tsx @@ -146,7 +146,7 @@ export function SortableItem(props: SortableItemProps) { previewRef.current = el; setDroppableNodeRef(el); // if (draggable) { - // setDraggableNodeRef(el); + // setDraggableNodeRef(el); // } }} > diff --git a/packages/client/src/components/admin-layout/Collections/index.tsx b/packages/client/src/components/admin-layout/Collections/index.tsx index 760f41b00..6be24e218 100644 --- a/packages/client/src/components/admin-layout/Collections/index.tsx +++ b/packages/client/src/components/admin-layout/Collections/index.tsx @@ -81,9 +81,12 @@ const useActionPermissionResource = ({ onSuccess }) => { console.log('RoleContext', role); // const { props } = useTable(); const ctx = useContext(TableRowContext); - const resource = useResourceRequest({ - resourceName: 'action_permissions', - }, ActionPermissionResource); + const resource = useResourceRequest( + { + resourceName: 'action_permissions', + }, + ActionPermissionResource, + ); const service = useRequest( (params?: any) => { return resource.list({ @@ -593,7 +596,11 @@ function CreateFieldButton() { option.children.length > 0 && ( {option.children.map((item) => ( - + {item.title} ))} diff --git a/packages/client/src/components/admin-layout/More.tsx b/packages/client/src/components/admin-layout/More.tsx index d2205aa1c..d22d174ee 100644 --- a/packages/client/src/components/admin-layout/More.tsx +++ b/packages/client/src/components/admin-layout/More.tsx @@ -51,7 +51,7 @@ const schema: ISchema = { type: 'void', title: `系统配置`, 'x-component': 'Menu.Action', - "x-component-props": { + 'x-component-props': { icon: 'SettingOutlined', }, properties: { diff --git a/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx b/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx index bf4ffa23d..2ad8274a4 100644 --- a/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx +++ b/packages/client/src/components/admin-layout/Permissions/MenuPermissionTable.tsx @@ -22,15 +22,12 @@ export const MenuPermissionTable = observer((props) => { const role = useContext(RoleContext); const [allUiSchemaKyes, setAllUiSchemaKyes] = useState([]); const [uiSchemaKyes, setUiSchemaKeys] = useState([]); - const { data, loading } = useRequest( - 'ui_schemas:getMenuItems', - { - formatResult: (data) => data?.data, - onSuccess(data) { - setAllUiSchemaKyes(getKeys(data)); - }, + const { data, loading } = useRequest('ui_schemas:getMenuItems', { + formatResult: (data) => data?.data, + onSuccess(data) { + setAllUiSchemaKyes(getKeys(data)); }, - ); + }); console.log('allUiSchemaKyes', allUiSchemaKyes); const resource = useResourceRequest({ associatedName: 'roles', diff --git a/packages/client/src/components/admin-layout/Permissions/index.tsx b/packages/client/src/components/admin-layout/Permissions/index.tsx index a5d012a16..e00138483 100644 --- a/packages/client/src/components/admin-layout/Permissions/index.tsx +++ b/packages/client/src/components/admin-layout/Permissions/index.tsx @@ -72,9 +72,12 @@ const useActionPermissionResource = ({ onSuccess }) => { console.log('RoleContext', role); // const { props } = useTable(); const ctx = useContext(TableRowContext); - const resource = useResourceRequest({ - resourceName: 'action_permissions', - }, ActionPermissionResource); + const resource = useResourceRequest( + { + resourceName: 'action_permissions', + }, + ActionPermissionResource, + ); const service = useRequest( (params?: any) => { return resource.list({ @@ -292,7 +295,7 @@ const schema: ISchema = { icon: 'DeleteOutlined', confirm: { title: '删除数据', - content: '删除后无法恢复,确定要删除吗?' + content: '删除后无法恢复,确定要删除吗?', }, useAction: '{{ Table.useTableDestroyAction }}', }, @@ -467,7 +470,7 @@ const schema: ISchema = { type: 'link', confirm: { title: '删除数据', - content: '删除后无法恢复,确定要删除吗?' + content: '删除后无法恢复,确定要删除吗?', }, useAction: '{{ Table.useTableDestroyAction }}', }, diff --git a/packages/client/src/components/admin-layout/UserInfo.tsx b/packages/client/src/components/admin-layout/UserInfo.tsx index 89222e80a..3828bcff3 100644 --- a/packages/client/src/components/admin-layout/UserInfo.tsx +++ b/packages/client/src/components/admin-layout/UserInfo.tsx @@ -64,7 +64,9 @@ export const UserInfo = () => {
- 角色切换 + + 角色切换 + { if (!schema) { @@ -232,12 +232,11 @@ export function AdminLayout({ route, ...others }: any) { }, []); }; - if (loading) { return ; } - const f = findMenuLinkProperties(new Schema(first||{})).shift(); + const f = findMenuLinkProperties(new Schema(first || {})).shift(); if (f?.['key'] && !match.params.name) { return ; diff --git a/packages/client/src/components/admin-layout/style.less b/packages/client/src/components/admin-layout/style.less index 5969c85eb..379880a75 100644 --- a/packages/client/src/components/admin-layout/style.less +++ b/packages/client/src/components/admin-layout/style.less @@ -75,7 +75,8 @@ .user-info { height: 46px; color: #fff; - &:hover, &:focus { + &:hover, + &:focus { color: #fff; } } @@ -95,7 +96,8 @@ } .site-header { - .ant-menu.ant-menu-dark .ant-menu-item-selected, .ant-menu-submenu-popup.ant-menu-dark .ant-menu-item-selected { + .ant-menu.ant-menu-dark .ant-menu-item-selected, + .ant-menu-submenu-popup.ant-menu-dark .ant-menu-item-selected { background-color: rgba(255, 255, 255, 0.1); } .ant-menu-dark.ant-menu-horizontal > .ant-menu-item:hover { @@ -105,11 +107,11 @@ color: rgba(255, 255, 255, 0.65) !important; &.nb-designable-toggle:hover { color: #fff !important; - background-color: #F18B62 !important + background-color: #f18b62 !important; } } .ant-btn:hover { color: #fff !important; background-color: rgba(255, 255, 255, 0.1) !important; } -} \ No newline at end of file +} diff --git a/packages/client/src/components/router-config/demos/demo1.tsx b/packages/client/src/components/router-config/demos/demo1.tsx index b50a55b77..db6597235 100644 --- a/packages/client/src/components/router-config/demos/demo1.tsx +++ b/packages/client/src/components/router-config/demos/demo1.tsx @@ -11,7 +11,7 @@ const RouteSwitch = createRouteSwitch({ components: { Home: (props) => { console.log({ props }); - return
Home {props.children}
+ return
Home {props.children}
; }, Login: () =>
Login
, }, diff --git a/packages/client/src/components/router-config/index.tsx b/packages/client/src/components/router-config/index.tsx index 9bb0488b8..b47455d0e 100644 --- a/packages/client/src/components/router-config/index.tsx +++ b/packages/client/src/components/router-config/index.tsx @@ -22,7 +22,7 @@ export interface RouteProps { strict?: boolean; sensitive?: boolean; component?: any; - routes?: RouteProps[], + routes?: RouteProps[]; [key: string]: any; } diff --git a/packages/client/src/constate/Client.tsx b/packages/client/src/constate/Client.tsx index 55e644fda..26f1c6b71 100644 --- a/packages/client/src/constate/Client.tsx +++ b/packages/client/src/constate/Client.tsx @@ -44,7 +44,7 @@ export function ClientProvider(props) { export function useResourceRequest(options, ResourceClass?: any) { const Cls = ResourceClass || Resource; const { request } = useClient(); - return Cls.make(options, request);; + return Cls.make(options, request); } export function useClient() { diff --git a/packages/client/src/constate/Collections.ts b/packages/client/src/constate/Collections.ts index 3005e9323..9f7634fe4 100644 --- a/packages/client/src/constate/Collections.ts +++ b/packages/client/src/constate/Collections.ts @@ -1,27 +1,32 @@ import { useRequest } from 'ahooks'; import constate from 'constate'; -const [CollectionsProvider, useCollectionsContext] = constate(() => { - const result = useRequest('collections:findAll', { - formatResult: (result) => result?.data, - }); - return { - ...result, collections: result.data || [], - findCollection(name) { - return result?.data?.find((item) => item.name === name); - }, - async loadCollections(field: any) { - return result?.data?.map((item: any) => ({ - label: item.title, - value: item.name, - })); - }, - getFieldsByCollection(collectionName) { - const collection = result?.data?.find((item) => item.name === collectionName); - return collection?.generalFields; - }, - }; -}); +const [CollectionsProvider, useCollectionsContext] = constate( + () => { + const result = useRequest('collections:findAll', { + formatResult: (result) => result?.data, + }); + return { + ...result, + collections: result.data || [], + findCollection(name) { + return result?.data?.find((item) => item.name === name); + }, + async loadCollections(field: any) { + return result?.data?.map((item: any) => ({ + label: item.title, + value: item.name, + })); + }, + getFieldsByCollection(collectionName) { + const collection = result?.data?.find( + (item) => item.name === collectionName, + ); + return collection?.generalFields; + }, + }; + }, +); export { CollectionsProvider, useCollectionsContext }; diff --git a/packages/client/src/constate/DesignableSwitch.ts b/packages/client/src/constate/DesignableSwitch.ts index 212405c24..a54158679 100644 --- a/packages/client/src/constate/DesignableSwitch.ts +++ b/packages/client/src/constate/DesignableSwitch.ts @@ -1,4 +1,4 @@ -import { useCookieState } from "ahooks"; +import { useCookieState } from 'ahooks'; import constate from 'constate'; const [DesignableSwitchProvider, useDesignableSwitchContext] = constate(() => { @@ -8,8 +8,8 @@ const [DesignableSwitchProvider, useDesignableSwitchContext] = constate(() => { designable: active === 'true', setDesignable(value) { setActive(value ? 'true' : 'false'); - } - } + }, + }; }); export { DesignableSwitchProvider, useDesignableSwitchContext }; diff --git a/packages/client/src/context.ts b/packages/client/src/context.ts index f333e01fc..325f6aab9 100644 --- a/packages/client/src/context.ts +++ b/packages/client/src/context.ts @@ -1,5 +1,5 @@ -import { createContext } from "react"; -import { Schema } from "@formily/react"; +import { createContext } from 'react'; +import { Schema } from '@formily/react'; export const VisibleContext = createContext([]); export const BlockSchemaContext = createContext(null); diff --git a/packages/client/src/demos/demo1.tsx b/packages/client/src/demos/demo1.tsx index 00346f205..88574aaa2 100644 --- a/packages/client/src/demos/demo1.tsx +++ b/packages/client/src/demos/demo1.tsx @@ -1,9 +1,7 @@ import { useRequest } from 'ahooks'; import { Spin } from 'antd'; import React, { useMemo } from 'react'; -import { - MemoryRouter as Router, -} from 'react-router-dom'; +import { MemoryRouter as Router } from 'react-router-dom'; import { createRouteSwitch, RouteRedirectProps, @@ -11,7 +9,7 @@ import { AuthLayout, RouteSchemaRenderer, ConfigProvider, - ClientSDK + ClientSDK, } from '../'; import { UseRequestProvider } from 'ahooks'; import { extend } from 'umi-request'; @@ -53,7 +51,7 @@ const App = () => { }); if (loading) { - return + return ; } return ( @@ -71,4 +69,4 @@ export default () => { ); -} +}; diff --git a/packages/client/src/locale/en_US.ts b/packages/client/src/locale/en_US.ts index 56004c9f9..ff8b4c563 100644 --- a/packages/client/src/locale/en_US.ts +++ b/packages/client/src/locale/en_US.ts @@ -1 +1 @@ -export default {} \ No newline at end of file +export default {}; diff --git a/packages/client/src/locale/zh_CN.ts b/packages/client/src/locale/zh_CN.ts index 56004c9f9..ff8b4c563 100644 --- a/packages/client/src/locale/zh_CN.ts +++ b/packages/client/src/locale/zh_CN.ts @@ -1 +1 @@ -export default {} \ No newline at end of file +export default {}; diff --git a/packages/client/src/resource.ts b/packages/client/src/resource.ts index 178ae6384..8acd5b981 100644 --- a/packages/client/src/resource.ts +++ b/packages/client/src/resource.ts @@ -28,13 +28,12 @@ export interface ListOptions { } export class Resource { - public options: ResourceOptions; public request: RequestMethod; constructor(options: string | ResourceOptions, request?: any) { if (typeof options === 'string') { - this.options = { resourceName: options } + this.options = { resourceName: options }; } else { this.options = options; } @@ -54,7 +53,14 @@ export class Resource { } list(options: ListOptions = {}) { - const { defaultAppends = [], appends = [], defaultFilter, filter, pageSize, ...others } = options; + const { + defaultAppends = [], + appends = [], + defaultFilter, + filter, + pageSize, + ...others + } = options; const { associatedKey, associatedName, resourceName } = this.options; let url = `${resourceName}:list`; if (associatedName && associatedKey) { @@ -63,7 +69,9 @@ export class Resource { return this.request(url, { method: 'get', params: { - filter: decodeURIComponent(JSON.stringify({ and: [defaultFilter, filter].filter(Boolean) })), + filter: decodeURIComponent( + JSON.stringify({ and: [defaultFilter, filter].filter(Boolean) }), + ), 'fields[appends]': defaultAppends.concat(appends).join(','), perPage: pageSize, ...others, @@ -90,7 +98,7 @@ export class Resource { const { associatedKey, associatedName, resourceName } = this.options; let url = `${resourceName}:create`; if (associatedKey && associatedName) { - url = `${associatedName}/${associatedKey}/${url}` + url = `${associatedName}/${associatedKey}/${url}`; } return this.request(url, { method: 'post', @@ -101,9 +109,11 @@ export class Resource { save(values: any, options: SaveOptions = {}) { const resourceKey = options.resourceKey || this.options.resourceKey; const { associatedKey, associatedName, resourceName } = this.options; - let url = `${resourceName}:${resourceKey ? `update/${resourceKey}` : 'create'}`; + let url = `${resourceName}:${ + resourceKey ? `update/${resourceKey}` : 'create' + }`; if (associatedKey && associatedName) { - url = `${associatedName}/${associatedKey}/${url}` + url = `${associatedName}/${associatedKey}/${url}`; } return this.request(url, { method: 'post', @@ -122,9 +132,13 @@ export class Resource { ...others, }, parseResponse: false, - responseType: 'blob' + responseType: 'blob', }).then(async (response: Response) => { - const filename = decodeURI(response.headers.get('Content-Disposition').replace('attachment; filename=', '')); + const filename = decodeURI( + response.headers + .get('Content-Disposition') + .replace('attachment; filename=', ''), + ); // ReadableStream let res = new Response(response.body); let blob = await res.blob(); @@ -151,7 +165,7 @@ export class Resource { return this.request(url, { method: 'get', params: { - filter + filter, }, }); } @@ -165,7 +179,10 @@ export class Resource { }); } - static make(options: null | string | Resource | ResourceOptions, request?: any): Resource | null { + static make( + options: null | string | Resource | ResourceOptions, + request?: any, + ): Resource | null { if (typeof options === 'string') { return new this({ resourceName: options }, request); } diff --git a/packages/client/src/schemas/action/style.less b/packages/client/src/schemas/action/style.less index 02d489e49..28956d277 100644 --- a/packages/client/src/schemas/action/style.less +++ b/packages/client/src/schemas/action/style.less @@ -74,14 +74,13 @@ } &[disabled] { color: #00000040; - background-color:#fff; - cursor:not-allowed; + background-color: #fff; + cursor: not-allowed; } } } } - .designable-bar-actions { .ant-btn { border: 0; @@ -106,4 +105,4 @@ right: -12px !important; } } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/add-new/index.tsx b/packages/client/src/schemas/add-new/index.tsx index 41026792d..42d4dee8a 100644 --- a/packages/client/src/schemas/add-new/index.tsx +++ b/packages/client/src/schemas/add-new/index.tsx @@ -1566,7 +1566,10 @@ AddNew.FormItem = observer((props: any) => { const values = await FormDialog(`添加字段`, () => { return ( - + ); }).open({ diff --git a/packages/client/src/schemas/calendar/ActionBar.tsx b/packages/client/src/schemas/calendar/ActionBar.tsx index ab47db913..e9b5f9a89 100644 --- a/packages/client/src/schemas/calendar/ActionBar.tsx +++ b/packages/client/src/schemas/calendar/ActionBar.tsx @@ -7,7 +7,11 @@ import { getSchemaPath, useDesignable, } from '../../components/schema-renderer'; -import { useClient, DisplayedMapProvider, useDisplayedMapContext } from '../../constate'; +import { + useClient, + DisplayedMapProvider, + useDisplayedMapContext, +} from '../../constate'; import cls from 'classnames'; import { Button, Dropdown, Menu, Space } from 'antd'; import SwitchMenuItem from '../../components/SwitchMenuItem'; diff --git a/packages/client/src/schemas/calendar/demos/events.ts b/packages/client/src/schemas/calendar/demos/events.ts index e9811a6ab..ab3a2f736 100644 --- a/packages/client/src/schemas/calendar/demos/events.ts +++ b/packages/client/src/schemas/calendar/demos/events.ts @@ -1,4 +1,4 @@ -const now = new Date() +const now = new Date(); export default [ { @@ -177,4 +177,4 @@ export default [ start: new Date(2015, 3, 14, 18, 30, 0), end: new Date(2015, 3, 14, 20, 0, 0), }, -] \ No newline at end of file +]; diff --git a/packages/client/src/schemas/calendar/designable.less b/packages/client/src/schemas/calendar/designable.less index 55398543c..fa12c67aa 100644 --- a/packages/client/src/schemas/calendar/designable.less +++ b/packages/client/src/schemas/calendar/designable.less @@ -32,4 +32,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/calendar/index.tsx b/packages/client/src/schemas/calendar/index.tsx index 34ef724f7..42bd1210b 100644 --- a/packages/client/src/schemas/calendar/index.tsx +++ b/packages/client/src/schemas/calendar/index.tsx @@ -209,7 +209,9 @@ export const Calendar: any = observer((props: any) => { { return ( - + ); }; diff --git a/packages/client/src/schemas/chart/G2Plot.tsx b/packages/client/src/schemas/chart/G2Plot.tsx index 70c25ba41..bc91acde7 100644 --- a/packages/client/src/schemas/chart/G2Plot.tsx +++ b/packages/client/src/schemas/chart/G2Plot.tsx @@ -7,7 +7,10 @@ export type ReactG2PlotProps = { readonly config: O; }; -export default forwardRef(function(props: ReactG2PlotProps, ref: any) { +export default forwardRef(function ( + props: ReactG2PlotProps, + ref: any, +) { const { className, plot, config } = props; const containerRef = useRef(undefined); diff --git a/packages/client/src/schemas/color-select/index.tsx b/packages/client/src/schemas/color-select/index.tsx index f3e086832..88bb669d3 100644 --- a/packages/client/src/schemas/color-select/index.tsx +++ b/packages/client/src/schemas/color-select/index.tsx @@ -1,7 +1,7 @@ -import React from 'react' -import { connect, mapProps, mapReadPretty } from '@formily/react' -import { Tag, Select } from 'antd' -import { LoadingOutlined } from '@ant-design/icons' +import React from 'react'; +import { connect, mapProps, mapReadPretty } from '@formily/react'; +import { Tag, Select } from 'antd'; +import { LoadingOutlined } from '@ant-design/icons'; const colors = { red: '薄暮', @@ -22,13 +22,13 @@ export const ColorSelect = connect( (props) => { return ( - ) + ); }, mapProps((props, field) => { return { @@ -42,17 +42,15 @@ export const ColorSelect = connect( )} ), - } + }; }), mapReadPretty((props) => { const { value } = props; if (!colors[value]) { return null; } - return ( - {colors[value]} - ); - }) -) + return {colors[value]}; + }), +); -export default ColorSelect +export default ColorSelect; diff --git a/packages/client/src/schemas/database-field/demos/demo1.tsx b/packages/client/src/schemas/database-field/demos/demo1.tsx index 59d2358ea..58706661e 100644 --- a/packages/client/src/schemas/database-field/demos/demo1.tsx +++ b/packages/client/src/schemas/database-field/demos/demo1.tsx @@ -40,5 +40,5 @@ export default observer(() => {
- ) -}) \ No newline at end of file + ); +}); diff --git a/packages/client/src/schemas/database-field/demos/demo2.tsx b/packages/client/src/schemas/database-field/demos/demo2.tsx index 03ce7b0db..902c6149f 100644 --- a/packages/client/src/schemas/database-field/demos/demo2.tsx +++ b/packages/client/src/schemas/database-field/demos/demo2.tsx @@ -16,7 +16,7 @@ const schema: ISchema = { { name: 'test2', title: '数据表 2', - } + }, ], properties: { title: { @@ -31,7 +31,7 @@ const schema: ISchema = { title: '数据表标识', 'x-decorator': 'FormItem', 'x-component': 'Input', - "x-read-pretty": true, + 'x-read-pretty': true, }, fields: { type: 'array', @@ -39,8 +39,8 @@ const schema: ISchema = { 'x-decorator': 'FormItem', 'x-component': 'DatabaseField', default: [], - } - } + }, + }, }; const form = createForm(); diff --git a/packages/client/src/schemas/database-field/index.tsx b/packages/client/src/schemas/database-field/index.tsx index 335169392..743d1b18b 100644 --- a/packages/client/src/schemas/database-field/index.tsx +++ b/packages/client/src/schemas/database-field/index.tsx @@ -42,10 +42,7 @@ import Modal from 'antd/lib/modal/Modal'; import { clone, cloneDeep, get } from 'lodash'; import { useEffect } from 'react'; import { useRequest } from 'ahooks'; -import { - createOrUpdateCollection, - deleteCollection, -} from '..'; +import { createOrUpdateCollection, deleteCollection } from '..'; import { useCollectionsContext } from '../../constate/Collections'; import { DragHandle, @@ -185,7 +182,11 @@ export const DatabaseCollection = observer((props) => { 创建} + enterButton={ + <> + 创建 + + } value={newValue} onChange={(e) => { setNewValue(e.target.value); diff --git a/packages/client/src/schemas/database-field/interfaces/index.ts b/packages/client/src/schemas/database-field/interfaces/index.ts index 89f247b30..59032d8c1 100644 --- a/packages/client/src/schemas/database-field/interfaces/index.ts +++ b/packages/client/src/schemas/database-field/interfaces/index.ts @@ -21,14 +21,14 @@ const groupLabels = {}; export function getDefaultFields() { const defaults = ['createdAt', 'updatedAt', 'createdBy', 'updatedBy']; - return defaults.map(key => { + return defaults.map((key) => { return { interface: key, key: uid(), name: uid(), privilege: 'undelete', ...cloneDeep(interfaces.get(key)?.default), - } + }; }); } @@ -55,19 +55,21 @@ registerGroupLabel('relation', '关系类型'); registerGroupLabel('systemInfo', '系统信息'); registerGroupLabel('others', '其他类型'); -export const options = Object.keys(groupLabels).map(groupName => { +export const options = Object.keys(groupLabels).map((groupName) => { return { label: groupLabels[groupName], - children: Object.keys(fields[groupName] || {}).map((type) => { - return { - name: type, - ...fields[groupName][type], - }; - }).sort((a, b) => a.order - b.order), - } + children: Object.keys(fields[groupName] || {}) + .map((type) => { + return { + name: type, + ...fields[groupName][type], + }; + }) + .sort((a, b) => a.order - b.order), + }; }); export const isAssociation = (field) => { const options = interfaces.get(field.interface); return options?.isAssociation; -} +}; diff --git a/packages/client/src/schemas/database-field/interfaces/percent.ts b/packages/client/src/schemas/database-field/interfaces/percent.ts index 9da55097f..aa54d6c01 100644 --- a/packages/client/src/schemas/database-field/interfaces/percent.ts +++ b/packages/client/src/schemas/database-field/interfaces/percent.ts @@ -40,7 +40,7 @@ export const percent: FieldOptions = { { value: '0.001', label: '1.000' }, { value: '0.0001', label: '1.0000' }, { value: '0.00001', label: '1.00000' }, - ] + ], }, }, operations: number.operations, diff --git a/packages/client/src/schemas/database-field/interfaces/phone.ts b/packages/client/src/schemas/database-field/interfaces/phone.ts index 25c5d37ef..241a9fc20 100644 --- a/packages/client/src/schemas/database-field/interfaces/phone.ts +++ b/packages/client/src/schemas/database-field/interfaces/phone.ts @@ -17,7 +17,7 @@ export const phone: FieldOptions = { // title, 'x-component': 'Input', 'x-decorator': 'FormItem', - "x-validator": 'phone', + 'x-validator': 'phone', 'x-designable-bar': 'Input.DesignableBar', }, }, diff --git a/packages/client/src/schemas/database-field/interfaces/select.ts b/packages/client/src/schemas/database-field/interfaces/select.ts index 3c2a640e6..811f40ea7 100644 --- a/packages/client/src/schemas/database-field/interfaces/select.ts +++ b/packages/client/src/schemas/database-field/interfaces/select.ts @@ -34,13 +34,17 @@ export const select: FieldOptions = { { label: '包含', value: 'in', - schema: { 'x-component': 'Select', 'x-component-props': { mode: 'tags' } }, + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, }, { label: '不包含', value: 'notIn', schema: { - 'x-component': 'Select', 'x-component-props': { mode: 'tags' }, + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, }, }, { label: '非空', value: '$notNull', noValue: true }, diff --git a/packages/client/src/schemas/database-field/interfaces/subTable.ts b/packages/client/src/schemas/database-field/interfaces/subTable.ts index 89bb0371e..5d583be7a 100644 --- a/packages/client/src/schemas/database-field/interfaces/subTable.ts +++ b/packages/client/src/schemas/database-field/interfaces/subTable.ts @@ -33,7 +33,7 @@ export const subTable: FieldOptions = { }, properties: { ...defaultProps, - 'children': { + children: { type: 'array', title: '子表格字段', 'x-decorator': 'FormItem', diff --git a/packages/client/src/schemas/database-field/style.less b/packages/client/src/schemas/database-field/style.less index 0bc961721..56b8b3c30 100644 --- a/packages/client/src/schemas/database-field/style.less +++ b/packages/client/src/schemas/database-field/style.less @@ -50,4 +50,4 @@ right: 16px; top: 12px; } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/date-picker/index.tsx b/packages/client/src/schemas/date-picker/index.tsx index b81f144c0..3c1f60522 100644 --- a/packages/client/src/schemas/date-picker/index.tsx +++ b/packages/client/src/schemas/date-picker/index.tsx @@ -1,66 +1,72 @@ -import moment from 'moment' -import { connect, mapProps, mapReadPretty, useField, useFieldSchema } from '@formily/react' -import { DatePicker as AntdDatePicker } from 'antd' +import moment from 'moment'; +import { + connect, + mapProps, + mapReadPretty, + useField, + useFieldSchema, +} from '@formily/react'; +import { DatePicker as AntdDatePicker } from 'antd'; import { DatePickerProps as AntdDatePickerProps, RangePickerProps, -} from 'antd/lib/date-picker' -import { Display } from '../display' -import { formatMomentValue, momentable } from '@formily/antd/esm/__builtins__' +} from 'antd/lib/date-picker'; +import { Display } from '../display'; +import { formatMomentValue, momentable } from '@formily/antd/esm/__builtins__'; type DatePickerProps = Exclude< PickerProps, 'value' | 'onChange' > & { - value: string - onChange: (value: string | string[]) => void -} + value: string; + onChange: (value: string | string[]) => void; +}; type ComposedDatePicker = React.FC & { - RangePicker?: React.FC -} + RangePicker?: React.FC; +}; const mapDateFormat = function () { const getDefaultFormat = (props: DatePickerProps) => { if (props['picker'] === 'month') { - return 'YYYY-MM' + return 'YYYY-MM'; } else if (props['picker'] === 'quarter') { - return 'YYYY-\\QQ' + return 'YYYY-\\QQ'; } else if (props['picker'] === 'year') { - return 'YYYY' + return 'YYYY'; } else if (props['picker'] === 'week') { - return 'YYYY-wo' + return 'YYYY-wo'; } - return props['showTime'] ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD' - } + return props['showTime'] ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'; + }; return (props: any) => { const field = useField(); const fieldSchema = useFieldSchema(); - const format = props['format'] || getDefaultFormat(props) - const onChange = props.onChange + const format = props['format'] || getDefaultFormat(props); + const onChange = props.onChange; return { ...props, format: format, value: momentable(props.value, format === 'YYYY-wo' ? 'YYYY-w' : format), onChange: (value: moment.Moment | moment.Moment[]) => { if (onChange) { - onChange(formatMomentValue(value, format)) + onChange(formatMomentValue(value, format)); } }, - } - } -} + }; + }; +}; export const DatePicker: ComposedDatePicker = connect( AntdDatePicker, mapProps(mapDateFormat()), - mapReadPretty(Display.DatePicker) -) + mapReadPretty(Display.DatePicker), +); DatePicker.RangePicker = connect( AntdDatePicker.RangePicker, mapProps(mapDateFormat()), - mapReadPretty(Display.DateRangePicker) -) + mapReadPretty(Display.DateRangePicker), +); -export default DatePicker +export default DatePicker; diff --git a/packages/client/src/schemas/drag-and-drop/index.tsx b/packages/client/src/schemas/drag-and-drop/index.tsx index 61e446699..ff64ff5b4 100644 --- a/packages/client/src/schemas/drag-and-drop/index.tsx +++ b/packages/client/src/schemas/drag-and-drop/index.tsx @@ -1,16 +1,13 @@ - import React from 'react'; import { observer, useFieldSchema } from '@formily/react'; -import { - DragDropManagerProvider, -} from './../../components/drag-and-drop'; +import { DragDropManagerProvider } from './../../components/drag-and-drop'; export const DragAndDrop = observer((props) => { const schema = useFieldSchema(); - console.log('DragAndDrop') + console.log('DragAndDrop'); return (
{props.children}
- ) + ); }); diff --git a/packages/client/src/schemas/filter/FilterItem.tsx b/packages/client/src/schemas/filter/FilterItem.tsx index 730a48f9a..ad51c79d6 100644 --- a/packages/client/src/schemas/filter/FilterItem.tsx +++ b/packages/client/src/schemas/filter/FilterItem.tsx @@ -171,7 +171,9 @@ export const FilterItem = (props) => { [], ); - const columnEnum: any = [...columns.values()].map((column) => column.toJSON()); + const columnEnum: any = [...columns.values()].map((column) => + column.toJSON(), + ); return ( diff --git a/packages/client/src/schemas/form-item/style.less b/packages/client/src/schemas/form-item/style.less index 6f4b86ea9..1ab14c705 100644 --- a/packages/client/src/schemas/form-item/style.less +++ b/packages/client/src/schemas/form-item/style.less @@ -40,4 +40,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/form/style.less b/packages/client/src/schemas/form/style.less index 105993089..922fcb354 100644 --- a/packages/client/src/schemas/form/style.less +++ b/packages/client/src/schemas/form/style.less @@ -42,4 +42,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/grid/demos/demo1.tsx b/packages/client/src/schemas/grid/demos/demo1.tsx index a9538f174..035af69a4 100644 --- a/packages/client/src/schemas/grid/demos/demo1.tsx +++ b/packages/client/src/schemas/grid/demos/demo1.tsx @@ -14,7 +14,7 @@ const schema: ISchema = { type: 'void', name: uid(), 'x-component': 'Grid', - "x-component-props": { + 'x-component-props': { addNewComponent: 'AddNew.CardItem', }, properties: { @@ -186,7 +186,5 @@ const schema: ISchema = { }; export default () => { - return ( - - ); + return ; }; diff --git a/packages/client/src/schemas/grid/style.less b/packages/client/src/schemas/grid/style.less index c06c31368..f53df5f81 100644 --- a/packages/client/src/schemas/grid/style.less +++ b/packages/client/src/schemas/grid/style.less @@ -101,7 +101,7 @@ body.dragging { .nb-block-item { position: relative; &.isDragging { - opacity: .3; + opacity: 0.3; } &.isOver::after { content: ''; diff --git a/packages/client/src/schemas/index.tsx b/packages/client/src/schemas/index.tsx index d7ddaa523..4fe42846f 100644 --- a/packages/client/src/schemas/index.tsx +++ b/packages/client/src/schemas/index.tsx @@ -1,10 +1,15 @@ import React from 'react'; -import { ISchema as IFormilySchema, observer, Schema, useField } from '@formily/react'; +import { + ISchema as IFormilySchema, + observer, + Schema, + useField, +} from '@formily/react'; import { extend } from 'umi-request'; import './designable-bar/style.less'; -export type FormilyISchema = IFormilySchema +export type FormilyISchema = IFormilySchema; export interface ISchema extends IFormilySchema { [key: string]: any; diff --git a/packages/client/src/schemas/input-number/style.less b/packages/client/src/schemas/input-number/style.less index 6ba9db9f2..658e000e1 100644 --- a/packages/client/src/schemas/input-number/style.less +++ b/packages/client/src/schemas/input-number/style.less @@ -24,4 +24,4 @@ border-bottom-right-radius: 0; } } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/input/index.tsx b/packages/client/src/schemas/input/index.tsx index 2f8ee22fc..01ca51047 100644 --- a/packages/client/src/schemas/input/index.tsx +++ b/packages/client/src/schemas/input/index.tsx @@ -1,7 +1,14 @@ -import React from 'react' -import { connect, mapProps, mapReadPretty, observer, useField, useFieldSchema } from '@formily/react' -import { Input as AntdInput } from 'antd' -import { InputProps, TextAreaProps } from 'antd/lib/input' +import React from 'react'; +import { + connect, + mapProps, + mapReadPretty, + observer, + useField, + useFieldSchema, +} from '@formily/react'; +import { Input as AntdInput } from 'antd'; +import { InputProps, TextAreaProps } from 'antd/lib/input'; import { Display } from '../display'; import { DesignableBar } from './DesignableBar'; import { Dropdown, Menu, Space } from 'antd'; @@ -17,10 +24,10 @@ import { isGridRowOrCol } from '../grid'; import { DragHandle } from '../../components/Sortable'; type ComposedInput = React.FC & { - TextArea?: React.FC - URL?: React.FC - DesignableBar?: React.FC -} + TextArea?: React.FC; + URL?: React.FC; + DesignableBar?: React.FC; +}; export const Input: ComposedInput = connect( AntdInput, @@ -36,12 +43,12 @@ export const Input: ComposedInput = connect( )} ), - } + }; }), - mapReadPretty(Display.Input) -) + mapReadPretty(Display.Input), +); -Input.TextArea = connect(AntdInput.TextArea, mapReadPretty(Display.TextArea)) -Input.URL = connect(AntdInput, mapReadPretty(Display.URL)) +Input.TextArea = connect(AntdInput.TextArea, mapReadPretty(Display.TextArea)); +Input.URL = connect(AntdInput, mapReadPretty(Display.URL)); -export default Input +export default Input; diff --git a/packages/client/src/schemas/kanban/CardDesignableBar.tsx b/packages/client/src/schemas/kanban/CardDesignableBar.tsx index d50030ec2..47b916f26 100644 --- a/packages/client/src/schemas/kanban/CardDesignableBar.tsx +++ b/packages/client/src/schemas/kanban/CardDesignableBar.tsx @@ -11,12 +11,7 @@ import { useForm, RecursionField, } from '@formily/react'; -import { - useSchemaPath, - SchemaField, - useDesignable, - ISchema, -} from '../'; +import { useSchemaPath, SchemaField, useDesignable, ISchema } from '../'; import get from 'lodash/get'; import { Button, Dropdown, Menu, Space } from 'antd'; import { MenuOutlined, DragOutlined } from '@ant-design/icons'; diff --git a/packages/client/src/schemas/kanban/demos/demo1.tsx b/packages/client/src/schemas/kanban/demos/demo1.tsx index 91f8e7343..741e40051 100644 --- a/packages/client/src/schemas/kanban/demos/demo1.tsx +++ b/packages/client/src/schemas/kanban/demos/demo1.tsx @@ -208,5 +208,11 @@ const schema: ISchema = { }; export default () => { - return ; + return ( + + ); }; diff --git a/packages/client/src/schemas/kanban/index.tsx b/packages/client/src/schemas/kanban/index.tsx index 22f9d4583..d0ab89863 100644 --- a/packages/client/src/schemas/kanban/index.tsx +++ b/packages/client/src/schemas/kanban/index.tsx @@ -29,7 +29,11 @@ import { useState } from 'react'; import { CSS } from '@dnd-kit/utilities'; import cls from 'classnames'; import './style.less'; -import { CollectionProvider, useCollectionContext, useResourceRequest } from '../../constate'; +import { + CollectionProvider, + useCollectionContext, + useResourceRequest, +} from '../../constate'; import { Resource } from '../../resource'; import { useRequest } from 'ahooks'; import { Action } from '../action'; diff --git a/packages/client/src/schemas/kanban/style.less b/packages/client/src/schemas/kanban/style.less index d3de60804..f00e3504b 100644 --- a/packages/client/src/schemas/kanban/style.less +++ b/packages/client/src/schemas/kanban/style.less @@ -26,7 +26,7 @@ .nb-kanban-item { margin-bottom: 12px; &.isDragging { - opacity: .2; + opacity: 0.2; } .ant-formily-item-control-content-component { @@ -51,7 +51,8 @@ .nb-kanban-drag-overlay { .isDragging { opacity: 1 !important; - box-shadow: 0 1px 2px -2px rgb(0 0 0 / 16%), 0 3px 6px 0 rgb(0 0 0 / 12%), 0 5px 12px 4px rgb(0 0 0 / 9%); + box-shadow: 0 1px 2px -2px rgb(0 0 0 / 16%), 0 3px 6px 0 rgb(0 0 0 / 12%), + 0 5px 12px 4px rgb(0 0 0 / 9%); } .designable-bar { display: none !important; @@ -61,7 +62,7 @@ .nb-kanban-item { position: relative; // padding: 0; - + .nb-block-item { &:last-child { .ant-formily-item { @@ -69,10 +70,11 @@ } } } - .nb-grid-block, .ant-formily-item { + .nb-grid-block, + .ant-formily-item { margin-bottom: 12px !important; } - + .ant-formily-layout { &:hover { > .designable-bar { @@ -132,7 +134,8 @@ .ant-upload-list-picture-card .ant-upload-list-item-name { display: none; } - .ant-upload-list-picture .ant-upload-list-item, .ant-upload-list-picture-card .ant-upload-list-item { + .ant-upload-list-picture .ant-upload-list-item, + .ant-upload-list-picture-card .ant-upload-list-item { padding: 1px; } } diff --git a/packages/client/src/schemas/markdown/style.less b/packages/client/src/schemas/markdown/style.less index 64bd143c9..9913de019 100644 --- a/packages/client/src/schemas/markdown/style.less +++ b/packages/client/src/schemas/markdown/style.less @@ -1,3 +1,3 @@ .nb-markdown > *:last-child { margin-bottom: 0; -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/menu/demos/demo1.tsx b/packages/client/src/schemas/menu/demos/demo1.tsx index 574569ae2..3ccfe77c6 100644 --- a/packages/client/src/schemas/menu/demos/demo1.tsx +++ b/packages/client/src/schemas/menu/demos/demo1.tsx @@ -29,7 +29,7 @@ const schema: ISchema = { title: `链接`, 'x-designable-bar': 'Menu.DesignableBar', 'x-component': 'Menu.Link', - "x-component-props": { + 'x-component-props': { to: '/abc/def', }, }, diff --git a/packages/client/src/schemas/menu/demos/demo4.tsx b/packages/client/src/schemas/menu/demos/demo4.tsx index 300243489..b95399de9 100644 --- a/packages/client/src/schemas/menu/demos/demo4.tsx +++ b/packages/client/src/schemas/menu/demos/demo4.tsx @@ -86,11 +86,7 @@ export default () => { return ( - + diff --git a/packages/client/src/schemas/menu/style.less b/packages/client/src/schemas/menu/style.less index 8349ad481..6c56085ae 100644 --- a/packages/client/src/schemas/menu/style.less +++ b/packages/client/src/schemas/menu/style.less @@ -126,7 +126,7 @@ height: 100%; width: 100%; background-color: #f18b62; - opacity: .5; + opacity: 0.5; } .droppable:not(.isDragging).isOver::after { content: ''; @@ -151,7 +151,7 @@ height: 100%; width: 100%; background-color: #f18b62; - opacity: .3; + opacity: 0.3; } .droppable:not(.isDragging).isOver::after { content: ''; diff --git a/packages/client/src/schemas/page/index.tsx b/packages/client/src/schemas/page/index.tsx index 985364c9d..51170463c 100644 --- a/packages/client/src/schemas/page/index.tsx +++ b/packages/client/src/schemas/page/index.tsx @@ -13,9 +13,7 @@ export const Page = observer((props) => { {documentTitle} -
- {children} -
+
{children}
); }); diff --git a/packages/client/src/schemas/password/PasswordStrength.tsx b/packages/client/src/schemas/password/PasswordStrength.tsx index 269e703f1..343bae7ba 100755 --- a/packages/client/src/schemas/password/PasswordStrength.tsx +++ b/packages/client/src/schemas/password/PasswordStrength.tsx @@ -1,164 +1,164 @@ -import React, { Fragment } from 'react' -import { isFn } from '@formily/shared' +import React, { Fragment } from 'react'; +import { isFn } from '@formily/shared'; type ReactRenderPropsChildren = | React.ReactNode - | ((props: T) => React.ReactElement) + | ((props: T) => React.ReactElement); interface IPasswordStrengthProps { - value?: React.ReactText - children?: ReactRenderPropsChildren + value?: React.ReactText; + children?: ReactRenderPropsChildren; } const isNum = function (c) { - return c >= 48 && c <= 57 -} + return c >= 48 && c <= 57; +}; const isLower = function (c) { - return c >= 97 && c <= 122 -} + return c >= 97 && c <= 122; +}; const isUpper = function (c) { - return c >= 65 && c <= 90 -} + return c >= 65 && c <= 90; +}; const isSymbol = function (c) { - return !(isLower(c) || isUpper(c) || isNum(c)) -} + return !(isLower(c) || isUpper(c) || isNum(c)); +}; const isLetter = function (c) { - return isLower(c) || isUpper(c) -} + return isLower(c) || isUpper(c); +}; const getStrength = (val) => { - if (!val) return 0 - let num = 0 - let lower = 0 - let upper = 0 - let symbol = 0 - let MNS = 0 - let rep = 0 - let repC = 0 - let consecutive = 0 - let sequential = 0 - const len = () => num + lower + upper + symbol + if (!val) return 0; + let num = 0; + let lower = 0; + let upper = 0; + let symbol = 0; + let MNS = 0; + let rep = 0; + let repC = 0; + let consecutive = 0; + let sequential = 0; + const len = () => num + lower + upper + symbol; const callme = () => { - let re = num > 0 ? 1 : 0 - re += lower > 0 ? 1 : 0 - re += upper > 0 ? 1 : 0 - re += symbol > 0 ? 1 : 0 + let re = num > 0 ? 1 : 0; + re += lower > 0 ? 1 : 0; + re += upper > 0 ? 1 : 0; + re += symbol > 0 ? 1 : 0; if (re > 2 && len() >= 8) { - return re + 1 + return re + 1; } else { - return 0 + return 0; } - } + }; for (let i = 0; i < val.length; i++) { - const c = val.charCodeAt(i) + const c = val.charCodeAt(i); if (isNum(c)) { - num++ + num++; if (i !== 0 && i !== val.length - 1) { - MNS++ + MNS++; } if (i > 0 && isNum(val.charCodeAt(i - 1))) { - consecutive++ + consecutive++; } } else if (isLower(c)) { - lower++ + lower++; if (i > 0 && isLower(val.charCodeAt(i - 1))) { - consecutive++ + consecutive++; } } else if (isUpper(c)) { - upper++ + upper++; if (i > 0 && isUpper(val.charCodeAt(i - 1))) { - consecutive++ + consecutive++; } } else { - symbol++ + symbol++; if (i !== 0 && i !== val.length - 1) { - MNS++ + MNS++; } } - let exists = false + let exists = false; for (let j = 0; j < val.length; j++) { if (val[i] === val[j] && i !== j) { - exists = true - repC += Math.abs(val.length / (j - i)) + exists = true; + repC += Math.abs(val.length / (j - i)); } } if (exists) { - rep++ - const unique = val.length - rep - repC = unique ? Math.ceil(repC / unique) : Math.ceil(repC) + rep++; + const unique = val.length - rep; + repC = unique ? Math.ceil(repC / unique) : Math.ceil(repC); } if (i > 1) { - const last1 = val.charCodeAt(i - 1) - const last2 = val.charCodeAt(i - 2) + const last1 = val.charCodeAt(i - 1); + const last2 = val.charCodeAt(i - 2); if (isLetter(c)) { if (isLetter(last1) && isLetter(last2)) { - const v = val.toLowerCase() - const vi = v.charCodeAt(i) - const vi1 = v.charCodeAt(i - 1) - const vi2 = v.charCodeAt(i - 2) + const v = val.toLowerCase(); + const vi = v.charCodeAt(i); + const vi1 = v.charCodeAt(i - 1); + const vi2 = v.charCodeAt(i - 2); if (vi - vi1 === vi1 - vi2 && Math.abs(vi - vi1) === 1) { - sequential++ + sequential++; } } } else if (isNum(c)) { if (isNum(last1) && isNum(last2)) { if (c - last1 === last1 - last2 && Math.abs(c - last1) === 1) { - sequential++ + sequential++; } } } else { if (isSymbol(last1) && isSymbol(last2)) { if (c - last1 === last1 - last2 && Math.abs(c - last1) === 1) { - sequential++ + sequential++; } } } } } - let sum = 0 - const length = len() - sum += 4 * length + let sum = 0; + const length = len(); + sum += 4 * length; if (lower > 0) { - sum += 2 * (length - lower) + sum += 2 * (length - lower); } if (upper > 0) { - sum += 2 * (length - upper) + sum += 2 * (length - upper); } if (num !== length) { - sum += 4 * num + sum += 4 * num; } - sum += 6 * symbol - sum += 2 * MNS - sum += 2 * callme() + sum += 6 * symbol; + sum += 2 * MNS; + sum += 2 * callme(); if (length === lower + upper) { - sum -= length + sum -= length; } if (length === num) { - sum -= num + sum -= num; } - sum -= repC - sum -= 2 * consecutive - sum -= 3 * sequential - sum = sum < 0 ? 0 : sum - sum = sum > 100 ? 100 : sum + sum -= repC; + sum -= 2 * consecutive; + sum -= 3 * sequential; + sum = sum < 0 ? 0 : sum; + sum = sum > 100 ? 100 : sum; if (sum >= 80) { - return 100 + return 100; } else if (sum >= 60) { - return 80 + return 80; } else if (sum >= 40) { - return 60 + return 60; } else if (sum >= 20) { - return 40 + return 40; } else { - return 20 + return 20; } -} +}; export const PasswordStrength: React.FC = (props) => { if (isFn(props.children)) { - return props.children(getStrength(String(props.value))) + return props.children(getStrength(String(props.value))); } else { - return {props.children} + return {props.children}; } -} +}; diff --git a/packages/client/src/schemas/radio/index.tsx b/packages/client/src/schemas/radio/index.tsx index 87e39f8d3..54533d0ea 100644 --- a/packages/client/src/schemas/radio/index.tsx +++ b/packages/client/src/schemas/radio/index.tsx @@ -1,23 +1,29 @@ import React from 'react'; -import { connect, mapProps, mapReadPretty, SchemaOptionsContext, useField } from '@formily/react' -import { Radio as AntdRadio, Tag } from 'antd' -import { RadioProps, RadioGroupProps } from 'antd/lib/radio' +import { + connect, + mapProps, + mapReadPretty, + SchemaOptionsContext, + useField, +} from '@formily/react'; +import { Radio as AntdRadio, Tag } from 'antd'; +import { RadioProps, RadioGroupProps } from 'antd/lib/radio'; import { isValid } from '@formily/shared'; type ComposedRadio = React.FC & { - Group?: React.FC - __ANT_RADIO?: boolean -} + Group?: React.FC; + __ANT_RADIO?: boolean; +}; export const Radio: ComposedRadio = connect( AntdRadio, mapProps({ value: 'checked', onInput: 'onChange', - }) -) + }), +); -Radio.__ANT_RADIO = true +Radio.__ANT_RADIO = true; Radio.Group = connect( AntdRadio.Group, @@ -31,17 +37,19 @@ Radio.Group = connect( const { options = [], value } = props; const field = useField(); const dataSource = field.dataSource || []; - console.log({dataSource}) + console.log({ dataSource }); return (
{dataSource .filter((option) => option.value === value) .map((option, key) => ( - {option.label} + + {option.label} + ))}
); }), -) +); -export default Radio +export default Radio; diff --git a/packages/client/src/schemas/select/index.tsx b/packages/client/src/schemas/select/index.tsx index 989e86018..380e1389d 100644 --- a/packages/client/src/schemas/select/index.tsx +++ b/packages/client/src/schemas/select/index.tsx @@ -25,7 +25,11 @@ import { BlockSchemaContext, VisibleContext } from '../../context'; import { SchemaRenderer } from '../../components/schema-renderer'; import { uid } from '@formily/shared'; import { CollectionFieldContext } from '../table'; -import { CollectionProvider, useCollectionContext, useResourceRequest } from '../../constate'; +import { + CollectionProvider, + useCollectionContext, + useResourceRequest, +} from '../../constate'; import { Resource } from '../../resource'; import { useRequest } from 'ahooks'; import constate from 'constate'; @@ -267,11 +271,13 @@ Select.useSelect = () => { export const useSelectedRowKeys = () => { const { selectedRows } = useContext(SelectedRowsContext); - const [selectedRowKeys, setSelectedRowKeys] = useState(selectedRows.map((row) => row.id)); + const [selectedRowKeys, setSelectedRowKeys] = useState( + selectedRows.map((row) => row.id), + ); useEffect(() => { setSelectedRowKeys(selectedRows.map((row) => row.id)); }, [selectedRows]); - console.log('useSelectedRowKeys', selectedRows) + console.log('useSelectedRowKeys', selectedRows); return { selectedRowKeys, setSelectedRowKeys }; }; @@ -322,7 +328,7 @@ Select.Drawer = connect( }; } const [selectedRows, setSelectedRows] = useState(toArr(field.value)); - console.log('useSelectedRowKeys.toArr', toArr(field.value)) + console.log('useSelectedRowKeys.toArr', toArr(field.value)); useEffect(() => { setSelectedRows(toArr(field.value)); }, [field.value]); diff --git a/packages/client/src/schemas/table/index.tsx b/packages/client/src/schemas/table/index.tsx index c366daa4c..5b5e69e58 100644 --- a/packages/client/src/schemas/table/index.tsx +++ b/packages/client/src/schemas/table/index.tsx @@ -11,11 +11,7 @@ import { cloneDeep, cloneDeepWith, findIndex, forIn, range, set } from 'lodash'; import React, { Fragment, useEffect, useState } from 'react'; import { useContext } from 'react'; import { createContext } from 'react'; -import { - useDesignable, - createCollectionField, - ISchema, -} from '..'; +import { useDesignable, createCollectionField, ISchema } from '..'; import { uid, merge } from '@formily/shared'; import useRequest from '@ahooksjs/use-request'; import { BaseResult } from '@ahooksjs/use-request/lib/types'; @@ -279,7 +275,7 @@ const useTableIndex = () => { const { pagination, props } = useTable(); const ctx = useContext(TableRowContext); const { pageSize, page = 1 } = pagination; - console.log({pageSize, page}, ctx.index); + console.log({ pageSize, page }, ctx.index); return ctx.index + (page - 1) * pageSize; if (pagination && !props.clientSidePagination) { const { pageSize, page = 1 } = pagination; diff --git a/packages/client/src/schemas/table/style.less b/packages/client/src/schemas/table/style.less index a18a70ff8..e7fe0753f 100644 --- a/packages/client/src/schemas/table/style.less +++ b/packages/client/src/schemas/table/style.less @@ -186,13 +186,14 @@ td.nb-table-operation { .ant-formily-item-feedback-layout-popover { margin-bottom: 0; } - .ant-formily-item-control .ant-formily-item-control-content .ant-formily-item-control-content-component { + .ant-formily-item-control + .ant-formily-item-control-content + .ant-formily-item-control-content-component { min-height: inherit; line-height: inherit; } } - .ant-dropdown-menu-item { &:hover { .designable-bar { @@ -238,7 +239,6 @@ td.nb-table-operation { justify-content: space-between; } - .field-interface-attachment { margin-top: -13px; margin-bottom: -13px; @@ -253,7 +253,7 @@ td.nb-table-operation { height: 100%; width: 100%; background-color: #f18b62; - opacity: .3; + opacity: 0.3; } &.droppable:not(.isDragging).isOver::after { content: ''; @@ -278,7 +278,7 @@ td.nb-table-operation { height: 100%; width: 100%; background-color: #f18b62; - opacity: .3; + opacity: 0.3; } .droppable:not(.isDragging).isOver::after { content: ''; @@ -289,4 +289,4 @@ td.nb-table-operation { width: 2px; background-color: #f18b62; } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/tabs/style.less b/packages/client/src/schemas/tabs/style.less index 6c43e61cc..1dfa68a82 100644 --- a/packages/client/src/schemas/tabs/style.less +++ b/packages/client/src/schemas/tabs/style.less @@ -39,7 +39,6 @@ } } - .ant-tabs-tab:first-child { .nb-tab-pane { .designable-bar { @@ -91,7 +90,7 @@ height: 100%; left: -16px; background-color: #f18b62; - opacity: .3; + opacity: 0.3; } .droppable:not(.isDragging).isOver::after { content: ''; @@ -102,4 +101,4 @@ width: 2px; background-color: #f18b62; } -} \ No newline at end of file +} diff --git a/packages/client/src/schemas/time-picker/index.tsx b/packages/client/src/schemas/time-picker/index.tsx index 3dcd0f6a4..00b252d29 100644 --- a/packages/client/src/schemas/time-picker/index.tsx +++ b/packages/client/src/schemas/time-picker/index.tsx @@ -1,44 +1,44 @@ -import moment from 'moment' -import { connect, mapProps, mapReadPretty } from '@formily/react' -import { TimePicker as AntdTimePicker } from 'antd' +import moment from 'moment'; +import { connect, mapProps, mapReadPretty } from '@formily/react'; +import { TimePicker as AntdTimePicker } from 'antd'; import { TimePickerProps as AntdTimePickerProps, TimeRangePickerProps, -} from 'antd/lib/time-picker' -import { Display } from '../display' -import { formatMomentValue, momentable } from '@formily/antd/esm/__builtins__' +} from 'antd/lib/time-picker'; +import { Display } from '../display'; +import { formatMomentValue, momentable } from '@formily/antd/esm/__builtins__'; type ComposedTimePicker = React.FC & { - RangePicker?: React.FC -} + RangePicker?: React.FC; +}; const mapTimeFormat = function () { return (props: any) => { - const format = props['format'] || 'HH:mm:ss' - const onChange = props.onChange + const format = props['format'] || 'HH:mm:ss'; + const onChange = props.onChange; return { ...props, format, value: momentable(props.value, format), onChange: (value: moment.Moment | moment.Moment[]) => { if (onChange) { - onChange(formatMomentValue(value, format)) + onChange(formatMomentValue(value, format)); } }, - } - } -} + }; + }; +}; export const TimePicker: ComposedTimePicker = connect( AntdTimePicker, mapProps(mapTimeFormat()), - mapReadPretty(Display.TimePicker) -) + mapReadPretty(Display.TimePicker), +); TimePicker.RangePicker = connect( AntdTimePicker.RangePicker, mapProps(mapTimeFormat()), - mapReadPretty(Display.TimeRangePicker) -) + mapReadPretty(Display.TimeRangePicker), +); -export default TimePicker +export default TimePicker; diff --git a/packages/client/src/schemas/tree-select/index.tsx b/packages/client/src/schemas/tree-select/index.tsx index 71c74a2db..0afbb83d5 100644 --- a/packages/client/src/schemas/tree-select/index.tsx +++ b/packages/client/src/schemas/tree-select/index.tsx @@ -1,8 +1,8 @@ -import React from 'react' -import { connect, mapReadPretty, mapProps } from '@formily/react' -import { TreeSelect as AntdTreeSelect } from 'antd' -import { Display } from '../display' -import { LoadingOutlined } from '@ant-design/icons' +import React from 'react'; +import { connect, mapReadPretty, mapProps } from '@formily/react'; +import { TreeSelect as AntdTreeSelect } from 'antd'; +import { Display } from '../display'; +import { LoadingOutlined } from '@ant-design/icons'; export const TreeSelect = connect( AntdTreeSelect, mapProps( @@ -18,10 +18,10 @@ export const TreeSelect = connect( ) : ( props.suffixIcon ), - } - } + }; + }, ), - mapReadPretty(Display.TreeSelect) -) + mapReadPretty(Display.TreeSelect), +); -export default TreeSelect +export default TreeSelect; diff --git a/packages/client/src/schemas/upload/demos/demo2.tsx b/packages/client/src/schemas/upload/demos/demo2.tsx index fade5091c..3684442e0 100644 --- a/packages/client/src/schemas/upload/demos/demo2.tsx +++ b/packages/client/src/schemas/upload/demos/demo2.tsx @@ -49,7 +49,7 @@ const schema = { value: '{{$self.value}}', }, }, - } + }, ], }, read: { diff --git a/packages/client/src/schemas/upload/placeholder.ts b/packages/client/src/schemas/upload/placeholder.ts index 14c2d5941..7be1a1ee2 100755 --- a/packages/client/src/schemas/upload/placeholder.ts +++ b/packages/client/src/schemas/upload/placeholder.ts @@ -1,62 +1,62 @@ export const UPLOAD_PLACEHOLDER = [ { ext: /\.docx?$/i, - icon: '//img.alicdn.com/tfs/TB1n8jfr1uSBuNjy1XcXXcYjFXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1n8jfr1uSBuNjy1XcXXcYjFXa-200-200.png', }, { ext: /\.pptx?$/i, - icon: '//img.alicdn.com/tfs/TB1ItgWr_tYBeNjy1XdXXXXyVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1ItgWr_tYBeNjy1XdXXXXyVXa-200-200.png', }, { ext: /\.jpe?g$/i, - icon: '//img.alicdn.com/tfs/TB1wrT5r9BYBeNjy0FeXXbnmFXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1wrT5r9BYBeNjy0FeXXbnmFXa-200-200.png', }, { ext: /\.pdf$/i, - icon: '//img.alicdn.com/tfs/TB1GwD8r9BYBeNjy0FeXXbnmFXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1GwD8r9BYBeNjy0FeXXbnmFXa-200-200.png', }, { ext: /\.png$/i, - icon: '//img.alicdn.com/tfs/TB1BHT5r9BYBeNjy0FeXXbnmFXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1BHT5r9BYBeNjy0FeXXbnmFXa-200-200.png', }, { ext: /\.eps$/i, - icon: '//img.alicdn.com/tfs/TB1G_iGrVOWBuNjy0FiXXXFxVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1G_iGrVOWBuNjy0FiXXXFxVXa-200-200.png', }, { ext: /\.ai$/i, - icon: '//img.alicdn.com/tfs/TB1B2cVr_tYBeNjy1XdXXXXyVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1B2cVr_tYBeNjy1XdXXXXyVXa-200-200.png', }, { ext: /\.gif$/i, - icon: '//img.alicdn.com/tfs/TB1DTiGrVOWBuNjy0FiXXXFxVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1DTiGrVOWBuNjy0FiXXXFxVXa-200-200.png', }, { ext: /\.svg$/i, - icon: '//img.alicdn.com/tfs/TB1uUm9rY9YBuNjy0FgXXcxcXXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1uUm9rY9YBuNjy0FgXXcxcXXa-200-200.png', }, { ext: /\.xlsx?$/i, - icon: '//img.alicdn.com/tfs/TB1any1r1OSBuNjy0FdXXbDnVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1any1r1OSBuNjy0FdXXbDnVXa-200-200.png', }, { ext: /\.psd?$/i, - icon: '//img.alicdn.com/tfs/TB1_nu1r1OSBuNjy0FdXXbDnVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1_nu1r1OSBuNjy0FdXXbDnVXa-200-200.png', }, { ext: /\.(wav|aif|aiff|au|mp1|mp2|mp3|ra|rm|ram|mid|rmi)$/i, - icon: '//img.alicdn.com/tfs/TB1jPvwr49YBuNjy0FfXXXIsVXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1jPvwr49YBuNjy0FfXXXIsVXa-200-200.png', }, { ext: /\.(avi|wmv|mpg|mpeg|vob|dat|3gp|mp4|mkv|rm|rmvb|mov|flv)$/i, - icon: '//img.alicdn.com/tfs/TB1FrT5r9BYBeNjy0FeXXbnmFXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB1FrT5r9BYBeNjy0FeXXbnmFXa-200-200.png', }, { ext: /\.(zip|rar|arj|z|gz|iso|jar|ace|tar|uue|dmg|pkg|lzh|cab)$/i, - icon: '//img.alicdn.com/tfs/TB10jmfr29TBuNjy0FcXXbeiFXa-200-200.png' + icon: '//img.alicdn.com/tfs/TB10jmfr29TBuNjy0FcXXbeiFXa-200-200.png', }, { ext: /\.[^.]+$/i, - icon: '//img.alicdn.com/tfs/TB10.R4r3mTBuNjy1XbXXaMrVXa-200-200.png' - } -] \ No newline at end of file + icon: '//img.alicdn.com/tfs/TB10.R4r3mTBuNjy1XbXXaMrVXa-200-200.png', + }, +]; diff --git a/packages/client/src/schemas/upload/style.less b/packages/client/src/schemas/upload/style.less index e6b5cc974..04e6c92f8 100644 --- a/packages/client/src/schemas/upload/style.less +++ b/packages/client/src/schemas/upload/style.less @@ -28,7 +28,9 @@ font-size: 13px; color: #636363; } - .ant-upload-list-picture-card .ant-upload-list-item:hover .ant-upload-list-item-info::before { + .ant-upload-list-picture-card + .ant-upload-list-item:hover + .ant-upload-list-item-info::before { display: none; } .ant-upload-list-picture-card .ant-upload-list-item-progress { @@ -36,7 +38,7 @@ pointer-events: none; } .ant-btn { - background: rgba(0,0,0,.5); + background: rgba(0, 0, 0, 0.5); // .anticon { // color: #1890ff; // } @@ -55,7 +57,8 @@ .ant-upload-list-picture-card .ant-upload-list-item-name { display: none; } - .ant-upload-list-picture .ant-upload-list-item, .ant-upload-list-picture-card .ant-upload-list-item { + .ant-upload-list-picture .ant-upload-list-item, + .ant-upload-list-picture-card .ant-upload-list-item { padding: 1px; } -} \ No newline at end of file +} diff --git a/packages/plugin-users/src/__tests__/fields.test.ts b/packages/plugin-users/src/__tests__/fields.test.ts index 330784c21..59950fee8 100644 --- a/packages/plugin-users/src/__tests__/fields.test.ts +++ b/packages/plugin-users/src/__tests__/fields.test.ts @@ -96,7 +96,7 @@ describe('user fields', () => { target: 'users', foreignKey: 'updated_by_id', }, - ] + ], }); await db.sync(); @@ -106,14 +106,19 @@ describe('user fields', () => { // 用户1 操作 const user1 = await User.create(); - const postWithUser = await Post.create({}, { context: { state: { currentUser: user1 } } }); + const postWithUser = await Post.create( + {}, + { context: { state: { currentUser: user1 } } }, + ); - const post = await Post.findOne(Post.parseApiJson({ - filter: { - id: postWithUser.id, - }, - fields: ['createdBy1', 'updatedBy1', 'createdBy2', 'updatedBy2'], - })); + const post = await Post.findOne( + Post.parseApiJson({ + filter: { + id: postWithUser.id, + }, + fields: ['createdBy1', 'updatedBy1', 'createdBy2', 'updatedBy2'], + }), + ); expect(post.createdBy1.id).toBe(user1.id); expect(post.updatedBy1.id).toBe(user1.id); @@ -122,14 +127,19 @@ describe('user fields', () => { // 换个用户 const user2 = await User.create(); - await postWithUser.update({ title: 'title1' }, { context: { state: { currentUser: user2 } } }); + await postWithUser.update( + { title: 'title1' }, + { context: { state: { currentUser: user2 } } }, + ); - const post2 = await Post.findOne(Post.parseApiJson({ - filter: { - id: postWithUser.id, - }, - fields: ['createdBy1', 'updatedBy1', 'createdBy2', 'updatedBy2'], - })); + const post2 = await Post.findOne( + Post.parseApiJson({ + filter: { + id: postWithUser.id, + }, + fields: ['createdBy1', 'updatedBy1', 'createdBy2', 'updatedBy2'], + }), + ); expect(post2.createdBy1.id).toBe(user1.id); expect(post2.createdBy2.id).toBe(user1.id); @@ -151,13 +161,19 @@ describe('user fields', () => { expect(postWithoutUser.created_by_id).toBe(null); expect(postWithoutUser.updated_by_id).toBe(null); // @ts-ignore - const postWithUser = await Post.create({}, { context: { state: { currentUser } } }); + const postWithUser = await Post.create( + {}, + { context: { state: { currentUser } } }, + ); expect(postWithUser.created_by_id).toBe(currentUser.id); expect(postWithUser.updated_by_id).toBe(currentUser.id); // 更新数据 createdBy 数据不变 // @ts-ignore - await postWithUser.update({ title: 'title1' }, { context: { state: { currentUser: user2 } } }); + await postWithUser.update( + { title: 'title1' }, + { context: { state: { currentUser: user2 } } }, + ); expect(postWithUser.created_by_id).toBe(currentUser.id); expect(postWithUser.updated_by_id).toBe(user2.id); }); @@ -170,11 +186,14 @@ describe('user fields', () => { const user2 = await User.create(); const Post = db.getModel('posts'); - const post = await Post.create({ - created_by_id: user1.id, - updated_by_id: user1.id, - // @ts-ignore - }, { context: { state: { currentUser: user2 } } }); + const post = await Post.create( + { + created_by_id: user1.id, + updated_by_id: user1.id, + // @ts-ignore + }, + { context: { state: { currentUser: user2 } } }, + ); expect(post.created_by_id).toBe(user1.id); expect(post.updated_by_id).toBe(user1.id); }); @@ -189,9 +208,9 @@ describe('user fields', () => { fields: [ { type: 'string', - name: 'title' - } - ] + name: 'title', + }, + ], }); await db.sync(); const User = db.getModel('users'); @@ -201,7 +220,10 @@ describe('user fields', () => { const post = await Post.create(); expect(post.updated_by_id).toBe(null); // @ts-ignore - await post.update({ title: 'title' }, { context: { state: { currentUser } } }) + await post.update( + { title: 'title' }, + { context: { state: { currentUser } } }, + ); expect(post.updated_by_id).toBe(currentUser.id); }); @@ -212,9 +234,9 @@ describe('user fields', () => { fields: [ { type: 'string', - name: 'title' - } - ] + name: 'title', + }, + ], }); await db.sync(); const User = db.getModel('users'); @@ -223,15 +245,21 @@ describe('user fields', () => { const Post = db.getModel('posts'); let context = { state: { currentUser: user2 } }; - const post = await Post.create({ - updated_by_id: user1.id, - }, { context }); + const post = await Post.create( + { + updated_by_id: user1.id, + }, + { context }, + ); expect(post.updated_by_id).toBe(user1.id); await post.update({ title: 'title' }, { context }); expect(post.updated_by_id).toBe(user2.id); - await post.update({ title: 'title', updated_by_id: user1.id }, { context }); + await post.update( + { title: 'title', updated_by_id: user1.id }, + { context }, + ); expect(post.updated_by_id).toBe(user1.id); // 不同用户更新数据 @@ -252,9 +280,9 @@ describe('user fields', () => { fields: [ { type: 'string', - name: 'title' - } - ] + name: 'title', + }, + ], }); await db.sync(); const User = db.getModel('users'); @@ -263,18 +291,20 @@ describe('user fields', () => { const Post = db.getModel('posts'); let context = { state: { currentUser: user2 } }; - await Post.bulkCreate([ - { title: 'title1' }, - { title: 'title2' }, - ]); + await Post.bulkCreate([{ title: 'title1' }, { title: 'title2' }]); - await Post.update({ title: 'title3' }, { - where: { title: 'title1' }, - context - }); + await Post.update( + { title: 'title3' }, + { + where: { title: 'title1' }, + context, + }, + ); const posts = await Post.findAll({ order: [['id', 'ASC']] }); - expect(posts.map(({ title, updated_by_id }) => ({ title, updated_by_id }))).toEqual([ + expect( + posts.map(({ title, updated_by_id }) => ({ title, updated_by_id })), + ).toEqual([ { title: 'title3', updated_by_id: 2 }, { title: 'title2', updated_by_id: null }, ]); diff --git a/packages/plugin-users/src/actions/users.ts b/packages/plugin-users/src/actions/users.ts index ed24cb411..3b1219f44 100644 --- a/packages/plugin-users/src/actions/users.ts +++ b/packages/plugin-users/src/actions/users.ts @@ -62,7 +62,9 @@ export async function register(ctx: Context, next: Next) { } export async function lostpassword(ctx: Context, next: Next) { - const { values: { email } } = ctx.action.params; + const { + values: { email }, + } = ctx.action.params; if (!email) { ctx.throw(401, '请填写邮箱账号'); } @@ -82,7 +84,9 @@ export async function lostpassword(ctx: Context, next: Next) { } export async function resetpassword(ctx: Context, next: Next) { - const { values: { email, password, reset_token } } = ctx.action.params; + const { + values: { email, password, reset_token }, + } = ctx.action.params; const User = ctx.db.getModel('users'); const user = await User.findOne({ where: { diff --git a/packages/plugin-users/src/fields/CreatedBy.ts b/packages/plugin-users/src/fields/CreatedBy.ts index b2b65d4d6..571c28b2e 100644 --- a/packages/plugin-users/src/fields/CreatedBy.ts +++ b/packages/plugin-users/src/fields/CreatedBy.ts @@ -2,13 +2,12 @@ import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database'; import { setUserValue } from './utils'; export interface CreatedByOptions extends Omit { - type: 'createdBy' | 'createdby' + type: 'createdBy' | 'createdby'; } export default class CreatedBy extends BELONGSTO { - static beforeBulkCreateHook(this: CreatedBy, models, { context }) { - models.forEach(model => { + models.forEach((model) => { setUserValue.call(this, model, { context }); }); } @@ -22,7 +21,10 @@ export default class CreatedBy extends BELONGSTO { const { sourceTable, database } = context; const name = sourceTable.getName(); database.on(`${name}.beforeCreate`, setUserValue.bind(this)); - database.on(`${name}.beforeBulkCreate`, CreatedBy.beforeBulkCreateHook.bind(this)); + database.on( + `${name}.beforeBulkCreate`, + CreatedBy.beforeBulkCreateHook.bind(this), + ); } public getDataType(): Function { diff --git a/packages/plugin-users/src/fields/UpdatedBy.ts b/packages/plugin-users/src/fields/UpdatedBy.ts index 5f4627d24..e09d62ed0 100644 --- a/packages/plugin-users/src/fields/UpdatedBy.ts +++ b/packages/plugin-users/src/fields/UpdatedBy.ts @@ -2,18 +2,20 @@ import { BelongsToOptions, BELONGSTO, FieldContext } from '@nocobase/database'; import { setUserValue } from './utils'; export interface UpdatedByOptions extends Omit { - type: 'updatedBy' | 'updatedby' + type: 'updatedBy' | 'updatedby'; } export default class UpdatedBy extends BELONGSTO { - static beforeBulkCreateHook(this: UpdatedBy, models, { context }) { - models.forEach(model => { + models.forEach((model) => { setUserValue.call(this, model, { context }); }); } - static beforeBulkUpdateHook(this: UpdatedBy, { attributes, fields, context }) { + static beforeBulkUpdateHook( + this: UpdatedBy, + { attributes, fields, context }, + ) { if (!context) { return; } @@ -22,7 +24,9 @@ export default class UpdatedBy extends BELONGSTO { return; } fields.push(this.options.foreignKey); - attributes[this.options.foreignKey] = currentUser.get(this.options.targetKey); + attributes[this.options.foreignKey] = currentUser.get( + this.options.targetKey, + ); } constructor({ type, ...options }: UpdatedByOptions, context: FieldContext) { @@ -36,9 +40,15 @@ export default class UpdatedBy extends BELONGSTO { const { sourceTable, database } = context; const name = sourceTable.getName(); database.on(`${name}.beforeCreate`, setUserValue.bind(this)); - database.on(`${name}.beforeBulkCreate`, UpdatedBy.beforeBulkCreateHook.bind(this)); + database.on( + `${name}.beforeBulkCreate`, + UpdatedBy.beforeBulkCreateHook.bind(this), + ); database.on(`${name}.beforeUpdate`, setUserValue.bind(this)); - database.on(`${name}.beforeBulkUpdate`, UpdatedBy.beforeBulkUpdateHook.bind(this)); + database.on( + `${name}.beforeBulkUpdate`, + UpdatedBy.beforeBulkUpdateHook.bind(this), + ); } public getDataType(): Function { diff --git a/packages/plugin-users/src/fields/utils.ts b/packages/plugin-users/src/fields/utils.ts index 8d04c7cbc..d7271bdcd 100644 --- a/packages/plugin-users/src/fields/utils.ts +++ b/packages/plugin-users/src/fields/utils.ts @@ -1,4 +1,4 @@ -import { CreatedBy, UpdatedBy } from "."; +import { CreatedBy, UpdatedBy } from '.'; export function setUserValue(this: CreatedBy | UpdatedBy, model, { context }) { const { foreignKey } = this.options; @@ -8,7 +8,7 @@ export function setUserValue(this: CreatedBy | UpdatedBy, model, { context }) { return; } const changed = model.changed(); - if (Array.isArray(changed) && changed.find(key => key === foreignKey)) { + if (Array.isArray(changed) && changed.find((key) => key === foreignKey)) { return; } }