123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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(){
- this.className = "Elbutton";
- 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$Module.prototype._dragComplete,
- _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(){
- this.node = new Element("div.o2_vue", {
- "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 || window.Vue.name!=='Vue'){
- o2.load(["vue", "elementui"], { "sequence": true }, function(){
- if( window.Vue.config )window.Vue.config = {};
- 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();
- });
- }else{
- if (callback) callback();
- }
- },
- _createElementHtml: function(){
- return "";
- },
- _filterHtml: function(html){
- var reg = /(?:@|v-on|v-model|:data)\S*(?:\=)\S*(?:\"|\'|\s)/g;
- var v = html.replace(reg, "");
- return v;
- },
- _checkVueHtml: function(){
- var nodes = this.node.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));
- },
- _resetVueModuleDomNode: function(callback){
- if (!this.vm){
- if (!this.node.hasClass("o2_vue")) this.node.addClass("o2_vue");
- var html = this._filterHtml(this._createElementHtml());
- this.node.set("html", html);
- this._checkVueHtml();
- 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);
- try{
- this.vm = new Vue(this.vueApp);
- this.vm.$o2module = this;
- this.vm.$o2callback = callback;
- this.vm.$mount(this.node);
- }catch(e){
- this.node.store("module", this);
- this._loadVueCss();
- if (callback) callback();
- }
- },
- _createVueData: function(){
- //var data = this.json;
- return function(){
- this.setElStyles();
- return Object.assign(this.json, this.tmpVueData||{});
- }.bind(this)
- },
- _createVueExtend: function(callback){
- var _self = this;
- return {
- data: this._createVueData(),
- mounted: function(){
- this.$nextTick(function(){
- _self._afterMounted(this.$el, callback);
- });
- },
- errorCaptured: function(err, vm, info){
- //alert("errorCaptured:"+info);
- return false;
- }
- };
- },
- // _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");
- }
- },
- _afterMounted: function(el, callback){
- this.node = el;
- this.node.store("module", this);
- this._loadVueCss();
- if (callback) callback();
- },
- _setOtherNodeEvent: function(){},
- setPropertiesOrStyles: function(name){
- if (name=="styles"){
- try{
- this.setCustomStyles();
- }catch(e){}
- }else if (name=="elStyles"){
- this.setElStyles();
- }else if (name=="properties"){
- try{
- this.setCustomProperties();
- }catch(e){}
- }
- },
- setElStyles: function(){
- var tmpElStyles = Object.clone(this.json.elStyles || {});
- if( tmpElStyles.display )delete tmpElStyles.display;
- if (this.json.elStyles) Object.each(this.json.elStyles, function(value, key){
- if (key){
- if (key.toString().toLowerCase()==="display"){
- if (value.toString().toLowerCase()==="none"){
- tmpElStyles["opacity"] = 0.3;
- }else{
- tmpElStyles["opacity"] = 1;
- }
- }else{
- tmpElStyles[key] = value;
- }
- }
- }.bind(this));
- this.json.tmpElStyles = tmpElStyles;
- },
- _setEditStyle_custom: function(name){
- switch (name){
- case "name": this.setPropertyName(); break;
- case "id": this.setPropertyId(); break;
- case "buttonRadio":
- case "vueSlot":
- if (this.isPropertyLoaded) if (this.vm) this.resetElement(); break;
- default: ;
- }
- },
- setPropertyName: function(){},
- setPropertyId: function(){},
- resetElement: function(){
- this.reseting = true;
- var node = this.vm.$el;
- this.vm.$destroy();
- node.empty();
- this.vm = null;
- this.isSetEvents = false;
- this._resetVueModuleDomNode(function(){
- this._setNodeProperty();
- if (!this.form.isSubform) this._createIconAction();
- this._setNodeEvent();
- this.reseting = false;
- }.bind(this));
- if (this._resetElementFun){
- this.form.removeEvent("postSave", this._resetElementFun);
- this._resetElementFun = null;
- }
- },
- _preprocessingModuleData: function(){
- if (this.node.nodeType===Node.COMMENT_NODE){
- var tmp = this.node;
- this._createVueAppNode();
- this.node.inject(tmp, "after");
- this.node.store("module", this);
- tmp.destroy();
- }
- try{
- this.node.empty();
- this.node.clearStyles();
- this.node.removeAttribute("class");
- //if (this.initialStyles) this.node.setStyles(this.initialStyles);
- if( this.json.tmpElStyles )delete this.json.tmpElStyles;
- 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";
- this._resetElementFun = this.resetElement.bind(this);
- this.form.addEvent("postSave", this._resetElementFun);
- }catch(e){};
- },
- });
|