This commit is contained in:
梁朝伟 2023-03-10 17:06:46 +08:00
commit 318c8c32d2
90 changed files with 99 additions and 713 deletions

View File

@ -1,9 +0,0 @@
{
"component": true,
"usingComponents": {
"l-dialog": "../../miniprogram_npm/lin-ui/dialog/index",
"l-button": "../../miniprogram_npm/lin-ui/button/index",
"popover": "../../miniprogram_npm/popover/popover",
"popover-item": "../../miniprogram_npm/popover/popover-item"
}
}

View File

@ -1,3 +0,0 @@
/// <reference types="react" />
declare const _default: (props: import("../..").ReactComponentProps<false, {}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export default _default;

View File

@ -1,18 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = OakComponent({
isList: false,
formData: function (_a) {
var props = _a.props, features = _a.features;
var colorDict = features.style.getColorDict();
var dataSchema = features.cache.getSchema();
return {
colorDict: colorDict,
dataSchema: dataSchema,
};
},
properties: {},
data: {},
lifetimes: {},
methods: {},
});

View File

@ -1,15 +0,0 @@
/// <reference types="react" />
import { EntityDict } from 'oak-domain/lib/types/Entity';
import { WebComponentProps } from '../../types/Page';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { ColorDict } from 'oak-domain/lib/types/Style';
import { StorageSchema } from 'oak-domain/lib/types/Storage';
import { OakAbsAttrDef } from '../../types/AbstractComponent';
export default function Render(props: WebComponentProps<EntityDict & BaseEntityDict, keyof EntityDict, false, {
data: any[];
columns: OakAbsAttrDef[];
disableOp?: boolean;
handleClick?: (id: string, action: string) => void;
colorDict: ColorDict<EntityDict & BaseEntityDict>;
dataSchema: StorageSchema<EntityDict>;
}, {}>): JSX.Element;

View File

@ -1,87 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_i18next_1 = require("react-i18next");
var antd_1 = require("antd");
var assert_1 = tslib_1.__importDefault(require("assert"));
var usefulFn_1 = require("../../utils/usefulFn");
var lodash_1 = require("oak-domain/lib/utils/lodash");
var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
var actionBtnPanel_1 = tslib_1.__importDefault(require("../actionBtnPanel"));
function decodeTitle(entity, attr) {
var t = (0, react_i18next_1.useTranslation)().t;
if (attr === ('$$createAt$$' || '$$updateAt$$')) {
return t("common:".concat(attr));
}
return t("".concat(entity, ":attr.").concat(attr));
}
function RenderCell(props) {
var content = props.content, entity = props.entity, path = props.path, attr = props.attr, attrType = props.attrType, t = props.t, colorDict = props.colorDict;
var value = (0, lodash_1.get)(content, path);
if (!value) {
return ((0, jsx_runtime_1.jsx)("div", { children: "--" }));
}
// 属性类型是enum要使用标签
else if (attrType === 'enum') {
return ((0, jsx_runtime_1.jsx)(antd_1.Tag, tslib_1.__assign({ color: colorDict[entity][attr][String(value)] }, { children: t("".concat(entity, ":v.").concat(attr, ".").concat(value)) })));
}
else if (attrType === 'datetime') {
return (0, jsx_runtime_1.jsx)("div", { children: (0, dayjs_1.default)(value).format('YYYY-MM-DD HH:mm') });
}
return ((0, jsx_runtime_1.jsx)("div", { children: value }));
}
function Render(props) {
var methods = props.methods, oakData = props.data;
var t = methods.t;
var oakEntity = oakData.oakEntity, data = oakData.data, columns = oakData.columns, _a = oakData.disableOp, disableOp = _a === void 0 ? false : _a, handleClick = oakData.handleClick, colorDict = oakData.colorDict, dataSchema = oakData.dataSchema;
var tableColumns = columns.map(function (ele) {
if (ele.path) {
var _a = (0, usefulFn_1.resolvePath)(dataSchema, entity, path) || {}, useEntity = _a.entity, attr = _a.attr, attribute = _a.attribute;
}
var title = '';
var render = function () { return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}); };
var path;
if (typeof ele === 'string') {
path = ele;
}
else {
path = ele.path;
}
title = decodeTitle(useEntity, attr);
render = function (value, row) { return ((0, jsx_runtime_1.jsx)(RenderCell, { entity: entity, content: row, path: path, attr: attr, attrType: attribute === null || attribute === void 0 ? void 0 : attribute.type, t: t, colorDict: colorDict })); };
var column = {
align: 'center',
title: title,
dataIndex: typeof ele === 'string' ? ele : ele.dataIndex,
render: render,
};
// 类型如果是枚举类型那么它的宽度一般不超过160
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'enum') {
Object.assign(column, { width: 160 });
}
return Object.assign(column, typeof ele !== 'string' && ele);
});
if (tableColumns && tableColumns) {
tableColumns.unshift({ title: '序号', width: 100, render: function (value, record, index) {
return index + 1;
}, });
}
if (!disableOp) {
tableColumns.push({
fixed: 'right',
align: 'center',
title: '操作',
key: 'operation',
width: 300,
render: function (value, row) {
var id = row === null || row === void 0 ? void 0 : row.id;
var oakActions = row === null || row === void 0 ? void 0 : row.oakActions;
(0, assert_1.default)(!!oakActions, '行数据中不存在oakActions, 请禁用(disableOp:true)或添加oakActions');
return ((0, jsx_runtime_1.jsx)(actionBtnPanel_1.default, { oakId: id, entity: entity, oakActions: oakActions, onClick: function (id, action) { return handleClick && handleClick(id, action); } }));
}
});
}
return ((0, jsx_runtime_1.jsx)(antd_1.Table, tslib_1.__assign({ dataSource: data, scroll: { x: 1500 }, columns: tableColumns }, tableProps)));
}
exports.default = Render;

