2020-12-28 11:38:23 +08:00
|
|
|
|
import { Model, ModelCtor, BELONGSTOMANY } from '@nocobase/database';
|
2021-01-23 17:09:33 +08:00
|
|
|
|
import { get, set, isString } from 'lodash';
|
2020-11-11 20:57:18 +08:00
|
|
|
|
|
2020-11-13 22:01:14 +08:00
|
|
|
|
const transforms = {
|
2020-12-08 14:33:28 +08:00
|
|
|
|
table: async (fields: Model[], context?: any) => {
|
2020-11-13 22:01:14 +08:00
|
|
|
|
const arr = [];
|
|
|
|
|
for (const field of fields) {
|
2020-12-12 16:36:02 +08:00
|
|
|
|
if (!field.get('component.showInTable')) {
|
2020-12-01 20:11:39 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-01-20 08:33:47 +08:00
|
|
|
|
if (!context.listFields.includes(field.id)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-11-13 22:01:14 +08:00
|
|
|
|
arr.push({
|
2020-12-12 16:36:02 +08:00
|
|
|
|
...field.get(),
|
|
|
|
|
sorter: field.get('sortable'),
|
2020-12-13 20:48:48 +08:00
|
|
|
|
dataIndex: field.name.split('.'),
|
2020-11-13 22:01:14 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return arr;
|
|
|
|
|
},
|
2020-12-08 14:33:28 +08:00
|
|
|
|
form: async (fields: Model[], ctx?: any) => {
|
2020-12-13 00:09:25 +08:00
|
|
|
|
const [Field] = ctx.db.getModels(['fields']) as ModelCtor<Model>[];
|
2020-12-08 14:33:28 +08:00
|
|
|
|
const mode = get(ctx.action.params, ['values', 'mode'], ctx.action.params.mode);
|
2020-11-19 21:12:15 +08:00
|
|
|
|
const schema = {};
|
2020-11-13 22:01:14 +08:00
|
|
|
|
for (const field of fields) {
|
2020-12-08 21:19:39 +08:00
|
|
|
|
if (!field.get('component.showInForm')) {
|
2020-12-01 20:11:39 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-01-20 08:33:47 +08:00
|
|
|
|
if (!ctx.listFields.includes(field.id)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-12-08 21:19:39 +08:00
|
|
|
|
const interfaceType = field.get('interface');
|
|
|
|
|
const type = field.get('component.type') || 'string';
|
2020-12-01 20:11:39 +08:00
|
|
|
|
const prop: any = {
|
|
|
|
|
type,
|
2020-11-19 21:12:15 +08:00
|
|
|
|
title: field.title||field.name,
|
2020-12-01 20:11:39 +08:00
|
|
|
|
...(field.component||{}),
|
|
|
|
|
}
|
2021-01-26 16:47:57 +08:00
|
|
|
|
if (field.interface === 'description') {
|
|
|
|
|
field.title && set(prop, 'x-component-props.title', field.title);
|
|
|
|
|
field.get('component.tooltip') && set(prop, 'x-component-props.children', field.get('component.tooltip'));
|
|
|
|
|
}
|
2021-01-20 08:33:47 +08:00
|
|
|
|
if (ctx.formMode === 'update') {
|
|
|
|
|
if (!ctx.updateFields.includes(field.id)) {
|
|
|
|
|
set(prop, 'x-component-props.disabled', true);
|
|
|
|
|
}
|
|
|
|
|
} else if (!ctx.createFields.includes(field.id)) {
|
|
|
|
|
set(prop, 'x-component-props.disabled', true);
|
|
|
|
|
}
|
2020-12-18 18:25:06 +08:00
|
|
|
|
if (field.get('name') === 'interface' && ctx.state.developerMode === false) {
|
|
|
|
|
const dataSource = field.get('dataSource').filter(item => item.key !== 'developerMode');
|
|
|
|
|
field.set('dataSource', dataSource);
|
|
|
|
|
}
|
2021-01-23 14:15:41 +08:00
|
|
|
|
const { values } = ctx.action.params;
|
2021-01-23 17:09:33 +08:00
|
|
|
|
if (field.get('component.type') === 'filter' && get(values, 'associatedKey') && isString(get(values, 'associatedKey'))) {
|
2021-01-13 16:23:15 +08:00
|
|
|
|
const options = Field.parseApiJson(ctx.state.developerMode ? {
|
2021-01-04 13:14:45 +08:00
|
|
|
|
filter: {
|
2020-12-13 00:09:25 +08:00
|
|
|
|
collection_name: get(values, 'associatedKey'),
|
2021-01-13 16:23:15 +08:00
|
|
|
|
},
|
|
|
|
|
sort: 'sort',
|
|
|
|
|
} : {
|
|
|
|
|
filter: {
|
|
|
|
|
collection_name: get(values, 'associatedKey'),
|
|
|
|
|
developerMode: {'$isFalsy': true},
|
2020-12-13 00:09:25 +08:00
|
|
|
|
},
|
2021-01-04 13:14:45 +08:00
|
|
|
|
sort: 'sort',
|
2020-12-13 00:09:25 +08:00
|
|
|
|
});
|
2021-01-04 13:14:45 +08:00
|
|
|
|
const all = await Field.findAll(options);
|
2020-12-13 00:09:25 +08:00
|
|
|
|
set(prop, 'x-component-props.fields', all.filter(f => f.get('filterable')));
|
|
|
|
|
}
|
2020-12-01 20:11:39 +08:00
|
|
|
|
if (type === 'select') {
|
|
|
|
|
prop.type = 'string'
|
|
|
|
|
}
|
2020-12-13 00:09:25 +08:00
|
|
|
|
if (field.get('component.tooltip')) {
|
2021-01-26 15:18:07 +08:00
|
|
|
|
// prop.description = `{{html('${encodeURIComponent(field.get('component.tooltip'))}')}}`;
|
2020-12-13 00:09:25 +08:00
|
|
|
|
}
|
2021-01-06 10:23:40 +08:00
|
|
|
|
if (field.get('name') === 'dataSource') {
|
|
|
|
|
|
|
|
|
|
set(prop, 'x-component-props.operationsWidth', 'auto');
|
|
|
|
|
set(prop, 'x-component-props.bordered', true);
|
|
|
|
|
set(prop, 'x-component-props.className', 'data-source-table');
|
|
|
|
|
const properties = {};
|
|
|
|
|
if (ctx.state.developerMode) {
|
|
|
|
|
Object.assign(properties, {
|
|
|
|
|
value: {
|
|
|
|
|
type: "string",
|
|
|
|
|
title: "值",
|
|
|
|
|
// required: true,
|
|
|
|
|
'x-component-props': {
|
|
|
|
|
bordered: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Object.assign(properties, {
|
|
|
|
|
label: {
|
|
|
|
|
type: "string",
|
|
|
|
|
title: "选项",
|
|
|
|
|
required: true,
|
|
|
|
|
'x-component-props': {
|
|
|
|
|
bordered: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
color: {
|
|
|
|
|
type: "colorSelect",
|
|
|
|
|
title: "颜色",
|
|
|
|
|
'x-component-props': {
|
|
|
|
|
bordered: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
set(prop, 'items.properties', properties);
|
|
|
|
|
}
|
2020-12-13 17:20:54 +08:00
|
|
|
|
if (['number', 'percent'].includes(interfaceType) && field.get('precision')) {
|
|
|
|
|
set(prop, 'x-component-props.step', field.get('precision'));
|
|
|
|
|
}
|
2020-12-13 00:09:25 +08:00
|
|
|
|
if (field.get('required')) {
|
|
|
|
|
prop.required = true;
|
|
|
|
|
}
|
2020-12-08 14:33:28 +08:00
|
|
|
|
if (mode === 'update' && field.get('createOnly')) {
|
|
|
|
|
set(prop, 'x-component-props.disabled', true);
|
|
|
|
|
}
|
2020-12-09 20:46:57 +08:00
|
|
|
|
if (typeof field.get('showTime') === 'boolean') {
|
|
|
|
|
set(prop, 'x-component-props.showTime', field.get('showTime'));
|
|
|
|
|
}
|
2020-12-01 20:11:39 +08:00
|
|
|
|
const defaultValue = get(field.options, 'defaultValue');
|
2020-12-13 17:20:54 +08:00
|
|
|
|
if (typeof defaultValue !== 'undefined') {
|
2020-12-01 20:11:39 +08:00
|
|
|
|
prop.default = defaultValue;
|
|
|
|
|
}
|
2020-12-13 00:09:25 +08:00
|
|
|
|
if (interfaceType === 'boolean') {
|
|
|
|
|
set(prop, 'x-component-props.children', prop.title);
|
|
|
|
|
delete prop.title;
|
|
|
|
|
}
|
2020-12-22 19:12:30 +08:00
|
|
|
|
if (interfaceType === 'linkTo') {
|
|
|
|
|
set(prop, 'x-component-props.associatedName', field.get('collection_name'));
|
|
|
|
|
set(prop, 'x-component-props.target', field.get('target'));
|
|
|
|
|
set(prop, 'x-component-props.multiple', field.get('multiple'));
|
|
|
|
|
set(prop, 'x-component-props.labelField', field.get('labelField'));
|
|
|
|
|
}
|
2020-12-13 20:48:48 +08:00
|
|
|
|
if (interfaceType === 'multipleSelect') {
|
|
|
|
|
set(prop, 'x-component-props.mode', 'multiple');
|
|
|
|
|
}
|
2020-12-20 12:52:15 +08:00
|
|
|
|
if (interfaceType === 'subTable' && field.get('target')) {
|
|
|
|
|
set(prop, 'x-component-props.target', field.get('target'));
|
|
|
|
|
// resourceName
|
|
|
|
|
}
|
2020-12-13 17:20:54 +08:00
|
|
|
|
if (['radio', 'select', 'multipleSelect', 'checkboxes'].includes(interfaceType)) {
|
2020-12-18 18:25:06 +08:00
|
|
|
|
prop.enum = field.get('dataSource');
|
2020-12-01 20:11:39 +08:00
|
|
|
|
}
|
|
|
|
|
schema[field.name] = {
|
2021-01-25 10:22:24 +08:00
|
|
|
|
id: field.id,
|
2020-12-01 20:11:39 +08:00
|
|
|
|
...prop,
|
2020-11-19 21:12:15 +08:00
|
|
|
|
};
|
2020-11-13 22:01:14 +08:00
|
|
|
|
}
|
2020-11-19 21:12:15 +08:00
|
|
|
|
return schema;
|
2020-11-13 22:01:14 +08:00
|
|
|
|
},
|
2020-12-08 14:33:28 +08:00
|
|
|
|
details: async (fields: Model[], context?: any) => {
|
2020-11-13 22:01:14 +08:00
|
|
|
|
const arr = [];
|
|
|
|
|
for (const field of fields) {
|
2020-12-01 20:11:39 +08:00
|
|
|
|
if (!get(field.component, 'showInDetail')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-01-20 08:33:47 +08:00
|
|
|
|
if (!context.listFields.includes(field.id)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-12-20 12:52:15 +08:00
|
|
|
|
const props = {};
|
|
|
|
|
if (field.get('interface') === 'subTable') {
|
2021-01-08 08:52:55 +08:00
|
|
|
|
const children = await field.getChildren({
|
|
|
|
|
order: [['sort', 'asc']],
|
|
|
|
|
});
|
2020-12-20 12:52:15 +08:00
|
|
|
|
props['children'] = children.map(child => ({...child.toJSON(), dataIndex: child.name.split('.')}))
|
|
|
|
|
}
|
2020-11-13 22:01:14 +08:00
|
|
|
|
arr.push({
|
|
|
|
|
...field.toJSON(),
|
2020-12-20 12:52:15 +08:00
|
|
|
|
...props,
|
2020-11-13 22:01:14 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return arr;
|
|
|
|
|
},
|
2020-12-08 21:19:39 +08:00
|
|
|
|
filter: async (fields: Model[], ctx?: any) => {
|
|
|
|
|
const properties = {
|
|
|
|
|
filter: {
|
|
|
|
|
type: 'filter',
|
|
|
|
|
'x-component-props': {
|
2021-01-20 08:33:47 +08:00
|
|
|
|
fields: fields.filter(field => ctx.listFields.includes(field.id) && field.get('filterable')),
|
2020-12-08 21:19:39 +08:00
|
|
|
|
},
|
2020-12-13 00:09:25 +08:00
|
|
|
|
},
|
2020-12-08 21:19:39 +08:00
|
|
|
|
}
|
|
|
|
|
return properties;
|
|
|
|
|
},
|
2020-11-13 22:01:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-11-11 20:57:18 +08:00
|
|
|
|
export default async (ctx, next) => {
|
2020-12-28 11:38:23 +08:00
|
|
|
|
const { resourceName, resourceKey, values = {} } = ctx.action.params;
|
2020-12-08 21:19:39 +08:00
|
|
|
|
const [View, Collection, Field, Action] = ctx.db.getModels(['views', 'collections', 'fields', 'actions']) as ModelCtor<Model>[];
|
2021-01-26 15:18:07 +08:00
|
|
|
|
const collection = await Collection.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
name: resourceName,
|
|
|
|
|
},
|
|
|
|
|
});
|
2020-12-08 21:19:39 +08:00
|
|
|
|
let view = await View.findOne(View.parseApiJson({
|
2020-11-11 20:57:18 +08:00
|
|
|
|
filter: {
|
|
|
|
|
collection_name: resourceName,
|
|
|
|
|
name: resourceKey,
|
|
|
|
|
},
|
2020-11-13 22:01:14 +08:00
|
|
|
|
// fields: {
|
|
|
|
|
// appends: ['actions', 'fields'],
|
|
|
|
|
// },
|
2020-11-11 20:57:18 +08:00
|
|
|
|
}));
|
2020-12-28 11:38:23 +08:00
|
|
|
|
let throughName;
|
2021-01-20 08:33:47 +08:00
|
|
|
|
const { resourceKey: resourceKey2, associatedName, resourceFieldName, associatedKey } = values;
|
2021-01-26 15:18:07 +08:00
|
|
|
|
// TODO: 暂时不处理 developerMode 和 internal 的情况
|
2021-01-27 14:02:46 +08:00
|
|
|
|
const permissions = (await ctx.ac.isRoot() || collection.developerMode || collection.internal)
|
2021-01-26 15:18:07 +08:00
|
|
|
|
? await ctx.ac.getRootPermissions()
|
|
|
|
|
: await ctx.ac.can(resourceName).permissions();
|
2021-01-20 08:33:47 +08:00
|
|
|
|
ctx.listFields = [];
|
|
|
|
|
ctx.createFields = [];
|
|
|
|
|
ctx.updateFields = [];
|
|
|
|
|
ctx.allowedActions = [];
|
|
|
|
|
for (const action of permissions.actions) {
|
|
|
|
|
ctx.allowedActions.push(action.name);
|
|
|
|
|
}
|
2021-01-22 10:18:02 +08:00
|
|
|
|
// console.log(ctx.allowedActions);
|
2021-01-20 08:33:47 +08:00
|
|
|
|
for (const permissionField of permissions.fields) {
|
|
|
|
|
const pfc = permissionField.actions;
|
|
|
|
|
if (pfc.includes(`${resourceName}:list`)) {
|
|
|
|
|
ctx.listFields.push(permissionField.field_id);
|
|
|
|
|
}
|
|
|
|
|
if (pfc.includes(`${resourceName}:create`)) {
|
|
|
|
|
ctx.createFields.push(permissionField.field_id);
|
|
|
|
|
}
|
|
|
|
|
if (pfc.includes(`${resourceName}:update`)) {
|
|
|
|
|
ctx.updateFields.push(permissionField.field_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-22 10:18:02 +08:00
|
|
|
|
// console.log({
|
2021-01-27 14:02:46 +08:00
|
|
|
|
// a: (await ctx.ac.isRoot() || collection.developerMode || collection.internal),
|
2021-01-22 10:18:02 +08:00
|
|
|
|
// listFields: ctx.listFields,
|
|
|
|
|
// createFields: ctx.createFields,
|
|
|
|
|
// updateFields: ctx.updateFields,
|
|
|
|
|
// })
|
2020-12-28 11:38:23 +08:00
|
|
|
|
if (associatedName) {
|
|
|
|
|
const table = ctx.db.getTable(associatedName);
|
|
|
|
|
const resourceField = table.getField(resourceFieldName);
|
|
|
|
|
if (resourceField instanceof BELONGSTOMANY) {
|
2021-01-07 08:57:44 +08:00
|
|
|
|
// console.log({associatedName, resourceField});
|
2020-12-28 11:38:23 +08:00
|
|
|
|
throughName = resourceField.options.through;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-08 21:19:39 +08:00
|
|
|
|
if (!view) {
|
|
|
|
|
// 如果不存在 view,新建一个
|
|
|
|
|
view = new View({type: resourceKey, template: 'FilterForm'});
|
|
|
|
|
}
|
2021-01-26 15:18:07 +08:00
|
|
|
|
|
2021-01-04 13:14:45 +08:00
|
|
|
|
// const where: any = {
|
|
|
|
|
// developerMode: ctx.state.developerMode,
|
|
|
|
|
// }
|
2021-01-13 16:23:15 +08:00
|
|
|
|
const filter: any = {}
|
|
|
|
|
if (!ctx.state.developerMode) {
|
|
|
|
|
filter.developerMode = {'$isFalsy': true}
|
2020-12-13 00:09:25 +08:00
|
|
|
|
}
|
|
|
|
|
if (!view.get('draggable')) {
|
2021-01-04 13:14:45 +08:00
|
|
|
|
filter.type = {
|
|
|
|
|
not: 'sort',
|
2020-12-13 00:09:25 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2021-01-04 13:14:45 +08:00
|
|
|
|
const fieldOptions = Field.parseApiJson({
|
|
|
|
|
filter,
|
|
|
|
|
sort: 'sort',
|
2020-11-19 21:12:15 +08:00
|
|
|
|
});
|
2021-01-04 13:14:45 +08:00
|
|
|
|
let fields = await collection.getFields(fieldOptions);
|
2020-12-28 11:38:23 +08:00
|
|
|
|
fields = fields.filter(field => {
|
|
|
|
|
if (field.get('interface') === 'linkTo') {
|
|
|
|
|
if (throughName && throughName === field.get('through')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
})
|
2021-01-13 16:23:15 +08:00
|
|
|
|
const options = Action.parseApiJson(ctx.state.developerMode ? {
|
|
|
|
|
filter: {},
|
|
|
|
|
sort: 'sort',
|
|
|
|
|
} : {
|
2021-01-04 13:14:45 +08:00
|
|
|
|
filter: {
|
2021-01-13 16:23:15 +08:00
|
|
|
|
developerMode: {'$isFalsy': true},
|
2020-12-08 14:33:28 +08:00
|
|
|
|
},
|
2021-01-04 13:14:45 +08:00
|
|
|
|
sort: 'sort',
|
2020-11-19 21:12:15 +08:00
|
|
|
|
});
|
2021-01-04 13:14:45 +08:00
|
|
|
|
const actions = await collection.getActions(options);
|
2020-12-15 22:44:20 +08:00
|
|
|
|
let actionNames = view.get('actionNames') || [];
|
2021-01-13 16:23:15 +08:00
|
|
|
|
if (actionNames.length === 0 && resourceKey !== 'permissionTable') {
|
2020-12-15 22:44:20 +08:00
|
|
|
|
actionNames = ['filter', 'create', 'destroy'];
|
|
|
|
|
}
|
2021-01-07 09:31:26 +08:00
|
|
|
|
const defaultTabs = await collection.getTabs({
|
|
|
|
|
where: {
|
|
|
|
|
default: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
view.setDataValue('defaultTabName', get(defaultTabs, [0, 'name']));
|
2020-12-28 11:11:49 +08:00
|
|
|
|
if (view.get('type') === 'table') {
|
2020-12-13 20:48:48 +08:00
|
|
|
|
view.setDataValue('rowViewName', 'form');
|
|
|
|
|
}
|
2021-01-04 13:14:45 +08:00
|
|
|
|
if (view.get('type') === 'calendar') {
|
|
|
|
|
view.setDataValue('template', 'Calendar');
|
|
|
|
|
view.setDataValue('rowViewName', 'form');
|
|
|
|
|
}
|
2020-12-08 21:19:39 +08:00
|
|
|
|
if (view.get('updateViewName')) {
|
|
|
|
|
view.setDataValue('rowViewName', view.get('updateViewName'));
|
2020-11-11 20:57:18 +08:00
|
|
|
|
}
|
2021-01-22 14:54:08 +08:00
|
|
|
|
if (!view.get('template')) {
|
|
|
|
|
if (view.get('type') === 'table') {
|
|
|
|
|
view.setDataValue('template', 'Table');
|
|
|
|
|
} else if (view.get('type') === 'calendar') {
|
|
|
|
|
view.setDataValue('template', 'Calendar');
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-13 00:09:25 +08:00
|
|
|
|
// view.setDataValue('viewCollectionName', view.collection_name);
|
2020-12-08 21:19:39 +08:00
|
|
|
|
let title = collection.get('title');
|
|
|
|
|
const mode = get(ctx.action.params, ['values', 'mode'], ctx.action.params.mode);
|
2021-01-20 08:33:47 +08:00
|
|
|
|
ctx.formMode = mode;
|
2020-12-08 21:19:39 +08:00
|
|
|
|
if (mode === 'update') {
|
|
|
|
|
title = `编辑${title}`;
|
|
|
|
|
} else {
|
2020-12-24 08:16:18 +08:00
|
|
|
|
title = `新增${title}`;
|
2020-12-08 21:19:39 +08:00
|
|
|
|
}
|
2020-12-21 14:19:31 +08:00
|
|
|
|
const viewType = view.get('type');
|
2020-12-21 10:41:12 +08:00
|
|
|
|
const actionDefaultParams:any = {};
|
2020-12-29 11:31:19 +08:00
|
|
|
|
if (resourceName === 'collections') {
|
|
|
|
|
actionDefaultParams.sort = ['sort'];
|
|
|
|
|
}
|
2020-12-31 21:04:03 +08:00
|
|
|
|
if (view.filter) {
|
|
|
|
|
actionDefaultParams.filter = view.filter;
|
|
|
|
|
}
|
2020-12-24 08:16:18 +08:00
|
|
|
|
const appends = [];
|
2020-12-28 11:38:23 +08:00
|
|
|
|
|
2020-12-24 08:16:18 +08:00
|
|
|
|
for (const field of fields) {
|
2021-01-07 09:31:26 +08:00
|
|
|
|
if (!['subTable', 'linkTo', 'attachment', 'createdBy', 'updatedBy'].includes(field.get('interface'))) {
|
2020-12-24 08:16:18 +08:00
|
|
|
|
continue;
|
2020-12-21 14:19:31 +08:00
|
|
|
|
}
|
2020-12-24 08:16:18 +08:00
|
|
|
|
let showInKey;
|
|
|
|
|
switch (viewType) {
|
|
|
|
|
case 'table':
|
|
|
|
|
showInKey = 'showInTable';
|
|
|
|
|
break;
|
|
|
|
|
case 'form':
|
|
|
|
|
showInKey = 'showInForm';
|
|
|
|
|
break;
|
|
|
|
|
case 'details':
|
|
|
|
|
showInKey = 'showInDetail';
|
|
|
|
|
break;
|
2020-12-21 14:19:31 +08:00
|
|
|
|
}
|
2020-12-24 08:16:18 +08:00
|
|
|
|
if (showInKey && field.get(`component.${showInKey}`)) {
|
|
|
|
|
appends.push(field.name);
|
|
|
|
|
if (field.get('interface') === 'attachment') {
|
|
|
|
|
appends.push(`${field.name}.storage`);
|
|
|
|
|
}
|
2020-12-30 15:01:28 +08:00
|
|
|
|
if (field.get('interface') === 'subTable') {
|
|
|
|
|
const children = await field.getChildren();
|
2021-01-06 17:38:08 +08:00
|
|
|
|
// console.log(children);
|
2020-12-30 15:01:28 +08:00
|
|
|
|
for (const child of children) {
|
|
|
|
|
if (!['subTable', 'linkTo', 'attachment', 'updatedBy', 'createdBy'].includes(child.get('interface'))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
console.log(child.name);
|
|
|
|
|
appends.push(`${field.name}.${child.name}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-21 14:19:31 +08:00
|
|
|
|
}
|
2020-12-24 08:16:18 +08:00
|
|
|
|
}
|
|
|
|
|
actionDefaultParams['fields[appends]'] = appends.join(',');
|
2021-01-13 16:23:15 +08:00
|
|
|
|
if (resourceFieldName === 'pages' && resourceKey === 'permissionTable') {
|
|
|
|
|
ctx.body = {
|
|
|
|
|
...view.get(),
|
|
|
|
|
title,
|
|
|
|
|
actionDefaultParams,
|
|
|
|
|
original: fields,
|
|
|
|
|
disableRowClick: true,
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
"title": "页面",
|
|
|
|
|
"name": "title",
|
|
|
|
|
"interface": "string",
|
|
|
|
|
"type": "string",
|
|
|
|
|
"parent_id": null,
|
|
|
|
|
"required": true,
|
|
|
|
|
"developerMode": false,
|
|
|
|
|
"component": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"className": "drag-visible",
|
|
|
|
|
"showInForm": true,
|
|
|
|
|
"showInTable": true,
|
|
|
|
|
"showInDetail": true
|
|
|
|
|
},
|
|
|
|
|
"dataIndex": ["title"]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"title": "访问权限",
|
2021-01-20 08:33:47 +08:00
|
|
|
|
"name": "accessible",
|
2021-01-13 16:23:15 +08:00
|
|
|
|
"interface": "boolean",
|
|
|
|
|
"type": "boolean",
|
|
|
|
|
"parent_id": null,
|
|
|
|
|
"required": true,
|
|
|
|
|
"editable": true,
|
|
|
|
|
"resource": 'roles.pages',
|
|
|
|
|
"developerMode": false,
|
|
|
|
|
"component": {
|
|
|
|
|
"type": "boolean",
|
|
|
|
|
"showInTable": true,
|
|
|
|
|
},
|
2021-01-20 08:33:47 +08:00
|
|
|
|
"dataIndex": ["accessible"]
|
2021-01-13 16:23:15 +08:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
} else if (resourceFieldName === 'collections' && resourceKey === 'permissionTable') {
|
|
|
|
|
ctx.body = {
|
|
|
|
|
...view.get(),
|
|
|
|
|
title,
|
|
|
|
|
actionDefaultParams,
|
|
|
|
|
original: fields,
|
|
|
|
|
rowKey: 'name',
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
"title": "数据表名称",
|
|
|
|
|
"name": "title",
|
|
|
|
|
"interface": "string",
|
|
|
|
|
"type": "string",
|
|
|
|
|
"parent_id": null,
|
|
|
|
|
"required": true,
|
|
|
|
|
"developerMode": false,
|
|
|
|
|
"component": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"className": "drag-visible",
|
|
|
|
|
"showInForm": true,
|
|
|
|
|
"showInTable": true,
|
|
|
|
|
"showInDetail": true
|
|
|
|
|
},
|
|
|
|
|
"dataIndex": ["title"]
|
2021-01-22 10:18:02 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"title": "描述",
|
|
|
|
|
"name": "permissions[0].description",
|
|
|
|
|
"interface": "string",
|
|
|
|
|
"type": "string",
|
|
|
|
|
"parent_id": null,
|
|
|
|
|
"required": true,
|
|
|
|
|
"developerMode": false,
|
|
|
|
|
"component": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"className": "drag-visible",
|
|
|
|
|
"showInForm": true,
|
|
|
|
|
"showInTable": true,
|
|
|
|
|
"showInDetail": true
|
|
|
|
|
},
|
|
|
|
|
"dataIndex": ["permissions", 0, 'description']
|
2021-01-13 16:23:15 +08:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
};
|
2021-01-14 10:52:20 +08:00
|
|
|
|
} else if (
|
|
|
|
|
(resourceFieldName === 'collections' && resourceKey === 'permissionForm')
|
|
|
|
|
||
|
|
|
|
|
(resourceFieldName === 'roles' && resourceKey === 'permissionForm')
|
|
|
|
|
) {
|
2021-01-13 16:23:15 +08:00
|
|
|
|
ctx.body = {
|
|
|
|
|
...view.get(),
|
|
|
|
|
title,
|
|
|
|
|
actionDefaultParams,
|
|
|
|
|
original: fields,
|
|
|
|
|
fields: {
|
|
|
|
|
actions: {
|
|
|
|
|
type: 'permissions.actions',
|
|
|
|
|
title: '数据操作权限',
|
|
|
|
|
'x-linkages': [
|
|
|
|
|
{
|
|
|
|
|
type: "value:schema",
|
|
|
|
|
target: "actions",
|
|
|
|
|
schema: {
|
|
|
|
|
"x-component-props": {
|
2021-01-14 10:52:20 +08:00
|
|
|
|
resourceKey: resourceFieldName === 'roles' ? associatedKey : "{{ $form.values && $form.values.resourceKey }}"
|
2021-01-13 16:23:15 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'x-component-props': {
|
|
|
|
|
dataSource: [],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
fields: {
|
|
|
|
|
type: 'permissions.fields',
|
|
|
|
|
title: '字段权限',
|
|
|
|
|
'x-linkages': [
|
|
|
|
|
{
|
|
|
|
|
type: "value:schema",
|
|
|
|
|
target: "fields",
|
|
|
|
|
schema: {
|
|
|
|
|
"x-component-props": {
|
2021-01-14 10:52:20 +08:00
|
|
|
|
resourceKey: resourceFieldName === 'roles' ? associatedKey : "{{ $form.values && $form.values.resourceKey }}"
|
2021-01-13 16:23:15 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'x-component-props': {
|
|
|
|
|
dataSource: [],
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tabs: {
|
|
|
|
|
type: 'permissions.tabs',
|
|
|
|
|
title: '标签页权限',
|
|
|
|
|
'x-linkages': [
|
|
|
|
|
{
|
|
|
|
|
type: "value:schema",
|
|
|
|
|
target: "tabs",
|
|
|
|
|
schema: {
|
|
|
|
|
"x-component-props": {
|
2021-01-14 10:52:20 +08:00
|
|
|
|
resourceKey: resourceFieldName === 'roles' ? associatedKey : "{{ $form.values && $form.values.resourceKey }}"
|
2021-01-13 16:23:15 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'x-component-props': {
|
|
|
|
|
dataSource: [],
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: 'textarea',
|
|
|
|
|
title: '权限描述',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
} else {
|
2021-01-20 08:33:47 +08:00
|
|
|
|
let allowedUpdate = false;
|
2021-01-22 10:18:02 +08:00
|
|
|
|
if (view.type === 'details' && await ctx.ac.can(resourceName).act('update').one(resourceKey2)) {
|
2021-01-20 08:33:47 +08:00
|
|
|
|
allowedUpdate = true;
|
|
|
|
|
}
|
2021-01-13 16:23:15 +08:00
|
|
|
|
ctx.body = {
|
|
|
|
|
...view.get(),
|
|
|
|
|
title,
|
|
|
|
|
actionDefaultParams,
|
|
|
|
|
original: fields,
|
|
|
|
|
fields: await (transforms[view.type]||transforms.table)(fields, ctx),
|
2021-01-20 08:33:47 +08:00
|
|
|
|
actions: actions.filter(action => {
|
|
|
|
|
if (view.type === 'details' && action.name === 'update') {
|
|
|
|
|
return allowedUpdate;
|
|
|
|
|
}
|
|
|
|
|
return actionNames.includes(action.name) && ctx.allowedActions.includes(`${resourceName}:${action.name}`);
|
|
|
|
|
}).map(action => ({
|
2021-01-13 16:23:15 +08:00
|
|
|
|
...action.toJSON(),
|
|
|
|
|
...action.options,
|
|
|
|
|
// viewCollectionName: action.collection_name,
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-11-11 20:57:18 +08:00
|
|
|
|
await next();
|
|
|
|
|
};
|