$ElElement.js 7.0 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){
NoSubject's avatar
NoSubject 已提交
77 78 79 80 81 82 83 84 85 86 87 88
			o2.load(["vue_develop", "elementui"], { "sequence": true }, function(){
				window.Vue.config.errorHandler = function (err, vm, info) {
					if (vm.$o2module && info=="nextTick"){
						vm.$o2module._createVueAppNode();
						vm.$o2module.node.setStyles(vm.$o2module.css.moduleNodeError);
						vm.$el.parentNode.replaceChild(vm.$o2module.node, vm.$el);
						vm.$el = vm.$o2module.node;
						if (vm.$o2callback) vm.$o2module._afterMounted(vm.$o2module.node, vm.$o2callback);
					}
				}
				if (callback) callback();
			});
NoSubject's avatar
NoSubject 已提交
89 90 91 92 93 94 95
		}else{
			if (callback) callback();
		}
	},
	_createElementHtml: function(){
		return "";
	},
96
	_filterHtml: function(html){
97
		var reg = /(?:@|v-on)\S*(?:\=)\S*(?:\"|\'|\s)/g;
98 99
		var v = html.replace(reg, "");

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
		// 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]");
115 116
		this.tmpVueData = {};
		nodes.forEach(function(node){
117 118 119 120 121 122
			var model = node.get("v-model");
			if (!model){
				model = o2.uuid();
				node.set("v-model", model);
			}
			this.tmpVueData[model] = "";
123
		}.bind(this));
124
	},
NoSubject's avatar
NoSubject 已提交
125 126
	_resetVueModuleDomNode: function(callback){
		if (!this.vm){
NoSubject's avatar
NoSubject 已提交
127
			if (!this.node.hasClass("o2_vue")) this.node.addClass("o2_vue");
128 129 130
			var html = this._filterHtml(this._createElementHtml());

			this.node.set("html", html);
131 132
			this._checkVueHtml();

NoSubject's avatar
NoSubject 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145
			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);
146 147
		try{
			this.vm = new Vue(this.vueApp);
NoSubject's avatar
NoSubject 已提交
148 149 150
			this.vm.$o2module = this;
			this.vm.$o2callback = callback;

151 152 153 154 155 156 157
			this.vm.$mount(this.node);
		}catch(e){
			this.node.store("module", this);
			this._loadVueCss();
			if (callback) callback();
		}

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

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

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

NoSubject's avatar
NoSubject 已提交
226 227 228 229 230 231 232 233
		this.vm = null;

		this.isSetEvents = false;
		this._resetVueModuleDomNode(function(){
			this._setNodeProperty();
			if (!this.form.isSubform) this._createIconAction();
			this._setNodeEvent();
		}.bind(this));
234 235 236 237 238
		if (this._resetElementFun){
			this.form.removeEvent("postSave", this._resetElementFun);
			this._resetElementFun = null;
		}

NoSubject's avatar
NoSubject 已提交
239 240
	},
	_preprocessingModuleData: function(){
241
		try{
242
			this.node.empty();
243 244 245 246
			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 已提交
247

248 249 250 251 252 253 254 255 256
			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";
257 258 259 260

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