View File

@ -22,6 +22,7 @@ exports.default = OakComponent({
},
data: {
transformer: (function () { return []; }),
mtoPickerDict: {},
},
listeners: {
data: function () {
@ -29,13 +30,14 @@ exports.default = OakComponent({
},
},
lifetimes: {
ready: function () {
attached: function () {
var _this = this;
var _a = this.props, attributes = _a.attributes, entity = _a.entity;
var schema = this.features.cache.getSchema();
var transformer = (0, usefulFn_1.makeDataUpsertTransformer)(schema, entity, attributes, function (k, params) { return _this.t(k, params); });
var _b = (0, usefulFn_1.analyzeDataUpsertTransformer)(schema, entity, attributes, function (k, params) { return _this.t(k, params); }), transformer = _b.transformer, mtoPickerDict = _b.mtoPickerDict;
this.setState({
transformer: transformer,
mtoPickerDict: mtoPickerDict,
});
}
}

View File

@ -3,7 +3,9 @@ import { EntityDict } from 'oak-domain/lib/types/Entity';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AttrUpsertRender } from '../../types/AbstractComponent';
import { WebComponentProps } from '../../types/Page';
export default function render(props: WebComponentProps<EntityDict & BaseEntityDict, keyof EntityDict, false, {
renderData: AttrUpsertRender<EntityDict & BaseEntityDict>[];
declare type ED = EntityDict & BaseEntityDict;
export default function render(props: WebComponentProps<ED, keyof EntityDict, false, {
renderData: AttrUpsertRender<ED>[];
children: any;
}, {}>): JSX.Element;
export {};

View File

@ -93,6 +93,9 @@ function makeAttrInput(attrRender, onValueChange) {
return ((0, jsx_runtime_1.jsx)(antd_1.Radio, tslib_1.__assign({ value: value }, { children: label })));
}) })));
}
case 'ref': {
var mode = attrRender.mode;
}
default: {
throw new Error("\u3010Abstract Update\u3011\u65E0\u6CD5\u652F\u6301\u7684\u6570\u636E\u7C7B\u522B".concat(type, "\u7684\u6E32\u67D3"));
}
@ -109,27 +112,11 @@ function render(props) {
required: ele.required,
},
] }, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: makeAttrInput(ele, function (value) {
var _a, _b;
if (ele.type === 'ref') {
var _c = ele, attr = _c.attr, entity = _c.entity;
if (attr) {
update((_a = {},
_a[attr] = value,
_a));
}
else {
update({
entity: entity,
entityId: value,
});
}
}
else {
var attr = ele.attr;
update((_b = {},
_b[attr] = value,
_b));
}
var _a;
var attr = ele.attr;
update((_a = {},
_a[attr] = value,
_a));
}) }) }))); }), children] })));
}
exports.default = render;

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,8 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-popup": "../popup/index",
"l-button": "../button/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-popup": "../popup/index"
}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,3 +0,0 @@
{
"component": true
}

