relation组件据actionAuth数据结构改动完成
This commit is contained in:
parent
d9155bf881
commit
1718bb4cc9
|
|
@ -28,7 +28,9 @@ exports.default = OakComponent({
|
|||
var _a = this.props, path = _a.path, entity = _a.entity;
|
||||
return {
|
||||
destEntity: entity,
|
||||
path: path === null || path === void 0 ? void 0 : path.replaceAll('(user)', ''),
|
||||
paths: {
|
||||
$contains: path === null || path === void 0 ? void 0 : path.replaceAll('(user)', ''),
|
||||
},
|
||||
};
|
||||
},
|
||||
'#name': 'path',
|
||||
|
|
@ -58,7 +60,9 @@ exports.default = OakComponent({
|
|||
this.getRelationAndActions();
|
||||
this.addNamedFilter({
|
||||
filter: {
|
||||
path: path === null || path === void 0 ? void 0 : path.replaceAll('(user)', ''),
|
||||
paths: {
|
||||
$contains: path === null || path === void 0 ? void 0 : path.replaceAll('(user)', ''),
|
||||
},
|
||||
destEntity: entity,
|
||||
},
|
||||
'#name': 'path'
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export default function render(props: WebComponentProps<ED, 'actionAuth', true,
|
|||
relations: EntityDict['relation']['Schema'][];
|
||||
actions: string[];
|
||||
datasource: TableData[];
|
||||
rows: EntityDict['actionAuth']['Schema'][];
|
||||
rows: ED['actionAuth']['Schema'][];
|
||||
path: string;
|
||||
entity: keyof ED;
|
||||
openTip: boolean;
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@ function render(props) {
|
|||
dataIndex: 'actions',
|
||||
title: '操作权限',
|
||||
render: function (value, row) {
|
||||
var _a;
|
||||
var options = value.map(function (ele) { return ({
|
||||
label: ele,
|
||||
value: ele,
|
||||
}); });
|
||||
var actionAuth = rows.find(function (ele) { return ele.relationId === row.relationId; });
|
||||
var actionAuth = (_a = rows.filter(function (ele) { return ele.relationId === row.relationId; })
|
||||
.sort(function (a, b) { return b.deActions.length - a.deActions.length; })) === null || _a === void 0 ? void 0 : _a[0];
|
||||
var defaultValue = actionAuth ? actionAuth.deActions : [];
|
||||
return ((0, jsx_runtime_1.jsx)(antd_1.Checkbox.Group, { style: {
|
||||
width: '100%',
|
||||
|
|
@ -43,7 +45,7 @@ function render(props) {
|
|||
if (!actionAuth) {
|
||||
methods.addItem({
|
||||
relationId: row.relationId || '',
|
||||
path: path2,
|
||||
paths: [path2],
|
||||
deActions: checkedArr,
|
||||
destEntity: entity,
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -57,7 +57,7 @@ exports.default = OakComponent({
|
|||
var cascadeEntities = this.features.relationAuth.getCascadeActionAuths(entity, true);
|
||||
var cascadeEntityActions = cascadeEntities.map(function (ele) {
|
||||
var _a = tslib_1.__read(ele, 3), de = _a[0], p = _a[1], se = _a[2];
|
||||
var actionAuths = data === null || data === void 0 ? void 0 : data.filter(function (ele) { return ele.path === p && ele.destEntity === de; });
|
||||
var actionAuths = data === null || data === void 0 ? void 0 : data.filter(function (ele) { return ele.destEntity === de; });
|
||||
var relations = _this.features.cache.get('relation', {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
@ -80,7 +80,17 @@ exports.default = OakComponent({
|
|||
};
|
||||
});
|
||||
// path里含有$
|
||||
var $pathActionAuths = data.filter(function (ele) { var _a; return (_a = ele.path) === null || _a === void 0 ? void 0 : _a.includes('$'); });
|
||||
var $pathActionAuths = [];
|
||||
data.forEach(function (ele) {
|
||||
var _a;
|
||||
if ((_a = ele.paths) === null || _a === void 0 ? void 0 : _a.join('').includes('$')) {
|
||||
ele.paths.forEach(function (path) {
|
||||
if (path.includes('$')) {
|
||||
$pathActionAuths.push(tslib_1.__assign(tslib_1.__assign({}, ele), { path: path }));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// groupBy
|
||||
// 分解groupBy 的key
|
||||
var $actionAuthsObject = (0, lodash_2.groupBy)($pathActionAuths, 'path');
|
||||
|
|
@ -115,7 +125,16 @@ exports.default = OakComponent({
|
|||
});
|
||||
});
|
||||
// relationId为空字符串 表示为user的actionAuth 也要特殊处理
|
||||
var hasUserActionAuths = data.filter(function (ele) { return ele.relationId === ''; });
|
||||
var hasUserActionAuths = [];
|
||||
data.forEach(function (ele) {
|
||||
var _a;
|
||||
if (ele.relationId === '') {
|
||||
(_a = ele.paths) === null || _a === void 0 ? void 0 : _a.forEach(function (path) {
|
||||
hasUserActionAuths.push(tslib_1.__assign(tslib_1.__assign({}, ele), { path: path }));
|
||||
});
|
||||
}
|
||||
});
|
||||
// const hasUserActionAuths = data.filter((ele) => ele.relationId === '');
|
||||
var $actionAuthsObject2 = (0, lodash_2.groupBy)(hasUserActionAuths, 'path');
|
||||
Object.keys($actionAuthsObject2).forEach(function (ele) {
|
||||
var entities = ele.split('.');
|
||||
|
|
@ -177,9 +196,10 @@ exports.default = OakComponent({
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
onChange: function (checked, relationId, path, actionAuth, relationName) {
|
||||
onChange: function (checked, relationId, path, actionAuths, relationName) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var actions, se, relations, deActions_1, deActions2;
|
||||
var actions, se, relations, dASameActionAuth;
|
||||
var _this = this;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
|
|
@ -215,26 +235,63 @@ exports.default = OakComponent({
|
|||
relationId = relations[0].id;
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
if (actionAuth) {
|
||||
deActions_1 = actionAuth.deActions;
|
||||
if (actionAuths && actionAuths.length) {
|
||||
// const { deActions } = actionAuth;
|
||||
if (checked) {
|
||||
deActions2 = (0, lodash_1.union)(deActions_1, actions);
|
||||
this.updateItem({
|
||||
deActions: deActions2,
|
||||
}, actionAuth.id);
|
||||
dASameActionAuth = actionAuths.find(function (ele) { return (0, lodash_1.difference)(actions, ele.deActions).length === 0; });
|
||||
// 存在deActions相同,paths push并做去重处理
|
||||
if (dASameActionAuth) {
|
||||
this.updateItem({
|
||||
paths: dASameActionAuth.paths.concat(path),
|
||||
}, dASameActionAuth.id);
|
||||
}
|
||||
else {
|
||||
this.addItem({
|
||||
paths: [path],
|
||||
relationId: relationId,
|
||||
destEntity: this.props.entity,
|
||||
deActions: actions,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
actions.forEach(function (action) { return (0, lodash_1.pull)(deActions_1, action); });
|
||||
this.updateItem({
|
||||
deActions: deActions_1,
|
||||
}, actionAuth.id);
|
||||
// 将path从paths中删除
|
||||
actionAuths.forEach(function (ele) {
|
||||
var pathIndex = ele.paths.findIndex(function (pathE) { return pathE === path; });
|
||||
if (pathIndex !== -1) {
|
||||
var newPaths = tslib_1.__spreadArray([], tslib_1.__read(ele.paths), false);
|
||||
newPaths.splice(pathIndex, 1);
|
||||
if (!newPaths.length) {
|
||||
_this.removeItem(ele.id);
|
||||
}
|
||||
else {
|
||||
_this.updateItem({
|
||||
paths: newPaths
|
||||
}, ele.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// if (checked) {
|
||||
// const deActions2 = union(deActions, actions);
|
||||
// this.updateItem({
|
||||
// deActions: deActions2,
|
||||
// }, actionAuth.id);
|
||||
// }
|
||||
// else {
|
||||
// actions.forEach(
|
||||
// action => pull(deActions, action)
|
||||
// );
|
||||
// this.updateItem({
|
||||
// deActions,
|
||||
// }, actionAuth.id);
|
||||
// }
|
||||
}
|
||||
else {
|
||||
// 新增actionAuth
|
||||
(0, assert_1.default)(checked);
|
||||
this.addItem({
|
||||
path: path,
|
||||
paths: [path],
|
||||
relationId: relationId,
|
||||
destEntity: this.props.entity,
|
||||
deActions: actions,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export default function render(props: WebComponentProps<ED, 'actionAuth', true,
|
|||
actions: string[];
|
||||
entity: keyof EntityDict;
|
||||
}, {
|
||||
onChange: (checked: boolean, relationId: string, path: string, actionAuth?: ED['actionAuth']['OpSchema']) => void;
|
||||
onChange: (checked: boolean, relationId: string, path: string, actionAuth?: ED['actionAuth']['Schema'][]) => void;
|
||||
confirm: () => void;
|
||||
}>): import("react/jsx-runtime").JSX.Element;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -43,10 +43,14 @@ function render(props) {
|
|||
var e_1, _a;
|
||||
var _b;
|
||||
var checked = false, indeterminate = false;
|
||||
if (actionAuths && actions.length > 0) {
|
||||
// filter出对应path的actionAuth来决定relation的check
|
||||
// sort deActions长的在后,不然会影响checked
|
||||
var actionAuthsByPath = actionAuths === null || actionAuths === void 0 ? void 0 : actionAuths.filter(function (ele) { return ele.paths.includes(path[1]); }).sort(function (a, b) { return b.deActions.length - a.deActions.length; });
|
||||
if (actionAuthsByPath && actions.length > 0) {
|
||||
try {
|
||||
for (var actionAuths_1 = tslib_1.__values(actionAuths), actionAuths_1_1 = actionAuths_1.next(); !actionAuths_1_1.done; actionAuths_1_1 = actionAuths_1.next()) {
|
||||
var aa = actionAuths_1_1.value;
|
||||
for (var actionAuthsByPath_1 = tslib_1.__values(actionAuthsByPath), actionAuthsByPath_1_1 = actionAuthsByPath_1.next(); !actionAuthsByPath_1_1.done; actionAuthsByPath_1_1 = actionAuthsByPath_1.next()) {
|
||||
var aa = actionAuthsByPath_1_1.value;
|
||||
// 1.relationId相同,deActions也要相同
|
||||
// 如果path中存在多对一的情况要使用name进行判断
|
||||
if (!aa.$$deleteAt$$ && (aa.relationId === r.id
|
||||
|| (record.path.includes('$') && ((_b = aa.relation) === null || _b === void 0 ? void 0 : _b.name) === r.name))) {
|
||||
|
|
@ -60,7 +64,7 @@ function render(props) {
|
|||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (actionAuths_1_1 && !actionAuths_1_1.done && (_a = actionAuths_1.return)) _a.call(actionAuths_1);
|
||||
if (actionAuthsByPath_1_1 && !actionAuthsByPath_1_1.done && (_a = actionAuthsByPath_1.return)) _a.call(actionAuthsByPath_1);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
|
|
@ -68,8 +72,8 @@ function render(props) {
|
|||
return ((0, jsx_runtime_1.jsx)(antd_1.Checkbox, tslib_1.__assign({ disabled: actions.length === 0, checked: checked, indeterminate: indeterminate, onChange: function (_a) {
|
||||
var target = _a.target;
|
||||
var checked = target.checked;
|
||||
var actionAuth = actionAuths === null || actionAuths === void 0 ? void 0 : actionAuths.find(function (ele) { var _a; return ele.relationId === r.id || (record.path.includes('$') && ((_a = ele.relation) === null || _a === void 0 ? void 0 : _a.name) === r.name); });
|
||||
onChange(checked, r.id, path[1], actionAuth);
|
||||
var actionAuths2 = actionAuths === null || actionAuths === void 0 ? void 0 : actionAuths.filter(function (ele) { var _a; return ele.relationId === r.id || (record.path.includes('$') && ((_a = ele.relation) === null || _a === void 0 ? void 0 : _a.name) === r.name); });
|
||||
onChange(checked, r.id, path[1], actionAuths2);
|
||||
} }, { children: r.name })));
|
||||
}) })));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ exports.default = OakComponent({
|
|||
var cascadeEntityActions = cascadeEntities.map(function (ele) {
|
||||
var path = ele.path;
|
||||
var cascadePath = path[1];
|
||||
var actionAuth = data === null || data === void 0 ? void 0 : data.find(function (ele) { return ele.path === cascadePath && ele.destEntity === path[0]; });
|
||||
var actionAuth = data === null || data === void 0 ? void 0 : data.find(function (ele) { var _a; return ((_a = ele.paths) === null || _a === void 0 ? void 0 : _a.includes(cascadePath)) && ele.destEntity === path[0]; });
|
||||
return tslib_1.__assign({ actionAuth: actionAuth }, ele);
|
||||
});
|
||||
return {
|
||||
|
|
@ -71,7 +71,7 @@ exports.default = OakComponent({
|
|||
else {
|
||||
this.addItem({
|
||||
relationId: this.props.relationId,
|
||||
path: path[1],
|
||||
paths: [path[1]],
|
||||
destEntity: path[0],
|
||||
deActions: actions,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,11 +19,13 @@ export declare function getAlign(attrType: DataType): 'left' | 'right' | 'center
|
|||
export declare function getType(attribute: OakAbsAttrDef, attrType: OakAbsDerivedAttrDef['type']): "link" | "ref" | DataType | undefined;
|
||||
export declare function makeDataTransformer<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: keyof ED, attrDefs: OakAbsAttrDef[], colorDict?: ColorDict<ED>): DataTransformer;
|
||||
export declare function analyzeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(dataSchema: StorageSchema<ED>, entity: T, attrUpsertDefs: OakAbsAttrUpsertDef<ED, T>[]): (data: any) => AttrUpsertRender<ED, T>[];
|
||||
export declare function analyzeAttrMobileForCard<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: keyof ED, t: (k: string, params?: object) => string, attributes: OakAbsAttrDef[]): (data: any[]) => {
|
||||
declare type CoverData = {
|
||||
data: {
|
||||
label: string;
|
||||
value: any;
|
||||
type: "link" | "ref" | DataType | undefined;
|
||||
type: OakAbsDerivedAttrDef['type'];
|
||||
}[];
|
||||
record: any;
|
||||
record: EntityDict[keyof EntityDict];
|
||||
}[];
|
||||
export declare function analyzeAttrMobileForCard<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: keyof ED, t: (k: string, params?: object) => string, attributes: OakAbsAttrDef[]): (data: any[]) => CoverData;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default OakComponent({
|
|||
},
|
||||
isList: true,
|
||||
properties: {
|
||||
path: '',
|
||||
path: '' as string,
|
||||
openTip: false,
|
||||
entity: '' as keyof ED,
|
||||
onClose: (() => undefined) as () => void,
|
||||
|
|
@ -29,7 +29,9 @@ export default OakComponent({
|
|||
const { path, entity } = this.props;
|
||||
return {
|
||||
destEntity: entity as string,
|
||||
path: path?.replaceAll('(user)', ''),
|
||||
paths: {
|
||||
$contains: path?.replaceAll('(user)', ''),
|
||||
},
|
||||
};
|
||||
},
|
||||
'#name': 'path',
|
||||
|
|
@ -55,7 +57,9 @@ export default OakComponent({
|
|||
this.getRelationAndActions();
|
||||
this.addNamedFilter({
|
||||
filter: {
|
||||
path: path?.replaceAll('(user)', ''),
|
||||
paths: {
|
||||
$contains: path?.replaceAll('(user)', ''),
|
||||
},
|
||||
destEntity: entity as string,
|
||||
},
|
||||
'#name': 'path'
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export default function render(
|
|||
relations: EntityDict['relation']['Schema'][],
|
||||
actions: string[];
|
||||
datasource: TableData[];
|
||||
rows: EntityDict['actionAuth']['Schema'][];
|
||||
rows: ED['actionAuth']['Schema'][];
|
||||
path: string;
|
||||
entity: keyof ED;
|
||||
openTip: boolean;
|
||||
|
|
@ -67,7 +67,8 @@ export default function render(
|
|||
label: ele,
|
||||
value: ele,
|
||||
}))
|
||||
const actionAuth = rows.find((ele) => ele.relationId === row.relationId);
|
||||
const actionAuth = rows.filter((ele) => ele.relationId === row.relationId)
|
||||
.sort((a, b) => b.deActions.length - a.deActions.length)?.[0];
|
||||
const defaultValue = actionAuth ? actionAuth.deActions : [];
|
||||
return (
|
||||
<Checkbox.Group
|
||||
|
|
@ -83,7 +84,7 @@ export default function render(
|
|||
if (!actionAuth) {
|
||||
methods.addItem({
|
||||
relationId: row.relationId || '',
|
||||
path: path2,
|
||||
paths: [path2],
|
||||
deActions: checkedArr as string[],
|
||||
destEntity: entity as string,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
type Options = {
|
||||
width?: number,
|
||||
height?: number,
|
||||
devicePixelRatio?: number // 像素
|
||||
}
|
||||
|
||||
export declare function init(dom: any, theme?: string | null, options?: Options): any;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import assert from "assert";
|
||||
import { uniq, pull, union } from 'oak-domain/lib/utils/lodash';
|
||||
import { uniq, pull, union, difference } from 'oak-domain/lib/utils/lodash';
|
||||
import { ED } from "../../../types/AbstractComponent";
|
||||
import { groupBy } from "oak-domain/lib/utils/lodash";
|
||||
import { AuthCascadePath } from "oak-domain/lib/types";
|
||||
|
|
@ -59,7 +59,7 @@ export default OakComponent({
|
|||
const [de, p, se] = ele;
|
||||
|
||||
const actionAuths = data?.filter(
|
||||
ele => ele.path === p && ele.destEntity === de
|
||||
ele => ele.destEntity === de
|
||||
);
|
||||
const relations = this.features.cache.get('relation', {
|
||||
data: {
|
||||
|
|
@ -84,7 +84,19 @@ export default OakComponent({
|
|||
}
|
||||
);
|
||||
// path里含有$
|
||||
const $pathActionAuths = data.filter((ele) => ele.path?.includes('$'));
|
||||
const $pathActionAuths: (RowWithActions<ED, 'actionAuth'> & { path: string })[] = [];
|
||||
data.forEach((ele) => {
|
||||
if (ele.paths?.join('').includes('$')) {
|
||||
ele.paths.forEach((path) => {
|
||||
if (path.includes('$')) {
|
||||
$pathActionAuths.push({
|
||||
...ele,
|
||||
path,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
// groupBy
|
||||
// 分解groupBy 的key
|
||||
const $actionAuthsObject = groupBy($pathActionAuths, 'path');
|
||||
|
|
@ -119,7 +131,18 @@ export default OakComponent({
|
|||
})
|
||||
|
||||
// relationId为空字符串 表示为user的actionAuth 也要特殊处理
|
||||
const hasUserActionAuths = data.filter((ele) => ele.relationId === '');
|
||||
const hasUserActionAuths: (RowWithActions<ED, 'actionAuth'> & { path: string })[] = [];
|
||||
data.forEach((ele) => {
|
||||
if (ele.relationId === '') {
|
||||
ele.paths?.forEach((path) => {
|
||||
hasUserActionAuths.push({
|
||||
...ele,
|
||||
path
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
// const hasUserActionAuths = data.filter((ele) => ele.relationId === '');
|
||||
const $actionAuthsObject2 = groupBy(hasUserActionAuths, 'path');
|
||||
Object.keys($actionAuthsObject2).forEach((ele) => {
|
||||
const entities = ele.split('.');
|
||||
|
|
@ -182,7 +205,7 @@ export default OakComponent({
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
async onChange(checked: boolean, relationId: string, path: string, actionAuth?: ED['actionAuth']['OpSchema'], relationName?: string) {
|
||||
async onChange(checked: boolean, relationId: string, path: string, actionAuths?: ED['actionAuth']['Schema'][], relationName?: string) {
|
||||
const { actions } = this.props;
|
||||
assert(actions && actions.length > 0);
|
||||
// 排除user这种情况
|
||||
|
|
@ -213,28 +236,63 @@ export default OakComponent({
|
|||
}
|
||||
relationId = relations[0].id!;
|
||||
}
|
||||
if (actionAuth) {
|
||||
const { deActions } = actionAuth;
|
||||
if (actionAuths && actionAuths.length) {
|
||||
// const { deActions } = actionAuth;
|
||||
if (checked) {
|
||||
const deActions2 = union(deActions, actions);
|
||||
this.updateItem({
|
||||
deActions: deActions2,
|
||||
}, actionAuth.id);
|
||||
const dASameActionAuth = actionAuths.find((ele) => difference(actions, ele.deActions).length === 0);
|
||||
// 存在deActions相同,paths push并做去重处理
|
||||
if (dASameActionAuth) {
|
||||
this.updateItem({
|
||||
paths: dASameActionAuth.paths.concat(path),
|
||||
}, dASameActionAuth.id)
|
||||
}
|
||||
else {
|
||||
this.addItem({
|
||||
paths: [path],
|
||||
relationId,
|
||||
destEntity: this.props.entity as string,
|
||||
deActions: actions,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
actions.forEach(
|
||||
action => pull(deActions, action)
|
||||
);
|
||||
this.updateItem({
|
||||
deActions,
|
||||
}, actionAuth.id);
|
||||
// 将path从paths中删除
|
||||
actionAuths.forEach((ele) => {
|
||||
const pathIndex = ele.paths.findIndex((pathE) => pathE === path);
|
||||
if (pathIndex !== -1) {
|
||||
const newPaths = [...ele.paths];
|
||||
newPaths.splice(pathIndex, 1);
|
||||
if (!newPaths.length) {
|
||||
this.removeItem(ele.id);
|
||||
}
|
||||
else {
|
||||
this.updateItem({
|
||||
paths: newPaths
|
||||
}, ele.id);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// if (checked) {
|
||||
// const deActions2 = union(deActions, actions);
|
||||
// this.updateItem({
|
||||
// deActions: deActions2,
|
||||
// }, actionAuth.id);
|
||||
// }
|
||||
// else {
|
||||
// actions.forEach(
|
||||
// action => pull(deActions, action)
|
||||
// );
|
||||
// this.updateItem({
|
||||
// deActions,
|
||||
// }, actionAuth.id);
|
||||
// }
|
||||
}
|
||||
else {
|
||||
// 新增actionAuth
|
||||
assert(checked);
|
||||
this.addItem({
|
||||
path,
|
||||
paths: [path],
|
||||
relationId,
|
||||
destEntity: this.props.entity as string,
|
||||
deActions: actions,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const { Title, Text } = Typography;
|
|||
import { RowWithActions, WebComponentProps } from '../../../types/Page';
|
||||
import { AuthCascadePath, EntityDict } from 'oak-domain/lib/types/Entity';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { difference, intersection } from 'oak-domain/lib/utils/lodash';
|
||||
import { difference, intersection, isEqual } from 'oak-domain/lib/utils/lodash';
|
||||
import { useState, useEffect } from 'react';
|
||||
import ActionAuthListSingle from '../../../components/relation/single';
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ export default function render(
|
|||
entity: keyof EntityDict;
|
||||
},
|
||||
{
|
||||
onChange: (checked: boolean, relationId: string, path: string, actionAuth?: ED['actionAuth']['OpSchema']) => void;
|
||||
onChange: (checked: boolean, relationId: string, path: string, actionAuth?: ED['actionAuth']['Schema'][]) => void;
|
||||
confirm: () => void;
|
||||
}
|
||||
>
|
||||
|
|
@ -77,11 +77,17 @@ export default function render(
|
|||
relations?.map(
|
||||
(r) => {
|
||||
let checked = false, indeterminate = false;
|
||||
if (actionAuths && actions.length > 0) {
|
||||
for (const aa of actionAuths) {
|
||||
// filter出对应path的actionAuth来决定relation的check
|
||||
// sort deActions长的在后,不然会影响checked
|
||||
const actionAuthsByPath = actionAuths?.filter((ele) => ele.paths.includes(path[1]))
|
||||
.sort((a, b) => b.deActions.length - a.deActions.length);
|
||||
if (actionAuthsByPath && actions.length > 0) {
|
||||
for (const aa of actionAuthsByPath) {
|
||||
// 1.relationId相同,deActions也要相同
|
||||
// 如果path中存在多对一的情况要使用name进行判断
|
||||
if (!aa.$$deleteAt$$ && (aa.relationId === r.id
|
||||
|| (record.path.includes('$') && aa.relation?.name === r.name))) {
|
||||
|| (record.path.includes('$') && aa.relation?.name === r.name))
|
||||
) {
|
||||
const { deActions } = aa;
|
||||
checked = difference(actions, deActions).length === 0;
|
||||
indeterminate = !checked && intersection(actions, deActions).length > 0;
|
||||
|
|
@ -96,11 +102,11 @@ export default function render(
|
|||
indeterminate={indeterminate}
|
||||
onChange={({ target }) => {
|
||||
const { checked } = target;
|
||||
const actionAuth = actionAuths?.find(
|
||||
const actionAuths2 = actionAuths?.filter(
|
||||
ele => ele.relationId === r.id || (record.path.includes('$') && ele.relation?.name === r.name)
|
||||
);
|
||||
|
||||
onChange(checked, r.id, path[1], actionAuth)
|
||||
onChange(checked, r.id, path[1], actionAuths2)
|
||||
}}
|
||||
>
|
||||
{r.name}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ export default OakComponent({
|
|||
const cascadePath = path[1];
|
||||
|
||||
const actionAuth = data?.find(
|
||||
ele => ele.path === cascadePath && ele.destEntity === path[0]
|
||||
ele => ele.paths?.includes(cascadePath) && ele.destEntity === path[0]
|
||||
);
|
||||
return {
|
||||
actionAuth,
|
||||
|
|
@ -78,7 +78,7 @@ export default OakComponent({
|
|||
else {
|
||||
this.addItem({
|
||||
relationId: this.props.relationId,
|
||||
path: path[1],
|
||||
paths: [path[1]],
|
||||
destEntity: path[0] as string,
|
||||
deActions: actions,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -396,6 +396,14 @@ export function analyzeDataUpsertTransformer<
|
|||
});
|
||||
}
|
||||
|
||||
type CoverData = {
|
||||
data: {
|
||||
label: string;
|
||||
value: any;
|
||||
type: OakAbsDerivedAttrDef['type'];
|
||||
}[];
|
||||
record: EntityDict[keyof EntityDict];
|
||||
}[]
|
||||
|
||||
export function analyzeAttrMobileForCard<
|
||||
ED extends EntityDict & BaseEntityDict
|
||||
|
|
@ -404,7 +412,7 @@ export function analyzeAttrMobileForCard<
|
|||
entity: keyof ED,
|
||||
t: (k: string, params?: object) => string,
|
||||
attributes: OakAbsAttrDef[],
|
||||
) {
|
||||
): (data: any[]) => CoverData {
|
||||
return (data: any[]) => {
|
||||
// 遍历用户传入的数据源
|
||||
const coverData = data.map((row) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue