diff --git a/src/components/detail/index.ts b/src/components/detail/index.ts index c621313a..0204d72c 100644 --- a/src/components/detail/index.ts +++ b/src/components/detail/index.ts @@ -39,10 +39,8 @@ export default OakComponent({ const { data, attributes } = this.props; const { transformer } = this.state; const renderData = transformer(data!); - const colorDict = this.features.style.getColorDict(); return { renderData, - colorDict, }; }, listeners: { @@ -98,6 +96,9 @@ export default OakComponent({ urls: urlList, // 需要预览的图片http链接列表 }); }, + getColor(attr: string, value: any) { + return this.features.style.getColor(this.props.entity!, attr, value); + } }, }) as ( props: ReactComponentProps< diff --git a/src/components/detail/web.pc.tsx b/src/components/detail/web.pc.tsx index fe137b25..239dc0e8 100644 --- a/src/components/detail/web.pc.tsx +++ b/src/components/detail/web.pc.tsx @@ -1,7 +1,6 @@ import React, { useState, useEffect } from 'react'; import { Tag, Descriptions, Image, Card, Breakpoint, Space } from 'antd'; import { WebComponentProps } from '../../types/Page'; -import { ColorDict } from 'oak-domain/lib/types/Style'; import styles from './web.module.less'; import { @@ -55,20 +54,20 @@ export default function Render( layout: 'horizontal' | 'vertical'; data: any; handleClick?: (id: string, action: string) => void; - colorDict: ColorDict; column: number | Record; renderData: AttrRender[]; judgeAttributes: OakAbsAttrJudgeDef[]; }, - {} + { + getColor: (attr: string, value: any) => `#${string}` | undefined; + } > ) { const { methods, data: oakData } = props; - const { t } = methods; + const { t, getColor } = methods; const { entity, title, - colorDict, bordered, column, renderData, @@ -105,12 +104,7 @@ export default function Render( } const stateValue = get(data, ele.path); - const color = - (colorDict && - (colorDict[ele.entity]?.[ele.attr]?.[ - stateValue - ] as string)) || - 'default'; + const color = getColor(ele.attr, stateValue) || 'default'; return ( void; - colorDict: ColorDict; column: ColumnMapType; renderData: AttrRender[]; judgeAttributes: OakAbsAttrJudgeDef[]; }, - {} + { + getColor: (attr: string, value: any) => `#${string}` | undefined; + } > ) { const { methods, data: oakData } = props; diff --git a/src/components/list/index.ts b/src/components/list/index.ts index ad9c12e5..4ea30025 100644 --- a/src/components/list/index.ts +++ b/src/components/list/index.ts @@ -56,7 +56,6 @@ export default OakComponent({ // 因为部分i18json数据请求较慢,会导致converter,columnDef解析出错 const { attributes, entity, data } = this.props; const schema = this.features.cache.getSchema(); - const colorDict = this.features.style.getColorDict(); // assert(!!data, 'data不能为空'); assert(!!entity, 'list属性entity不能为空'); // assert(attributes?.length, 'attributes不能为空'); @@ -75,7 +74,6 @@ export default OakComponent({ this.setState({ converter, schema, - colorDict, judgeAttributes, }); }, @@ -91,6 +89,9 @@ export default OakComponent({ cascadeAction, }); }, + getColor(attr: string, value: any) { + return this.features.style.getColor(this.props.entity!, attr, value); + } }, }) as ( props: ReactComponentProps< diff --git a/src/components/list/web.pc.tsx b/src/components/list/web.pc.tsx index 9f8dab3d..2e90098b 100644 --- a/src/components/list/web.pc.tsx +++ b/src/components/list/web.pc.tsx @@ -4,7 +4,7 @@ import type { ColumnsType, ColumnType, ColumnGroupType } from 'antd/es/table'; import { assert } from 'oak-domain/lib/utils/assert'; import { get } from 'oak-domain/lib/utils/lodash'; -import { ColorDict } from 'oak-domain/lib/types/Style'; +import { StyleDict } from 'oak-domain/lib/types/Style'; import { StorageSchema } from 'oak-domain/lib/types/Storage'; import { DataType } from 'oak-domain/lib/types/schema/DataTypes'; import { OakAbsAttrDef, onActionFnDef, CascadeActionProps, OakAbsDerivedAttrDef, OakExtraActionProps, OakAbsAttrJudgeDef, ED } from '../../types/AbstractComponent'; @@ -32,7 +32,6 @@ export default function Render( attributes: OakAbsAttrDef[]; data: any[]; disabledOp: boolean; - colorDict: ColorDict; tablePagination?: TableProps['pagination']; onAction?: onActionFnDef; rowSelection?: TableProps['rowSelection']; @@ -41,18 +40,19 @@ export default function Render( judgeAttributes: OakAbsAttrJudgeDef[]; size?: 'large' | 'middle' | 'small'; }, - {} + { + getColor: (attr: string, value: any) => `#${string}` | undefined; + } > ) { const { methods, data: oakData } = props; - const { t } = methods; + const { t, getColor } = methods; const { loading, entity, schema, extraActions, data, - colorDict, disabledOp = false, tablePagination, onAction, @@ -133,11 +133,7 @@ export default function Render( if ([null, undefined, ''].includes(stateValue)) { return <>; } - const color = - colorDict && - (colorDict[ele.entity]?.[ele.attr]?.[ - stateValue - ] as string); + const color = getColor(ele.attr, stateValue); if (type === 'enum' && !color) { console.warn( color, diff --git a/src/debugStore/index.ts b/src/debugStore/index.ts index fe5cd7e1..5ecb1a60 100644 --- a/src/debugStore/index.ts +++ b/src/debugStore/index.ts @@ -2,7 +2,7 @@ import { scheduleJob } from 'node-schedule'; import { LOCAL_STORAGE_KEYS } from '../constant/constant'; import { DebugStore } from './DebugStore'; import { - Checker, Trigger, StorageSchema, EntityDict, ActionDictOfEntityDict, Watcher, BBWatcher, WBWatcher, Routine, Timer, AuthDeduceRelationMap, FreeTimer, FreeRoutine, OperationResult + Checker, Trigger, StorageSchema, EntityDict, ActionDefDict, Watcher, BBWatcher, WBWatcher, Routine, Timer, AuthDeduceRelationMap, FreeTimer, FreeRoutine, OperationResult } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; @@ -214,7 +214,7 @@ export function createDebugStore; }, - actionDict: ActionDictOfEntityDict, + actionDict: ActionDefDict, authDeduceRelationMap: AuthDeduceRelationMap, localStorage: LocalStorage, selectFreeEntities?: (keyof ED)[], diff --git a/src/features/index.ts b/src/features/index.ts index 48181a23..08842e1d 100644 --- a/src/features/index.ts +++ b/src/features/index.ts @@ -1,6 +1,6 @@ import { Aspect, AspectWrapper, AttrUpdateMatrix, AuthDeduceRelationMap, Checker, EntityDict } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; -import { ColorDict } from 'oak-domain/lib/types/Style'; +import { StyleDict } from 'oak-domain/lib/types/Style'; import { CommonAspectDict } from 'oak-common-aspect'; import { Cache } from './cache'; @@ -34,7 +34,7 @@ export function initializeStep2< frontendContextBuilder: () => (store: CacheStore) => FrontCxt, checkers: Array>, authDeduceRelationMap: AuthDeduceRelationMap, - colorDict: ColorDict, + styleDict: StyleDict, getFullDataFn: () => any, getSubscribePointFn: () => Promise<{ url: string; @@ -55,7 +55,7 @@ export function initializeStep2< const runningTree = new RunningTree>(cache, storageSchema, relationAuth); const geo = new Geo(aspectWrapper); const port = new Port>(aspectWrapper); - const style = new Style(colorDict); + const style = new Style(styleDict); const locales = new Locales(cache, localStorage, environment, 'zh-CN', makeBridgeUrlFn); // 临时性代码,应由上层传入 const contextMenuFactory = new ContextMenuFactory>(cache, relationAuth); const subscriber = new SubScriber(cache, message, getSubscribePointFn); diff --git a/src/features/style.ts b/src/features/style.ts index 9a15c2be..f79b2904 100644 --- a/src/features/style.ts +++ b/src/features/style.ts @@ -1,16 +1,26 @@ -import { ColorDict } from 'oak-domain/lib/types/Style'; +import { StyleDict } from 'oak-domain/lib/types/Style'; import { EntityDict } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { Feature } from '../types/Feature'; export class Style extends Feature { - colorDict: ColorDict; - constructor(colorDict: ColorDict) { + styleDict: StyleDict; + constructor(styleDict: StyleDict) { super(); - this.colorDict = colorDict; + this.styleDict = styleDict; } - getColorDict() { - return this.colorDict; + getStyleDict() { + return this.styleDict; + } + + getActionIcon(entity: T, action: A) { + const icon = this.styleDict[entity]?.icon; + return icon && icon[action] as string; + } + + getColor(entity: T, attr: A, value: V) { + const color = this.styleDict[entity]?.color; + return color && color[attr] && color[attr]![value] as `#${string}`; } }; diff --git a/src/initialize-dev.ts b/src/initialize-dev.ts index a9e4b504..1951f191 100644 --- a/src/initialize-dev.ts +++ b/src/initialize-dev.ts @@ -57,9 +57,11 @@ export function initialize< }, option: InitializeOptions ) { - const { actionDict, authDeduceRelationMap, attrUpdateMatrix, - colorDict, importations, exportations, selectFreeEntities, updateFreeDict, - cacheKeepFreshPeriod, cacheSavedEntities } = option; + const { common, render } = option; + const { actionDefDict, authDeduceRelationMap, attrUpdateMatrix, + importations, exportations, selectFreeEntities, updateFreeDict, + cacheKeepFreshPeriod, cacheSavedEntities } = common; + const { styleDict } = render; let intersected = intersection(Object.keys(commonAspectDict), Object.keys(aspectDict)); if (intersected.length > 0) { throw new Error( @@ -67,7 +69,7 @@ export function initialize< ); } const aspectDict2 = Object.assign({}, aspectDict, commonAspectDict); - const { checkers: intCheckers, triggers: intTriggers, watchers: intWatchers } = makeIntrinsicCTWs(storageSchema, actionDict, attrUpdateMatrix); + const { checkers: intCheckers, triggers: intTriggers, watchers: intWatchers } = makeIntrinsicCTWs(storageSchema, actionDefDict, attrUpdateMatrix); const checkers2 = checkers.concat(intCheckers); const triggers2 = triggers.concat(intTriggers); const watchers2 = watchers.concat(intWatchers); @@ -83,7 +85,7 @@ export function initialize< timers, startRoutines, initialData, - actionDict, + actionDefDict, authDeduceRelationMap, features1.localStorage, selectFreeEntities, @@ -124,7 +126,7 @@ export function initialize< frontendContextBuilder, checkers2, authDeduceRelationMap, - colorDict, + styleDict, () => debugStore.getCurrentData(), async () => ({ url: '', path: '' }), undefined, diff --git a/src/initialize-prod.ts b/src/initialize-prod.ts index fc25e46e..fdfb7c91 100644 --- a/src/initialize-prod.ts +++ b/src/initialize-prod.ts @@ -41,9 +41,11 @@ export function initialize< checkers: Array>, option: InitializeOptions ) { - const { authDeduceRelationMap, actionDict, selectFreeEntities, updateFreeDict, colorDict, cacheKeepFreshPeriod, cacheSavedEntities } = option; + const { common, render } = option; + const { authDeduceRelationMap, actionDefDict, selectFreeEntities, updateFreeDict, cacheKeepFreshPeriod, cacheSavedEntities } = common; + const { styleDict } = render; - const intrinsicCheckers = makeIntrinsicCheckers(storageSchema, actionDict); + const intrinsicCheckers = makeIntrinsicCheckers(storageSchema, actionDefDict); const checkers2 = checkers.concat(intrinsicCheckers); const features1 = initBasicFeaturesStep1(); @@ -67,7 +69,7 @@ export function initialize< frontendContextBuilder, checkers2, authDeduceRelationMap, - colorDict, + styleDict, () => '请查看数据库中的数据', () => connector.getSubscribePoint(), (url, headers) => connector.makeBridgeUrl(url, headers), diff --git a/src/types/Initialize.ts b/src/types/Initialize.ts index 187ad885..668a0bce 100644 --- a/src/types/Initialize.ts +++ b/src/types/Initialize.ts @@ -1,19 +1,9 @@ import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; -import { ActionDictOfEntityDict, CascadeRemoveDefDict, ColorDict, Importation, Exportation, AttrUpdateMatrix } from 'oak-domain/lib/types'; -import { AuthDeduceRelationMap, EntityDict } from 'oak-domain/lib/types/Entity'; +import { EntityDict } from 'oak-domain/lib/types/Entity'; +import { CommonConfiguration, RenderConfiguration } from 'oak-domain/lib/types/Configuration'; export type InitializeOptions> = { - actionDict: ActionDictOfEntityDict; - attrUpdateMatrix?: AttrUpdateMatrix; - authDeduceRelationMap: AuthDeduceRelationMap; - colorDict: ColorDict; - importations?: Importation[]; - exportations?: Exportation[]; - selectFreeEntities?: (keyof ED)[]; - updateFreeDict?: { - [A in keyof ED]?: string[]; - }; - cacheSavedEntities?: (keyof ED)[]; - cacheKeepFreshPeriod?: number; + common: CommonConfiguration, + render: RenderConfiguration; }; diff --git a/src/utils/usefulFn.ts b/src/utils/usefulFn.ts index 8f1f721f..913020db 100644 --- a/src/utils/usefulFn.ts +++ b/src/utils/usefulFn.ts @@ -1,5 +1,5 @@ import { assert } from 'oak-domain/lib/utils/assert'; -import { EntityDict } from 'oak-domain/lib/types'; +import { EntityDict, StyleDict } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { StorageSchema, Attribute } from 'oak-domain/lib/types'; import { judgeRelation } from 'oak-domain/lib/store/relation'; @@ -21,13 +21,11 @@ import { OakAbsNativeAttrUpsertDef, OakAbsAttrJudgeDef, } from '../types/AbstractComponent'; -import { Attributes } from 'oak-domain/lib/types'; import { get } from 'oak-domain/lib/utils/lodash'; import { DataType, DataTypeParams, } from 'oak-domain/lib/types/schema/DataTypes'; -import { ColorDict } from 'oak-domain/lib/types/Style'; import dayjs from 'dayjs'; import { ThousandCont } from 'oak-domain/lib/utils/money'; @@ -260,7 +258,6 @@ export function makeDataTransformer( entity: keyof ED, attrDefs: OakAbsAttrDef[], t: (k: string, params?: object) => string, - colorDict?: ColorDict ): DataTransformer { const transformerFixedPart = attrDefs.map((ele) => { if (typeof ele === 'string') {