代码拉取完成,页面将自动刷新
/* eslint-disable no-unused-vars */
import Element from '../graphic/Element';
import Group from '../graphic/Group';
import Text from '../graphic/Text';
import * as dataUtil from '../utils/data_structure_util';
class BORect extends Group {
constructor(options = {}) {
super(
dataUtil.merge(
{
title: 'BO_Title',
fields: [], //[{name:"userName",type="String"}]
},
options,
true,
),
);
/**
* @property {String} type
*/
this.type = 'BORect';
this.createFieldComponents();
}
render() {
super.render();
this.createFieldComponents();
}
createFieldComponents() {
this.removeAll();
const text = new Text({
style: {
x: 0,
y: 0,
text: this.title,
textFont: '24px Microsoft Yahei',
textPadding: [10, 10],
textPosition: 'insideLeft',
textFill: '#393e46',
},
draggable: false,
});
this.add(text);
this.fields.forEach((field, index) => {
const text = new Text({
style: {
x: 0,
y: (18 + 10) * (index + 2), //这里的 18 是字号,注意:这里手动计算高度有风险
text: `${field.name} ${field.type}`,
textFont: '18px Microsoft Yahei',
textPadding: [10, 10],
textPosition: 'insideLeft',
textFill: '#393e46',
},
draggable: false,
});
this.add(text);
});
}
/**
* 添加一个字段,name 不能重复
* JSON like Array.
* [{name:"userName",type="String"}]
* @param {*} field
* @returns
*/
addField(field) {
let exists = false;
this.fields &&
this.fields.length &&
this.fields.forEach(item => {
if (item.name === field.name) {
console.error(`Field ${item.name} already exists, add failed.`);
exists = true;
}
});
if (exists) return;
this.fields.push(field);
}
/**
* 根据 name 删掉一个字段
* @param {*} name
* @returns
*/
removeField(name) {
let exist = false;
this.fields &&
this.fields.length &&
this.fields.forEach((item, index) => {
if (item.name === name) {
exist = true;
this.fields.splice(index, 1);
return;
}
});
if (!exist) {
console.warn(`Field ${name} does not exist.`);
return;
}
}
toJSONObject() {
let result = Element.prototype.toJSONObject.call(this);
result.linkable = this.linkable;
result.title = this.title;
result.fields = this.fields;
result.nodeData = { fields: [...this.fields] };
return result;
}
}
export default BORect;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。