View File

@ -1,3 +0,0 @@
{
"component": true
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"day": "../day/index"
}
}

View File

@ -1,10 +0,0 @@
{
"component": true,
"usingComponents": {
"header": "./components/header/index",
"mounth": "./components/mounth/index",
"l-toast": "../toast/index",
"l-popup": "../popup/index",
"l-button": "../button/index"
}
}

View File

@ -1,3 +0,0 @@
{
"component": true
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-error-tip": "../error-tip/index",
"l-checkbox": "../checkbox/index"
}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-button": "../button/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-list": "../list/index",
"l-icon": "../icon/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-badge": "../badge/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,3 +0,0 @@
{
"component": true
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-popup": "../popup/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-error-tip": "../error-tip/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-grid-item": "../grid-item/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-index-list": "../index-list/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-error-tip": "../error-tip/index"
}
}

View File

@ -1,8 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-badge": "../badge/index",
"l-tag": "../tag/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-loading": "../loading/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-error-tip": "../error-tip/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-error-tip": "../error-tip/index",
"l-radio": "../radio/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-input": "../input/index",
"l-icon": "../icon/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,8 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-badge": "../badge/index",
"l-segment-item": "../segment-item/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-button": "../button/index"
}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-step": "../step/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {
"l-badge": "../badge/index"
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,8 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-badge": "../badge/index",
"l-tabpanel": "../tabpanel/index"
}
}

View File

@ -1,6 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-error-tip": "../error-tip/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-mask": "../mask/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {
"l-icon": "../icon/index",
"l-mask": "../mask/index"
}
}

View File

