tachybase_todo/packages/plugin-full-collections/src/views/index.ts
chenos 6c39ac3538
Develop (#68)
* refactor: fields/views/pages...

* update

* update

* update

* updates

* updates

* add yarn.lock

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* developerMode

* 一大波更新

* bugfix

* fix: hide the sorting settings

* fix: reload menu when menu is updated

* 页面重构

* modify text

* 补充细节

* system settings

* 继续更新补充

* fix: 多级菜单支持

* 无限嵌套

* fix: icon

* 省市区参数调整

* 表单描述、文案调整

* 支持草稿

* 邮箱登录

* 细节补充

* 菜单页面权限初步

* 详情页打开方式

* 菜单父级、草稿问题

* 描述文字

* 详情分组显示

* 状态改为 radio

* 菜单权限

* 跳过省市区 api

* 修复权限数据范围

* onDraft

* 页面跳转

* 修改文案

* 注册、登录

* fix: 权限过滤问题

* 微调上传组件样式

* 0.4.0-alpha.0

* father-build

* remove father-build

* 细节调整
2021-03-16 14:31:54 +08:00

93 lines
2.2 KiB
TypeScript

import * as types from './types';
export const views = new Map();
export function registerView(type: string, value: any) {
views.set(type, value);
}
export function registerViews(values: any) {
Object.keys(values).forEach(type => {
registerView(type, {
...values[type],
type,
});
});
}
registerViews(types);
export function getOptions() {
const options = [];
for (const [type, view] of views) {
options.push({
key: type,
value: type,
label: view.title,
});
}
return options;
}
export function getViewTypeLinkages() {
let xlinkages = [];
for (const [key, item] of views) {
const { linkages = {}, properties = {} } = item;
xlinkages.push({
"type": "value:visible",
"target": `x-${key}-props.*`,
"condition": `{{ $self.value === '${key}' }}`,
});
if (linkages.type) {
xlinkages = xlinkages.concat(linkages.type.map(linkage => {
if (properties[linkage.target]) {
linkage.condition = `{{ $self.value === '${key}' }}`;
linkage.target = `x-${key}-props.${linkage.target}`;
}
return linkage;
}));
}
}
return xlinkages;
}
export function getViewFields() {
const fields = new Map();
fields.set('type', {
interface: 'select',
type: 'string',
name: 'type',
title: '视图类型',
required: true,
dataSource: getOptions(),
createOnly: true,
component: {
type: 'select',
},
linkages: getViewTypeLinkages(),
});
for (const [key, item] of views) {
const { properties = {}, linkages = {} } = item;
Object.keys(properties).forEach(name => {
const property = {
...properties[name],
name,
};
if (!property.type) {
property.type = 'virtual';
}
if (property.type === 'virtual') {
property.name = `x-${key}-props.${name}`;
}
if (linkages[name]) {
property.linkages = linkages[name].map((linkage: any) => {
linkage.target = `x-${key}-props.${linkage.target}`;
return linkage;
});
}
fields.set(`x-${key}-props.${name}`, property);
});
}
return [...fields.values()];
}