【乐吾乐2D可视化组态编辑器】表单控件

表单控件

乐吾乐2D可视化组态编辑器demo:https://2d.le5le.com/

导入使用

复制代码
import { formPens ,formPath2DPens} from '@meta2d/form-diagram';
meta2d.registerCanvasDraw(formPens());
meta2d.register(formPath2DPens());//版本>=1.0.9

time 时间显示

form-diagram1.0.9版本以后新增

|------------|---------|-----------------------------------------------------------------|
| 名称 | 类型 | 描述 |
| fillZero | boolean | 是否填充0,例如"1"填充为"01" |
| timeFormat | string | 显示格式,语法遵循模版字符串,可以拿到year、month、day、hours、minutes、seconds、week参数。 |

复制代码
const time = {
  name: "time",
  x: 100,
  y: 100,
  width: 300,
  height: 40,
  text: '当前时间',
  lineWidth: 0,
  fillZero: true,
  timeFormat:
    '`${year}-${month}-${day} ${hours}:${minutes}:${seconds} 星期${week}`',
          
};

meta2d.addPens([time]);

radio 单选框

|----------------|------------|-------------------------------------------------------------------|
| 名称 | 类型 | 描述 |
| direction | string | 单选框的排列方向('vertical'|'horizontal') |
| optionInterval | number | 单选框选项间的间距(默认 20,仅针对垂直分布) |
| optionHeight | number | 单选框所占高度(默认 20,仅针对垂直分布) |
| checked | string | 选中项(与text对应) |
| options | object[] | 选项值,格式: { text:string,//显示文本 isForbidden:boolean,//是否禁用 ...样式属性 } |

复制代码
const radio = {
  name: "radio",
  x: 100,
  y: 100,
  width: 150,
  height: 100,
  direction: "vertical",
  checked: '选项二',
  options: [
    { text: "选项一", background: "#ff0000" },
    { text: "选项二", background: "#00ff00" },
    { text: "选项三", background: "#0000ff", isForbidden: true },
  ],
};

meta2d.addPens([radio]);

checkbox 复选框

|-------------|---------|------|
| 名称 | 类型 | 描述 |
| isForbidden | boolean | 是否禁用 |
| checked | boolean | 是否选中 |
| value | string | 选项值 |

复制代码
const checkbox = {
  name: "checkbox",
  x: 100,
  y: 100,
  width: 30,
  height: 30,
  checked: true,
  // isForbidden: true,
  value: '选项一',
};

meta2d.addPens([checkbox]);

switch 开关

|-----------------|---------|-----------|
| 名称 | 类型 | 描述 |
| checked | boolean | 是否打开 |
| offColor | string | 关闭时背景颜色 |
| onColor | string | 打开时背景颜色 |
| disable | boolean | 是否禁用 |
| disableOffColor | string | 关闭时禁用背景颜色 |
| disableOnColor | string | 打开时禁用背景颜色 |

复制代码
const lSwitch = {
  name: "switch",
  x: 100,
  y: 100,
  height: 30,
  width: 60,
  checked: false,
  offColor: "#BFBFBF",
  onColor: "#1890ff",
  disableOffColor: "#E5E5E5",
  disableOnColor: "#A3D3FF",
  //disable: true,
};

meta2d.addPen(lSwitch);

slider 滑动输入条

【注意】当滑动条禁止移动时(locked=1),才允许拖动滑块。

|-----------|--------|--------------|
| 名称 | 类型 | 描述 |
| barHeight | number | 滑动条高度 |
| textWidth | number | 文字区域宽度(靠右对齐) |
| min | number | 最小值 |
| max | number | 最大值 |
| unit | string | 单位 |
| value | number | 当前值 |

复制代码
const slider = {
  name: "slider",
  x: 100,
  y: 100,
  width: 300,
  height: 30,
  value: 10,
  textWidth: 50,
  barHeight: 4,
  min: 0,
  max: 100,
  color: "#1890ff",
  background: "#D4D6D9",
  textColor: "#222222",
  unit: "%",
};

meta2d.addPen(slider);

button 按钮

按钮本质上和 rectangle 一样,但为了达到按钮的效果,我们需要配置一些样式属性。

复制代码
const button = {
  name: "rectangle",
  x: 100,
  y: 100,
  width: 80,
  height: 30,
  borderRadius: 0.2,
  text: "按钮",
  background: "#1890ff",
  color: "#1890ff",
  textColor: "#ffffff",
  activeBackground: "#40a9ff", //选中
  activeColor: "#40a9ff",
  activeTextColor: "#ffffff",
  hoverBackground: "#40a9ff", //鼠标经过
  hoverColor: "#40a9ff",
  hoverTextColor: "#ffffff",
};

meta2d.addPen(button);

输入框

复制代码
const input = {
  x: 100,
  y: 100,
  height: 50,
  width: 200,
  input: true,
  name: "rectangle",
  borderRadius: 0.05,
  ellipsis: true,
  text: "输入数据",
  textAlign: "left",
  color: "#D9D9D9FF",
  textColor: "#000000FF",
  hoverTextColor: "#000000FF",
  activeTextColor: "#000000FF",
  textLeft: 10,
};

meta2d.addPen(input);

选择器

复制代码
const select = {
  x: 100,
  y: 100,
  height: 50,
  width: 200,
  name: "rectangle",
  borderRadius: 0.05,
  ellipsis: true,
  text: "选项1",
  textAlign: "left",
  color: "#D9D9D9FF",
  textColor: "#000000FF",
  hoverTextColor: "#000000FF",
  activeTextColor: "#000000FF",
  textLeft: 10,
  // dropdownList: ["选项1", "选项2", "选项3"],
  dropdownList: [
    { text: "选项1", background: "#ff0000" },
    { text: "选项2", background: "#00ff00" },
    { text: "选项3", background: "#0000ff" },
  ],
};

meta2d.addPen(select);
相关推荐
桃子不吃李子4 分钟前
前端学习10—Ajax
前端·学习·ajax
狂炫一碗大米饭15 分钟前
快刷每日面经😋
前端·面试
涵信22 分钟前
第二节:React 基础篇-受控组件 vs 非受控组件
前端·javascript·react.js
二月垂耳兔79838 分钟前
jQueryHTML与插件
前端·jquery
quo-te1 小时前
AJAX简介
前端·ajax·okhttp
bingbingyihao1 小时前
通过代码获取接口文档工具
开发语言·前端·javascript
月伤591 小时前
JS中Map对象与数组的相互转换
前端·javascript·html
SEO_juper3 小时前
解密 URL 参数:如何利用它们提升网站性能和用户体验
前端·javascript·ux·seo·url·数字营销·谷歌seo
nuIl3 小时前
让 Cursor 帮你把想法落地
前端·ai编程
去伪存真3 小时前
看我如何破解api接口文档定义空白, 还不想手动写接口TS类型定义的困局
前端·typescript