$ElElement.js 6.8 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
		this.moduleType = "element";
		this.moduleName = "elbutton";
	},

	initialize: function(form, options){
14
		debugger;
NoSubject's avatar
NoSubject 已提交
15 16 17 18 19 20 21 22 23 24
		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;
	},
NoSubject's avatar
NoSubject 已提交
25
	_dragMoveComplete: MWF.FC$Module.prototype._dragComplete,
NoSubject's avatar
NoSubject 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	_dragComplete: function(){
		if (!this.node){
			this._createNode(function(){
				this._dragMoveComplete();
			}.bind(this));
		}else{
			this._dragMoveComplete();
		}
	},
	_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 已提交
49
		this.node = new Element("div.o2_vue", {
NoSubject's avatar
NoSubject 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63
			"MWFType": this.moduleName,
			"id": this.json.id,
			"styles": this.css.moduleNode,
			"events": {
				"selectstart": function(){
					return false;
				}
			}
		});
	},
	_createNode: function(callback){
		this._createVueAppNode();
		this._resetVueModuleDomNode(callback);
	},
64

NoSubject's avatar
NoSubject 已提交
65 66 67 68 69 70 71 72 73 74 75 76
	_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){
77
			o2.load(["vue_develop", "elementui"], { "sequence": true }, callback);
NoSubject's avatar
NoSubject 已提交
78 79 80 81 82 83 84
		}else{
			if (callback) callback();
		}
	},
	_createElementHtml: function(){
		return "";
	},
85
	_filterHtml: function(html){
86
		var reg = /(?:@|v-on)\S*(?:\=)\S*(?:\"|\'|\s)/g;
87 88
		var v = html.replace(reg, "");

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
		// var tmp = new Element("div", {"html": v});
		// var nodes = tmp.querySelectorAll("*[v-model]");
		// this.tmpVueData = {};
		// nodes.forEach(function(node){
		// 	var model = node.get("v-model");
		// 	if (!model) model = o2.uuid();
		// 	node.set("v-model", model);
		// 	this.tmpVueData[model] = "";
		// }.bind(this));
		// var v = tmp.get("html");
		// tmp.destroy();
		return v;
	},
	_checkVueHtml: function(){
		var nodes = this.node.querySelectorAll("*[v-model]");
104 105
		this.tmpVueData = {};
		nodes.forEach(function(node){
106 107 108 109 110 111
			var model = node.get("v-model");
			if (!model){
				model = o2.uuid();
				node.set("v-model", model);
			}
			this.tmpVueData[model] = "";
112
		}.bind(this));
113
	},
NoSubject's avatar
NoSubject 已提交
114 115
	_resetVueModuleDomNode: function(callback){
		if (!this.vm){
NoSubject's avatar
NoSubject 已提交
116
			if (!this.node.hasClass("o2_vue")) this.node.addClass("o2_vue");
117 118 119
			var html = this._filterHtml(this._createElementHtml());

			this.node.set("html", html);
120 121
			this._checkVueHtml();

NoSubject's avatar
NoSubject 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134
			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);
135 136
		try{
			this.vm = new Vue(this.vueApp);
137 138 139 140 141 142 143 144
			// var p = {
			// 	"$options": {
			// 		"errorCaptured": function(err, vm, info){
			// 			alert("p: errorCaptured:"+info);
			// 		}
			// 	}
			// }
			// this.vm.$parent = p;
145 146 147
			// this.vm.config.errorHandler = function (err, vm, info) {
			// 	alert("errorHandler: "+info)
			// }
148 149 150 151 152 153 154
			this.vm.$mount(this.node);
		}catch(e){
			this.node.store("module", this);
			this._loadVueCss();
			if (callback) callback();
		}

NoSubject's avatar
NoSubject 已提交
155 156
	},
	_createVueData: function(){
157 158 159 160
		//var data = this.json;
		return function(){
			return Object.assign(this.json, this.tmpVueData||{});
		}.bind(this)
NoSubject's avatar
NoSubject 已提交
161 162 163 164 165 166
	},
	_createVueExtend: function(callback){
		var _self = this;
		return {
			data: this._createVueData(),
			mounted: function(){
NoSubject's avatar
NoSubject 已提交
167 168 169
				this.$nextTick(function(){
					_self._afterMounted(this.$el, callback);
				});
170 171 172 173
			},
			errorCaptured: function(err, vm, info){
				alert("errorCaptured:"+info);
				// return false;
NoSubject's avatar
NoSubject 已提交
174 175 176
			}
		};
	},
NoSubject's avatar
NoSubject 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190
	// _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 已提交
191
	_afterMounted: function(el, callback){
NoSubject's avatar
NoSubject 已提交
192
		debugger;
NoSubject's avatar
NoSubject 已提交
193 194
		this.node = el;
		this.node.store("module", this);
NoSubject's avatar
NoSubject 已提交
195
		this._loadVueCss();
NoSubject's avatar
NoSubject 已提交
196 197 198 199 200 201 202 203
		if (callback) callback();
	},
	_setOtherNodeEvent: function(){},

	_setEditStyle_custom: function(name){
		switch (name){
			case "name": this.setPropertyName(); break;
			case "id": this.setPropertyId(); break;
204 205 206
			case "buttonRadio":
				if (this.isPropertyLoaded) if (this.vm) this.resetElement(); break;
			default: ;
NoSubject's avatar
NoSubject 已提交
207 208 209 210 211
		}
	},
	setPropertyName: function(){},
	setPropertyId: function(){},
	resetElement: function(){
NoSubject's avatar
NoSubject 已提交
212 213 214 215 216
		//this._createVueAppNode();
		//this.node.inject(this.vm.$el,"before");
		// var node = this.vm.$el;
		// this.vm.$destroy();
		// node.destroy();
NoSubject's avatar
NoSubject 已提交
217 218 219

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

NoSubject's avatar
NoSubject 已提交
222 223 224 225 226 227 228 229
		this.vm = null;

		this.isSetEvents = false;
		this._resetVueModuleDomNode(function(){
			this._setNodeProperty();
			if (!this.form.isSubform) this._createIconAction();
			this._setNodeEvent();
		}.bind(this));
230 231 232 233 234
		if (this._resetElementFun){
			this.form.removeEvent("postSave", this._resetElementFun);
			this._resetElementFun = null;
		}

NoSubject's avatar
NoSubject 已提交
235 236
	},
	_preprocessingModuleData: function(){
237
		try{
238
			this.node.empty();
239 240 241 242
			this.node.clearStyles();
			this.node.removeAttribute("class");
			//if (this.initialStyles) this.node.setStyles(this.initialStyles);
			this.json.recoveryStyles = Object.clone(this.json.styles);
NoSubject's avatar
NoSubject 已提交
243

244 245 246 247 248 249 250 251 252
			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";
253 254 255 256

			debugger;
			this._resetElementFun = this.resetElement.bind(this);
			this.form.addEvent("postSave", this._resetElementFun);
257
		}catch(e){};
NoSubject's avatar
NoSubject 已提交
258
	},
NoSubject's avatar
NoSubject 已提交
259
});