@ -1,7 +0,0 @@
{
"component": true,
"usingComponents": {},
"componentGenerics": {
"l-water-flow-item": true
}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,4 +0,0 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -1,110 +0,0 @@
var Interpreter = (function (r) {
var o = '';
function i(r, n) {
return r
? 'string' == typeof r
? r
: r
.reduce(function (r, t) {
return r.concat([
(function (n, e) {
if (((e = e || {}), 'string' == typeof n))
return n;
{
var r, t, u;
if (n[2] && 'object' == typeof n[2])
return (
(r = Object.keys(n[2]).reduce(
function (r, t) {
return (
(r[t] = i(
n[2][t],
e
)),
r
);
},
{}
)),
(t = r[e[0]]),
void 0 !== (u = e[n[0]])
? r[u.toString()] ||
r.other ||
o
: t || r.other || o
);
}
if ('object' == typeof n && 0 < n.length)
return (function r(t, n, e) {
void 0 === e && (e = 0);
if (!n || !t || t.length <= 0)
return '';
n = n[t[e]];
if ('string' == typeof n) return n;
if ('number' == typeof n)
return n.toString();
if (!n)
return '{'.concat(
t.join('.'),
'}'
);
return r(t, n, ++e);
})(n[0].split('.'), e, 0);
return '';
})(t, n),
]);
}, [])
.join('')
: o;
}
function c(r, t, n) {
return (
('object' == typeof r &&
((t = t).constructor && 'Array' === t.constructor
? t
: t
.replace(getRegExp('\[', 'ig'), '.')
.replace(getRegExp('\]', 'ig'), '')
.split('.')
).reduce(function (r, t) {
return (r || {})[t];
}, r)) ||
n
);
}
function f(r) {
var t = r;
return (t =
r && -1 !== r.indexOf(':')
? r.replace(getRegExp(':', 'ig'), '.')
: t);
}
function g(r, t, n) {
var e = f(n),
r = r[t];
return (r && (r[e] || c(r, e))) || n;
}
return (
(r.getMessageInterpreter = function () {
function u(r, t, n, e) {
return i(
(function (r, t, n, e) {
var u = f(r);
if (!(n = t[n])) return g(t, e, r);
var o = n[u];
return (o = o || c(n, u)) ? o : g(t, e, r);
})(r, e, n, n),
t
);
}
return function (r, t, n, e) {
return 3 === arguments.length
? u(r, null, t, n)
: 4 === arguments.length
? u(r, t, n, e)
: '';
};
}),
r
);
})({});

View File

@ -40,12 +40,13 @@ export interface OakAbsRefAttrPickerDef<ED extends EntityDict & BaseEntityDict,
label?: string;
allowNull?: boolean;
}
export declare type OakAbsRefAttrPickerRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = Pick<OakAbsRefAttrPickerDef<ED, T>, 'mode' | 'projection' | 'entity' | 'projection' | 'title' | 'filter' | 'count'> & {
export declare type OakAbsRefAttrPickerRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
type: 'ref';
attr?: string;
attr: string;
label: string;
value: any;
required?: boolean;
mode: OakAbsRefAttrPickerDef<ED, T>['mode'];
};
export declare type OakAbsGeoAttrsDef = {
amapSecurityJsCode: string;

3
lib/types/Page.d.ts vendored
View File

@ -42,6 +42,9 @@ export declare type ActionDef<ED extends EntityDict & BaseEntityDict, T extends
action: ED[T]['Action'];
filter?: ED[T]['Selection']['filter'];
data?: Partial<ED[T]['CreateSingle']['data']>;
label?: string;
color?: string;
key?: string;
} | ED[T]['Action'];
export declare type RowWithActions<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = Partial<ED[T]['Schema']> & {
'#oakLegalActions': ActionDef<ED, T>[];

View File

@ -1,6 +0,0 @@
export declare type OakActionBtnProps = {
label: string;
action: string;
type?: 'a' | 'button';
ctxType?: string;
};

View File

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -1,7 +1,7 @@
import { EntityDict } 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 { OakAbsAttrDef, CardDef, DataTransformer, DataConverter, ColumnDefProps, OakAbsAttrUpsertDef, DataUpsertTransformer } from '../types/AbstractComponent';
import { OakAbsAttrDef, CardDef, DataTransformer, DataConverter, ColumnDefProps, OakAbsAttrUpsertDef, AttrUpsertRender, OakAbsRefAttrPickerDef } from '../types/AbstractComponent';
import { DataType } from 'oak-domain/lib/types/schema/DataTypes';
import { ColorDict } from 'oak-domain/lib/types/Style';
export declare function getAttributes(attributes: Record<string, Attribute>): Record<string, Attribute>;
@ -12,7 +12,10 @@ export declare function resolvePath<ED extends EntityDict & BaseEntityDict>(data
attribute: Attribute;
};
export declare function makeDataTransformer<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: string, attrDefs: OakAbsAttrDef[], t: (k: string, params?: object) => string, colorDict?: ColorDict<ED>): DataTransformer;
export declare function makeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: string, attrUpsertDefs: OakAbsAttrUpsertDef<ED>[], t: (k: string, params?: object) => string): DataUpsertTransformer<ED>;
export declare function analyzeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: string, attrUpsertDefs: OakAbsAttrUpsertDef<ED>[], t: (k: string, params?: object) => string): {
transformer: (data: any) => AttrUpsertRender<ED>[];
mtoPickerDict: Record<string, OakAbsRefAttrPickerDef<ED, keyof ED>>;
};
export declare function analyzeAttrDefForTable<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: string, attrDefs: OakAbsAttrDef[], t: (k: string, params?: object) => string, mobileAttrDef?: CardDef, colorDict?: ColorDict<ED>): {
columnDef: ColumnDefProps[];
converter: DataConverter | undefined;

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.analyzeAttrDefForTable = exports.makeDataUpsertTransformer = exports.makeDataTransformer = exports.resolvePath = exports.getAttributes = void 0;
exports.analyzeAttrDefForTable = exports.analyzeDataUpsertTransformer = exports.makeDataTransformer = exports.resolvePath = exports.getAttributes = void 0;
var tslib_1 = require("tslib");
var assert_1 = tslib_1.__importDefault(require("assert"));
var relation_1 = require("oak-domain/lib/store/relation");
@ -168,7 +168,8 @@ function makeDataTransformer(dataSchema, entity, attrDefs, t, colorDict) {
};
}
exports.makeDataTransformer = makeDataTransformer;
function makeDataUpsertTransformer(dataSchema, entity, attrUpsertDefs, t) {
function analyzeDataUpsertTransformer(dataSchema, entity, attrUpsertDefs, t) {
var mtoPickerDict = {};
var transformerFixedPart = attrUpsertDefs.map(function (ele) {
if (typeof ele === 'string') {
var rel = (0, relation_1.judgeRelation)(dataSchema, entity, ele);
@ -193,14 +194,19 @@ function makeDataUpsertTransformer(dataSchema, entity, attrUpsertDefs, t) {
var rel = (0, relation_1.judgeRelation)(dataSchema, entity, attr_1);
(0, assert_1.default)(rel === 2 || rel === ele.entity);
var refEntity = typeof rel === 'string' ? rel : attr_1;
return {
type: 'ref',
attr: typeof rel === 'string' && "".concat(attr_1, "Id"),
(0, assert_1.default)(!mtoPickerDict[attr_1]);
mtoPickerDict[attr_1] = {
mode: mode,
attr: attr_1,
entity: refEntity,
projection: projection,
title: title_1,
filter: filter,
count: count,
title: title_1,
};
return {
type: 'ref',
attr: typeof rel === 'string' ? "".concat(attr_1, "Id") : 'entityId',
mode: mode,
get: function (data) { return title_1(data[attr_1]); },
label: label || t("".concat(refEntity, ":name")),
@ -208,13 +214,16 @@ function makeDataUpsertTransformer(dataSchema, entity, attrUpsertDefs, t) {
};
}
});
return function (data) { return transformerFixedPart.map(function (ele) {
var get = ele.get;
var value = get(data);
return tslib_1.__assign({ value: value }, ele);
}); };
return {
transformer: function (data) { return transformerFixedPart.map(function (ele) {
var get = ele.get;
var value = get(data);
return tslib_1.__assign({ value: value }, ele);
}); },
mtoPickerDict: mtoPickerDict,
};
}
exports.makeDataUpsertTransformer = makeDataUpsertTransformer;
exports.analyzeDataUpsertTransformer = analyzeDataUpsertTransformer;
function analyzeAttrDefForTable(dataSchema, entity, attrDefs, t, mobileAttrDef, colorDict) {
// web使用
var columnDef = attrDefs.map(function (ele) {

View File

@ -1,7 +1,7 @@
import { EntityDict } from 'oak-domain/lib/types/Entity';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { DataUpsertTransformer } from '../../types/AbstractComponent';
import { makeDataUpsertTransformer } from '../../utils/usefulFn';
import { DataUpsertTransformer, OakAbsRefAttrPickerDef } from '../../types/AbstractComponent';
import { analyzeDataUpsertTransformer } from '../../utils/usefulFn';
export default OakComponent({
isList: false,
@ -24,6 +24,7 @@ export default OakComponent({
},
data: {
transformer: (() => []) as DataUpsertTransformer<EntityDict & BaseEntityDict>,
mtoPickerDict: {} as Record<string, OakAbsRefAttrPickerDef<EntityDict & BaseEntityDict, keyof (EntityDict & BaseEntityDict)>>,
},
listeners: {
data() {
@ -31,13 +32,14 @@ export default OakComponent({
},
},
lifetimes: {
ready() {
attached() {
const { attributes, entity } = this.props;
const schema = this.features.cache.getSchema();
const transformer = makeDataUpsertTransformer(schema, entity!, attributes!, (k, params) => this.t(k, params));
const { transformer, mtoPickerDict } = analyzeDataUpsertTransformer(schema, entity!, attributes!, (k, params) => this.t(k, params));
this.setState({
transformer,
mtoPickerDict,
});
}
}

View File

@ -20,7 +20,8 @@ import dayjs from 'dayjs';
import { AttrRender, AttrUpsertRender, OakAbsRefAttrPickerRender, OakNativeAttrUpsertRender } from '../../types/AbstractComponent';
import { WebComponentProps } from '../../types/Page';
function makeAttrInput(attrRender: AttrUpsertRender<EntityDict & BaseEntityDict>, onValueChange: (value: any) => void) {
type ED = EntityDict & BaseEntityDict;
function makeAttrInput(attrRender: AttrUpsertRender<ED>, onValueChange: (value: any) => void) {
const { value, type, params, label, defaultValue, required } = attrRender as OakNativeAttrUpsertRender;
switch (type) {
case 'string':
@ -182,6 +183,9 @@ function makeAttrInput(attrRender: AttrUpsertRender<EntityDict & BaseEntityDict>
</Radio.Group>
);
}
case 'ref': {
const { mode, } = attrRender as OakAbsRefAttrPickerRender<ED, keyof ED>;
}
default: {
throw new Error(`【Abstract Update】无法支持的数据类别${type}的渲染`);
}
@ -189,11 +193,11 @@ function makeAttrInput(attrRender: AttrUpsertRender<EntityDict & BaseEntityDict>
}
export default function render(props: WebComponentProps<
EntityDict & BaseEntityDict,
ED,
keyof EntityDict,
false,
{
renderData: AttrUpsertRender<EntityDict & BaseEntityDict>[];
renderData: AttrUpsertRender<ED>[];
children: any;
},
{
@ -224,26 +228,10 @@ export default function render(props: WebComponentProps<
<>
{
makeAttrInput(ele, (value) => {
if (ele.type === 'ref') {
const { attr, entity } = ele as OakAbsRefAttrPickerRender<EntityDict & BaseEntityDict, keyof (EntityDict & BaseEntityDict)>;
if (attr) {
update({
[attr]: value,
});
}
else {
update({
entity,
entityId: value,
});
}
}
else {
const { attr } = ele;
update({
[attr]: value,
})
}
const { attr } = ele;
update({
[attr]: value,
})
})
}
</>

View File

@ -50,15 +50,13 @@ export interface OakAbsRefAttrPickerDef<ED extends EntityDict & BaseEntityDict,
allowNull?: boolean;
};
export type OakAbsRefAttrPickerRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = Pick<
OakAbsRefAttrPickerDef<ED, T>,
'mode' | 'projection' | 'entity' | 'projection' | 'title' | 'filter' | 'count'
> & {
export type OakAbsRefAttrPickerRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
type: 'ref';
attr?: string; // 为undefined意味着是entity/entityId的指针
attr: string;
label: string;
value: any;
required?: boolean;
mode: OakAbsRefAttrPickerDef<ED, T>['mode'],
}
export type OakAbsGeoAttrsDef = {

View File

@ -89,6 +89,9 @@ export type ActionDef<
action: ED[T]['Action'],
filter?: ED[T]['Selection']['filter'];
data?: Partial<ED[T]['CreateSingle']['data']>;
label?: string;
color?: string;
key?: string;
} | ED[T]['Action'];
export type RowWithActions<

View File

@ -16,6 +16,7 @@ import {
DataUpsertTransformer,
AttrUpsertRender,
OakAbsDerivedAttrDef,
OakAbsRefAttrPickerDef,
} from '../types/AbstractComponent';
import { Attributes } from 'oak-domain/lib/types';
import { get } from 'oak-domain/lib/utils/lodash';
@ -230,11 +231,14 @@ export function makeDataTransformer<ED extends EntityDict & BaseEntityDict>(data
});
}
export function makeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict>(
export function analyzeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict>(
dataSchema: StorageSchema<ED>,
entity: string,
attrUpsertDefs: OakAbsAttrUpsertDef<ED>[],
t: (k: string, params?: object) => string): DataUpsertTransformer<ED> {
t: (k: string, params?: object) => string) {
const mtoPickerDict: Record<string, OakAbsRefAttrPickerDef<ED, keyof ED>> = {};
const transformerFixedPart = attrUpsertDefs.map(
(ele) => {
if (typeof ele === 'string') {
@ -260,14 +264,19 @@ export function makeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict
const rel = judgeRelation(dataSchema, entity, attr);
assert(rel === 2 || rel === ele.entity);
const refEntity = typeof rel === 'string' ? rel : attr;
return {
type: 'ref',
attr: typeof rel === 'string' && `${attr}Id`,
assert(!mtoPickerDict[attr]);
mtoPickerDict[attr] = {
mode,
attr,
entity: refEntity as keyof ED,
projection,
title,
filter,
count,
title,
};
return {
type: 'ref',
attr: typeof rel === 'string' ? `${attr}Id` : 'entityId',
mode,
get: (data: Record<string, any>) => title(data[attr]),
label: label || t(`${refEntity}:name`),
@ -276,16 +285,19 @@ export function makeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict
}
}
);
return (data: any) => transformerFixedPart.map(
(ele) => {
const { get } = ele;
const value = get(data);
return {
value,
...ele,
} as AttrUpsertRender<ED>;
}
);
return {
transformer: (data: any) => transformerFixedPart.map(
(ele) => {
const { get } = ele;
const value = get(data);
return {
value,
...ele,
} as AttrUpsertRender<ED>;
}
),
mtoPickerDict,
};
}
export function analyzeAttrDefForTable<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: string, attrDefs: OakAbsAttrDef[], t: (k: string, params?: object) => string, mobileAttrDef?: CardDef, colorDict?: ColorDict<ED>) : {