$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 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
			"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){
89
			o2.load(["vue_develop", "elementui"], { "sequence": true }, callback);
NoSubject's avatar
NoSubject 已提交
90 91 92 93 94 95 96
		}else{
			if (callback) callback();
		}
	},
	_createElementHtml: function(){
		return "";
	},
97
	_filterHtml: function(html){
98
		var reg = /(?:@|\:)\S*(?:\=)\S*(?:\"|\'|\s)/g;
99 100
		var v = html.replace(reg, "");

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

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

NoSubject's avatar
NoSubject 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146
			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);
147 148
		try{
			this.vm = new Vue(this.vueApp);
149 150 151 152 153 154 155 156
			// var p = {
			// 	"$options": {
			// 		"errorCaptured": function(err, vm, info){
			// 			alert("p: errorCaptured:"+info);
			// 		}
			// 	}
			// }
			// this.vm.$parent = p;
157 158 159
			// this.vm.config.errorHandler = function (err, vm, info) {
			// 	alert("errorHandler: "+info)
			// }
160 161 162 163 164 165 166
			this.vm.$mount(this.node);
		}catch(e){
			this.node.store("module", this);
			this._loadVueCss();
			if (callback) callback();
		}

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

	_setEditStyle_custom: function(name){
208
		debugger;
NoSubject's avatar
NoSubject 已提交
209 210 211 212 213 214 215 216 217
		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 已提交
218 219 220 221 222
		//this._createVueAppNode();
		//this.node.inject(this.vm.$el,"before");
		// var node = this.vm.$el;
		// this.vm.$destroy();
		// node.destroy();
NoSubject's avatar
NoSubject 已提交
223 224 225

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

NoSubject's avatar
NoSubject 已提交
228 229 230 231 232 233 234 235
		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 已提交
236 237
	},
	_preprocessingModuleData: function(){
238 239 240 241 242
		try{
			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 253
			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";
		}catch(e){};
NoSubject's avatar
NoSubject 已提交
254
	},
NoSubject's avatar
NoSubject 已提交
255
});