# Visual editing supports third party component library display capabilities
For the existing Weixin Mini Program component library, the tool visualization adds new capabilities.Simply place the component library package in the miniprogram_npm directory and configure the corresponding profile interface in the component library root directory The tool visually parses and adds the component information of the component library, making it drag-and-drop to the corresponding pages WXML and JSON.
# Operating environment
1.05.2206242 or above Developer Tools
# New operational processes
Tool visualization of third-party component library access, need to add a JSON configuration to manage
# 1. New configuration
- Create a new [[] in the root directory of the component library
.wechatide.ib.json, need packaged miniprogram_root
# 2. Dxplaination of configuration composition
# 2.1 Main structural components and menu
..Inside wechatide-ib.jsonis a json object containing the followingkey
export interface IIBComponentLibConfig {
key: string // 组件库标识,如 tdesign
label: string // 可读名称,如 "Tdesign 组件"
// 组件列表说明配置
components: {
[propName: string]: IIBComponentLibConfigComponent
};
// 菜单相关
menu: IIBComponentLibConfigMenu[], // 组件面板菜单情况
common: IIBComponentLibConfigCommon // @TODO 通用属性和配置
}
# 2.2 Component definition: IIBComponentLibConfigComponent
The tool gets basic information about defining components from the contents of components
export interface IIBComponentLibConfigComponent {
key?: string; // 组件标签名称, 如 "t-button", 应该和组件列表的 key 是一样的,工具会默认补齐,可不配置
label: string; // 组件可读名称,如 "按钮"
icon: string; // 组件 icon 示意图、本地或者网络地址,建议尺寸为 200 * 100, 如 "../../xxx.png" 或者 “https://xxxx/xx.png”
topIcon?: string // 组件如果需要放在头部,本地或者网络地址,建议尺寸 44 * 44, 内边距为 10, 如 "../../xxx.png" 或者 “https://xxxx/xx.png”
events?: IIBComponentLibConfigEvent[]; // 事件列表
properties?: IIBComponentLibConfigProperty[]; // 属性列表
tpl?: string; // 自定义组件模块代码,为空则用 key 作为标签名生成默认 tpl `<$key></$key>`
path?: string, // 原子组件的相对 npm 根目录的位置
require?: {
[propName: string]: string
} // 组件依赖的其他组件,填写的是依赖的组件的 key,通常是组合组件tpl 才会需要填写
externalClasses?: string[] // 外部样式类
}
Component icon, as shown below
Component topIcon, as shown below
For example, the simplest component button, although it is not useful
{
"button": {
"key": "td-button",
"icon": "",
"label": "按钮"
}
# 2.2.1 Component Custom Template tpl
Tpl indicates the node structure content generated by the component, if empty, it is quite default to use the component key to spell an empty label.
{
"key": "td-button",
"icon": "",
"label": "按钮",
"tpl": "<td-button />"
}
If you need to customize it, the corresponding tpl 'button will be output.
{
"key": "td-button",
"icon": "",
"label": "按钮",
"tpl": "<td-button type=\"warn\">按钮</td-button>"
}
# 2.2.2 Component dependency path path
If a component is a custom component of the contents of the component, it is necessary to rely on the load, path that is the component of the component set path, relative to the component library root directory
{
"key": "td-button",
"icon": "",
"label": "按钮",
"tpl": "<td-button type=\"warn\">按钮</td-button>",
"path": "./dist/components/button/index"
}
# 2. 2. 3 Composite component dependency specification require
If tpl is configured to combine multiple custom components, and is not a custom component, you can configure require to have multiple dependencies
{
"key": "td-button-group",
"icon": "",
"label": "按钮",
"tpl": "<view><td-button type=\"warn\">按钮</td-button> <t-icon></t-icon><view>",
"require": {
"td-icon": "./dist/components/icon/index",
"td-button": "./dist/components/button/index"
}
}
# 2.2.4 Component Events IComponentEvent
Component Events IComponentEvent Explains the events that custom components can configure
interface IIBComponentLibConfigEvent {
key: string; // 事件名称,如"onChange"
label: string; // 事件展示可读名称
desc: string; // 事件展示的描述
references?: IIBComponentLibConfigPropertyReferences // 组件属性说明文档
}
// Event Dxplaination Document Address
interface IIBComponentLibConfigPropertyReferences {
desc: string,
url: string
}
Example, the following defines the event attribute of an onClick
{
"key": "td-button-group",
"icon": "",
"label": "按钮",
"tpl": "<td-button type=\"warn\">按钮</td-button>",
"path": "./dist/components/button/index",
"events": [
{
"key": "onClick",
"label": "点击处理",
"desc": "点击按钮后触发绑定"
}
]
}
# 2.2.5 Component Properties IComponentProperty
Component Properties IComponentProperty Explains the properties that a component can configure
type ComponentPropertyType = 'Boolean' | 'String' | 'Color' | 'Image' | 'Enum' | 'Number' | 'Object' | 'Array'
export interface IIBComponentLibConfigProperty {
key: string; // 属性名称, 如 "value"
label: string; // 属性展示可读名称
desc: string; // 属性展示的描述
type: ComponentPropertyType[]; // 属性值类型(多种)
defaultValue?: any // @TODO
enum?: any[] // @TODO 枚举,对应下拉选择
references?: IIBComponentLibConfigPropertyReferences // @TODO 组件属性说明文档
}
For example, the following defines a type property for a button whose type is a character string and defaults to "normal "
{
"key": "td-button-group",
"icon": "",
"label": "按钮",
"tpl": "<td-button type=\"warn\">按钮</td-button>",
"path": "./dist/components/button/index",
"properties": [
{
"key": "text",
"label": "文本",
"desc": "按钮文本",
"type": "String",
"defaultValue": "normal"
},
{
"key": "type",
"label": "类型",
"desc": "按钮类型",
"type": "Enum",
"defaultValue": "a",
"details": [
"a", "b", "c"
]
}
]
}
# 2. 2. 6 Reuse public properties and events (not supported)
You can define a common property and event in common, and then you only need to write the corresponding key value when the component is used.
{
"common": {
"properties": {
"commonText": {
"key": "text",
"label": "文本",
"desc": "按钮文本",
"type": "String",
"defaultValue": "normal"
}
}
},
"components": [
{
"key": "td-button-group",
"icon": "",
"label": "按钮",
"tpl": "<td-button type=\"warn\">按钮</td-button>",
"path": "./dist/components/button/index",
"properties": [
"commonText",
{
"key": "type",
"label": "类型",
"desc": "按钮类型",
"type": "Enum",
"defaultValue": "a",
"details": ["a", "b", "c"]
}
]
}
]
}
# 2.3 Component Definition Menu
The menu defines the hierarchical structure of the presentation of components, and currently only supports a total of three levels of structure
- Component Type
- Component Type II
- Specific components
// Level 1 Menu
// Level 1 Menu
export interface IIBComponentLibConfigMenu {
key: string; // 菜单唯一标识
label: string; // 菜单可读名称
icon?: string // 菜单 menu 图标 20*20
submenu: IIBComponentLibConfigSubMenu[];
}
// Second Level Menu
export interface IIBComponentLibConfigSubMenu {
key: string; // 二级菜单唯一标识
label: string; // 二级菜单可读名称
components: string[]; // 对应的组件 key
}
Examples are as follows
{
"menu": [
{
"key": "form",
"label": "表单组件",
"icon": "",
"submenu": [
{
"label": "按钮",
"key": "button",
"compnents": ["button", "button-group"]
}
]
}
]
}
# Full description
/**
* 可视化组件库配置规范
*/
export interface IIBComponentLibConfig {
key: string // 组件库标识
label: string // 可读名称
// 组件列表说明配置
components: {
[propName: string]: IIBComponentLibConfigComponent
};
// 菜单相关
topList?: string[], // 组件面板顶部通用组件列表 max 5个,配置的内容是 components 中组件的 key
menu: IIBComponentLibConfigMenu[], // 组件面板菜单情况
// @TODO: 其他配置
remote?: string // @TODO 远程配置地址,后续读取配置进行更新
common: IIBComponentLibConfigCommon // @TODO
}
// Generic properties and events
export interface IIBComponentLibConfigCommon {
properties?: {
[proName: string]: IIBComponentLibConfigProperty;
}, // 通用属性
events?: {
[proName: string]: IIBComponentLibConfigEvent;
}, // 通用事件
}
export interface IIBComponentLibConfigComponent {
key?: string; // 组件标签名称, 应该和组件列表的 key 是一样的,工具会默认补齐
label: string; // 组件可读名称
icon: string; // 组件 icon 示意图、本地或者网络地址,建议尺寸为 200 * 100
topIcon?: string // 组件如果需要放在头部,本地或者网络地址,建议尺寸 44 * 44, 内边距为 10
events?: IIBComponentLibConfigEvent[]; // 事件列表
properties?: IIBComponentLibConfigProperty[]; // 属性列表
tpl?: string; // 自定义组件模块代码,为空则用 key 作为标签名生成默认 tpl `<$key></$key>`
path?: string, // 原子组件的相对 npm 根目录的位置
require?: string[] // 组件依赖的其他组件,填写的是依赖的组件的 key,通常是组合组件tpl 才会需要填写
}
interface IIBComponentLibConfigEvent {
key: string; // 事件名称,如"onChange"
label: string; // 事件展示可读名称
desc: string; // 事件展示的描述
references?: IIBComponentLibConfigPropertyReferences // 组件属性说明文档
}
type ComponentPropertyType = 'Boolean' | 'String' | 'Color' | 'Image' | 'Enum' | 'Number' | 'Object' | 'Array'
export interface IIBComponentLibConfigProperty {
key: string; // 属性名称, 如 "value"
label: string; // 属性展示可读名称
desc: string; // 属性展示的描述
type: ComponentPropertyType[]; // 属性值类型(多种)
defaultValue?: any // @TODO
enum?: any[] // @TODO 枚举,对应下拉选择
references?: IIBComponentLibConfigPropertyReferences // @TODO 组件属性说明文档
}
// Corresponding document address
export interface IIBComponentLibConfigPropertyReferences {
desc: string,
url: string
}
// Level 1 Menu
export interface IIBComponentLibConfigMenu {
key: string; // 菜单唯一标识
label: string; // 菜单可读名称
icon?: string // 菜单 menu 图标 20*20
submenu: IIBComponentLibConfigSubMenu[];
}
// Second Level Menu
export interface IIBComponentLibConfigSubMenu {
key: string; // 二级菜单唯一标识
label: string; // 二级菜单可读名称
components: string[]; // 对应的组件 key
}