【乐吾乐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);
相关推荐
AI袋鼠帝6 小时前
火爆全网的Seedance2.0 十万人排队,我2分钟就用上了
前端
IT_陈寒6 小时前
React Hooks闭包陷阱:你以为的state可能早就过期了
前端·人工智能·后端
Jenlybein6 小时前
快速了解熟悉 Vite ,即刻上手使用
前端·javascript·vite
小码哥_常6 小时前
安卓开发避坑指南:全局异常捕获与优雅处理实战
前端
lihaozecq6 小时前
我用 1 天的时间 vibe coding 了一个多人德州扑克游戏
前端·react.js·ai编程
momo061176 小时前
AI Skill是什么?
前端·ai编程
言萧凡_CookieBoty6 小时前
用 AI 搞定用户系统:Superpowers 工程化开发教程
前端·ai编程
小小小小宇6 小时前
Go 语言协程
前端
牛奶6 小时前
5MB vs 4KB vs 无限大:浏览器存储谁更强?
前端·浏览器·indexeddb
牛奶6 小时前
setTimeout设为0就马上执行?JS异步背后的秘密
前端·性能优化·promise