5.0修改了初始化和style相关的一些调用方法
This commit is contained in:
parent
99d5731f5a
commit
2b7368fe88
|
|
@ -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 <ED2 extends ED, T2 extends keyof ED2>(
|
||||
props: ReactComponentProps<
|
||||
|
|
|
|||
|
|
@ -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<ED>;
|
||||
column: number | Record<Breakpoint, number>;
|
||||
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 (
|
||||
<Descriptions.Item
|
||||
label={renderLabel}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import { Tag, Space, Image } from 'antd-mobile';
|
||||
import { WebComponentProps } from '../../types/Page';
|
||||
import { ColorDict } from 'oak-domain/lib/types/Style';
|
||||
import styles from './mobile.module.less';
|
||||
import { AttrRender, OakAbsAttrJudgeDef, ED } from '../../types/AbstractComponent';
|
||||
|
||||
|
|
@ -70,12 +69,13 @@ export default function Render(
|
|||
layout: 'horizontal' | 'vertical';
|
||||
data: any;
|
||||
handleClick?: (id: string, action: string) => void;
|
||||
colorDict: ColorDict<ED>;
|
||||
column: ColumnMapType;
|
||||
renderData: AttrRender[];
|
||||
judgeAttributes: OakAbsAttrJudgeDef[];
|
||||
},
|
||||
{}
|
||||
{
|
||||
getColor: (attr: string, value: any) => `#${string}` | undefined;
|
||||
}
|
||||
>
|
||||
) {
|
||||
const { methods, data: oakData } = props;
|
||||
|
|
|
|||
|
|
@ -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 <ED2 extends ED, T2 extends keyof ED2>(
|
||||
props: ReactComponentProps<
|
||||
|
|
|
|||
|
|
@ -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<ED>;
|
||||
tablePagination?: TableProps<any[]>['pagination'];
|
||||
onAction?: onActionFnDef;
|
||||
rowSelection?: TableProps<any[]>['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,
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt ext
|
|||
initialData: {
|
||||
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
||||
},
|
||||
actionDict: ActionDictOfEntityDict<ED>,
|
||||
actionDict: ActionDefDict<ED>,
|
||||
authDeduceRelationMap: AuthDeduceRelationMap<ED>,
|
||||
localStorage: LocalStorage,
|
||||
selectFreeEntities?: (keyof ED)[],
|
||||
|
|
|
|||
|
|
@ -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<ED, FrontCxt>) => FrontCxt,
|
||||
checkers: Array<Checker<ED, keyof ED, FrontCxt | Cxt>>,
|
||||
authDeduceRelationMap: AuthDeduceRelationMap<ED>,
|
||||
colorDict: ColorDict<ED>,
|
||||
styleDict: StyleDict<ED>,
|
||||
getFullDataFn: () => any,
|
||||
getSubscribePointFn: () => Promise<{
|
||||
url: string;
|
||||
|
|
@ -55,7 +55,7 @@ export function initializeStep2<
|
|||
const runningTree = new RunningTree<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>(cache, storageSchema, relationAuth);
|
||||
const geo = new Geo(aspectWrapper);
|
||||
const port = new Port<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>(aspectWrapper);
|
||||
const style = new Style<ED>(colorDict);
|
||||
const style = new Style<ED>(styleDict);
|
||||
const locales = new Locales(cache, localStorage, environment, 'zh-CN', makeBridgeUrlFn); // 临时性代码,应由上层传入
|
||||
const contextMenuFactory = new ContextMenuFactory<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>(cache, relationAuth);
|
||||
const subscriber = new SubScriber(cache, message, getSubscribePointFn);
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict> extends Feature {
|
||||
colorDict: ColorDict<ED>;
|
||||
constructor(colorDict: ColorDict<ED>) {
|
||||
styleDict: StyleDict<ED>;
|
||||
constructor(styleDict: StyleDict<ED>) {
|
||||
super();
|
||||
this.colorDict = colorDict;
|
||||
this.styleDict = styleDict;
|
||||
}
|
||||
|
||||
getColorDict() {
|
||||
return this.colorDict;
|
||||
getStyleDict() {
|
||||
return this.styleDict;
|
||||
}
|
||||
|
||||
getActionIcon<T extends keyof ED, A extends ED[T]['Action']>(entity: T, action: A) {
|
||||
const icon = this.styleDict[entity]?.icon;
|
||||
return icon && icon[action] as string;
|
||||
}
|
||||
|
||||
getColor<T extends keyof ED, A extends keyof ED[T]['OpSchema'], V extends ED[T]['OpSchema'][A]>(entity: T, attr: A, value: V) {
|
||||
const color = this.styleDict[entity]?.color;
|
||||
return color && color[attr] && color[attr]![value] as `#${string}`;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,9 +57,11 @@ export function initialize<
|
|||
},
|
||||
option: InitializeOptions<ED, Cxt>
|
||||
) {
|
||||
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<ED, Cxt, FrontCxt>(storageSchema, actionDict, attrUpdateMatrix);
|
||||
const { checkers: intCheckers, triggers: intTriggers, watchers: intWatchers } = makeIntrinsicCTWs<ED, Cxt, FrontCxt>(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,
|
||||
|
|
|
|||
|
|
@ -41,9 +41,11 @@ export function initialize<
|
|||
checkers: Array<Checker<ED, keyof ED, FrontCxt | Cxt>>,
|
||||
option: InitializeOptions<ED, Cxt>
|
||||
) {
|
||||
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<ED, Cxt, FrontCxt>(storageSchema, actionDict);
|
||||
const intrinsicCheckers = makeIntrinsicCheckers<ED, Cxt, FrontCxt>(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),
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = {
|
||||
actionDict: ActionDictOfEntityDict<ED>;
|
||||
attrUpdateMatrix?: AttrUpdateMatrix<ED>;
|
||||
authDeduceRelationMap: AuthDeduceRelationMap<ED>;
|
||||
colorDict: ColorDict<ED>;
|
||||
importations?: Importation<ED, keyof ED, any, Cxt>[];
|
||||
exportations?: Exportation<ED, keyof ED, any, Cxt>[];
|
||||
selectFreeEntities?: (keyof ED)[];
|
||||
updateFreeDict?: {
|
||||
[A in keyof ED]?: string[];
|
||||
};
|
||||
cacheSavedEntities?: (keyof ED)[];
|
||||
cacheKeepFreshPeriod?: number;
|
||||
common: CommonConfiguration<ED, Cxt>,
|
||||
render: RenderConfiguration<ED>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict>(
|
|||
entity: keyof ED,
|
||||
attrDefs: OakAbsAttrDef[],
|
||||
t: (k: string, params?: object) => string,
|
||||
colorDict?: ColorDict<ED>
|
||||
): DataTransformer {
|
||||
const transformerFixedPart = attrDefs.map((ele) => {
|
||||
if (typeof ele === 'string') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue