From e8c682e402e5601f80aab8a5709a0a2fa329a3c2 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 6 Aug 2020 15:50:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8java=E8=BF=90?= =?UTF-8?q?=E8=A1=8Cjs=E8=84=9A=E6=9C=AC=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3jar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 33 +++++++++++++++++++ .../src/main/resources/javascript/mock-min.js | 10 ++++++ 2 files changed, 43 insertions(+) create mode 100644 backend/src/main/resources/javascript/mock-min.js diff --git a/backend/pom.xml b/backend/pom.xml index 2e0bb201d4..8e38b46fa9 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -20,6 +20,7 @@ 5.2.1 1.1.3 2.7.7 + 20.1.0 @@ -233,6 +234,38 @@ 1.0.51 + + + org.graalvm.sdk + graal-sdk + ${graalvm.version} + compile + + + org.graalvm.js + js + ${graalvm.version} + runtime + + + org.graalvm.js + js-scriptengine + ${graalvm.version} + runtime + + + org.graalvm.tools + profiler + ${graalvm.version} + runtime + + + org.graalvm.tools + chromeinspector + ${graalvm.version} + runtime + + diff --git a/backend/src/main/resources/javascript/mock-min.js b/backend/src/main/resources/javascript/mock-min.js new file mode 100644 index 0000000000..0bf1677eaf --- /dev/null +++ b/backend/src/main/resources/javascript/mock-min.js @@ -0,0 +1,10 @@ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Mock=e():t.Mock=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var a=n[r]={exports:{},id:r,loaded:!1};return t[r].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){var r,a=n(1),o=n(3),u=n(5),i=n(20),l=n(23),c=n(25);"undefined"!=typeof window&&(r=n(27));/*! + Mock - 模拟请求 & 模拟数据 + https://github.com/nuysoft/Mock + 墨智 mozhi.gyy@taobao.com nuysoft@gmail.com + */ + var s={Handler:a,Random:u,Util:o,XHR:r,RE:i,toJSONSchema:l,valid:c,heredoc:o.heredoc,setup:function(t){return r.setup(t)},_mocked:{}};s.version="1.0.1-beta3",r&&(r.Mock=s),s.mock=function(t,e,n){return 1===arguments.length?a.gen(t):(2===arguments.length&&(n=e,e=void 0),r&&(window.XMLHttpRequest=r),s._mocked[t+(e||"")]={rurl:t,rtype:e,template:n},s)},t.exports=s},function(module,exports,__webpack_require__){var Constant=__webpack_require__(2),Util=__webpack_require__(3),Parser=__webpack_require__(4),Random=__webpack_require__(5),RE=__webpack_require__(20),Handler={extend:Util.extend};Handler.gen=function(t,e,n){e=void 0==e?"":e+"",n=n||{},n={path:n.path||[Constant.GUID],templatePath:n.templatePath||[Constant.GUID++],currentContext:n.currentContext,templateCurrentContext:n.templateCurrentContext||t,root:n.root||n.currentContext,templateRoot:n.templateRoot||n.templateCurrentContext||t};var r,a=Parser.parse(e),o=Util.type(t);return Handler[o]?(r=Handler[o]({type:o,template:t,name:e,parsedName:e?e.replace(Constant.RE_KEY,"$1"):e,rule:a,context:n}),n.root||(n.root=r),r):t},Handler.extend({array:function(t){var e,n,r=[];if(0===t.template.length)return r;if(t.rule.parameters)if(1===t.rule.min&&void 0===t.rule.max)t.context.path.push(t.name),t.context.templatePath.push(t.name),r=Random.pick(Handler.gen(t.template,void 0,{path:t.context.path,templatePath:t.context.templatePath,currentContext:r,templateCurrentContext:t.template,root:t.context.root||r,templateRoot:t.context.templateRoot||t.template})),t.context.path.pop(),t.context.templatePath.pop();else if(t.rule.parameters[2])t.template.__order_index=t.template.__order_index||0,t.context.path.push(t.name),t.context.templatePath.push(t.name),r=Handler.gen(t.template,void 0,{path:t.context.path,templatePath:t.context.templatePath,currentContext:r,templateCurrentContext:t.template,root:t.context.root||r,templateRoot:t.context.templateRoot||t.template})[t.template.__order_index%t.template.length],t.template.__order_index+=+t.rule.parameters[2],t.context.path.pop(),t.context.templatePath.pop();else for(e=0;e1)return this.getValueByKeyPath(key,options);if(templateContext&&"object"==typeof templateContext&&key in templateContext&&placeholder!==templateContext[key])return templateContext[key]=Handler.gen(templateContext[key],key,{currentContext:obj,templateCurrentContext:templateContext}),templateContext[key];if(!(key in Random||lkey in Random||okey in Random))return placeholder;for(var i=0;i1&&(a=e.context.path.slice(0),a.pop(),a=this.normalizePath(a.concat(r)));try{t=r[r.length-1];for(var o=e.context.root,u=e.context.templateRoot,i=1;i1/(t+e)*t?!n:n):Math.random()>=.5},bool:function(t,e,n){return this.boolean(t,e,n)},natural:function(t,e){return t="undefined"!=typeof t?parseInt(t,10):0,e="undefined"!=typeof e?parseInt(e,10):9007199254740992,Math.round(Math.random()*(e-t))+t},integer:function(t,e){return t="undefined"!=typeof t?parseInt(t,10):-9007199254740992,e="undefined"!=typeof e?parseInt(e,10):9007199254740992,Math.round(Math.random()*(e-t))+t},int:function(t,e){return this.integer(t,e)},float:function(t,e,n,r){n=void 0===n?0:n,n=Math.max(Math.min(n,17),0),r=void 0===r?17:r,r=Math.max(Math.min(r,17),0);for(var a=this.integer(t,e)+".",o=0,u=this.natural(n,r);o1&&r--,o=6*r<1?e+6*(n-e)*r:2*r<1?n:3*r<2?e+(n-e)*(2/3-r)*6:e,a[c]=255*o;return a},hsl2hsv:function(t){var e,n,r=t[0],a=t[1]/100,o=t[2]/100;return o*=2,a*=o<=1?o:2-o,n=(o+a)/2,e=2*a/(o+a),[r,100*e,100*n]},hsv2rgb:function(t){var e=t[0]/60,n=t[1]/100,r=t[2]/100,a=Math.floor(e)%6,o=e-Math.floor(e),u=255*r*(1-n),i=255*r*(1-n*o),l=255*r*(1-n*(1-o));switch(r*=255,a){case 0:return[r,l,u];case 1:return[i,r,u];case 2:return[u,r,l];case 3:return[u,i,r];case 4:return[l,u,r];case 5:return[r,u,i]}},hsv2hsl:function(t){var e,n,r=t[0],a=t[1]/100,o=t[2]/100;return n=(2-a)*o,e=a*o,e/=n<=1?n:2-n,n/=2,[r,100*e,100*n]},rgb2hex:function(t,e,n){return"#"+((256+t<<8|e)<<8|n).toString(16).slice(1)},hex2rgb:function(t){return t="0x"+t.slice(1).replace(t.length>4?t:/./g,"$&$&")|0,[t>>16,t>>8&255,255&t]}}},function(t,e){t.exports={navy:{value:"#000080",nicer:"#001F3F"},blue:{value:"#0000ff",nicer:"#0074D9"},aqua:{value:"#00ffff",nicer:"#7FDBFF"},teal:{value:"#008080",nicer:"#39CCCC"},olive:{value:"#008000",nicer:"#3D9970"},green:{value:"#008000",nicer:"#2ECC40"},lime:{value:"#00ff00",nicer:"#01FF70"},yellow:{value:"#ffff00",nicer:"#FFDC00"},orange:{value:"#ffa500",nicer:"#FF851B"},red:{value:"#ff0000",nicer:"#FF4136"},maroon:{value:"#800000",nicer:"#85144B"},fuchsia:{value:"#ff00ff",nicer:"#F012BE"},purple:{value:"#800080",nicer:"#B10DC9"},silver:{value:"#c0c0c0",nicer:"#DDDDDD"},gray:{value:"#808080",nicer:"#AAAAAA"},black:{value:"#000000",nicer:"#111111"},white:{value:"#FFFFFF",nicer:"#FFFFFF"}}},function(t,e,n){function r(t,e,n,r){return void 0===n?a.natural(t,e):void 0===r?n:a.natural(parseInt(n,10),parseInt(r,10))}var a=n(6),o=n(14);t.exports={paragraph:function(t,e){for(var n=r(3,7,t,e),a=[],o=0;o1&&(e=[].slice.call(arguments,0));var n=t.options,r=n.context.templatePath.join("."),a=t.cache[r]=t.cache[r]||{index:0,array:e};return a.array[a.index++%a.array.length]}}},function(t,e){t.exports={first:function(){var t=["James","John","Robert","Michael","William","David","Richard","Charles","Joseph","Thomas","Christopher","Daniel","Paul","Mark","Donald","George","Kenneth","Steven","Edward","Brian","Ronald","Anthony","Kevin","Jason","Matthew","Gary","Timothy","Jose","Larry","Jeffrey","Frank","Scott","Eric"].concat(["Mary","Patricia","Linda","Barbara","Elizabeth","Jennifer","Maria","Susan","Margaret","Dorothy","Lisa","Nancy","Karen","Betty","Helen","Sandra","Donna","Carol","Ruth","Sharon","Michelle","Laura","Sarah","Kimberly","Deborah","Jessica","Shirley","Cynthia","Angela","Melissa","Brenda","Amy","Anna"]);return this.pick(t)},last:function(){var t=["Smith","Johnson","Williams","Brown","Jones","Miller","Davis","Garcia","Rodriguez","Wilson","Martinez","Anderson","Taylor","Thomas","Hernandez","Moore","Martin","Jackson","Thompson","White","Lopez","Lee","Gonzalez","Harris","Clark","Lewis","Robinson","Walker","Perez","Hall","Young","Allen"];return this.pick(t)},name:function(t){return this.first()+" "+(t?this.first()+" ":"")+this.last()},cfirst:function(){var t="王 李 张 刘 陈 杨 赵 黄 周 吴 徐 孙 胡 朱 高 林 何 郭 马 罗 梁 宋 郑 谢 韩 唐 冯 于 董 萧 程 曹 袁 邓 许 傅 沈 曾 彭 吕 苏 卢 蒋 蔡 贾 丁 魏 薛 叶 阎 余 潘 杜 戴 夏 锺 汪 田 任 姜 范 方 石 姚 谭 廖 邹 熊 金 陆 郝 孔 白 崔 康 毛 邱 秦 江 史 顾 侯 邵 孟 龙 万 段 雷 钱 汤 尹 黎 易 常 武 乔 贺 赖 龚 文".split(" ");return this.pick(t)},clast:function(){var t="伟 芳 娜 秀英 敏 静 丽 强 磊 军 洋 勇 艳 杰 娟 涛 明 超 秀兰 霞 平 刚 桂英".split(" ");return this.pick(t)},cname:function(){return this.cfirst()+this.clast()}}},function(t,e){t.exports={url:function(t,e){return(t||this.protocol())+"://"+(e||this.domain())+"/"+this.word()},protocol:function(){return this.pick("http ftp gopher mailto mid cid news nntp prospero telnet rlogin tn3270 wais".split(" "))},domain:function(t){return this.word()+"."+(t||this.tld())},tld:function(){return this.pick("com net org edu gov int mil cn com.cn net.cn gov.cn org.cn 中国 中国互联.公司 中国互联.网络 tel biz cc tv info name hk mobi asia cd travel pro museum coop aero ad ae af ag ai al am an ao aq ar as at au aw az ba bb bd be bf bg bh bi bj bm bn bo br bs bt bv bw by bz ca cc cf cg ch ci ck cl cm cn co cq cr cu cv cx cy cz de dj dk dm do dz ec ee eg eh es et ev fi fj fk fm fo fr ga gb gd ge gf gh gi gl gm gn gp gr gt gu gw gy hk hm hn hr ht hu id ie il in io iq ir is it jm jo jp ke kg kh ki km kn kp kr kw ky kz la lb lc li lk lr ls lt lu lv ly ma mc md mg mh ml mm mn mo mp mq mr ms mt mv mw mx my mz na nc ne nf ng ni nl no np nr nt nu nz om qa pa pe pf pg ph pk pl pm pn pr pt pw py re ro ru rw sa sb sc sd se sg sh si sj sk sl sm sn so sr st su sy sz tc td tf tg th tj tk tm tn to tp tr tt tv tw tz ua ug uk us uy va vc ve vg vn vu wf ws ye yu za zm zr zw".split(" "))},email:function(t){return this.character("lower")+"."+this.word()+"@"+(t||this.word()+"."+this.tld())},ip:function(){return this.natural(0,255)+"."+this.natural(0,255)+"."+this.natural(0,255)+"."+this.natural(0,255)}}},function(t,e,n){var r=n(18),a=["东北","华北","华东","华中","华南","西南","西北"];t.exports={region:function(){return this.pick(a)},province:function(){return this.pick(r).name},city:function(t){var e=this.pick(r),n=this.pick(e.children);return t?[e.name,n.name].join(" "):n.name},county:function(t){var e=this.pick(r),n=this.pick(e.children),a=this.pick(n.children)||{name:"-"};return t?[e.name,n.name,a.name].join(" "):a.name},zip:function(t){for(var e="",n=0;n<(t||6);n++)e+=this.natural(0,9);return e}}},function(t,e){function n(t){for(var e,n={},r=0;ra;a++)o=t.charAt(a),"\n"===o?(e.seenCR||e.line++,e.column=1,e.seenCR=!1):"\r"===o||"\u2028"===o||"\u2029"===o?(e.line++,e.column=1,e.seenCR=!0):(e.column++,e.seenCR=!1)}return tr!==e&&(tr>e&&(tr=0,er={line:1,column:1,seenCR:!1}),n(er,tr,e),tr=e),er}function b(t){nr>Zn||(Zn>nr&&(nr=Zn,rr=[]),rr.push(t))}function w(t){var e=0;for(t.sort();eZn?(r=t.charAt(Zn),Zn++):(r=null,0===ar&&b(Hn)),null!==r?(Qn=e,n=Sn(r),null===n?(Zn=e,e=n):e=n):(Zn=e,e=kt)):(Zn=e,e=kt),e}function ft(){var e,n,r;return e=Zn,92===t.charCodeAt(Zn)?(n=Dn,Zn++):(n=null,0===ar&&b(qn)),null!==n?(Fn.test(t.charAt(Zn))?(r=t.charAt(Zn),Zn++):(r=null,0===ar&&b(Ln)),null!==r?(Qn=e,n=On(r),null===n?(Zn=e,e=n):e=n):(Zn=e,e=kt)):(Zn=e,e=kt),e}function dt(){var e,n,r,a;if(e=Zn,t.substr(Zn,2)===In?(n=In,Zn+=2):(n=null,0===ar&&b(jn)),null!==n){if(r=[],Nn.test(t.charAt(Zn))?(a=t.charAt(Zn),Zn++):(a=null,0===ar&&b(zn)),null!==a)for(;null!==a;)r.push(a),Nn.test(t.charAt(Zn))?(a=t.charAt(Zn),Zn++):(a=null,0===ar&&b(zn));else r=kt;null!==r?(Qn=e,n=Un(r),null===n?(Zn=e,e=n):e=n):(Zn=e,e=kt)}else Zn=e,e=kt;return e}function mt(){var e,n,r,a;if(e=Zn,t.substr(Zn,2)===Bn?(n=Bn,Zn+=2):(n=null,0===ar&&b(Gn)),null!==n){if(r=[],Xn.test(t.charAt(Zn))?(a=t.charAt(Zn),Zn++):(a=null,0===ar&&b(Kn)),null!==a)for(;null!==a;)r.push(a),Xn.test(t.charAt(Zn))?(a=t.charAt(Zn),Zn++):(a=null,0===ar&&b(Kn));else r=kt;null!==r?(Qn=e,n=Wn(r),null===n?(Zn=e,e=n):e=n):(Zn=e,e=kt)}else Zn=e,e=kt;return e}function vt(){var e,n,r,a;if(e=Zn,t.substr(Zn,2)===Yn?(n=Yn,Zn+=2):(n=null,0===ar&&b($n)),null!==n){if(r=[],Xn.test(t.charAt(Zn))?(a=t.charAt(Zn),Zn++):(a=null,0===ar&&b(Kn)),null!==a)for(;null!==a;)r.push(a),Xn.test(t.charAt(Zn))?(a=t.charAt(Zn),Zn++):(a=null,0===ar&&b(Kn));else r=kt;null!==r?(Qn=e,n=Jn(r),null===n?(Zn=e,e=n):e=n):(Zn=e,e=kt)}else Zn=e,e=kt;return e}function gt(){var e,n;return e=Zn,t.substr(Zn,2)===In?(n=In,Zn+=2):(n=null,0===ar&&b(jn)),null!==n&&(Qn=e,n=Vn()),null===n?(Zn=e,e=n):e=n,e}function xt(){var e,n,r;return e=Zn,92===t.charCodeAt(Zn)?(n=Dn,Zn++):(n=null,0===ar&&b(qn)),null!==n?(t.length>Zn?(r=t.charAt(Zn),Zn++):(r=null,0===ar&&b(Hn)),null!==r?(Qn=e,n=Fe(r),null===n?(Zn=e,e=n):e=n):(Zn=e,e=kt)):(Zn=e,e=kt),e}var yt,bt=arguments.length>1?arguments[1]:{},wt={regexp:C},Ct=C,kt=null,Et="",Rt="|",At='"|"',_t=function(t,e){return e?new r(t,e[1]):t},Mt=function(t,e,n){return new a([t].concat(e).concat([n]))},Pt="^",Tt='"^"',Ht=function(){return new n("start")},St="$",Dt='"$"',qt=function(){return new n("end")},Ft=function(t,e){return new i(t,e)},Lt="Quantifier",Ot=function(t,e){return e&&(t.greedy=!1),t},It="{",jt='"{"',Nt=",",zt='","',Ut="}",Bt='"}"',Gt=function(t,e){return new l(t,e)},Xt=",}",Kt='",}"',Wt=function(t){return new l(t,1/0)},Yt=function(t){return new l(t,t)},$t="+",Jt='"+"',Vt=function(){return new l(1,1/0)},Zt="*",Qt='"*"',te=function(){return new l(0,1/0)},ee="?",ne='"?"',re=function(){return new l(0,1)},ae=/^[0-9]/,oe="[0-9]",ue=function(t){return+t.join("")},ie="(",le='"("',ce=")",se='")"',he=function(t){return t},pe=function(t){return new u(t)},fe="?:",de='"?:"',me=function(t){return new o("non-capture-group",t)},ve="?=",ge='"?="',xe=function(t){return new o("positive-lookahead",t)},ye="?!",be='"?!"',we=function(t){return new o("negative-lookahead",t)},Ce="CharacterSet",ke="[",Ee='"["',Re="]",Ae='"]"',_e=function(t,e){return new c(!!t,e)},Me="CharacterRange",Pe="-",Te='"-"',He=function(t,e){return new s(t,e)},Se="Character",De=/^[^\\\]]/,qe="[^\\\\\\]]",Fe=function(t){return new h(t)},Le=".",Oe='"."',Ie=function(){return new n("any-character")},je="Literal",Ne=/^[^|\\\/.[()?+*$\^]/,ze="[^|\\\\\\/.[()?+*$\\^]",Ue="\\b",Be='"\\\\b"',Ge=function(){return new n("backspace")},Xe=function(){return new n("word-boundary")},Ke="\\B",We='"\\\\B"',Ye=function(){return new n("non-word-boundary")},$e="\\d",Je='"\\\\d"',Ve=function(){return new n("digit")},Ze="\\D",Qe='"\\\\D"',tn=function(){return new n("non-digit")},en="\\f",nn='"\\\\f"',rn=function(){return new n("form-feed")},an="\\n",on='"\\\\n"',un=function(){return new n("line-feed")},ln="\\r",cn='"\\\\r"',sn=function(){return new n("carriage-return")},hn="\\s",pn='"\\\\s"',fn=function(){return new n("white-space")},dn="\\S",mn='"\\\\S"',vn=function(){return new n("non-white-space")},gn="\\t",xn='"\\\\t"',yn=function(){return new n("tab")},bn="\\v",wn='"\\\\v"',Cn=function(){return new n("vertical-tab"); +},kn="\\w",En='"\\\\w"',Rn=function(){return new n("word")},An="\\W",_n='"\\\\W"',Mn=function(){return new n("non-word")},Pn="\\c",Tn='"\\\\c"',Hn="any character",Sn=function(t){return new v(t)},Dn="\\",qn='"\\\\"',Fn=/^[1-9]/,Ln="[1-9]",On=function(t){return new m(t)},In="\\0",jn='"\\\\0"',Nn=/^[0-7]/,zn="[0-7]",Un=function(t){return new d(t.join(""))},Bn="\\x",Gn='"\\\\x"',Xn=/^[0-9a-fA-F]/,Kn="[0-9a-fA-F]",Wn=function(t){return new f(t.join(""))},Yn="\\u",$n='"\\\\u"',Jn=function(t){return new p(t.join(""))},Vn=function(){return new n("null-character")},Zn=0,Qn=0,tr=0,er={line:1,column:1,seenCR:!1},nr=0,rr=[],ar=0;if("startRule"in bt){if(!(bt.startRule in wt))throw new Error("Can't start parsing from rule \""+bt.startRule+'".');Ct=wt[bt.startRule]}if(n.offset=x,n.text=g,yt=Ct(),null!==yt&&Zn===t.length)return yt;throw w(rr),Qn=Math.max(Zn,nr),new e(rr,Qnr)return!0;var u={path:e,type:t,actual:n,expected:r,action:"is greater than",message:o};return u.message=l.message(u),a.push(u),!1},lessThan:function(t,e,n,r,a,o){if(n=r)return!0;var u={path:e,type:t,actual:n,expected:r,action:"is greater than or equal to",message:o};return u.message=l.message(u),a.push(u),!1},lessThanOrEqualTo:function(t,e,n,r,a,o){if(n<=r)return!0;var u={path:e,type:t,actual:n,expected:r,action:"is less than or equal to",message:o};return u.message=l.message(u),a.push(u),!1}};r.Diff=i,r.Assert=l,t.exports=r},function(t,e,n){t.exports=n(28)},function(t,e,n){function r(){this.custom={events:{},requestHeaders:{},responseHeaders:{}}}function a(){function t(){try{return new window._XMLHttpRequest}catch(t){}}function e(){try{return new window._ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}var n=function(){var t=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,e=/^([\w.+-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,n=location.href,r=e.exec(n.toLowerCase())||[];return t.test(r[1])}();return window.ActiveXObject?!n&&t()||e():t()}function o(t){function e(t,e){return"string"===i.type(t)?t===e:"regexp"===i.type(t)?t.test(e):void 0}for(var n in r.Mock._mocked){var a=r.Mock._mocked[n];if((!a.rurl||e(a.rurl,t.url))&&(!a.rtype||e(a.rtype,t.type.toLowerCase())))return a}}function u(t,e){return i.isFunction(t.template)?t.template(e):r.Mock.mock(t.template)}var i=n(3);window._XMLHttpRequest=window.XMLHttpRequest,window._ActiveXObject=window.ActiveXObject;try{new window.Event("custom")}catch(t){window.Event=function(t,e,n,r){var a=document.createEvent("CustomEvent");return a.initCustomEvent(t,e,n,r),a}}var l={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4},c="readystatechange loadstart progress abort error load timeout loadend".split(" "),s="timeout withCredentials".split(" "),h="readyState responseURL status statusText responseType response responseText responseXML".split(" "),p={100:"Continue",101:"Switching Protocols",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",300:"Multiple Choice",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",422:"Unprocessable Entity",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported"};r._settings={timeout:"10-100"},r.setup=function(t){return i.extend(r._settings,t),r._settings},i.extend(r,l),i.extend(r.prototype,l),r.prototype.mock=!0,r.prototype.match=!1,i.extend(r.prototype,{open:function(t,e,n,u,l){function p(t){for(var e=0;e Date: Thu, 6 Aug 2020 18:01:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E9=AB=98=E7=BA=A7=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 6 +- .../api/test/components/ApiKeyValue.vue | 271 +++++++++++++----- frontend/src/common/js/constants.js | 54 ++++ frontend/src/common/js/func-filter.js | 199 +++++++++++++ frontend/src/i18n/en-US.js | 4 + frontend/src/i18n/zh-CN.js | 12 +- frontend/src/i18n/zh-TW.js | 4 + 7 files changed, 473 insertions(+), 77 deletions(-) create mode 100644 frontend/src/common/js/func-filter.js diff --git a/frontend/package.json b/frontend/package.json index 04e7741894..5d19b7cda7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -25,7 +25,11 @@ "vue-router": "^3.1.3", "vuedraggable": "^2.23.2", "vuex": "^3.1.2", - "vue-calendar-heatmap": "^0.8.4" + "vue-calendar-heatmap": "^0.8.4", + "mockjs": "^1.1.0", + "md5": "^2.3.0", + "sha.js": "^2.4.11", + "js-base64": "^3.4.4" }, "devDependencies": { "@vue/cli-plugin-babel": "^4.1.0", diff --git a/frontend/src/business/components/api/test/components/ApiKeyValue.vue b/frontend/src/business/components/api/test/components/ApiKeyValue.vue index 697035533e..f4777b31bd 100644 --- a/frontend/src/business/components/api/test/components/ApiKeyValue.vue +++ b/frontend/src/business/components/api/test/components/ApiKeyValue.vue @@ -1,7 +1,7 @@ diff --git a/frontend/src/common/js/constants.js b/frontend/src/common/js/constants.js index cb33a9a0b2..349daa7119 100644 --- a/frontend/src/common/js/constants.js +++ b/frontend/src/common/js/constants.js @@ -57,3 +57,57 @@ export const REQUEST_HEADERS = [ {value: 'Via'}, {value: 'Warning'} ] + +export const MOCKJS_FUNC = [ + {name: '@boolean'}, + {name: '@natural'}, + {name: '@integer'}, + {name: '@float'}, + {name: '@character'}, + {name: '@string'}, + {name: '@range'}, + {name: '@date'}, + {name: '@time'}, + {name: '@datetime'}, + {name: '@now'}, + {name: '@img'}, + {name: '@dataImage'}, + {name: '@color'}, + {name: '@hex'}, + {name: '@rgb'}, + {name: '@rgba'}, + {name: '@hsl'}, + {name: '@paragraph'}, + {name: '@sentence'}, + {name: '@word'}, + {name: '@title'}, + {name: '@cparagraph'}, + {name: '@csentence'}, + {name: '@cword'}, + {name: '@ctitle'}, + {name: '@first'}, + {name: '@last'}, + {name: '@name'}, + {name: '@cfirst'}, + {name: '@clast'}, + {name: '@cname'}, + {name: '@url'}, + {name: '@domain'}, + {name: '@protocol'}, + {name: '@tld'}, + {name: '@email'}, + {name: '@ip'}, + {name: '@region'}, + {name: '@province'}, + {name: '@city'}, + {name: '@county'}, + {name: '@zip'}, + {name: '@capitalize'}, + {name: '@upper'}, + {name: '@lower'}, + {name: '@pick'}, + {name: '@shuffle'}, + {name: '@guid'}, + {name: '@id'}, + {name: '@increment'} +] diff --git a/frontend/src/common/js/func-filter.js b/frontend/src/common/js/func-filter.js new file mode 100644 index 0000000000..356de3099f --- /dev/null +++ b/frontend/src/common/js/func-filter.js @@ -0,0 +1,199 @@ +const aUniqueVerticalStringNotFoundInData = '___UNIQUE_VERTICAL___'; +const aUniqueCommaStringNotFoundInData = '___UNIQUE_COMMA___'; +const segmentSeparateChar = '|'; +const methodAndArgsSeparateChar = ':'; +const argsSeparateChar = ','; + +const md5 = require('md5'); +const sha = require('sha.js'); +const Base64 = require('js-base64').Base64; + +export const funcFilters = { + md5: function (str) { + return md5(str); + }, + + sha: function (str, arg) { + return sha(arg) + .update(str) + .digest('hex'); + }, + + /** + * type: sha1 sha224 sha256 sha384 sha512 + */ + sha1: function (str) { + return sha('sha1') + .update(str) + .digest('hex'); + }, + + sha224: function (str) { + return sha('sha224') + .update(str) + .digest('hex'); + }, + + sha256: function (str) { + return sha('sha256') + .update(str) + .digest('hex'); + }, + + sha384: function (str) { + return sha('sha384') + .update(str) + .digest('hex'); + }, + + sha512: function (str) { + return sha('sha512') + .update(str) + .digest('hex'); + }, + + base64: function (str) { + return Base64.encode(str); + }, + + unbase64: function (str) { + return Base64.decode(str); + }, + + substr: function (str, ...args) { + return str.substr(...args); + }, + + concat: function (str, ...args) { + args.forEach(item => { + str += item; + }); + return str; + }, + + lconcat: function (str, ...args) { + args.forEach(item => { + str = item + this._string; + }); + return str; + }, + + lower: function (str) { + return str.toLowerCase(); + }, + + upper: function (str) { + return str.toUpperCase(); + }, + + length: function (str) { + return str.length; + }, + + number: function (str) { + return !isNaN(str) ? +str : str; + } +}; + +let handleValue = function (str) { + return str; +}; + +const _handleValue = function (str) { + if (str[0] === str[str.length - 1] && (str[0] === '"' || str[0] === "'")) { + str = str.substr(1, str.length - 2); + } + return handleValue( + str + .replace(new RegExp(aUniqueVerticalStringNotFoundInData, 'g'), segmentSeparateChar) + .replace(new RegExp(aUniqueCommaStringNotFoundInData, 'g'), argsSeparateChar) + ); +}; + +class PowerString { + constructor(str) { + this._string = str; + } + + toString() { + return this._string; + } +} + +function addMethod(method, fn) { + PowerString.prototype[method] = function (...args) { + args.unshift(this._string + ''); + this._string = fn.apply(this, args); + return this; + }; +} + +function importMethods(handles) { + for (let method in handles) { + addMethod(method, handles[method]); + } +} + +importMethods(funcFilters); + +function handleOriginStr(str, handleValueFn) { + if (!str) return str; + if (typeof handleValueFn === 'function') { + handleValue = handleValueFn; + } + str = str + .replace('\\' + segmentSeparateChar, aUniqueVerticalStringNotFoundInData) + .replace('\\' + argsSeparateChar, aUniqueCommaStringNotFoundInData) + .split(segmentSeparateChar) + .map(handleSegment) + .reduce(execute, null) + .toString(); + return str; +} + +function execute(str, curItem, index) { + if (index === 0) { + return new PowerString(curItem); + } + return str[curItem.method].apply(str, curItem.args); +} + +function handleSegment(str, index) { + str = str.trim(); + if (index === 0) { + return _handleValue(str); + } + + let method, + args = []; + if (str.indexOf(methodAndArgsSeparateChar) > 0) { + str = str.split(methodAndArgsSeparateChar); + method = str[0].trim(); + args = str[1].split(argsSeparateChar).map(item => _handleValue(item.trim())); + } else { + method = str; + } + if (typeof funcFilters[method] !== 'function') { + throw new Error(`This method name(${method}) is not exist.`); + } + + return { + method, + args + }; +} + + +// module.exports = { +// utils: stringHandles, +// PowerString, +// /** +// * 类似于 angularJs的 filter 功能 +// * @params string +// * @params fn 处理参数值函数,默认是一个返回原有参数值函数 +// * +// * @expamle +// * filter('string | substr: 1, 10 | md5 | concat: hello ') +// */ +// filter: handleOriginStr +// }; diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index f575398f0f..ed2fc1de72 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -386,6 +386,10 @@ export default { url_description: "etc: https://fit2cloud.com", path_description: "etc:/login", parameters: "Query parameters", + parameters_filter_example: "Example", + parameters_advance: "Advanced parameter settings", + parameters_preview: "Preview", + parameters_preview_warning: "Please enter the template first", parameters_desc: "Parameters will be appended to the URL e.g. https://fit2cloud.com?Name=Value&Name2=Value2", headers: "Headers", body: "Body", diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index a1f2d22042..e2864bb86a 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -384,6 +384,12 @@ export default { path_description: "例如:/login", url_invalid: "URL无效", parameters: "请求参数", + parameters_filter: "内置函数", + parameters_filter_desc: "使用方法", + parameters_filter_example: "示例", + parameters_advance: "高级参数设置", + parameters_preview: "预览", + parameters_preview_warning: "请先输入模版", parameters_desc: "参数追加到URL,例如https://fit2cloud.com/entries?key1=Value1&Key2=Value2", headers: "请求头", body: "请求内容", @@ -493,9 +499,9 @@ export default { actual_result: ": 实际结果为空", case: { - input_test_case:'请输入关联用例名称', - test_name:'测试名称', - other:"--其他--", + input_test_case: '请输入关联用例名称', + test_name: '测试名称', + other: "--其他--", test_case: "测试用例", move: "移动用例", case_list: "用例列表", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 5c42ee604b..4fb598ddb3 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -385,6 +385,10 @@ export default { path_description: "例如:/login", url_invalid: "URL無效", parameters: "請求參數", + parameters_filter_example: "示例", + parameters_advance: "高級參數設置", + parameters_preview: "預覽", + parameters_preview_warning: "請先輸入模版", parameters_desc: "參數追加到URL,例如https://fit2cloud.com/entries?key1=Value1&Key2=Value2", headers: "請求頭", body: "請求內容",