支持的技术栈包括但不仅限于 Vue
、React
、jQuery
、art-template
,以及原生开发
init
控件初始化调用,只调用一次update
控件props值变化时调用,用以更新控件destoryed
控件销毁,只调用一次model
模型对象,自定义控件默认提供,值不能修改,其中包含以下内容
pageId
页面标识key
控件标识dom
自定义控件挂载的dom元素对象schemaId
方案idisvId
开发商标识moduleId
领域标识invoke
函数,将自定义控件事件发送给平台后端,接收两个参数,eventName
执行事件名称,eventArgs(String|Object)
执行事件所需参数,推荐使用字符串props
自定义控件数据对象,其中包含以下内容
themeColor
主题色lock
是否锁定data
数据对象,插件中setData
接口设置的数据configItems
控件配置项cardRowData
卡片行数据KDApi.register
将自定义控件注册到苍穹平台中,所有自定义控件都需调用,接收两个参数
type: String
组件标识,必须,值与方案ID
相同ctrl: Object
组件对象,必须,需包含init
方法的组件对象 KDApi.getHTMLStringBytemplate
通过模版引擎art-template
获取html
字符串,接收两个参数
tpl: String
模版字符串,必须data: Object
模版所需数据对象,必须KDApi.getTemplateStringByFilePath
从给定的文件路径中获取模版引擎字符串,接收三个参数
filePath: String
模版文件路径,必须,文件路径为相对路径model: Object
组件的model
对象,必须data: Object
模版所需数据对象,必须KDApi.loadFile
通常是将js
、css
文件加载到苍穹平台
filePaths: String|Array
模版文件路径,可以是单个文件,也可以是多个文件路径数组,必须,文件路径为相对路径model: Object
组件的model
对象,必须callback: Function
回调函数,文件加载完成后进入回调,必须KDApi.getNameSpace
获取当前服务的路径前缀
model: Object
组件的model
对象,必须KDApi.template
功能同 getHTMLStringBytemplate
接口,已经不维护,不建议使用
KDApi.templateFilePath
功能同 getTemplateStringByFilePath
接口,已经不维护,不建议使用
KDApi.nameSpace
功能同 getNameSpace
接口,已经不维护,不建议使用
kd.bos.ext.form.control.CustomControl
模型中包含三个方法:
getData
获取自定义控件数据,没有参数,返回为String
setData(Object data)
设置自定义控件数据,参数为Object
setConfigItems(List<Map<String, String>> items)
设置自定义控件配置项自定义控件在卡片中通常通过以下方式设置数据
// ...
Map<String, Object> data = new HashMap();
// ...
IClientViewProxy proxy = ((IClientViewProxy)this.getView().getService(IClientViewProxy.class));
// entryentity是卡片分录标识,setCustomProperties 是指令名, index是卡片行号
proxy.invokeControlMethod("entryentity" ,"setCustomProperties",index, data);
// ...
(function (KDApi, $) {
function MyComponent (model) {
this._setModel(model)
}
var themeColor // 顶层变量声明
var isUpdate = false
MyComponent.prototype = { // 内部函数不推荐修改
_setModel: function (model) {
this.model = model // 内部变量挂载
},
init: function (props) {
console.log('-----init', this.model, props)
setHtml(this.model, props)
},
update: function (props) {
console.log('-----update', this.model, props)
themeColor = getThemeColor(props.theme)
updateHtml(this.model, props)
},
destoryed: function () {
console.log('-----destoryed', this.model)
}
}
/*
* 外部函数声明
*/
var setHtml = function (model, props, isUpdate) {
// 编写模板字符串
var template = '<div class="hr-delLabel" title="<%= text %>">' +
'<div class="hr-delLabel-text">' +
'<%= text %>' +
'</div>' +
'<div class="hr-delLabel-icon"></div>' +
'</div>'
// 获取html字符串
var result = KDApi.getHTMLStringBytemplate(template, {
text: props.data && props.data.get('text') ? props.data.get('text') : model.configItems ? model.configItems.getIn([0, 'value']) : '标签'
})
model.dom.innerHTML = result // 渲染html
initEvent(model, props) // 给自定义控件增加点击事件
}
var updateHtml = function (model, props) {
var template = '<div class="hr-delLabel" title="<%= text %>">' +
'<div class="hr-delLabel-text">' +
'<%= text %>' +
'</div>' +
'<div class="hr-delLabel-icon"></div>' +
'</div>'
var result = KDApi.getHTMLStringBytemplate(template, {
text: props.data && props.data.get('text') ? props.data.get('text') : model.configItems ? model.configItems.getIn([0, 'value']) : '标签'
})
model.dom.innerHTML = result
initEvent(model, props)
}
/*
* 将主题色转为对应色值
*/
function getThemeColor (themeColor) {
switch (themeColor) {
case 'blue':
return '#5582F3'
break
case 'green':
return '#29C392'
break
case 'orange':
return '#FC8555'
break
case 'purple':
return '#6869FB'
break
}
}
/*
* 通过自定义控件,向平台后端发送点击事件
*/
var initEvent = function (model, props) {
$(model.dom).click(function () {
model.invoke('click', '')
})
}
console.log('-----------------init')
// 注册自定义控件
KDApi.register('dellabel', MyComponent)
})(window.KDApi, jQuery)
Vue
开发时,需要修改模板变量的识别标识{{}}
,这与项目中的模板引擎识别标识冲突。index.html
命名的文件jQuery
,模板放入移动端运行需清除jQuery