o2.xdesktop.requireapp("process.xform", "$elinput", null, false);
/** @class elcarousel 基于element ui的输入框组件。
* @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/tree|element ui tree 树形控件}
*/
mwf.xapplication.process.xform.elcarousel = mwf.appelcarousel = new class(
/** @lends o2.xapplication.process.xform.elcarousel# */
{
implements: [events],
extends: mwf.app$elinput,
options: {
"moduleevents": ["load", "queryload", "postload"],
/**
* 幻灯片切换时触发。this.event[0]为目前激活的幻灯片的索引;
* @event mwf.xapplication.process.xform.elcarousel#change
* @see {@link https://element.eleme.cn/#/zh-cn/component/carousel|幻灯片组件的events章节}
*/
"elevents": ["change"]
},
_loadnode: function(){
this._loadnodeedit();
},
_loadnodeedit: function(){
this._createelementhtml().then(function(html){
var id = (this.json.id.indexof("..")!==-1) ? this.json.id.replace(/\.\./g, "_") : this.json.id;
this.json["$id"] = (id.indexof("-")!==-1) ? id.replace(/-/g, "_") : id;
this.node.appendhtml(html, "before");
var input = this.node.getprevious();
this.node.destroy();
this.node = input;
this.node.set({
"id": this.json.id,
"mwftype": this.json.type
});
this.node.addclass("o2_vue");
this._createvueapp();
}.bind(this));
},
_appendvuedata: function(){
if (!this.json.heighttext) this.json.heighttext = this.json.height "px";
if( !this.json.initialindex )this.json.initialindex = 0;
if( !this.json.carouseltype )this.json.carouseltype = "";
if( !this.json.trigger )this.json.trigger = "";
// if (this.json.datatype === "script"){
// this.json.data = this.form.macro.exec(((this.json.datascript) ? this.json.datascript.code : ""), this);
// }else{
// this.json.data = this.json.datajson;
// }
// this.parsedata();
},
_createelementhtml: function() {
return this.parseitem().then(function ( data ) {
var itemhtml = data[0];
var html = "";
html = "";
html = "{{item.title}}";
html = "";
return html;
}else{
return this.parsecontentconfig()
}
// }
}else{ //if( this.json.contenttype === "config" ){
return this.parsecontentconfig()
}
},
parsecontentconfig: function(){
var _self = this;
var html = "";
html = "";
this.configfun = {};
this.json.contentconfig.each(function (config, i) {
var srcfunname, textfunname, clickfunname, srchtml = "", clickhtml = "", texthtml="";
if( config.type === "img" && config.srcscript && config.srcscript.code) {
srcfunname = "getimagesrc_" i;
srchtml = " :src=\"" srcfunname "(item)\"";
this.configfun[srcfunname] = function (item) {
return _self.form.macro.fire(this.srcscript.code, _self, item);
}.bind(config);
}
if( config.clickscript && config.clickscript.code ){
clickfunname = "click_" i;
clickhtml = " @click=\"" clickfunname "(item, $event)\"";
this.configfun[clickfunname] = function (item, ev) {
return _self.form.macro.fire(this.clickscript.code, _self, [item, ev]);
}.bind(config);
}
if( config.type === "text" && config.textscript && config.textscript.code) {
textfunname = "gettext_" i;
texthtml = "{{" textfunname "(item)}}";
this.configfun[textfunname] = function (item) {
return _self.form.macro.fire(this.textscript.code, _self, item);
}.bind(config);
}
if( config.type === "img" ){
html = "
";
}else{
html = "" texthtml "
source
";
}
}.bind(this));
html = "";
return html;
},
_aftercreatevueextend: function (app) {
var _self = this;
var flag = false;
if( this.json.datatype === "hotpicture" ) {
// if (this.json.contenttype === "config") {
if( (!this.json.contentconfig || !this.json.contentconfig.length) ) {
app.methods.clickhotpictureitem = function (item, ev) {
if (item.application === "cms") {
_self.opendocument(item.infoid, item.title)
} else if (item.application === "bbs") {
_self.openbbsdocument(item.infoid);
}
};
app.methods.getimagesrc = function (picid) {
return mwf.xdesktop.getimagesrc(picid);
}
flag = true;
}
// }
}
if( !flag && this.configfun ){
object.each(this.configfun, function (fun, key) {
app.methods[key] = function (item, ev) {
return fun(item, ev);
}.bind(this)
})
}
},
jsontostyle: function(styles){
var style = "";
for( var key in styles ){
style = key ":" styles[key] ";";
}
return style;
},
_geto2source: function(){
this._geto2address();
this._geto2uri();
return mwf.restful(this.json.httpmethod, this.uri, json.encode(this.body), function(json){
return json;
}.bind(this), true, true);
},
_geto2address: function(){
try {
this.json.service = json.parse(this.json.contextroot);
}catch(e){
this.json.service = {"root": this.json.contextroot, "action":"", "method": "", "url": ""};
}
var addressobj = layout.serviceaddresslist[this.json.service.root];
if (addressobj){
this.address = layout.config.app_protocol "//" addressobj.host (( !addressobj.port || addressobj.port==80 ) ? "" : ":" addressobj.port) addressobj.context;
}else{
var host = layout.desktop.centerserver.host || window.location.hostname;
var port = layout.desktop.centerserver.port;
this.address = layout.config.app_protocol "//" host ((!port || port=="80") ? "" : ":" port) "/" this.json.service.root;
}
},
_geto2uri: function(){
//var uri = this.json.path || this.json.selectpath;
var uri = this.json.path;
var pars = {};
if (this.json.parameters){
object.each(this.json.parameters, function(v, key){
if (uri.indexof("{" key "}")!=-1){
var reg = new regexp("{" key "}", "g");
uri = uri.replace(reg, encodeuricomponent((v && v.code) ? (this.form.macro.exec(v.code, this) || "") : v));
}else{
pars[key] = v;
}
}.bind(this));
}
var data = null;
if (this.json.requestbody){
if (this.json.requestbody.code){
data = this.form.macro.exec(this.json.requestbody.code, this)
}
}
if (this.json.httpmethod=="get" || this.json.httpmethod=="options" || this.json.httpmethod=="head" || this.json.httpmethod=="delete"){
var tag = "?";
if (uri.indexof("?")!=-1) tag = "&";
object.each(pars, function(v, k){
var value = (v && v.code) ? (this.form.macro.exec(v.code, this) || "") : v;
uri = uri tag k "=" value;
}.bind(this));
}else{
object.each(pars, function(v, k){
if (!data) data = {};
var value = (v && v.code) ? (this.form.macro.exec(v.code, this) || "") : v;
data[k] = value;
}.bind(this));
}
this.body = data;
this.uri = this.address uri;
},
opendocument: function(id, title, options){
var op = options || {};
op.documentid = id;
op.doctitle = title;
op.appid = (op.appid) || ("cms.document" id);
return layout.desktop.openapplication(null, "cms.document", op);
},
openbbsdocument: function(id){
var appid = "forumdocument" id;
if (layout.desktop.apps && layout.desktop.apps[appid]){
layout.desktop.apps[appid].setcurrent();
}else {
return layout.desktop.openapplication(null, "forumdocument", {
"id" : id,
"appid": appid,
"isedited" : false,
"isnew" : false
});
}
}
});