diff --git a/es/components/filterPanel/web.js b/es/components/filterPanel/web.js index d9ba2851..4e4588d7 100644 --- a/es/components/filterPanel/web.js +++ b/es/components/filterPanel/web.js @@ -62,7 +62,7 @@ export default function Render(props) { tfColumns.forEach((column, index) => { const { colSpan } = column; const colSpan2 = getSpan(colSpan || 1, mergedColumn); - const item = ( + const item = ( ); if (index === 0) { @@ -120,7 +120,7 @@ export default function Render(props) { } } else { - if (width === 'xs') { + if (width === 'xs' && !!firstItem) { items.push(firstItem); } } @@ -137,7 +137,7 @@ export default function Render(props) { const buttonItemLayout = formLayout === 'horizontal' ? { wrapperCol: { span: 18, offset: 6 } } : null; - items.push( + items.push( @@ -162,7 +162,9 @@ export default function Render(props) { setOpen(!open); }}> - {open ? t('common::shrink') : t('common::expand')} + {open + ? t('common::shrink') + : t('common::expand')} {open ? : } diff --git a/es/components/list/buttonGroup/web.d.ts b/es/components/list/buttonGroup/web.d.ts index afdaa28e..20d96e10 100644 --- a/es/components/list/buttonGroup/web.d.ts +++ b/es/components/list/buttonGroup/web.d.ts @@ -1,8 +1,7 @@ import React from 'react'; import { EntityDict } from 'oak-domain/lib/types/Entity'; -import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; -import { ListButtonProps } from '../../../types/AbstractComponent'; +import { ListButtonProps, ED } from '../../../types/AbstractComponent'; import { WebComponentProps } from '../../../types/Page'; -export default function Render(props: WebComponentProps): React.JSX.Element; +}, {}>): React.JSX.Element | null; diff --git a/es/components/list/buttonGroup/web.js b/es/components/list/buttonGroup/web.js index 6593a0b0..de8fbccb 100644 --- a/es/components/list/buttonGroup/web.js +++ b/es/components/list/buttonGroup/web.js @@ -4,13 +4,15 @@ import { FloatButton } from 'antd'; import { BarsOutlined, } from '@ant-design/icons'; export default function Render(props) { const { methods, data } = props; - const { t } = methods; const { items } = data; - if (items && items.length === 1) { + if (!items || items.length === 0) { + return null; + } + if (items?.length === 1) { const item = items[0]; return ( item.onClick()}/>); } - return (}> - {items && items.map((ele) => ( ele.onClick()}/>))} + return (}> + {items?.map((ele, index) => ( ele.onClick()}/>))} ); } diff --git a/es/components/list/buttonGroup/web.pc.d.ts b/es/components/list/buttonGroup/web.pc.d.ts index 813977d6..416bf753 100644 --- a/es/components/list/buttonGroup/web.pc.d.ts +++ b/es/components/list/buttonGroup/web.pc.d.ts @@ -1,8 +1,7 @@ import React from 'react'; import { EntityDict } from 'oak-domain/lib/types/Entity'; import { WebComponentProps } from '../../../types/Page'; -import { ListButtonProps } from '../../../types/AbstractComponent'; -import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; -export default function Render(props: WebComponentProps): React.JSX.Element; +}, {}>): React.JSX.Element | null; diff --git a/es/components/list/buttonGroup/web.pc.js b/es/components/list/buttonGroup/web.pc.js index af5b264d..e716e489 100644 --- a/es/components/list/buttonGroup/web.pc.js +++ b/es/components/list/buttonGroup/web.pc.js @@ -1,12 +1,15 @@ import React from 'react'; import { Space, Button } from 'antd'; export default function Render(props) { - const { methods, data: oakData } = props; - const { items } = oakData; - // 为了i18更新时能够重新渲染 + const { methods, data } = props; + const { items } = data; + if (!items || items.length === 0) { + return null; + } return ( - {items.filter((ele) => ele.show).map((ele) => ())} + {items?.filter((ele) => ele.show) + .map((ele, index) => ())} ); } diff --git a/es/components/list/index.js b/es/components/list/index.js index 7b3cb435..02640dff 100644 --- a/es/components/list/index.js +++ b/es/components/list/index.js @@ -5,7 +5,7 @@ export default OakComponent({ properties: { entity: '', extraActions: [], - onAction: (() => undefined), + onAction: (() => { }), disabledOp: false, attributes: [], data: [], diff --git a/es/features/contextMenuFactory.d.ts b/es/features/contextMenuFactory.d.ts index c644195d..95021e27 100644 --- a/es/features/contextMenuFactory.d.ts +++ b/es/features/contextMenuFactory.d.ts @@ -9,7 +9,7 @@ import { RelationAuth } from './relationAuth'; interface IMenu { name: string; entity: T; - action: ED[T]['Action']; + action: ED[T]['Action'] | ED[T]['Action'][]; paths: string[]; } export declare class ContextMenuFactory, FrontCxt extends SyncContext, AD extends CommonAspectDict & Record>> extends Feature { diff --git a/es/features/contextMenuFactory.js b/es/features/contextMenuFactory.js index 9bb0200e..62e032cb 100644 --- a/es/features/contextMenuFactory.js +++ b/es/features/contextMenuFactory.js @@ -28,9 +28,9 @@ export class ContextMenuFactory extends Feature { } return; } - const pathhh = path.split('.'); + const pathArr = path.split('.'); const judgeIter = (e2, idx) => { - const attr = pathhh[idx]; + const attr = pathArr[idx]; const rel = judgeRelation(schema, e2, attr); let e3 = e2; if (typeof rel === 'string') { @@ -43,14 +43,14 @@ export class ContextMenuFactory extends Feature { assert(rel instanceof Array); e3 = rel[0]; } - if (idx === pathhh.length - 1) { + if (idx === pathArr.length - 1) { if (e3 === 'user') { // 用user连接说明一定满足 return true; } if (e3 === entity) { const filter = {}; - const paths2 = pathhh.slice(0, pathhh.length - 1); + const paths2 = pathArr.slice(0, pathArr.length - 1); if (rel === 2) { set(filter, paths2.concat('entity'), entity); set(filter, paths2.concat('entityId'), entityId); @@ -87,6 +87,28 @@ export class ContextMenuFactory extends Feature { return true; } // relationAuth和其它的checker现在分开判断 + let result = false; + if (action instanceof Array) { + for (let i = 0; i < action.length; i++) { + // action有一个满足就行了 + const checkResult = this.relationAuth.checkRelation(destEntity, { + action: action[i], + data: undefined, + filter, + }) && + this.cache.checkOperation(destEntity, action[i], undefined, filter, [ + 'logical', + 'relation', + 'logicalRelation', + 'row', + ]); + if (checkResult) { + result = checkResult; + break; + } + } + return result; + } return (this.relationAuth.checkRelation(destEntity, { action, data: undefined, diff --git a/es/utils/usefulFn.js b/es/utils/usefulFn.js index 17e09ccb..42bd3f6c 100644 --- a/es/utils/usefulFn.js +++ b/es/utils/usefulFn.js @@ -73,7 +73,9 @@ export function resolvePath(dataSchema, entity, path) { idx++; } catch (err) { - console.log(`存在非schema属性${path}`); + if (process.env.NODE_ENV === 'development') { + console.warn(`存在非「${_entity}」schema属性: ${path}`); + } return { entity: 'notExist', attr: path, diff --git a/lib/features/contextMenuFactory.d.ts b/lib/features/contextMenuFactory.d.ts index c644195d..95021e27 100644 --- a/lib/features/contextMenuFactory.d.ts +++ b/lib/features/contextMenuFactory.d.ts @@ -9,7 +9,7 @@ import { RelationAuth } from './relationAuth'; interface IMenu { name: string; entity: T; - action: ED[T]['Action']; + action: ED[T]['Action'] | ED[T]['Action'][]; paths: string[]; } export declare class ContextMenuFactory, FrontCxt extends SyncContext, AD extends CommonAspectDict & Record>> extends Feature { diff --git a/lib/features/contextMenuFactory.js b/lib/features/contextMenuFactory.js index 108e9f2c..b0a2dc9f 100644 --- a/lib/features/contextMenuFactory.js +++ b/lib/features/contextMenuFactory.js @@ -31,9 +31,9 @@ class ContextMenuFactory extends Feature_1.Feature { } return; } - const pathhh = path.split('.'); + const pathArr = path.split('.'); const judgeIter = (e2, idx) => { - const attr = pathhh[idx]; + const attr = pathArr[idx]; const rel = (0, relation_1.judgeRelation)(schema, e2, attr); let e3 = e2; if (typeof rel === 'string') { @@ -46,14 +46,14 @@ class ContextMenuFactory extends Feature_1.Feature { (0, assert_1.assert)(rel instanceof Array); e3 = rel[0]; } - if (idx === pathhh.length - 1) { + if (idx === pathArr.length - 1) { if (e3 === 'user') { // 用user连接说明一定满足 return true; } if (e3 === entity) { const filter = {}; - const paths2 = pathhh.slice(0, pathhh.length - 1); + const paths2 = pathArr.slice(0, pathArr.length - 1); if (rel === 2) { (0, lodash_1.set)(filter, paths2.concat('entity'), entity); (0, lodash_1.set)(filter, paths2.concat('entityId'), entityId); @@ -90,6 +90,28 @@ class ContextMenuFactory extends Feature_1.Feature { return true; } // relationAuth和其它的checker现在分开判断 + let result = false; + if (action instanceof Array) { + for (let i = 0; i < action.length; i++) { + // action有一个满足就行了 + const checkResult = this.relationAuth.checkRelation(destEntity, { + action: action[i], + data: undefined, + filter, + }) && + this.cache.checkOperation(destEntity, action[i], undefined, filter, [ + 'logical', + 'relation', + 'logicalRelation', + 'row', + ]); + if (checkResult) { + result = checkResult; + break; + } + } + return result; + } return (this.relationAuth.checkRelation(destEntity, { action, data: undefined, diff --git a/lib/utils/usefulFn.js b/lib/utils/usefulFn.js index 18a2df6c..f4424278 100644 --- a/lib/utils/usefulFn.js +++ b/lib/utils/usefulFn.js @@ -78,7 +78,9 @@ function resolvePath(dataSchema, entity, path) { idx++; } catch (err) { - console.log(`存在非schema属性${path}`); + if (process.env.NODE_ENV === 'development') { + console.warn(`存在非「${_entity}」schema属性: ${path}`); + } return { entity: 'notExist', attr: path, diff --git a/src/components/filterPanel/web.tsx b/src/components/filterPanel/web.tsx index 7295093a..ee0e39ec 100644 --- a/src/components/filterPanel/web.tsx +++ b/src/components/filterPanel/web.tsx @@ -111,7 +111,7 @@ export default function Render( ); const count = filters2?.length || 0; //查询条件个数 - const items: any = []; + const items: React.JSX.Element[] = []; let rowSum = 0; let rowSum2 = 0; let rows2 = 1; @@ -122,7 +122,10 @@ export default function Render( const colSpan2 = getSpan(colSpan || 1, mergedColumn); const item = ( - + } entity={entity} @@ -183,7 +186,7 @@ export default function Render( _gridColumn = gridColumn * (mergedColumn - rowSum); } } else { - if (width === 'xs') { + if (width === 'xs' && !!firstItem) { items.push(firstItem); } } @@ -204,7 +207,7 @@ export default function Render( ? { wrapperCol: { span: 18, offset: 6 } } : null; items.push( - + @@ -241,7 +244,9 @@ export default function Render( }} > - {open ? t('common::shrink') : t('common::expand')} + {open + ? t('common::shrink') + : t('common::expand')} {open ? : } diff --git a/src/components/list/buttonGroup/web.pc.tsx b/src/components/list/buttonGroup/web.pc.tsx index d50535cf..1672f8e1 100644 --- a/src/components/list/buttonGroup/web.pc.tsx +++ b/src/components/list/buttonGroup/web.pc.tsx @@ -2,36 +2,36 @@ import React from 'react'; import { Space, Button } from 'antd'; import { EntityDict } from 'oak-domain/lib/types/Entity'; import { WebComponentProps } from '../../../types/Page'; -import { ListButtonProps } from '../../../types/AbstractComponent'; -import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; - -type ED = EntityDict & BaseEntityDict; - +import { ListButtonProps, ED } from '../../../types/AbstractComponent'; export default function Render( props: WebComponentProps< - EntityDict & BaseEntityDict, + ED, keyof EntityDict, false, { items: ListButtonProps[]; }, - { - } + {} > ) { - const { methods, data: oakData } = props; - const { - items - } = oakData; - // 为了i18更新时能够重新渲染 + const { methods, data } = props; + const { items } = data; + if (!items || items.length === 0) { + return null; + } return ( - {items.filter((ele) => ele.show).map((ele) => ( - - ))} + {items?.filter((ele) => ele.show) + .map((ele, index) => ( + + ))} ); } diff --git a/src/components/list/buttonGroup/web.tsx b/src/components/list/buttonGroup/web.tsx index 10baa664..2ccb75be 100644 --- a/src/components/list/buttonGroup/web.tsx +++ b/src/components/list/buttonGroup/web.tsx @@ -3,33 +3,30 @@ import React from 'react'; import { FloatButton } from 'antd'; import { EntityDict } from 'oak-domain/lib/types/Entity'; -import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; -import { ListButtonProps } from '../../../types/AbstractComponent'; +import { ListButtonProps, ED } from '../../../types/AbstractComponent'; import { WebComponentProps } from '../../../types/Page'; import { BarsOutlined, } from '@ant-design/icons'; -type ED = EntityDict & BaseEntityDict; export default function Render( props: WebComponentProps< - EntityDict & BaseEntityDict, + ED, keyof EntityDict, false, { items: ListButtonProps[]; }, - { - } + {} > ) { const { methods, data } = props; - const { t } = methods; - const { - items - } = data; - if (items && items.length === 1) { + const { items } = data; + if (!items || items.length === 0) { + return null; + } + if (items?.length === 1) { const item = items[0]; return ( item.onClick()} /> - ) + ); } return ( } > - {items && items.map((ele) => ( + {items?.map((ele, index) => ( ele.onClick()} diff --git a/src/components/list/index.ts b/src/components/list/index.ts index 73f80116..8ec4ce23 100644 --- a/src/components/list/index.ts +++ b/src/components/list/index.ts @@ -1,15 +1,17 @@ -import { CardDef, ED, OakAbsAttrDef, onActionFnDef, OakExtraActionProps, ListButtonProps, OakAbsAttrJudgeDef } from '../../types/AbstractComponent'; +import { ED, OakAbsAttrDef, onActionFnDef, OakExtraActionProps, OakAbsAttrJudgeDef } from '../../types/AbstractComponent'; import { analyzeAttrMobileForCard, translateAttributes } from '../../utils/usefulFn'; import { assert } from 'oak-domain/lib/utils/assert'; -import { TableProps, PaginationProps } from 'antd'; +import { TableProps } from 'antd'; import { RowWithActions, ReactComponentProps } from '../../types/Page'; export default OakComponent({ isList: false, properties: { entity: '' as keyof ED, - extraActions: [] as OakExtraActionProps[] | ((row: any) => OakExtraActionProps[]), - onAction: (() => undefined) as Function, + extraActions: [] as + | OakExtraActionProps[] + | ((row: RowWithActions) => OakExtraActionProps[]), + onAction: (() => {}) as Function, disabledOp: false, attributes: [] as OakAbsAttrDef[], data: [] as RowWithActions[], @@ -40,7 +42,7 @@ export default OakComponent({ return {}; }, data: { - converter: (data: any) => [], + converter: (data: RowWithActions[]) => [], judgeAttributes: [] as OakAbsAttrJudgeDef[], }, listeners: { @@ -62,9 +64,13 @@ export default OakComponent({ schema, entity, ttt, - attributes!, + attributes! + ); + const judgeAttributes = translateAttributes( + schema, + entity, + attributes! ); - const judgeAttributes = translateAttributes(schema, entity, attributes!); this.setState({ converter, schema, @@ -92,7 +98,9 @@ export default OakComponent({ false, { entity: T2; - extraActions: OakExtraActionProps[] | ((row: ED2[T2]['Schema']) => OakExtraActionProps[]); + extraActions: + | OakExtraActionProps[] + | ((row: ED2[T2]['Schema']) => OakExtraActionProps[]); onAction: onActionFnDef; disabledOp: boolean; attributes: OakAbsAttrDef[]; diff --git a/src/features/contextMenuFactory.ts b/src/features/contextMenuFactory.ts index 0eb9d8f6..f76b38b4 100644 --- a/src/features/contextMenuFactory.ts +++ b/src/features/contextMenuFactory.ts @@ -13,7 +13,7 @@ import { RelationAuth } from './relationAuth'; interface IMenu { name: string; entity: T; - action: ED[T]['Action']; + action: ED[T]['Action'] | ED[T]['Action'][]; paths: string[]; } @@ -60,13 +60,13 @@ export class ContextMenuFactory< } return; } - const pathhh = path.split('.'); + const pathArr = path.split('.'); const judgeIter = ( e2: keyof ED, idx: number ): true | undefined | ED[keyof ED]['Selection']['filter'] => { - const attr = pathhh[idx]; + const attr = pathArr[idx]; const rel = judgeRelation(schema, e2, attr); let e3 = e2; if (typeof rel === 'string') { @@ -77,7 +77,7 @@ export class ContextMenuFactory< assert(rel instanceof Array); e3 = rel[0]; } - if (idx === pathhh.length - 1) { + if (idx === pathArr.length - 1) { if (e3 === 'user') { // 用user连接说明一定满足 return true; @@ -85,7 +85,7 @@ export class ContextMenuFactory< if (e3 === entity) { const filter: ED[keyof ED]['Selection']['filter'] = {}; - const paths2 = pathhh.slice(0, pathhh.length - 1); + const paths2 = pathArr.slice(0, pathArr.length - 1); if (rel === 2) { set(filter, paths2.concat('entity'), entity); set( @@ -140,6 +140,42 @@ export class ContextMenuFactory< return true; } // relationAuth和其它的checker现在分开判断 + let result = false; + if (action instanceof Array) { + for (let i = 0; i < action.length; i++) { + // action有一个满足就行了 + const checkResult = + this.relationAuth.checkRelation( + destEntity, + { + action: action[i], + data: undefined as any, + filter, + } as Omit< + ED[keyof ED]['Operation'], + 'id' + > + ) && + this.cache.checkOperation( + destEntity, + action[i], + undefined, + filter, + [ + 'logical', + 'relation', + 'logicalRelation', + 'row', + ] + ); + + if (checkResult) { + result = checkResult; + break; + } + } + return result; + } return ( this.relationAuth.checkRelation(destEntity, { action, diff --git a/src/utils/usefulFn.ts b/src/utils/usefulFn.ts index 5871b49f..4d88f6d1 100644 --- a/src/utils/usefulFn.ts +++ b/src/utils/usefulFn.ts @@ -111,7 +111,9 @@ export function resolvePath( } idx++; } catch (err) { - console.log(`存在非schema属性${path}`); + if (process.env.NODE_ENV === 'development') { + console.warn(`存在非「${_entity as string}」schema属性: ${path}`); + } return { entity: 'notExist', attr: path,