切换主题
快速开始
Light Components 的每个物料都以标准 Web Component 发布,同时携带一份描述能力契约的 manifest.json。这让组件能够跨框架运行,也让编辑器与文档站读取同一份元数据。
环境要求
- Node.js 18 或更高版本
- Vue 3
- Vite 5 或兼容版本
安装构建插件
在物料项目中安装平台 SDK:
bash
npm install -D @platform/vite-plugin-component1
当前工作区也可以通过本地依赖接入:
json
{
"devDependencies": {
"@platform/vite-plugin-component": "file:../light-platform-sdk"
}
}1
2
3
4
5
2
3
4
5
配置组件契约
在 vite.config.ts 中声明组件名称、说明和公开能力。这里的数据既供低代码编辑器使用,也会成为在线文档的 API 数据源。
ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import platformPlugin from '@platform/vite-plugin-component'
export default defineConfig({
plugins: [
vue({ customElement: true }),
platformPlugin({
componentName: 'status-card',
title: '状态卡片',
description: '展示业务指标与当前状态',
propsConfig: [
{
name: 'title',
type: 'string',
title: '卡片标题',
defaultValue: '',
},
{
name: 'status',
type: 'string',
title: '状态',
defaultValue: 'normal',
options: [
{ label: '正常', value: 'normal' },
{ label: '告警', value: 'warning' },
],
},
],
eventsConfig: [
{ eventName: 'status-card:click', title: '点击卡片' },
],
}),
],
})1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
构建物料
bash
npm run build1
构建完成后会得到:
text
dist/
├─ index.js # 注册自定义元素的组件脚本
└─ manifest.json # 组件能力契约1
2
3
2
3
在页面中使用
html
<script type="module" src="/materials/status-card/index.js"></script>
<status-card title="设备在线率" status="normal"></status-card>1
2
3
2
3
组件名称
组件标识符必须与 manifest.json 中的 componentName 完全一致,否则编辑器和运行时无法正确加载物料。