Home > LIB_LibrariesList > registerExtendLibrary
LIB_LibrariesList.registerExtendLibrary() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
注册外部库
签名
typescript
function registerExtendLibrary(
title: string,
libraryFunctions: {
device?: undefined | ILIB_ExtendLibraryDeviceFunctions;
symbol?: undefined | ILIB_ExtendLibrarySymbolFunctions;
footprint?: undefined | ILIB_ExtendLibraryFootprintFunctions;
cbb?: undefined | ILIB_ExtendLibraryCbbFunctions;
model3d?: undefined | ILIB_ExtendLibrary3DModelFunctions;
},
): Promise<string | undefined>;1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
参数名
参数 | 类型 | 描述 |
|---|---|---|
title | string | 标题 |
libraryFunctions | { device?: undefined | ILIB_ExtendLibraryDeviceFunctions; symbol?: undefined | ILIB_ExtendLibrarySymbolFunctions; footprint?: undefined | ILIB_ExtendLibraryFootprintFunctions; cbb?: undefined | ILIB_ExtendLibraryCbbFunctions; model3d?: undefined | ILIB_ExtendLibrary3DModelFunctions } |
返回值
Promise<string | undefined>
库 UUID
备注
注意:本接口仅扩展有效,在独立脚本环境内调用将始终 throw Error
示例
javascript
// 1. 实现外部库的符号数据回调(真实场景中在此对接自己的数据源)
const symbolFunctions = {
// 分类树:库面板左侧的分类目录
getClassificationTree: async () => [
{ name: '电阻', uuid: 'resistor' },
{ name: '电容', uuid: 'capacitor' }
],
// 列表搜索:响应用户的关键字搜索与分页,返回分页结构
getList: async (props) => {
const all = [{ uuid: 'demo_0402', title: '示例符号 0402' }];
return {
count: all.length,
lists: all,
page: props.page || 1,
pageSize: props.pageSize || 10,
totalPage: 1
};
},
// 详情:用户选中条目后获取完整信息
getDetail: async (uuid) => {
return { uuid, title: '示例符号 0402' };
}
};
// 2. 以指定标题注册外部库,挂载符号类型资源
const libUuid = await eda.lib_LibrariesList.registerExtendLibrary('嘉立创示例_外部库', {
symbol: symbolFunctions
});
// 3. 输出注册结果,库面板中即可看到「嘉立创示例_外部库」
console.log('libUuid:', libUuid);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
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