$ElElement.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.$ElElement = MWF.FC$ElElement = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. _initModuleType: function(){
  7. this.className = "Elbutton";
  8. this.moduleType = "element";
  9. this.moduleName = "elbutton";
  10. },
  11. initialize: function(form, options){
  12. this.setOptions(options);
  13. this._initModuleType();
  14. this.path = "../x_component_process_FormDesigner/Module/"+this.className+"/";
  15. this.cssPath = "../x_component_process_FormDesigner/Module/"+this.className+"/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. this.isPropertyLoaded = false;
  21. },
  22. _dragMoveComplete: MWF.FC$Module.prototype._dragComplete,
  23. _dragComplete: function(){
  24. if (!this.node){
  25. this._createNode(function(){
  26. this._dragMoveComplete();
  27. }.bind(this));
  28. }else{
  29. this._dragMoveComplete();
  30. }
  31. },
  32. _createMoveNode: function(){
  33. this.moveNode = new Element("div", {
  34. "MWFType": this.moduleName,
  35. "id": this.json.id,
  36. "styles": this.css.moduleNodeMove,
  37. "text": this.json.name || this.json.id,
  38. "events": {
  39. "selectstart": function(){
  40. return false;
  41. }
  42. }
  43. }).inject(this.form.container);
  44. },
  45. _createVueAppNode: function(){
  46. this.node = new Element("div.o2_vue", {
  47. "MWFType": this.moduleName,
  48. "id": this.json.id,
  49. "styles": this.css.moduleNode,
  50. "events": {
  51. "selectstart": function(){
  52. return false;
  53. }
  54. }
  55. });
  56. },
  57. _createNode: function(callback){
  58. this._createVueAppNode();
  59. this._resetVueModuleDomNode(callback);
  60. },
  61. _initModule: function(){
  62. if (!this.json.isSaved) this.setStyleTemplate();
  63. this._resetVueModuleDomNode(function(){
  64. this._setNodeProperty();
  65. if (!this.form.isSubform) this._createIconAction();
  66. this._setNodeEvent();
  67. //this.selected(true);
  68. }.bind(this));
  69. this.json.isSaved = true;
  70. },
  71. _loadVue: function(callback){
  72. if (!window.Vue || window.Vue.name!=='Vue'){
  73. o2.load(["vue", "elementui"], { "sequence": true }, function(){
  74. if( window.Vue.config )window.Vue.config = {};
  75. window.Vue.config.errorHandler = function (err, vm, info) {
  76. if (vm.$o2module && info=="nextTick"){
  77. vm.$o2module._createVueAppNode();
  78. vm.$o2module.node.setStyles(vm.$o2module.css.moduleNodeError);
  79. vm.$el.parentNode.replaceChild(vm.$o2module.node, vm.$el);
  80. vm.$el = vm.$o2module.node;
  81. if (vm.$o2callback) vm.$o2module._afterMounted(vm.$o2module.node, vm.$o2callback);
  82. }
  83. }
  84. if (callback) callback();
  85. });
  86. }else{
  87. if (callback) callback();
  88. }
  89. },
  90. _createElementHtml: function(){
  91. return "";
  92. },
  93. _filterHtml: function(html){
  94. var reg = /(?:@|v-on|v-model|:data)\S*(?:\=)\S*(?:\"|\'|\s)/g;
  95. var v = html.replace(reg, "");
  96. return v;
  97. },
  98. _checkVueHtml: function(){
  99. var nodes = this.node.querySelectorAll("*[v-model]");
  100. this.tmpVueData = {};
  101. nodes.forEach(function(node){
  102. var model = node.get("v-model");
  103. if (!model){
  104. model = o2.uuid();
  105. node.set("v-model", model);
  106. }
  107. this.tmpVueData[model] = "";
  108. }.bind(this));
  109. },
  110. _resetVueModuleDomNode: function(callback){
  111. if (!this.vm){
  112. if (!this.node.hasClass("o2_vue")) this.node.addClass("o2_vue");
  113. var html = this._filterHtml(this._createElementHtml());
  114. this.node.set("html", html);
  115. this._checkVueHtml();
  116. this._loadVue(function(){
  117. this._mountVueApp(callback);
  118. }.bind(this));
  119. }else{
  120. if (callback) callback();
  121. }
  122. },
  123. _resetModuleDomNode: function(){
  124. },
  125. _mountVueApp: function(callback){
  126. //if (!this.vueApp)
  127. this.vueApp = this._createVueExtend(callback);
  128. try{
  129. this.vm = new Vue(this.vueApp);
  130. this.vm.$o2module = this;
  131. this.vm.$o2callback = callback;
  132. this.vm.$mount(this.node);
  133. }catch(e){
  134. this.node.store("module", this);
  135. this._loadVueCss();
  136. if (callback) callback();
  137. }
  138. },
  139. _createVueData: function(){
  140. //var data = this.json;
  141. return function(){
  142. this.setElStyles();
  143. return Object.assign(this.json, this.tmpVueData||{});
  144. }.bind(this)
  145. },
  146. _createVueExtend: function(callback){
  147. var _self = this;
  148. return {
  149. data: this._createVueData(),
  150. mounted: function(){
  151. this.$nextTick(function(){
  152. _self._afterMounted(this.$el, callback);
  153. });
  154. },
  155. errorCaptured: function(err, vm, info){
  156. //alert("errorCaptured:"+info);
  157. return false;
  158. }
  159. };
  160. },
  161. // _afterMounted: function(el, callback){
  162. // this.node = el;
  163. // this.node.store("module", this);
  164. // if (callback) callback();
  165. // },
  166. _loadVueCss: function(){
  167. if (this.styleNode){
  168. this.node.removeClass(this.styleNode.get("id"));
  169. }
  170. if (this.json.vueCss && this.json.vueCss.code){
  171. this.styleNode = this.node.loadCssText(this.json.vueCss.code, {"notInject": true});
  172. this.styleNode.inject(this.node, "top");
  173. }
  174. },
  175. _afterMounted: function(el, callback){
  176. this.node = el;
  177. this.node.store("module", this);
  178. this._loadVueCss();
  179. if (callback) callback();
  180. },
  181. _setOtherNodeEvent: function(){},
  182. setPropertiesOrStyles: function(name){
  183. if (name=="styles"){
  184. try{
  185. this.setCustomStyles();
  186. }catch(e){}
  187. }else if (name=="elStyles"){
  188. this.setElStyles();
  189. }else if (name=="properties"){
  190. try{
  191. this.setCustomProperties();
  192. }catch(e){}
  193. }
  194. },
  195. setElStyles: function(){
  196. var tmpElStyles = Object.clone(this.json.elStyles || {});
  197. if( tmpElStyles.display )delete tmpElStyles.display;
  198. if (this.json.elStyles) Object.each(this.json.elStyles, function(value, key){
  199. if (key){
  200. if (key.toString().toLowerCase()==="display"){
  201. if (value.toString().toLowerCase()==="none"){
  202. tmpElStyles["opacity"] = 0.3;
  203. }else{
  204. tmpElStyles["opacity"] = 1;
  205. }
  206. }else{
  207. tmpElStyles[key] = value;
  208. }
  209. }
  210. }.bind(this));
  211. this.json.tmpElStyles = tmpElStyles;
  212. },
  213. _setEditStyle_custom: function(name){
  214. switch (name){
  215. case "name": this.setPropertyName(); break;
  216. case "id": this.setPropertyId(); break;
  217. case "buttonRadio":
  218. case "vueSlot":
  219. if (this.isPropertyLoaded) if (this.vm) this.resetElement(); break;
  220. default: ;
  221. }
  222. },
  223. setPropertyName: function(){},
  224. setPropertyId: function(){},
  225. resetElement: function(){
  226. this.reseting = true;
  227. var node = this.vm.$el;
  228. this.vm.$destroy();
  229. node.empty();
  230. this.vm = null;
  231. this.isSetEvents = false;
  232. this._resetVueModuleDomNode(function(){
  233. this._setNodeProperty();
  234. if (!this.form.isSubform) this._createIconAction();
  235. this._setNodeEvent();
  236. this.reseting = false;
  237. }.bind(this));
  238. if (this._resetElementFun){
  239. this.form.removeEvent("postSave", this._resetElementFun);
  240. this._resetElementFun = null;
  241. }
  242. },
  243. _preprocessingModuleData: function(){
  244. if (this.node.nodeType===Node.COMMENT_NODE){
  245. var tmp = this.node;
  246. this._createVueAppNode();
  247. this.node.inject(tmp, "after");
  248. this.node.store("module", this);
  249. tmp.destroy();
  250. }
  251. try{
  252. this.node.empty();
  253. this.node.clearStyles();
  254. this.node.removeAttribute("class");
  255. //if (this.initialStyles) this.node.setStyles(this.initialStyles);
  256. if( this.json.tmpElStyles )delete this.json.tmpElStyles;
  257. this.json.recoveryStyles = Object.clone(this.json.styles);
  258. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  259. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  260. //需要运行时处理
  261. }else{
  262. this.node.setStyle(key, value);
  263. delete this.json.styles[key];
  264. }
  265. }.bind(this));
  266. this.json.preprocessing = "y";
  267. this._resetElementFun = this.resetElement.bind(this);
  268. this.form.addEvent("postSave", this._resetElementFun);
  269. }catch(e){};
  270. },
  271. });