o2.xdesktop.requireapp("process.xform", "$elinput", null, false);
/** @class elcascader 基于element ui的级联选择框组件。
* @o2cn 级联选择框
* @example
* //可以在脚本中获取该组件
* //方法1:
* var input = this.form.get("name"); //获取组件
* //方法2
* var input = this.target; //在组件事件脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|element ui cascader 级联选择器}
*/
mwf.xapplication.process.xform.elcascader = mwf.appelcascader = new class(
/** @lends o2.xapplication.process.xform.elcascader# */
{
implements: [events],
extends: mwf.app$elinput,
options: {
/**
* 组件加载后触发。如果选项加载为异步,则异步处理完成后触发此事件
* @event mwf.xapplication.process.xform.elcascader#load
*/
"moduleevents": ["load", "queryload", "postload"],
/**
* 当获得焦点时触发。this.event[0]指向event
* @event mwf.xapplication.process.xform.elcascader#focus
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
/**
* 当失去焦点时触发。this.event[0]指向event
* @event mwf.xapplication.process.xform.elcascader#blur
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
/**
* 当选中节点变化时触发。this.event[0]为选中节点的值
* @event mwf.xapplication.process.xform.elcascader#change
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
/**
* 下拉框出现/隐藏时触发。this.event[0]的值:出现则为 true,隐藏则为 false
* @event mwf.xapplication.process.xform.elcascader#visible-change
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
/**
* 在多选模式下,移除tag时触发。this.event[0]为移除的tag对应的节点的值
* @event mwf.xapplication.process.xform.elcascader#remove-tag
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
/**
* 当展开节点发生变化时触发。this.event[0]指向各父级选项值组成的数组
* @event mwf.xapplication.process.xform.elcascader#expand-change
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
/**
* 过滤函数调用之前的钩子函数。this.event[0]指向value参数:如果该函数的返回值是 false 或者是一个被拒绝的promise,那么接下来的过滤便不会执行。
* @event mwf.xapplication.process.xform.elcascader#before-filter
* @see {@link https://element.eleme.cn/#/zh-cn/component/cascader|级联选择框的cascader events章节}
*/
"elevents": ["focus", "blur", "change", "visible-change", "remove-tag", "expand-change", "before-filter"]
},
// _loadnode: function(){
// if (this.isreadonly()) this.json.disabled = true;
// this._loadnodeedit();
// },
_loadmergereadcontentnode: function( contentnode, data ){
this._loadoptions();
promise.resolve(this.json.options).then(function(options){
if (data.data){
var text = this.__getoptionstext(options, data.data);
contentnode.set("text", text);
}
}.bind(this));
},
_appendvuedata: function(){
this.form.macro.environment.data.check(this.json.id);
this.json[this.json.id] = this._getbusinessdata();
if (!this.json.options) this.json.options = [];
if (!this.json.clearable) this.json.clearable = false;
if (!this.json.size) this.json.size = "";
if (!this.json.popperclass) this.json.popperclass = "";
if (this.json.showalllevels!==false) this.json.showalllevels = true;
if (!this.json.separator) this.json.separator = "/";
if (!this.json.disabled) this.json.disabled = false;
if (!this.json.description) this.json.description = "";
if (!this.json.filterable) this.json.filterable = false;
if (!this.json.collapsetags) this.json.collapsetags = false;
if (!this.json.props) this.json.props = {};
if (!this.json.props.expandtrigger) this.json.props.expandtrigger = "click";
if (!this.json.props.multiple) this.json.props.multiple = false;
if (this.json.props.emitpath!==false) this.json.props.emitpath = true;
if (!this.json.props.lazy) this.json.props.lazy = false;
if (!this.json.props.lazyload) this.json.props.lazyload = null;
if (!this.json.props.value) this.json.props.value = "value";
if (!this.json.props.label) this.json.props.label = "label";
if (!this.json.props.children) this.json.props.children = "children";
if (!this.json.props.disabled) this.json.props.disabled = "disabled";
if (!this.json.props.leaf) this.json.props.leaf = "leaf";
this._loadoptions();
//if (this.json.props.multiple===true) if (!this.json[this.json.id] || !this.json[this.json.id].length) this.json[this.json.id] = [];
if (this.json.props.multiple===true) if (!this.json[this.json.$id] || !this.json[this.json.$id].length) this.json[this.json.$id] = [];
},
appendvuemethods: function(methods){
if (this.json.filtermethod && this.json.filtermethod.code){
var fn = this.form.macro.exec(this.json.filtermethod.code, this);
methods.$filtermethod = function(){
fn.apply(this, arguments);
}.bind(this);
}
if (this.json.lazyloadscript && this.json.lazyloadscript.code){
var fn = this.form.macro.exec(this.json.lazyloadscript.code, this);
this.json.props.lazyload = function(){
fn.apply(this, arguments);
}.bind(this);
}
if (this.json.beforefilter && this.json.beforefilter.code){
var fn = this.form.macro.exec(this.json.beforefilter.code, this);
methods.$beforefilter = function(){
fn.apply(this, arguments);
}.bind(this);
}
},
_setoptionswithcode: function(code){
var v = this.form.macro.exec(code, this);
if (v.then){
this.moduleselectag = v.then(function(o){
if (o2.typeof(o)==="array"){
this.json.options = o;
this.json.$options = o;
}
return this.json.options || [];
}.bind(this));
}else if (o2.typeof(v)==="array"){
this.json.options = v;
this.json.$options = v;
}
},
_loadoptions: function(){
if (this.json.itemsscript && this.json.itemsscript.code) this._setoptionswithcode(this.json.itemsscript.code);
},
_createelementhtml: function(){
if (!this.json.options) this.json.options = [];
if (!this.json.clearable) this.json.clearable = false;
if (!this.json.size) this.json.size = "";
if (!this.json.popperclass) this.json.popperclass = "";
if (this.json.showalllevels!==false) this.json.showalllevels = true;
if (!this.json.separator) this.json.separator = "/";
if (!this.json.disabled) this.json.disabled = false;
if (!this.json.description) this.json.description = "";
if (!this.json.filterable) this.json.filterable = false;
if (!this.json.props) this.json.props = {};
var html = " 1 ){
values = values.concat(this._geteachdatabytext(options, t));
}else{
values = values.concat(this._getlastdatabytext(options, typeof( t ) === "array" ? (t[0] || "") : t));
}
}.bind(this));
return values;
}else{
if( typeof( text ) === "array" && typeof( text[0] ) === "array" ){
text = text[0];
}
if( typeof( text ) === "array" && text.length > 1 ){
values = this._geteachdatabytext(options, text);
return values.length ? values[0] : [];
}else{
return this._getlastdatabytext(options, typeof( text ) === "array" ? (text[0] || "") : text);
}
}
},
_geteachdatabytext: function(options, texts, prefix, prefixlabel){
var value = [];
var t = typeof( texts ) === "string" ? texts : texts.join("/");
options.foreach(function(op){
var opvalue = (prefix) ? prefix "/" op[this.json.props.value] : op[this.json.props.value];
var oplabel = (prefixlabel) ? prefixlabel "/" op[this.json.props.label] : op[this.json.props.label];
if (oplabel === t) {
value.push(opvalue.split("/"));
}else if (t.startswith(oplabel) && op[this.json.props.children] && op[this.json.props.children].length){
value = value.concat(this._geteachdatabytext(op[this.json.props.children], texts, opvalue, oplabel));
}
}.bind(this));
if (!this.json.showalllevels){
return value.map(function(t){
return typeof( t ) === "array" ? t.getlast() : t;
});
}else{
return value;
}
},
_getlastdatabytext: function (options, text) {
var value;
for( var i=0; i