From 6e813af216171014fb37a76e7764cfbe773ae943 Mon Sep 17 00:00:00 2001 From: huqi Date: Tue, 24 Aug 2021 02:48:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ElementUI=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=20autocomplete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Module/Elautocomplete.js | 56 +-- .../Module/Elautocomplete/default/css.wcss | 56 +++ .../Elautocomplete/default/icon/copy1.png | Bin 0 -> 692 bytes .../Elautocomplete/default/icon/delete1.png | Bin 0 -> 794 bytes .../Elautocomplete/default/icon/move1.png | Bin 0 -> 707 bytes .../Module/Elautocomplete/elautocomplete.html | 113 ++++++ .../Module/Elautocomplete/template.json | 72 ++++ .../Module/Elinput.js | 5 +- .../Module/Elinput/elinput.html | 12 +- .../x_component_process_FormDesigner/lp/en.js | 30 +- .../lp/zh-cn.js | 6 +- .../x_component_process_Xform/$ElInput.js | 3 +- .../x_component_process_Xform/$ElModule.js | 13 +- .../Elautocomplete.js | 119 +++++++ .../x_component_process_Xform/Elinput.js | 26 +- .../source/x_desktop/js/initialScriptText.js | 331 +++++++++++++----- 16 files changed, 713 insertions(+), 129 deletions(-) create mode 100644 o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/css.wcss create mode 100644 o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/copy1.png create mode 100644 o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/delete1.png create mode 100644 o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/move1.png create mode 100644 o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/elautocomplete.html create mode 100644 o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/template.json create mode 100644 o2web/source/x_component_process_Xform/Elautocomplete.js diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete.js b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete.js index 82bfca628f..4b788697b0 100644 --- a/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete.js +++ b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete.js @@ -1,40 +1,29 @@ MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {}; MWF.xDesktop.requireApp("process.FormDesigner", "Module.$ElElement", null, false); -MWF.xApplication.process.FormDesigner.Module.Elinput = MWF.FCElinput = new Class({ +MWF.xApplication.process.FormDesigner.Module.Elautocomplete = MWF.FCElautocomplete = new Class({ Extends: MWF.FC$ElElement, Implements: [Options, Events], options: { "style": "default", - "propertyPath": "../x_component_process_FormDesigner/Module/Elinput/elinput.html" + "propertyPath": "../x_component_process_FormDesigner/Module/Elautocomplete/elautocomplete.html" }, _initModuleType: function(){ - this.className = "Elinput"; + this.className = "Elautocomplete"; this.moduleType = "element"; - this.moduleName = "elinput"; + this.moduleName = "elautocomplete"; }, _createElementHtml: function(){ - debugger; //var html = ""; - var html = ""; + html += " value=\""+this.json.id+"\">"; + if (this.json.vueSlot) html += this.json.vueSlot; + html += ""; return html; }, + _createVueExtend: function(callback){ + var _self = this; + return { + data: this._createVueData(), + mounted: function(){ + _self._afterMounted(this.$el, callback); + }, + methods: { + $fetchSuggestions: function(qs, cb){ + if (this.json.itemType!=='script'){ + if (this.json.itemValues){ + cb(this.json.itemValues.map(function(v){ + return {"value": v}; + })); + return; + } + } + cb([]); + }.bind(this) + } + }; + }, _createCopyNode: function(){ this.copyNode = new Element("div", { "styles": this.css.moduleNodeShow diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/css.wcss b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/css.wcss new file mode 100644 index 0000000000..d87fddb807 --- /dev/null +++ b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/css.wcss @@ -0,0 +1,56 @@ +{ + "moduleNodeMove": { + "border-radius": "5px", + "border": "1px solid #ffa200", + "overflow": "hidden", + "margin": "3px", + "-webkit-user-select": "none", + "-moz-user-select": "none", + "position": "absolute", + "z-index": 10002, + "opacity": 0.7, + "cursor": "move", + "height": "26px", + "line-height": "26px", + "padding": "0 10px", + "display": "block" + }, + "moduleNodeShow": { + "border": "1px solid #333", + "margin": "3px", + "-webkit-user-select": "none", + "-moz-user-select": "none", + "position": "static", + "top": "auto", + "left": "auto", + "width": "18px", + "height": "2px", + "opacity": 0.5, + "display": "inline-block", + "background": "#ffa200" + }, + "moduleNode": { + "border-radius": "5px", + "border-top": "1px solid #999", + "border-left": "1px solid #999", + "border-right": "1px solid #333", + "border-bottom": "1px solid #333", + "overflow": "hidden", + "cursor": "pointer", + "margin": "3px", + "-webkit-user-select": "none", + "-moz-user-select": "none", + "position": "static", + "top": "auto", + "left": "auto", + "opacity": 1, + "display": "inline-block" + }, + "buttonIcon": { + "height": "26px", + "cursor": "pointer", + "border": "0px", + "margin": "0px" + } + +} diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/copy1.png b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/copy1.png new file mode 100644 index 0000000000000000000000000000000000000000..1398026fb8577130ad7d3bfebf8f4f148dc312a9 GIT binary patch literal 692 zcmV;l0!#ggP)USP(WM*2h3jsNd*dGY#Eq+)=zIm7nTNO~@T@k#^TQ6V<>E`NuvQX|p!7GUuELig&>gy% zQ2EKk#ok5$Pv6+s`ZVwQY0`J;=Y{m@iX4cR+9h0et zX}pSsl%DE*`&X;&vek)-Diu z%A>vjNvJ~8d5&^R!q~^ED_KSf~G=bMrO2>Qa~phliJdSj^0F} z-J^oa?|+%#^s|E(hh5l?3+|#lnBwyG86qMBLbHMatcGc!;Rk`36L97)noxERrW(Ld zLo{1Gs;vC!b6Y%Ez5t=T-xHjV%Y}P>*{~4_DjJ366RprOD?$cP3p4QM59!yiZ3p)s z9>b%i1z)|UVCVuz?E$XuSWMu_dcA&BC=_T|`jWw|LeziKKfS&0>%9mZ#{p|~`h1AT zcswrYx^Dc>q6}rZNF;JA7z~yXLagkDqClRXM}B%5 zN@5K}FM@SB;B0D!r>z5y>Y#OwGL+>QhVhkPB8te3kHg5O;XM}t*VPI`mQl>4ku?+k zntX@K+jrqlqfk1mJc)t&8Pah-q zV-A#|ENd8swV~QZavi>l9YE|GF+~IPR9jiHLKok`umjh!aa-Hvny{&y;?};Q~=g|Y`ss`9?2Mu&P z2YEdKhrb%q=nH7iUxG0WN@1Ao`LF0oUCFZ`Wn(b_%l5 zXf&p(s+Exqor3%3J#0BxEX}+}qL4z8k+2+_LG1S&oP9S?*>?wowSh8}W&D2sadWC( z_xAR-nA3RTGzjVJ}6NX*A^BQ#)`$_(q91v Y050~uP_q{>b^rhX07*qoM6N<$f&s=-HUIzs literal 0 HcmV?d00001 diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/move1.png b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/default/icon/move1.png new file mode 100644 index 0000000000000000000000000000000000000000..c50bda51149245dfc2f8d081b359c898173eb2f3 GIT binary patch literal 707 zcmV;!0zCbRP)$q^8(fZDIp?*dkQ%v8md+i7ycUj39)98y6DLT_NDYMMW2d zqNorAUD?#whc6T>q;1k^GPO;kojfKs$t2D|}rRQewihOo55;karr7@CU3BL1`_6)-dN8V?`b zhbU%HT_+4-X^Ns+s*A*8MnrJ>6`nnr#7ZQLdOd_?0^J-D=E(9w!!l}gsmU2+ibXV z^A@nVfxNjN(I|&iehoccU1)CJ1+`kOjIop8-P>8r&(C3cCWu2?7S7R8G)-Ito#w%< zkKqfYgYVv5^q7q3A2^Cjm#--a=yHNsEQ-0=DJ0@N(rE#uqyVh^L@A`kHWxugOoCqv zV|no_K7V?zFck@g&Wyn696<2R6q0MJ$QmsWTw{>9B{ZJ90)2Q9!$W6re%J-G*{U!V zJ0NP=+lrA9m-4Gz3xRKARP*YmU6k=&aW)Hp`j5rn-hootT1-$tEm%)u#EhO z>U6r(CX-3eFpLtbY*Xic3?4fLl}c4{E{Y=je*Xub&v%28N1<7k?Y3Af7qnV!2Wj}5 p +
+ + + + + + + + + + + + + + + + + + + + + +
{{$.lp.id}}:
{{$.lp.name}}:
{{$.lp.description}}:
{{$.lp.readonly}}: + {{$.lp.yes}} + {{$.lp.no}} +
{{$.lp.options}}: + {{$.lp.textValue}} + {{$.lp.script}} +
+
+
+ + + + + + + + + + + + + +
{{$.lp.el_placement}}: +
top
+
top-start
+
top-end
+
bottom
+
bottom-start
+
bottom-end
+ + + + + + + + +
{{$.lp.popperClass}}:
{{$.lp.triggerOnFocus}}: + {{$.lp.yes}} + {{$.lp.no}} +
+
{{$.lp.prefixIcon}}
+
+ +
{{$.lp.suffixIcon}}
+
+ +
+
+ + + + + + +
{{$.lp.compute}}: + {{$.lp.create}} + {{$.lp.save}} + {{$.lp.show}} +
+ +
+ +
+
+ +
+
+
Vue Data
+
+
Vue Method
+
+
Vue CSS
+
+ +
Vue Slots
+
+
+
+
+
+
+
+
+
+
+
+
+
+ diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/template.json b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/template.json new file mode 100644 index 0000000000..519757f9a5 --- /dev/null +++ b/o2web/source/x_component_process_FormDesigner/Module/Elautocomplete/template.json @@ -0,0 +1,72 @@ +{ + "id": "", + "name": "", + "type": "Elautocomplete", + "description": "", + "events": { + "queryLoad": { + "code": "", + "html": "" + }, + "postLoad": { + "code": "", + "html": "" + }, + "load": { + "code": "", + "html": "" + }, + "select": { + "code": "", + "html": "" + }, + "change": { + "code": "", + "html": "" + }, + "click": { + "code": "", + "html": "" + }, + "dblclick": { + "code": "", + "html": "" + }, + "keydown": { + "code": "", + "html": "" + }, + "keypress": { + "code": "", + "html": "" + }, + "keyup": { + "code": "", + "html": "" + }, + "mousedown": { + "code": "", + "html": "" + }, + "mousemove": { + "code": "", + "html": "" + }, + "mouseout": { + "code": "", + "html": "" + }, + "mouseover": { + "code": "", + "html": "" + }, + "mouseup": { + "code": "", + "html": "" + } + }, + "properties": {}, + "class": "", + "styles": {}, + "container": "" +} diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elinput.js b/o2web/source/x_component_process_FormDesigner/Module/Elinput.js index 82bfca628f..0dd906130f 100644 --- a/o2web/source/x_component_process_FormDesigner/Module/Elinput.js +++ b/o2web/source/x_component_process_FormDesigner/Module/Elinput.js @@ -14,7 +14,6 @@ MWF.xApplication.process.FormDesigner.Module.Elinput = MWF.FCElinput = new Class this.moduleName = "elinput"; }, _createElementHtml: function(){ - debugger; //var html = ""; var html = ""; + html += " value=\""+this.json.id+"\">"; + if (this.json.vueSlot) html += this.json.vueSlot; + html += ""; return html; }, _createCopyNode: function(){ diff --git a/o2web/source/x_component_process_FormDesigner/Module/Elinput/elinput.html b/o2web/source/x_component_process_FormDesigner/Module/Elinput/elinput.html index 7fc43512e8..396c6039bc 100644 --- a/o2web/source/x_component_process_FormDesigner/Module/Elinput/elinput.html +++ b/o2web/source/x_component_process_FormDesigner/Module/Elinput/elinput.html @@ -131,7 +131,17 @@
-
+
Vue Data
+
+
Vue Method
+
+
Vue CSS
+
+ +
Vue Slots
+
+
+
diff --git a/o2web/source/x_component_process_FormDesigner/lp/en.js b/o2web/source/x_component_process_FormDesigner/lp/en.js index 41a3a4dfd7..7c1bd1b9fb 100644 --- a/o2web/source/x_component_process_FormDesigner/lp/en.js +++ b/o2web/source/x_component_process_FormDesigner/lp/en.js @@ -1001,7 +1001,35 @@ MWF.xApplication.process.FormDesigner.LP = { "ckeditConfigInfor4": "For more configuration, please check the official website of Ckeditor", "ckeditConfigInfor5": "https://ckeditor.com/ckeditor-4/", - "ckeditConfigInfor6": "Note: After the editor properties are customized, the text format may no longer meet the national party and government agency official document format standards" + "ckeditConfigInfor6": "Note: After the editor properties are customized, the text format may no longer meet the national party and government agency official document format standards", + + "password": "password", + "search": "search", + "email": "email", + "datetime-local":"datetime-local", + "month": "month", + "date": "date", + "time": "time", + "week": "week", + "textarea": "textarea", + "wordNumber": "wordNumber", + "maxlength": "maxlength", + "clearable": "clearable", + "showPassword": "showPassword", + "prefixIcon": "prefixIcon", + "suffixIcon": "suffixIcon", + "textareaRows": "Textarea Rows", + "autosize": "autosize", + "minRows": "minRows", + "maxRows": "maxRows", + "resize": "resize", + "resizeNone": "none", + "resizeBoth": "both", + "resizeHorizontal": "horizontal", + "resizeVertical": "vertical", + "el_placement": "placement", + "popperClass": "Popper Class", + "triggerOnFocus": "trigger on focus" }, "actionBar": { "close":"Close", diff --git a/o2web/source/x_component_process_FormDesigner/lp/zh-cn.js b/o2web/source/x_component_process_FormDesigner/lp/zh-cn.js index d3e814e718..b5ce1f79b0 100644 --- a/o2web/source/x_component_process_FormDesigner/lp/zh-cn.js +++ b/o2web/source/x_component_process_FormDesigner/lp/zh-cn.js @@ -1032,7 +1032,11 @@ MWF.xApplication.process.FormDesigner.LP = { "resizeNone": "不允许", "resizeBoth": "允许", "resizeHorizontal": "横向", - "resizeVertical": "纵向" + "resizeVertical": "纵向", + "el_placement": "弹出位置", + "popperClass": "列表类名", + "triggerOnFocus": "激活即列出输入建议" + }, "actionBar": { "close":"关闭", diff --git a/o2web/source/x_component_process_Xform/$ElInput.js b/o2web/source/x_component_process_Xform/$ElInput.js index 358639465f..278945e631 100644 --- a/o2web/source/x_component_process_Xform/$ElInput.js +++ b/o2web/source/x_component_process_Xform/$ElInput.js @@ -22,9 +22,10 @@ Object.assign(o2.APP$Elinput.prototype, { if (this.readonly || this.json.isReadonly) this.node.set("text", value); if (old!==data) this.fireEvent("change"); this.moduleValueAG = null; + this.validationMode(); }, getInputData: function(){ - return this.json[this.json.id] || this._getBusinessData(); + return this.json[this.json.id]; }, _loadNodeEdit: function(){ this.node.appendHTML(this._createElementHtml(), "before"); diff --git a/o2web/source/x_component_process_Xform/$ElModule.js b/o2web/source/x_component_process_Xform/$ElModule.js index 90c7a842ec..c66e81ee04 100644 --- a/o2web/source/x_component_process_Xform/$ElModule.js +++ b/o2web/source/x_component_process_Xform/$ElModule.js @@ -80,7 +80,8 @@ o2.xApplication.process.Xform.$ElModule = MWF.APP$ElModule = new Class( * @see https://vuejs.org/ * @member {VueInstance} */ - this.vm = new Vue(this.vueApp).$mount(this.node); + this.vm = new Vue(this.vueApp); + this.vm.$mount(this.node); }, _createVueExtend: function(){ @@ -91,10 +92,20 @@ o2.xApplication.process.Xform.$ElModule = MWF.APP$ElModule = new Class( _self._afterMounted(this.$el); } }; + app.methods = this._createVueMethods(app); this.appendVueExtend(app); return app; }, + appendVueMethods: function(app){}, appendVueExtend: function(app){}, + _createVueMethods: function(){ + var methods = {}; + if (this.json.vueMethods && this.json.vueMethods.code){ + methods = this.form.Macro.exec(this.json.vueMethods.code, this); + } + this.appendVueMethods(); + return methods || {}; + }, _createVueData: function(){ if (this.json.vueData && this.json.vueData.code){ var d = this.form.Macro.exec(this.json.vueData.code, this); diff --git a/o2web/source/x_component_process_Xform/Elautocomplete.js b/o2web/source/x_component_process_Xform/Elautocomplete.js new file mode 100644 index 0000000000..264d80818b --- /dev/null +++ b/o2web/source/x_component_process_Xform/Elautocomplete.js @@ -0,0 +1,119 @@ +o2.xDesktop.requireApp("process.Xform", "$Elinput", null, false); +/** @class Elautocomplete 基于Element UI的自动完成输入框组件。 + * @example + * //可以在脚本中获取该组件 + * //方法1: + * var input = this.form.get("name"); //获取组件 + * //方法2 + * var input = this.target; //在组件事件脚本中获取 + * @extends MWF.xApplication.process.Xform.$Module + * @o2category FormComponents + * @o2range {Process|CMS|Portal} + * @hideconstructor + */ +MWF.xApplication.process.Xform.Elautocomplete = MWF.APPElautocomplete = new Class( + /** @lends o2.xApplication.process.Xform.Elautocomplete# */ + { + Implements: [Events], + Extends: MWF.APP$Elinput, + options: { + "moduleEvents": ["load", "queryLoad", "postLoad"], + "elEvents": ["select", "change"] + }, + /** + * @summary 组件的配置信息,同时也是Vue组件的data。 + * @member MWF.xApplication.process.Xform.Elinput#json {JsonObject} + * @example + * //可以在脚本中获取此对象,下面两行代码是等价的,它们获取的是同一个对象 + * var json = this.form.get("elinput").json; //获取组件的json对象 + * var json = this.form.get("elinput").vm.$data; //获取Vue组件的data数据, + * + * //通过json对象操作Element组件 + * json.size = "mini"; //改变输入框大小 + * json.disabled = true; //设置输入框为禁用 + */ + _appendVueData: function(){ + if (!this.json[this.json.id]){ + this.json[this.json.id] = this._getBusinessData(); + } + + if (!this.json.placement) this.json.placement = "bottom-start"; + if (!this.json.popperClass) this.json.popperClass = ""; + if (!this.json.triggerOnFocus && this.json.triggerOnFocus!==false) this.json.triggerOnFocus = true; + if (!this.json.prefixIcon) this.json.prefixIcon = ""; + if (!this.json.suffixIcon) this.json.suffixIcon = ""; + if (!this.json.description) this.json.description = ""; + }, + appendVueExtend: function(app){ + if (!app.methods) app.methods = {}; + app.methods.$loadElEvent = function(ev){ + this.validationMode(); + if (this.json.events[ev] && this.json.events[ev].code){ + this.form.Macro.fire(this.json.events[ev].code, this, event); + } + }.bind(this); + app.methods.$fetchSuggestions = function(qs, cb){ + debugger; + if (this.json.itemType!=='script'){ + if (this.json.itemValues){ + var items = this.json.itemValues.filter(function(v){ + return !qs || v.indexOf(qs)!=-1; + }).map(function(v){ + return {"value": v}; + }) + cb(items); + return; + } + cb(); + }else{ + this.form.Macro.environment.queryString = qs; + var list = this.form.Macro.exec(this.json.itemScript.code, this); + Promise.resolve(list).then(function(items){ + cb(items); + delete this.form.Macro.environment.queryString; + }).catch(function(){ + cb(); + delete this.form.Macro.environment.queryString; + }); + } + }.bind(this); + }, + _createElementHtml: function(){ + var html = ""; + html += ">"; + + if (this.json.vueSlot) html += this.json.vueSlot; + + html += ""; return html; } }); diff --git a/o2web/source/x_desktop/js/initialScriptText.js b/o2web/source/x_desktop/js/initialScriptText.js index cb22218a8f..3202589eda 100644 --- a/o2web/source/x_desktop/js/initialScriptText.js +++ b/o2web/source/x_desktop/js/initialScriptText.js @@ -1,6 +1,6 @@ bind = {}; var library = { - 'version': '4.0', + 'version': '6.2', "defineProperties": Object.defineProperties || function (obj, properties) { function convertToDescriptor(desc) { function hasProperty(obj, prop) { @@ -151,23 +151,22 @@ var wrapWorkContext = { //applications -var includedScripts = []; -var _self = this; -var include = function(name, callback){ - if (includedScripts.indexOf(name)==-1){ - var json = JSON.parse(_self.workContext.getScript(name, includedScripts)); - includedScripts = includedScripts.concat(json.importedList); - if (json.text){ - //MWF.Macro.exec(json.data.text, bind); - var f = eval("(function(){return function(){\n"+json.text+"\n}})();"); - returnValue = f.apply(bind); - - if (callback) callback.apply(bind); - } - } -}; - -var define = function(name, fun, overwrite){ +// var includedScripts = []; +// var _self = this; +// var include = function(name, callback){ +// if (includedScripts.indexOf(name)==-1){ +// var json = JSON.parse(_self.workContext.getScript(name, includedScripts)); +// includedScripts = includedScripts.concat(json.importedList); +// if (json.text){ +// //MWF.Macro.exec(json.data.text, bind); +// var f = eval("(function(){return function(){\n"+json.text+"\n}})();"); +// returnValue = f.apply(bind); +// +// if (callback) callback.apply(bind); +// } +// } +// }; +var _define = function(name, fun, overwrite){ var over = true; if (overwrite===false) over = false; var o = {}; @@ -175,29 +174,30 @@ var define = function(name, fun, overwrite){ library.defineProperties(bind, o); }; -var Dict = function(name){ - var dictionary = _self.dictionary; - this.name = name; - this.get = function(path){ - return JSON.parse(dictionary.select(this.name, path)); - }; - this.set = function(path, value){ - try { - dictionary.update(this.name, library.JSONEncode(value), path); - return true; - }catch(e){ - return false; - } - }; - this.add = function(path, value){ - try { - dictionary.insert(this.name, library.JSONEncode(value), path); - return true; - }catch(e){ - return false; - } - }; -}; +// var Dict = function(name){ +// var dictionary = _self.dictionary; +// this.name = name; +// this.get = function(path){ +// return JSON.parse(dictionary.select(this.name, path)); +// }; +// this.set = function(path, value){ +// try { +// dictionary.update(this.name, library.JSONEncode(value), path); +// return true; +// }catch(e){ +// return false; +// } +// }; +// this.add = function(path, value){ +// try { +// dictionary.insert(this.name, library.JSONEncode(value), path); +// return true; +// }catch(e){ +// return false; +// } +// }; +// }; + if ((typeof JSON) == 'undefined'){ JSON = {}; } @@ -814,6 +814,200 @@ var _Actions = { }; bind.Actions = _Actions; +//定义所需的服务 +var _processActions = new _Action("x_processplatform_assemble_surface", { + "getDictionary": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{applicationFlag}"}, + "getDictRoot": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/data"}, + "getDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data"}, + "setDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "PUT"}, + "addDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "POST"}, + "deleteDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "DELETE"}, + "getScript": {"uri": "/jaxrs/script/{flag}/application/{applicationFlag}", "method": "POST"}, +}); +var _cmsActions = new _Action("x_cms_assemble_control", { + "getDictionary": {"uri": "/jaxrs/design/appdict/{appDictId}"}, + "getDictRoot": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/data"}, + "getDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"}, + "setDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "PUT"}, + "addDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "POST"}, + "deleteDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "DELETE"}, + "getDictRootAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/data"}, + "getDictDataAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"}, + "getScript": {"uri": "/jaxrs/script/{flag}/appInfo/{appInfoFlag}", "method": "POST"}, +}); +var _portalActions = new _Action("x_portal_assemble_surface", { + "getScript": {"uri": "/jaxrs/script/portal/{portal}/name/{ }","method": "POST"} +}); + +//include 引用脚本 +//optionsOrName : { +// type : "", 默认为process, 可以为 portal process cms +// application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用 +// name : "" // 脚本名称/别名/id +//} +//或者name: "" // 脚本名称/别名/id +var _exec = function(code, _self){ + var returnValue; + //try{ + if (!_self) _self = this; + try { + var f = eval("(function(){return function(){\n"+code+"\n}})();"); + returnValue = f.apply(_self); + }catch(e){ + console.log("exec", new Error("exec script error")); + console.log(e); + } + return returnValue; +} + +var includedScripts = this.includedScripts || {}; +this.includedScripts = includedScripts; + +var _include = function( optionsOrName , callback ){ + var options = optionsOrName; + if( typeOf( options ) == "string" ){ + options = { name : options }; + } + var name = options.name; + var type = ( options.type && options.application ) ? options.type : "process"; + var application = options.application + + if (!name || !type || !application){ + console.log("include", new Error("can not find script. missing script name or application")); + return false; + } + + if (!includedScripts[application]) includedScripts[application] = []; + + if (includedScripts[application].indexOf( name )> -1){ + if (callback) callback.apply(this); + return; + } + + var scriptAction; + var scriptData; + switch ( type ){ + case "portal" : + _portalActions.getScript( application, name, {"importedList":includedScripts[application]}, function(json){ + if (json.data){ + includedScripts[application] = includedScripts[application].concat(json.data.importedList); + scriptData = json.data; + } + }.bind(this)); + break; + case "process" : + _processActions.getScript( name, application, {"importedList":includedScripts[application]}, function(json){ + if (json.data){ + includedScripts[application] = includedScripts[application].concat(json.data.importedList); + scriptData = json.data; + } + }.bind(this)); + break; + case "cms" : + _cmsActions.getScript(name, application, {"importedList":includedScripts[application]}, function(json){ + if (json.data){ + includedScripts[application] = includedScripts[application].concat(json.data.importedList); + scriptData = json.data; + } + }.bind(this)); + break; + } + includedScripts[application].push(name); + if (scriptData && scriptData.text){ + bind.exec(scriptData.text, this); + if (callback) callback.apply(this); + } +}; + +var _createDict = function(application){ + //optionsOrName : { + // type : "", //默认为process, 可以为 process cms + // application : "", //流程/CMS的名称/别名/id, 默认为当前应用 + // name : "", // 数据字典名称/别名/id + // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典 + //} + //或者name: "" // 数据字典名称/别名/id + return function(optionsOrName){ + var options = optionsOrName; + if( typeOf( options ) == "string" ){ + options = { name : options }; + } + var name = this.name = options.name; + var type = ( options.type && options.application ) ? options.type : "process"; + var applicationId = options.application || application; + var enableAnonymous = options.enableAnonymous || false; + + //MWF.require("MWF.xScript.Actions.DictActions", null, false); + if( type == "cms" ){ + var action = bind.cmsActions; + }else{ + var action = bind.processActions; + } + + var encodePath = function( path ){ + var arr = path.split(/\./g); + var ar = arr.map(function(v){ + return encodeURIComponent(v); + }); + return ar.join("/"); + }; + + this.get = function(path, success, failure){ + var value = null; + if (path){ + var p = encodePath( path ); + action[(enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData"](encodeURIComponent(this.name), applicationId, p, function(json){ + value = json.data; + if (success) success(json.data); + }, function(xhr, text, error){ + if (failure) failure(xhr, text, error); + }); + }else{ + action[(enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot"](encodeURIComponent(this.name), applicationId, function(json){ + value = json.data; + if (success) success(json.data); + }, function(xhr, text, error){ + if (failure) failure(xhr, text, error); + }, false); + } + + return value; + }; + + this.set = function(path, value, success, failure){ + var p = encodePath( path ); + //var p = path.replace(/\./g, "/"); + action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){ + if (success) success(json.data); + }, function(xhr, text, error){ + if (failure) failure(xhr, text, error); + }, false, false); + }; + this.add = function(path, value, success, failure){ + var p = encodePath( path ); + //var p = path.replace(/\./g, "/"); + action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){ + if (success) success(json.data); + }, function(xhr, text, error){ + if (failure) failure(xhr, text, error); + }, false, false); + }; + this["delete"] = function(path, success, failure){ + var p = encodePath( path ); + //var p = path.replace(/\./g, "/"); + action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){ + if (success) success(json.data); + }, function(xhr, text, error){ + if (failure) failure(xhr, text, error); + }, false, false); + }; + this.destory = this["delete"]; + } +}; +bind.exec = _exec; +bind.include = _include; +bind.Dict = _createDict(); + try{ oPrint = oPrint; }catch(e){ @@ -836,9 +1030,9 @@ bind.service = this.webservicesClient; bind.org = _org; bind.Action = _Action; //bind.organization = this.organization; -bind.include = include; -bind.define = define; -bind.Dict = Dict; +//bind.include = include; +bind.define = _define; +//bind.Dict = Dict; bind.form = null; bind.body = { "set": function(data){ @@ -928,55 +1122,6 @@ Object.defineProperty(response, "get", {enumerable: true,configurable: true, }); bind.response = response; -// bind.response = (function(){ -// // var _self = this; -// // if (this.jaxrsResponse){ -// if (this.jaxrsResponse.get()){ -// var value = this.jaxrsResponse.get(); -// if (JSON.validate(value)){ -// return { -// "status": this.jaxrsResponse.status, -// "value": JSON.decode(value), -// "get": function(){ JSON.decode(value) } -// }; -// }else{ -// return { -// "status": this.jaxrsResponse.status, -// "value": value, -// "get": function(){ return value; } -// }; -// } -// }else{ -// return { -// "status": this.jaxrsResponse.status, -// "value": this.jaxrsResponse.value, -// "get": function(){ return _self.jaxrsResponse.value; } -// }; -// } -// }else{ -// return { -// "get": function(){ -// return _self.jaxwsResponse || null; -// // if (_self.jaxwsResponse && _self.jaxwsResponse.get()){ -// // if (JSON.validate(_self.jaxwsResponse.get())){ -// // return { -// // "status": _self.jaxwsResponse.status, -// // "value": JSON.decode(_self.jaxwsResponse.get()) -// // }; -// // }else{ -// // return { -// // "status": _self.jaxwsResponse.status, -// // "value": _self.jaxwsResponse.value -// // }; -// // } -// // }else{ -// // return {"status": _self.jaxwsResponse.status}; -// // } -// } -// } -// } -// }).apply(this); - bind.assginData = { "data": null, "get": function(){ -- GitLab