$ElElement.js 5.9 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2 3 4 5 6 7
MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
MWF.xApplication.process.FormDesigner.Module.$ElElement = MWF.FC$ElElement = new Class({
	Extends: MWF.FC$Element,
	Implements: [Options, Events],

	_initModuleType: function(){
NoSubject's avatar
NoSubject 已提交
8
		this.className = "Elbutton";
NoSubject's avatar
NoSubject 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
		this.moduleType = "element";
		this.moduleName = "elbutton";
	},

	initialize: function(form, options){
		this.setOptions(options);
		this._initModuleType();
		this.path = "../x_component_process_FormDesigner/Module/"+this.className+"/";
		this.cssPath = "../x_component_process_FormDesigner/Module/"+this.className+"/"+this.options.style+"/css.wcss";
		this._loadCss();
		this.form = form;
		this.container = null;
		this.containerNode = null;
		this.isPropertyLoaded = false;
	},
	_dragMoveComplete: MWF.FC$Component.prototype._dragComplete,
	_dragComplete: function(){
		if (!this.node){
			this._createNode(function(){
				this._dragMoveComplete();
			}.bind(this));
		}else{
			this._dragMoveComplete();
		}
	},
	showProperty: function(){
		if (!this.property){
			this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.form.designer.propertyContentArea, this.form.designer, {
				"path": this.options.propertyPath,
				"onPostLoad": function(){
					this.property.show();
					this.isPropertyLoaded = true;
				}.bind(this)
			});
			this.property.load();
		}else{
			this.property.show();
		}
	},
	_createMoveNode: function(){
		this.moveNode = new Element("div", {
			"MWFType": this.moduleName,
			"id": this.json.id,
			"styles": this.css.moduleNodeMove,
			"text": this.json.name || this.json.id,
			"events": {
				"selectstart": function(){
					return false;
				}
			}
		}).inject(this.form.container);
	},
	_createVueAppNode: function(){
NoSubject's avatar
NoSubject 已提交
62
		this.node = new Element("div.o2_vue", {
NoSubject's avatar
NoSubject 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
			"MWFType": this.moduleName,
			"id": this.json.id,
			"styles": this.css.moduleNode,
			"events": {
				"selectstart": function(){
					return false;
				}
			}
		});
	},
	_createNode: function(callback){
		this._createVueAppNode();
		this._resetVueModuleDomNode(callback);
	},
	_initModule: function(){
		if (!this.json.isSaved) this.setStyleTemplate();
		this._resetVueModuleDomNode(function(){
			this._setNodeProperty();
			if (!this.form.isSubform) this._createIconAction();
			this._setNodeEvent();
			//this.selected(true);
		}.bind(this));
		this.json.isSaved = true;
	},
	_loadVue: function(callback){
		if (!window.Vue){
			o2.load(["vue", "elementui"], { "sequence": true }, callback);
		}else{
			if (callback) callback();
		}
	},
	_createElementHtml: function(){
		return "";
	},
97
	_filterHtml: function(html){
98 99 100 101 102 103 104 105 106 107
		var reg = /(?:@|\:)\S*(?:\=)\S*(?:\"|\')/g;
		var v = html.replace(reg, "");

		var tmp = new Element("div", {"html": v});
		var nodes = tmp.querySelectorAll("*[v-model]");
		this.tmpVueData = {};
		nodes.forEach(function(node){
			this.tmpVueData[node.get("v-model")] = "";
		}.bind(this));
		return v;
108
	},
NoSubject's avatar
NoSubject 已提交
109 110
	_resetVueModuleDomNode: function(callback){
		if (!this.vm){
NoSubject's avatar
NoSubject 已提交
111
			if (!this.node.hasClass("o2_vue")) this.node.addClass("o2_vue");
112 113 114
			var html = this._filterHtml(this._createElementHtml());

			this.node.set("html", html);
NoSubject's avatar
NoSubject 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127
			this._loadVue(function(){
				this._mountVueApp(callback);
			}.bind(this));
		}else{
			if (callback) callback();
		}
	},
	_resetModuleDomNode: function(){

	},
	_mountVueApp: function(callback){
		//if (!this.vueApp)
		this.vueApp = this._createVueExtend(callback);
128 129 130 131 132 133 134 135 136
		try{
			this.vm = new Vue(this.vueApp);
			this.vm.$mount(this.node);
		}catch(e){
			this.node.store("module", this);
			this._loadVueCss();
			if (callback) callback();
		}

NoSubject's avatar
NoSubject 已提交
137 138 139
	},
	_createVueData: function(){
		var data = {};
140
		return Object.assign(data, this.tmpVueData||{});
NoSubject's avatar
NoSubject 已提交
141 142 143 144 145 146 147 148 149 150
	},
	_createVueExtend: function(callback){
		var _self = this;
		return {
			data: this._createVueData(),
			mounted: function(){
				_self._afterMounted(this.$el, callback);
			}
		};
	},
NoSubject's avatar
NoSubject 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164
	// _afterMounted: function(el, callback){
	// 	this.node = el;
	// 	this.node.store("module", this);
	// 	if (callback) callback();
	// },
	_loadVueCss: function(){
		if (this.styleNode){
			this.node.removeClass(this.styleNode.get("id"));
		}
		if (this.json.vueCss && this.json.vueCss.code){
			this.styleNode = this.node.loadCssText(this.json.vueCss.code, {"notInject": true});
			this.styleNode.inject(this.node, "top");
		}
	},
NoSubject's avatar
NoSubject 已提交
165 166 167
	_afterMounted: function(el, callback){
		this.node = el;
		this.node.store("module", this);
NoSubject's avatar
NoSubject 已提交
168
		this._loadVueCss();
NoSubject's avatar
NoSubject 已提交
169 170 171 172 173
		if (callback) callback();
	},
	_setOtherNodeEvent: function(){},

	_setEditStyle_custom: function(name){
NoSubject's avatar
NoSubject 已提交
174
		debugger;
NoSubject's avatar
NoSubject 已提交
175 176 177 178 179 180 181 182 183
		switch (name){
			case "name": this.setPropertyName(); break;
			case "id": this.setPropertyId(); break;
			default: if (this.isPropertyLoaded) if (this.vm) this.resetElement();
		}
	},
	setPropertyName: function(){},
	setPropertyId: function(){},
	resetElement: function(){
NoSubject's avatar
NoSubject 已提交
184 185 186 187 188
		//this._createVueAppNode();
		//this.node.inject(this.vm.$el,"before");
		// var node = this.vm.$el;
		// this.vm.$destroy();
		// node.destroy();
NoSubject's avatar
NoSubject 已提交
189 190 191

		var node = this.vm.$el;
		this.vm.$destroy();
NoSubject's avatar
NoSubject 已提交
192 193
		node.empty();

NoSubject's avatar
NoSubject 已提交
194 195 196 197 198 199 200 201
		this.vm = null;

		this.isSetEvents = false;
		this._resetVueModuleDomNode(function(){
			this._setNodeProperty();
			if (!this.form.isSubform) this._createIconAction();
			this._setNodeEvent();
		}.bind(this));
NoSubject's avatar
NoSubject 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
	},
	_preprocessingModuleData: function(){
		this.node.clearStyles();
		this.node.removeAttribute("class");
		//if (this.initialStyles) this.node.setStyles(this.initialStyles);
		this.json.recoveryStyles = Object.clone(this.json.styles);

		if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
			if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
				//需要运行时处理
			}else{
				this.node.setStyle(key, value);
				delete this.json.styles[key];
			}
		}.bind(this));
		this.json.preprocessing = "y";
	},
NoSubject's avatar
NoSubject 已提交
219
});