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;
|
var _a = this.props, path = _a.path, entity = _a.entity;
|
||||||
return {
|
return {
|
||||||
destEntity: entity,
|
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',
|
'#name': 'path',
|
||||||
|
|
@ -58,7 +60,9 @@ exports.default = OakComponent({
|
||||||
this.getRelationAndActions();
|
this.getRelationAndActions();
|
||||||
this.addNamedFilter({
|
this.addNamedFilter({
|
||||||
filter: {
|
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,
|
destEntity: entity,
|
||||||
},
|
},
|
||||||
'#name': 'path'
|
'#name': 'path'
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export default function render(props: WebComponentProps<ED, 'actionAuth', true,
|
||||||
relations: EntityDict['relation']['Schema'][];
|
relations: EntityDict['relation']['Schema'][];
|
||||||
actions: string[];
|
actions: string[];
|
||||||
datasource: TableData[];
|
datasource: TableData[];
|
||||||
rows: EntityDict['actionAuth']['Schema'][];
|
rows: ED['actionAuth']['Schema'][];
|
||||||
path: string;
|
path: string;
|
||||||
entity: keyof ED;
|
entity: keyof ED;
|
||||||
openTip: boolean;
|
openTip: boolean;
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,13 @@ function render(props) {
|
||||||
dataIndex: 'actions',
|
dataIndex: 'actions',
|
||||||
title: '操作权限',
|
title: '操作权限',
|
||||||
render: function (value, row) {
|
render: function (value, row) {
|
||||||
|
var _a;
|
||||||
var options = value.map(function (ele) { return ({
|
var options = value.map(function (ele) { return ({
|
||||||
label: ele,
|
label: ele,
|
||||||
value: 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 : [];
|
var defaultValue = actionAuth ? actionAuth.deActions : [];
|
||||||
return ((0, jsx_runtime_1.jsx)(antd_1.Checkbox.Group, { style: {
|
return ((0, jsx_runtime_1.jsx)(antd_1.Checkbox.Group, { style: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|
@ -43,7 +45,7 @@ function render(props) {
|
||||||
if (!actionAuth) {
|
if (!actionAuth) {
|
||||||
methods.addItem({
|
methods.addItem({
|
||||||
relationId: row.relationId || '',
|
relationId: row.relationId || '',
|
||||||
path: path2,
|
paths: [path2],
|
||||||
deActions: checkedArr,
|
deActions: checkedArr,
|
||||||
destEntity: entity,
|
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 cascadeEntities = this.features.relationAuth.getCascadeActionAuths(entity, true);
|
||||||
var cascadeEntityActions = cascadeEntities.map(function (ele) {
|
var cascadeEntityActions = cascadeEntities.map(function (ele) {
|
||||||
var _a = tslib_1.__read(ele, 3), de = _a[0], p = _a[1], se = _a[2];
|
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', {
|
var relations = _this.features.cache.get('relation', {
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
|
@ -80,7 +80,17 @@ exports.default = OakComponent({
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
// path里含有$
|
// 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
|
||||||
// 分解groupBy 的key
|
// 分解groupBy 的key
|
||||||
var $actionAuthsObject = (0, lodash_2.groupBy)($pathActionAuths, 'path');
|
var $actionAuthsObject = (0, lodash_2.groupBy)($pathActionAuths, 'path');
|
||||||
|
|
@ -115,7 +125,16 @@ exports.default = OakComponent({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// relationId为空字符串 表示为user的actionAuth 也要特殊处理
|
// 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');
|
var $actionAuthsObject2 = (0, lodash_2.groupBy)(hasUserActionAuths, 'path');
|
||||||
Object.keys($actionAuthsObject2).forEach(function (ele) {
|
Object.keys($actionAuthsObject2).forEach(function (ele) {
|
||||||
var entities = ele.split('.');
|
var entities = ele.split('.');
|
||||||
|
|
@ -177,9 +196,10 @@ exports.default = OakComponent({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
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 () {
|
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) {
|
return tslib_1.__generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -215,26 +235,63 @@ exports.default = OakComponent({
|
||||||
relationId = relations[0].id;
|
relationId = relations[0].id;
|
||||||
_a.label = 2;
|
_a.label = 2;
|
||||||
case 2:
|
case 2:
|
||||||
if (actionAuth) {
|
if (actionAuths && actionAuths.length) {
|
||||||
deActions_1 = actionAuth.deActions;
|
// const { deActions } = actionAuth;
|
||||||
if (checked) {
|
if (checked) {
|
||||||
deActions2 = (0, lodash_1.union)(deActions_1, actions);
|
dASameActionAuth = actionAuths.find(function (ele) { return (0, lodash_1.difference)(actions, ele.deActions).length === 0; });
|
||||||
this.updateItem({
|
// 存在deActions相同,paths push并做去重处理
|
||||||
deActions: deActions2,
|
if (dASameActionAuth) {
|
||||||
}, actionAuth.id);
|
this.updateItem({
|
||||||
|
paths: dASameActionAuth.paths.concat(path),
|
||||||
|
}, dASameActionAuth.id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.addItem({
|
||||||
|
paths: [path],
|
||||||
|
relationId: relationId,
|
||||||
|
destEntity: this.props.entity,
|
||||||
|
deActions: actions,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actions.forEach(function (action) { return (0, lodash_1.pull)(deActions_1, action); });
|
// 将path从paths中删除
|
||||||
this.updateItem({
|
actionAuths.forEach(function (ele) {
|
||||||
deActions: deActions_1,
|
var pathIndex = ele.paths.findIndex(function (pathE) { return pathE === path; });
|
||||||
}, actionAuth.id);
|
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 {
|
else {
|
||||||
// 新增actionAuth
|
// 新增actionAuth
|
||||||
(0, assert_1.default)(checked);
|
(0, assert_1.default)(checked);
|
||||||
this.addItem({
|
this.addItem({
|
||||||
path: path,
|
paths: [path],
|
||||||
relationId: relationId,
|
relationId: relationId,
|
||||||
destEntity: this.props.entity,
|
destEntity: this.props.entity,
|
||||||
deActions: actions,
|
deActions: actions,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export default function render(props: WebComponentProps<ED, 'actionAuth', true,
|
||||||
actions: string[];
|
actions: string[];
|
||||||
entity: keyof EntityDict;
|
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;
|
confirm: () => void;
|
||||||
}>): import("react/jsx-runtime").JSX.Element;
|
}>): import("react/jsx-runtime").JSX.Element;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,14 @@ function render(props) {
|
||||||
var e_1, _a;
|
var e_1, _a;
|
||||||
var _b;
|
var _b;
|
||||||
var checked = false, indeterminate = false;
|
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 {
|
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()) {
|
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 = actionAuths_1_1.value;
|
var aa = actionAuthsByPath_1_1.value;
|
||||||
|
// 1.relationId相同,deActions也要相同
|
||||||
// 如果path中存在多对一的情况要使用name进行判断
|
// 如果path中存在多对一的情况要使用name进行判断
|
||||||
if (!aa.$$deleteAt$$ && (aa.relationId === r.id
|
if (!aa.$$deleteAt$$ && (aa.relationId === r.id
|
||||||
|| (record.path.includes('$') && ((_b = aa.relation) === null || _b === void 0 ? void 0 : _b.name) === r.name))) {
|
|| (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 }; }
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
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; }
|
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) {
|
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 target = _a.target;
|
||||||
var checked = target.checked;
|
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); });
|
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], actionAuth);
|
onChange(checked, r.id, path[1], actionAuths2);
|
||||||
} }, { children: r.name })));
|
} }, { children: r.name })));
|
||||||
}) })));
|
}) })));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ exports.default = OakComponent({
|
||||||
var cascadeEntityActions = cascadeEntities.map(function (ele) {
|
var cascadeEntityActions = cascadeEntities.map(function (ele) {
|
||||||
var path = ele.path;
|
var path = ele.path;
|
||||||
var cascadePath = path[1];
|
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 tslib_1.__assign({ actionAuth: actionAuth }, ele);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
|
@ -71,7 +71,7 @@ exports.default = OakComponent({
|
||||||
else {
|
else {
|
||||||
this.addItem({
|
this.addItem({
|
||||||
relationId: this.props.relationId,
|
relationId: this.props.relationId,
|
||||||
path: path[1],
|
paths: [path[1]],
|
||||||
destEntity: path[0],
|
destEntity: path[0],
|
||||||
deActions: actions,
|
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 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 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 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: {
|
data: {
|
||||||
label: string;
|
label: string;
|
||||||
value: any;
|
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,
|
isList: true,
|
||||||
properties: {
|
properties: {
|
||||||
path: '',
|
path: '' as string,
|
||||||
openTip: false,
|
openTip: false,
|
||||||
entity: '' as keyof ED,
|
entity: '' as keyof ED,
|
||||||
onClose: (() => undefined) as () => void,
|
onClose: (() => undefined) as () => void,
|
||||||
|
|
@ -29,7 +29,9 @@ export default OakComponent({
|
||||||
const { path, entity } = this.props;
|
const { path, entity } = this.props;
|
||||||
return {
|
return {
|
||||||
destEntity: entity as string,
|
destEntity: entity as string,
|
||||||
path: path?.replaceAll('(user)', ''),
|
paths: {
|
||||||
|
$contains: path?.replaceAll('(user)', ''),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'#name': 'path',
|
'#name': 'path',
|
||||||
|
|
@ -55,7 +57,9 @@ export default OakComponent({
|
||||||
this.getRelationAndActions();
|
this.getRelationAndActions();
|
||||||
this.addNamedFilter({
|
this.addNamedFilter({
|
||||||
filter: {
|
filter: {
|
||||||
path: path?.replaceAll('(user)', ''),
|
paths: {
|
||||||
|
$contains: path?.replaceAll('(user)', ''),
|
||||||
|
},
|
||||||
destEntity: entity as string,
|
destEntity: entity as string,
|
||||||
},
|
},
|
||||||
'#name': 'path'
|
'#name': 'path'
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export default function render(
|
||||||
relations: EntityDict['relation']['Schema'][],
|
relations: EntityDict['relation']['Schema'][],
|
||||||
actions: string[];
|
actions: string[];
|
||||||
datasource: TableData[];
|
datasource: TableData[];
|
||||||
rows: EntityDict['actionAuth']['Schema'][];
|
rows: ED['actionAuth']['Schema'][];
|
||||||
path: string;
|
path: string;
|
||||||
entity: keyof ED;
|
entity: keyof ED;
|
||||||
openTip: boolean;
|
openTip: boolean;
|
||||||
|
|
@ -67,7 +67,8 @@ export default function render(
|
||||||
label: ele,
|
label: ele,
|
||||||
value: 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 : [];
|
const defaultValue = actionAuth ? actionAuth.deActions : [];
|
||||||
return (
|
return (
|
||||||
<Checkbox.Group
|
<Checkbox.Group
|
||||||
|
|
@ -83,7 +84,7 @@ export default function render(
|
||||||
if (!actionAuth) {
|
if (!actionAuth) {
|
||||||
methods.addItem({
|
methods.addItem({
|
||||||
relationId: row.relationId || '',
|
relationId: row.relationId || '',
|
||||||
path: path2,
|
paths: [path2],
|
||||||
deActions: checkedArr as string[],
|
deActions: checkedArr as string[],
|
||||||
destEntity: entity 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 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 { ED } from "../../../types/AbstractComponent";
|
||||||
import { groupBy } from "oak-domain/lib/utils/lodash";
|
import { groupBy } from "oak-domain/lib/utils/lodash";
|
||||||
import { AuthCascadePath } from "oak-domain/lib/types";
|
import { AuthCascadePath } from "oak-domain/lib/types";
|
||||||
|
|
@ -59,7 +59,7 @@ export default OakComponent({
|
||||||
const [de, p, se] = ele;
|
const [de, p, se] = ele;
|
||||||
|
|
||||||
const actionAuths = data?.filter(
|
const actionAuths = data?.filter(
|
||||||
ele => ele.path === p && ele.destEntity === de
|
ele => ele.destEntity === de
|
||||||
);
|
);
|
||||||
const relations = this.features.cache.get('relation', {
|
const relations = this.features.cache.get('relation', {
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -84,7 +84,19 @@ export default OakComponent({
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// path里含有$
|
// 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
|
||||||
// 分解groupBy 的key
|
// 分解groupBy 的key
|
||||||
const $actionAuthsObject = groupBy($pathActionAuths, 'path');
|
const $actionAuthsObject = groupBy($pathActionAuths, 'path');
|
||||||
|
|
@ -119,7 +131,18 @@ export default OakComponent({
|
||||||
})
|
})
|
||||||
|
|
||||||
// relationId为空字符串 表示为user的actionAuth 也要特殊处理
|
// 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');
|
const $actionAuthsObject2 = groupBy(hasUserActionAuths, 'path');
|
||||||
Object.keys($actionAuthsObject2).forEach((ele) => {
|
Object.keys($actionAuthsObject2).forEach((ele) => {
|
||||||
const entities = ele.split('.');
|
const entities = ele.split('.');
|
||||||
|
|
@ -182,7 +205,7 @@ export default OakComponent({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
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;
|
const { actions } = this.props;
|
||||||
assert(actions && actions.length > 0);
|
assert(actions && actions.length > 0);
|
||||||
// 排除user这种情况
|
// 排除user这种情况
|
||||||
|
|
@ -213,28 +236,63 @@ export default OakComponent({
|
||||||
}
|
}
|
||||||
relationId = relations[0].id!;
|
relationId = relations[0].id!;
|
||||||
}
|
}
|
||||||
if (actionAuth) {
|
if (actionAuths && actionAuths.length) {
|
||||||
const { deActions } = actionAuth;
|
// const { deActions } = actionAuth;
|
||||||
if (checked) {
|
if (checked) {
|
||||||
const deActions2 = union(deActions, actions);
|
const dASameActionAuth = actionAuths.find((ele) => difference(actions, ele.deActions).length === 0);
|
||||||
this.updateItem({
|
// 存在deActions相同,paths push并做去重处理
|
||||||
deActions: deActions2,
|
if (dASameActionAuth) {
|
||||||
}, actionAuth.id);
|
this.updateItem({
|
||||||
|
paths: dASameActionAuth.paths.concat(path),
|
||||||
|
}, dASameActionAuth.id)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.addItem({
|
||||||
|
paths: [path],
|
||||||
|
relationId,
|
||||||
|
destEntity: this.props.entity as string,
|
||||||
|
deActions: actions,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actions.forEach(
|
// 将path从paths中删除
|
||||||
action => pull(deActions, action)
|
actionAuths.forEach((ele) => {
|
||||||
);
|
const pathIndex = ele.paths.findIndex((pathE) => pathE === path);
|
||||||
this.updateItem({
|
if (pathIndex !== -1) {
|
||||||
deActions,
|
const newPaths = [...ele.paths];
|
||||||
}, actionAuth.id);
|
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 {
|
else {
|
||||||
// 新增actionAuth
|
// 新增actionAuth
|
||||||
assert(checked);
|
assert(checked);
|
||||||
this.addItem({
|
this.addItem({
|
||||||
path,
|
paths: [path],
|
||||||
relationId,
|
relationId,
|
||||||
destEntity: this.props.entity as string,
|
destEntity: this.props.entity as string,
|
||||||
deActions: actions,
|
deActions: actions,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ const { Title, Text } = Typography;
|
||||||
import { RowWithActions, WebComponentProps } from '../../../types/Page';
|
import { RowWithActions, WebComponentProps } from '../../../types/Page';
|
||||||
import { AuthCascadePath, EntityDict } from 'oak-domain/lib/types/Entity';
|
import { AuthCascadePath, EntityDict } from 'oak-domain/lib/types/Entity';
|
||||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
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 { useState, useEffect } from 'react';
|
||||||
import ActionAuthListSingle from '../../../components/relation/single';
|
import ActionAuthListSingle from '../../../components/relation/single';
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ export default function render(
|
||||||
entity: keyof EntityDict;
|
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;
|
confirm: () => void;
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|
@ -77,11 +77,17 @@ export default function render(
|
||||||
relations?.map(
|
relations?.map(
|
||||||
(r) => {
|
(r) => {
|
||||||
let checked = false, indeterminate = false;
|
let checked = false, indeterminate = false;
|
||||||
if (actionAuths && actions.length > 0) {
|
// filter出对应path的actionAuth来决定relation的check
|
||||||
for (const aa of actionAuths) {
|
// 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进行判断
|
// 如果path中存在多对一的情况要使用name进行判断
|
||||||
if (!aa.$$deleteAt$$ && (aa.relationId === r.id
|
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;
|
const { deActions } = aa;
|
||||||
checked = difference(actions, deActions).length === 0;
|
checked = difference(actions, deActions).length === 0;
|
||||||
indeterminate = !checked && intersection(actions, deActions).length > 0;
|
indeterminate = !checked && intersection(actions, deActions).length > 0;
|
||||||
|
|
@ -96,11 +102,11 @@ export default function render(
|
||||||
indeterminate={indeterminate}
|
indeterminate={indeterminate}
|
||||||
onChange={({ target }) => {
|
onChange={({ target }) => {
|
||||||
const { checked } = 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)
|
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}
|
{r.name}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ export default OakComponent({
|
||||||
const cascadePath = path[1];
|
const cascadePath = path[1];
|
||||||
|
|
||||||
const actionAuth = data?.find(
|
const actionAuth = data?.find(
|
||||||
ele => ele.path === cascadePath && ele.destEntity === path[0]
|
ele => ele.paths?.includes(cascadePath) && ele.destEntity === path[0]
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
actionAuth,
|
actionAuth,
|
||||||
|
|
@ -78,7 +78,7 @@ export default OakComponent({
|
||||||
else {
|
else {
|
||||||
this.addItem({
|
this.addItem({
|
||||||
relationId: this.props.relationId,
|
relationId: this.props.relationId,
|
||||||
path: path[1],
|
paths: [path[1]],
|
||||||
destEntity: path[0] as string,
|
destEntity: path[0] as string,
|
||||||
deActions: actions,
|
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<
|
export function analyzeAttrMobileForCard<
|
||||||
ED extends EntityDict & BaseEntityDict
|
ED extends EntityDict & BaseEntityDict
|
||||||
|
|
@ -404,7 +412,7 @@ export function analyzeAttrMobileForCard<
|
||||||
entity: keyof ED,
|
entity: keyof ED,
|
||||||
t: (k: string, params?: object) => string,
|
t: (k: string, params?: object) => string,
|
||||||
attributes: OakAbsAttrDef[],
|
attributes: OakAbsAttrDef[],
|
||||||
) {
|
): (data: any[]) => CoverData {
|
||||||
return (data: any[]) => {
|
return (data: any[]) => {
|
||||||
// 遍历用户传入的数据源
|
// 遍历用户传入的数据源
|
||||||
const coverData = data.map((row) => {
|
const coverData = data.map((row) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue