Commit 3ce590a0 by liimin

加入版本比较功能

1 parent 35571c66
module.exports = { module.exports = {
root: true, root: true,
env: { env: {
node: true node: true,
}, },
parser: '@typescript-eslint/parser', "parser": "babel-eslint",
parserOptions: { parserOptions: {
parser: 'babel-eslint' ecmaVersion: 7,
sourceType: "module",
}, },
rules: { rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
} },
} };
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("crypt"),require("charenc")):"function"==typeof define&&define.amd?define(["exports","crypt","charenc"],t):t((e=e||self)["glsx-common-sdk"]={},e.crypt,e.charenc)}(this,function(exports,crypt,charenc){"use strict";crypt=crypt&&Object.prototype.hasOwnProperty.call(crypt,"default")?crypt.default:crypt,charenc=charenc&&Object.prototype.hasOwnProperty.call(charenc,"default")?charenc.default:charenc;var RequestMethods={GET:"GET",POST:"POST"},wxRequest=async({method:r,obj:o={},baseUrl:n})=>{wx.showNavigationBarLoading();const s=r.toUpperCase()===RequestMethods.POST?{"content-type":"application/json"}:{};try{var{statusCode:e,data:t,errMsg:i}=await new Promise((e,t)=>{wx.request({url:n,data:o,method:r,header:s,dataType:"json",responseType:"text",success:e,fail:t})});if("200"==e){if("1"==t.status)return t;wx.showToast({title:t.info,icon:"none"})}else wx.showToast({title:i,icon:"error"})}catch(e){throw wx.hideLoading(),console.error("接口异常:",e),wx.showToast({title:"系统异常",icon:"error"}),e}finally{wx.hideNavigationBarLoading()}},commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var md5=createCommonjsModule(function(module){!function(){var ERROR="input is invalid type",WINDOW="object"==typeof window,root=WINDOW?window:{},WEB_WORKER=(root.JS_MD5_NO_WINDOW&&(WINDOW=!1),!WINDOW&&"object"==typeof self),NODE_JS=!root.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node,COMMON_JS=(NODE_JS?root=commonjsGlobal:WEB_WORKER&&(root=self),!root.JS_MD5_NO_COMMON_JS&&module.exports),ARRAY_BUFFER=!root.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,HEX_CHARS="0123456789abcdef".split(""),EXTRA=[128,32768,8388608,-2147483648],SHIFT=[0,8,16,24],OUTPUT_TYPES=["hex","array","digest","buffer","arrayBuffer","base64"],BASE64_ENCODE_CHAR="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),blocks=[],buffer8,buffer,buffer8,blocks,createOutputMethod=(ARRAY_BUFFER&&(buffer=new ArrayBuffer(68),buffer8=new Uint8Array(buffer),blocks=new Uint32Array(buffer)),!root.JS_MD5_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!ARRAY_BUFFER||!root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer}),function(t){return function(e){return new Md5(!0).update(e)[t]()}}),createMethod=function(){var t=createOutputMethod("hex");(t=NODE_JS?nodeWrap(t):t).create=function(){return new Md5},t.update=function(e){return t.create().update(e)};for(var e=0;e<OUTPUT_TYPES.length;++e){var r=OUTPUT_TYPES[e];t[r]=createOutputMethod(r)}return t},nodeWrap=function(method){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),nodeMethod=function(e){if("string"==typeof e)return crypto.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw ERROR;return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||ArrayBuffer.isView(e)||e.constructor===Buffer?crypto.createHash("md5").update(new Buffer(e)).digest("hex"):method(e)};return nodeMethod};function Md5(e){e?(blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,this.blocks=blocks,this.buffer8=buffer8):ARRAY_BUFFER?(e=new ArrayBuffer(68),this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}Md5.prototype.update=function(e){if(!this.finalized){var t,r=typeof e;if("string"!=r){if("object"!=r)throw ERROR;if(null===e)throw ERROR;if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||ARRAY_BUFFER&&ArrayBuffer.isView(e)))throw ERROR;t=!0}for(var o,n,s=0,i=e.length,a=this.blocks,c=this.buffer8;s<i;){if(this.hashed&&(this.hashed=!1,a[0]=a[16],a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),t)if(ARRAY_BUFFER)for(n=this.start;s<i&&n<64;++s)c[n++]=e[s];else for(n=this.start;s<i&&n<64;++s)a[n>>2]|=e[s]<<SHIFT[3&n++];else if(ARRAY_BUFFER)for(n=this.start;s<i&&n<64;++s)(o=e.charCodeAt(s))<128?c[n++]=o:(o<2048?c[n++]=192|o>>6:(o<55296||57344<=o?c[n++]=224|o>>12:(o=65536+((1023&o)<<10|1023&e.charCodeAt(++s)),c[n++]=240|o>>18,c[n++]=128|o>>12&63),c[n++]=128|o>>6&63),c[n++]=128|63&o);else for(n=this.start;s<i&&n<64;++s)(o=e.charCodeAt(s))<128?a[n>>2]|=o<<SHIFT[3&n++]:(o<2048?a[n>>2]|=(192|o>>6)<<SHIFT[3&n++]:(o<55296||57344<=o?a[n>>2]|=(224|o>>12)<<SHIFT[3&n++]:(o=65536+((1023&o)<<10|1023&e.charCodeAt(++s)),a[n>>2]|=(240|o>>18)<<SHIFT[3&n++],a[n>>2]|=(128|o>>12&63)<<SHIFT[3&n++]),a[n>>2]|=(128|o>>6&63)<<SHIFT[3&n++]),a[n>>2]|=(128|63&o)<<SHIFT[3&n++]);this.lastByteIndex=n,this.bytes+=n-this.start,64<=n?(this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return 4294967295<this.bytes&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},Md5.prototype.finalize=function(){var e,t;this.finalized||(this.finalized=!0,(e=this.blocks)[(t=this.lastByteIndex)>>2]|=EXTRA[3&t],56<=t&&(this.hashed||this.hash(),e[0]=e[16],e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.bytes<<3,e[15]=this.hBytes<<3|this.bytes>>>29,this.hash())},Md5.prototype.hash=function(){var e,t,r,o,n,s=this.blocks,i=this.first?((i=((e=((e=s[0]-680876937)<<7|e>>>25)-271733879<<0)^(t=((t=(-271733879^(r=((r=(-1732584194^2004318071&e)+s[1]-117830708)<<12|r>>>20)+e<<0)&(-271733879^e))+s[2]-1126478375)<<17|t>>>15)+r<<0)&(r^e))+s[3]-1316259209)<<22|i>>>10)+t<<0:(e=this.h0,i=this.h1,t=this.h2,((i+=((e=((e+=((r=this.h3)^i&(t^r))+s[0]-680876936)<<7|e>>>25)+i<<0)^(t=((t+=(i^(r=((r+=(t^e&(i^t))+s[1]-389564586)<<12|r>>>20)+e<<0)&(e^i))+s[2]+606105819)<<17|t>>>15)+r<<0)&(r^e))+s[3]-1044525330)<<22|i>>>10)+t<<0);i=((i+=((e=((e+=(r^i&(t^r))+s[4]-176418897)<<7|e>>>25)+i<<0)^(t=((t+=(i^(r=((r+=(t^e&(i^t))+s[5]+1200080426)<<12|r>>>20)+e<<0)&(e^i))+s[6]-1473231341)<<17|t>>>15)+r<<0)&(r^e))+s[7]-45705983)<<22|i>>>10)+t<<0,i=((i+=((e=((e+=(r^i&(t^r))+s[8]+1770035416)<<7|e>>>25)+i<<0)^(t=((t+=(i^(r=((r+=(t^e&(i^t))+s[9]-1958414417)<<12|r>>>20)+e<<0)&(e^i))+s[10]-42063)<<17|t>>>15)+r<<0)&(r^e))+s[11]-1990404162)<<22|i>>>10)+t<<0,i=((i+=((e=((e+=(r^i&(t^r))+s[12]+1804603682)<<7|e>>>25)+i<<0)^(t=((t+=(i^(r=((r+=(t^e&(i^t))+s[13]-40341101)<<12|r>>>20)+e<<0)&(e^i))+s[14]-1502002290)<<17|t>>>15)+r<<0)&(r^e))+s[15]+1236535329)<<22|i>>>10)+t<<0,i=((i+=((r=((r+=(i^t&((e=((e+=(t^r&(i^t))+s[1]-165796510)<<5|e>>>27)+i<<0)^i))+s[6]-1069501632)<<9|r>>>23)+e<<0)^e&((t=((t+=(e^i&(r^e))+s[11]+643717713)<<14|t>>>18)+r<<0)^r))+s[0]-373897302)<<20|i>>>12)+t<<0,i=((i+=((r=((r+=(i^t&((e=((e+=(t^r&(i^t))+s[5]-701558691)<<5|e>>>27)+i<<0)^i))+s[10]+38016083)<<9|r>>>23)+e<<0)^e&((t=((t+=(e^i&(r^e))+s[15]-660478335)<<14|t>>>18)+r<<0)^r))+s[4]-405537848)<<20|i>>>12)+t<<0,i=((i+=((r=((r+=(i^t&((e=((e+=(t^r&(i^t))+s[9]+568446438)<<5|e>>>27)+i<<0)^i))+s[14]-1019803690)<<9|r>>>23)+e<<0)^e&((t=((t+=(e^i&(r^e))+s[3]-187363961)<<14|t>>>18)+r<<0)^r))+s[8]+1163531501)<<20|i>>>12)+t<<0,i=((i+=((r=((r+=(i^t&((e=((e+=(t^r&(i^t))+s[13]-1444681467)<<5|e>>>27)+i<<0)^i))+s[2]-51403784)<<9|r>>>23)+e<<0)^e&((t=((t+=(e^i&(r^e))+s[7]+1735328473)<<14|t>>>18)+r<<0)^r))+s[12]-1926607734)<<20|i>>>12)+t<<0,i=((i+=((n=(r=((r+=((o=i^t)^(e=((e+=(o^r)+s[5]-378558)<<4|e>>>28)+i<<0))+s[8]-2022574463)<<11|r>>>21)+e<<0)^e)^(t=((t+=(n^i)+s[11]+1839030562)<<16|t>>>16)+r<<0))+s[14]-35309556)<<23|i>>>9)+t<<0,i=((i+=((n=(r=((r+=((o=i^t)^(e=((e+=(o^r)+s[1]-1530992060)<<4|e>>>28)+i<<0))+s[4]+1272893353)<<11|r>>>21)+e<<0)^e)^(t=((t+=(n^i)+s[7]-155497632)<<16|t>>>16)+r<<0))+s[10]-1094730640)<<23|i>>>9)+t<<0,i=((i+=((n=(r=((r+=((o=i^t)^(e=((e+=(o^r)+s[13]+681279174)<<4|e>>>28)+i<<0))+s[0]-358537222)<<11|r>>>21)+e<<0)^e)^(t=((t+=(n^i)+s[3]-722521979)<<16|t>>>16)+r<<0))+s[6]+76029189)<<23|i>>>9)+t<<0,i=((i+=((n=(r=((r+=((o=i^t)^(e=((e+=(o^r)+s[9]-640364487)<<4|e>>>28)+i<<0))+s[12]-421815835)<<11|r>>>21)+e<<0)^e)^(t=((t+=(n^i)+s[15]+530742520)<<16|t>>>16)+r<<0))+s[2]-995338651)<<23|i>>>9)+t<<0,i=((i+=((r=((r+=(i^((e=((e+=(t^(i|~r))+s[0]-198630844)<<6|e>>>26)+i<<0)|~t))+s[7]+1126891415)<<10|r>>>22)+e<<0)^((t=((t+=(e^(r|~i))+s[14]-1416354905)<<15|t>>>17)+r<<0)|~e))+s[5]-57434055)<<21|i>>>11)+t<<0,i=((i+=((r=((r+=(i^((e=((e+=(t^(i|~r))+s[12]+1700485571)<<6|e>>>26)+i<<0)|~t))+s[3]-1894986606)<<10|r>>>22)+e<<0)^((t=((t+=(e^(r|~i))+s[10]-1051523)<<15|t>>>17)+r<<0)|~e))+s[1]-2054922799)<<21|i>>>11)+t<<0,i=((i+=((r=((r+=(i^((e=((e+=(t^(i|~r))+s[8]+1873313359)<<6|e>>>26)+i<<0)|~t))+s[15]-30611744)<<10|r>>>22)+e<<0)^((t=((t+=(e^(r|~i))+s[6]-1560198380)<<15|t>>>17)+r<<0)|~e))+s[13]+1309151649)<<21|i>>>11)+t<<0,i=((i+=((r=((r+=(i^((e=((e+=(t^(i|~r))+s[4]-145523070)<<6|e>>>26)+i<<0)|~t))+s[11]-1120210379)<<10|r>>>22)+e<<0)^((t=((t+=(e^(r|~i))+s[2]+718787259)<<15|t>>>17)+r<<0)|~e))+s[9]-343485551)<<21|i>>>11)+t<<0,this.first?(this.h0=e+1732584193<<0,this.h1=i-271733879<<0,this.h2=t-1732584194<<0,this.h3=r+271733878<<0,this.first=!1):(this.h0=this.h0+e<<0,this.h1=this.h1+i<<0,this.h2=this.h2+t<<0,this.h3=this.h3+r<<0)},Md5.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,o=this.h3;return HEX_CHARS[e>>4&15]+HEX_CHARS[15&e]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[15&t]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[15&r]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[o>>4&15]+HEX_CHARS[15&o]+HEX_CHARS[o>>12&15]+HEX_CHARS[o>>8&15]+HEX_CHARS[o>>20&15]+HEX_CHARS[o>>16&15]+HEX_CHARS[o>>28&15]+HEX_CHARS[o>>24&15]},Md5.prototype.toString=Md5.prototype.hex,Md5.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,o=this.h3;return[255&e,e>>8&255,e>>16&255,e>>24&255,255&t,t>>8&255,t>>16&255,t>>24&255,255&r,r>>8&255,r>>16&255,r>>24&255,255&o,o>>8&255,o>>16&255,o>>24&255]},Md5.prototype.array=Md5.prototype.digest,Md5.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(16),t=new Uint32Array(e);return t[0]=this.h0,t[1]=this.h1,t[2]=this.h2,t[3]=this.h3,e},Md5.prototype.buffer=Md5.prototype.arrayBuffer,Md5.prototype.base64=function(){for(var e,t,r,o="",n=this.array(),s=0;s<15;)e=n[s++],t=n[s++],r=n[s++],o+=BASE64_ENCODE_CHAR[e>>>2]+BASE64_ENCODE_CHAR[63&(e<<4|t>>>4)]+BASE64_ENCODE_CHAR[63&(t<<2|r>>>6)]+BASE64_ENCODE_CHAR[63&r];return e=n[s],o+=BASE64_ENCODE_CHAR[e>>>2]+BASE64_ENCODE_CHAR[e<<4&63]+"=="};var exports=createMethod();COMMON_JS?module.exports=exports:root.md5=exports}()}),sha1=createCommonjsModule(function(e){function t(e,t){return e=b.wordsToBytes(function(e){e.constructor==String?e=S.stringToBytes(e):"undefined"!=typeof Buffer&&"function"==typeof Buffer.isBuffer&&Buffer.isBuffer(e)?e=Array.prototype.slice.call(e,0):Array.isArray(e)||(e=e.toString());var t=b.bytesToWords(e),e=8*e.length,r=[],o=1732584193,n=-271733879,s=-1732584194,i=271733878,a=-1009589776;t[e>>5]|=128<<24-e%32,t[15+(64+e>>>9<<4)]=e;for(var c=0;c<t.length;c+=16){for(var u=o,f=n,l=s,p=i,h=a,d=0;d<80;d++){r[d]=d<16?t[c+d]:(y=r[d-3]^r[d-8]^r[d-14]^r[d-16])<<1|y>>>31;var y=(o<<5|o>>>27)+a+(r[d]>>>0)+(d<20?1518500249+(n&s|~n&i):d<40?1859775393+(n^s^i):d<60?(n&s|n&i|s&i)-1894007588:(n^s^i)-899497514),a=i,i=s,s=n<<30|n>>>2,n=o,o=y}o+=u,n+=f,s+=l,i+=p,a+=h}return[o,n,s,i,a]}(e)),t&&t.asBytes?e:t&&t.asString?r.bytesToString(e):b.bytesToHex(e)}var b,S,r;b=crypt,S=charenc.utf8,r=charenc.bin,t._blocksize=16,t._digestsize=20,e.exports=t}),qs=createCommonjsModule(function(e,t){e.exports=function o(n,s,i){function a(t,e){if(!s[t]){if(!n[t]){var r="function"==typeof commonjsRequire&&commonjsRequire;if(!e&&r)return r(t,!0);if(c)return c(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}r=s[t]={exports:{}},n[t][0].call(r.exports,function(e){return a(n[t][1][e]||e)},r,r.exports,o,n,s,i)}return s[t].exports}for(var c="function"==typeof commonjsRequire&&commonjsRequire,e=0;e<i.length;e++)a(i[e]);return a}({1:[function(e,t,r){var o=String.prototype.replace,n=/%20/g;t.exports={default:"RFC3986",formatters:{RFC1738:function(e){return o.call(e,n,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},{}],2:[function(e,t,r){var o=e("./stringify"),n=e("./parse"),e=e("./formats");t.exports={formats:e,parse:n,stringify:o}},{"./formats":1,"./parse":3,"./stringify":4}],3:[function(e,t,r){function c(e,t,r){if(e){var o=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,n=/(\[[^[\]]*])/g,s=/(\[[^[\]]*])/.exec(o),e=s?o.slice(0,s.index):o,i=[];if(e){if(!r.plainObjects&&b.call(Object.prototype,e)&&!r.allowPrototypes)return;i.push(e)}for(var a=0;null!==(s=n.exec(o))&&a<r.depth;){if(a+=1,!r.plainObjects&&b.call(Object.prototype,s[1].slice(1,-1))&&!r.allowPrototypes)return;i.push(s[1])}s&&i.push("["+o.slice(s.index)+"]");for(var c=i,u=r,f=t,l=c.length-1;0<=l;--l){var p,h,d,y=c[l];"[]"===y?p=(p=[]).concat(f):(p=u.plainObjects?Object.create(null):{},h="["===y.charAt(0)&&"]"===y.charAt(y.length-1)?y.slice(1,-1):y,d=parseInt(h,10),!isNaN(d)&&y!==h&&String(d)===h&&0<=d&&u.parseArrays&&d<=u.arrayLimit?(p=[])[d]=f:p[h]=f),f=p}return f}}var u=e("./utils"),b=Object.prototype.hasOwnProperty,f={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:u.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1};t.exports=function(e,t){var r=t?u.assign({},t):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter=("string"==typeof r.delimiter||u.isRegExp(r.delimiter)?r:f).delimiter,r.depth=("number"==typeof r.depth?r:f).depth,r.arrayLimit=("number"==typeof r.arrayLimit?r:f).arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder=("function"==typeof r.decoder?r:f).decoder,r.allowDots=("boolean"==typeof r.allowDots?r:f).allowDots,r.plainObjects=("boolean"==typeof r.plainObjects?r:f).plainObjects,r.allowPrototypes=("boolean"==typeof r.allowPrototypes?r:f).allowPrototypes,r.parameterLimit=("number"==typeof r.parameterLimit?r:f).parameterLimit,r.strictNullHandling=("boolean"==typeof r.strictNullHandling?r:f).strictNullHandling,""===e||null==e)return r.plainObjects?Object.create(null):{};for(var o="string"==typeof e?function(e,t){for(var r={},e=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,o=t.parameterLimit===1/0?void 0:t.parameterLimit,n=e.split(t.delimiter,o),s=0;s<n.length;++s){var i,a=n[s],c=a.indexOf("]="),c=-1===c?a.indexOf("="):c+1,a=-1===c?(i=t.decoder(a,f.decoder),t.strictNullHandling?null:""):(i=t.decoder(a.slice(0,c),f.decoder),t.decoder(a.slice(c+1),f.decoder));b.call(r,i)?r[i]=[].concat(r[i]).concat(a):r[i]=a}return r}(e,r):e,n=r.plainObjects?Object.create(null):{},s=Object.keys(o),i=0;i<s.length;++i)var a=s[i],a=c(a,o[a],r),n=u.merge(n,a,r);return u.compact(n)}},{"./utils":5}],4:[function(e,t,r){function A(e,t,r,o,n,s,i,a,c,u,f,l){var p=e;if("function"==typeof i)p=i(t,p);else if(p instanceof Date)p=u(p);else if(null===p){if(o)return s&&!l?s(t,E.encoder):t;p=""}if("string"==typeof p||"number"==typeof p||"boolean"==typeof p||R.isBuffer(p))return s?[f(l?t:s(t,E.encoder))+"="+f(s(p,E.encoder))]:[f(t)+"="+f(String(p))];var h,d=[];if(void 0!==p){h=Array.isArray(i)?i:(e=Object.keys(p),a?e.sort(a):e);for(var y=0;y<h.length;++y){var b=h[y];n&&null===p[b]||(d=Array.isArray(p)?d.concat(A(p[b],r(t,b),r,o,n,s,i,a,c,u,f,l)):d.concat(A(p[b],t+(c?"."+b:"["+b+"]"),r,o,n,s,i,a,c,u,f,l)))}}return d}var R=e("./utils"),g=e("./formats"),m={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},o=Date.prototype.toISOString,E={delimiter:"&",encode:!0,encoder:R.encode,encodeValuesOnly:!1,serializeDate:function(e){return o.call(e)},skipNulls:!1,strictNullHandling:!1};t.exports=function(e,t){var r=e,e=t?R.assign({},t):{};if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=(void 0===e.delimiter?E:e).delimiter,o=("boolean"==typeof e.strictNullHandling?e:E).strictNullHandling,n=("boolean"==typeof e.skipNulls?e:E).skipNulls,s=("boolean"==typeof e.encode?e:E).encode,i=("function"==typeof e.encoder?e:E).encoder,a="function"==typeof e.sort?e.sort:null,c=void 0!==e.allowDots&&e.allowDots,u=("function"==typeof e.serializeDate?e:E).serializeDate,f=("boolean"==typeof e.encodeValuesOnly?e:E).encodeValuesOnly;if(void 0===e.format)e.format=g.default;else if(!Object.prototype.hasOwnProperty.call(g.formatters,e.format))throw new TypeError("Unknown format option provided.");var l,p=g.formatters[e.format],h=("function"==typeof e.filter?r=(l=e.filter)("",r):Array.isArray(e.filter)&&(b=l=e.filter),[]);if("object"!=typeof r||null===r)return"";var d=e.arrayFormat in m?e.arrayFormat:!("indices"in e)||e.indices?"indices":"repeat",y=m[d],b=b||Object.keys(r);a&&b.sort(a);for(var S=0;S<b.length;++S){var O=b[S];n&&null===r[O]||(h=h.concat(A(r[O],O,y,o,n,s?i:null,l,a,c,u,p,f)))}d=h.join(t),t=!0===e.addQueryPrefix?"?":"";return 0<d.length?t+d:""}},{"./formats":1,"./utils":5}],5:[function(e,t,r){function i(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},o=0;o<e.length;++o)void 0!==e[o]&&(r[o]=e[o]);return r}var a=Object.prototype.hasOwnProperty,s=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}();t.exports={arrayToObject:i,assign:function(e,r){return Object.keys(r).reduce(function(e,t){return e[t]=r[t],e},e)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],o=0;o<t.length;++o)for(var n=t[o],s=n.obj[n.prop],i=Object.keys(s),a=0;a<i.length;++a){var c=i[a],u=s[c];"object"==typeof u&&null!==u&&-1===r.indexOf(u)&&(t.push({obj:s,prop:c}),r.push(u))}for(var f=t;f.length;){var l=f.pop(),p=l.obj[l.prop];if(Array.isArray(p)){for(var h=[],d=0;d<p.length;++d)void 0!==p[d]&&h.push(p[d]);l.obj[l.prop]=h}}return p},decode:function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},encode:function(e){if(0===e.length)return e;for(var t="string"==typeof e?e:String(e),r="",o=0;o<t.length;++o){var n=t.charCodeAt(o);45===n||46===n||95===n||126===n||48<=n&&n<=57||65<=n&&n<=90||97<=n&&n<=122?r+=t.charAt(o):n<128?r+=s[n]:n<2048?r+=s[192|n>>6]+s[128|63&n]:n<55296||57344<=n?r+=s[224|n>>12]+s[128|n>>6&63]+s[128|63&n]:(o+=1,n=65536+((1023&n)<<10|1023&t.charCodeAt(o)),r+=s[240|n>>18]+s[128|n>>12&63]+s[128|n>>6&63]+s[128|63&n])}return r},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function o(r,n,s){if(!n)return r;if("object"!=typeof n){if(Array.isArray(r))r.push(n);else{if("object"!=typeof r)return[r,n];!s.plainObjects&&!s.allowPrototypes&&a.call(Object.prototype,n)||(r[n]=!0)}return r}var e;return"object"!=typeof r?[r].concat(n):(e=r,Array.isArray(r)&&!Array.isArray(n)&&(e=i(r,s)),Array.isArray(r)&&Array.isArray(n)?(n.forEach(function(e,t){a.call(r,t)?r[t]&&"object"==typeof r[t]?r[t]=o(r[t],e,s):r.push(e):r[t]=e}),r):Object.keys(n).reduce(function(e,t){var r=n[t];return a.call(e,t)?e[t]=o(e[t],r,s):e[t]=r,e},e))}}},{}]},{},[2])(2)});const response={data_key:"data",message_key:"message",code_key:["code","returnCode"],code_success_value:"0",errId_logout_value:"21",logout_function:"reLogin",code_message_map:{}};var webRequest=async({method:e,obj:t={},baseUrl:r,headers:o={}})=>{let n=r;var s={method:e};if(e.toUpperCase()===RequestMethods.GET){const a=[];Object.keys(t).map(e=>a.push(e+"="+encodeURIComponent(t[e]))),n=r+"?"+a.join("&"),s.headers=o}else s.headers=Object.assign({"Content-Type":"application/json"},o),s.body=qs.stringify(t);try{var i=await(await window.fetch(n,s)).json();if("1"==i.status)return i;throw i.info}catch(e){throw console.error("接口异常:",e),e}};function createSign(e,t,r=[],o="sha1"){delete e.sign,e.timestamp=(new Date).getTime();const n=qs.stringify(e,{arrayFormat:"indices",allowDots:!0,encodeValuesOnly:!0}).split("&").reduce((e,t)=>{const[r,o]=t.split("=");return null===o?o="":"object"==typeof o&&(o=JSON.stringify(o)),e[r]=decodeURIComponent(o),e},{});e=Object.keys(n).sort().reduce((e,t)=>(r.includes(t)||e.push(t,n[t]),e),[]);return n.sign={sha1:sha1,md5:md5}[o](t+e.join("")+t).toUpperCase(),n}class Request{constructor({response:e=response,request:t=e,headers:r={},alert:o,isMP:n}={}){this.response=e,this.request=t,this.headers=r,this.alert=o,this.isMiniprogram=+n}get(e,t){return this.fetch({method:RequestMethods.GET,data:e,noSignAttr:t})}post(e,t){return this.fetch({method:RequestMethods.POST,data:e,noSignAttr:t})}fetch({data:e,noSignAttr:t=[],method:r=RequestMethods.POST}){e={obj:createSign(e,this.request.secret,t,this.request.signWay),method:r,baseUrl:this.request.baseUrl,headers:this.headers};return[webRequest,wxRequest][this.isMiniprogram](e)}}const TYPE={LOCAL:"localStorage",SESSION:"sessionStorage"};function isObject(e){return null!==e&&"object"==typeof e}function encrypt(e){return e}function decrypt(e){return e}function set(e,t,r=TYPE.LOCAL){isObject(t)?window[r].setItem(e,JSON.stringify(t)):window[r].setItem(e,encrypt(t))}function get(e,t=TYPE.LOCAL){t=window[t].getItem(e);try{return t&&t.startsWith("#")?t:isObject(t)?JSON.parse(decrypt(t)):decrypt(t)}catch(e){throw e}}function remove(e,t=TYPE.LOCAL){window[t].removeItem(e)}function setSession(e,t,r=0){set(e,t,TYPE.SESSION)}function getSession(e){return get(e,TYPE.SESSION)}function removeSession(e){remove(e,TYPE.SESSION)}function setExpire(e,t,r=18e5){set(e,{v:t,t:Date.now()+r})}function getExpire(e){e=get(e);return e.t>Date.now()?e.v:null}var storage={set:set,get:get,remove:remove,setSession:setSession,getSession:getSession,removeSession:removeSession,setExpire:setExpire,getExpire:getExpire};const isMiniprogram$1=!window,webwx=(e,t,r=isMiniprogram$1)=>[e,t][+r],GLSX_COMMON_VERSION_STORAGE_VERSION="GLSX_COMMON_VERSION_STORAGE_VERSION",web={getBody:e=>{return result(storage.get(GLSX_COMMON_VERSION_STORAGE_VERSION),e)},setVersion:e=>storage.set(GLSX_COMMON_VERSION_STORAGE_VERSION,e)},wx$1={getBody:e=>{return result(wx$1.getStorageSync(GLSX_COMMON_VERSION_STORAGE_VERSION),e)},setVersion:e=>wx$1.setStorage({key:GLSX_COMMON_VERSION_STORAGE_VERSION,data:e})};function result(e,t){var r=compare(e,t.version);return{compare:r,origin:e,new:t.version,isNew:-1===r,...t}}function compare(e,t){return compareVersions(e,t)}function compareVersions(e="0",t){var r=e.split("."),o=t.split(".");for(let e=0;e<Math.max(r.length,o.length);e++){var n=parseInt(r[e]||0),s=parseInt(o[e]||0);if(n<s)return-1;if(s<n)return 1}return 0}var webwx$1=webwx(web,wx$1);class Version{constructor({http:e,isMP:t=isMiniprogram,alert:r}={}){this.request=new Request({...e,isMP:t,alert:r})}async get(e){e=await this.request.get(e);return webwx$1.getBody(e)}setVersion(e){return webwx$1.setVersion(e)}}exports.Version=Version,Object.defineProperty(exports,"__esModule",{value:!0})});
This diff could not be displayed because it is too large.
{ {
"name": "glsx-common-sdk", "name": "glsx-common-sdk",
"version": "0.2.0", "version": "0.1.3",
"description": "glsx-common-sdk", "description": "glsx-common-sdk",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c", "build": "rollup -c",
"doc":"jsdoc src/index.js" "doc": "jsdoc src/index.js"
}, },
"author": "limin", "author": "limin",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"babel-eslint": "^10.1.0",
"rollup": "^1.32.1", "rollup": "^1.32.1",
"rollup-plugin-babel": "^4.4.0", "rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",
......
import Version from './version'
export { Version }
export const GLSX_COMMON_VERSION_STORAGE_VERSION = 'GLSX_COMMON_VERSION_STORAGE_VERSION'
\ No newline at end of file \ No newline at end of file
import { storage } from '../../helper/storage/index'
import { webwx } from '../../helper/index'
import { GLSX_COMMON_VERSION_STORAGE_VERSION } from './constants'
const web = {
getBody: data => {
const v = storage.get(GLSX_COMMON_VERSION_STORAGE_VERSION)
return result(v, data)
},
setVersion: version => storage.set(GLSX_COMMON_VERSION_STORAGE_VERSION, version)
}
const wx = {
getBody: data => {
const v = wx.getStorageSync(GLSX_COMMON_VERSION_STORAGE_VERSION)
return result(v, data)
},
setVersion: version => wx.setStorage({ key: GLSX_COMMON_VERSION_STORAGE_VERSION, data: version })
}
function result(v, data) {
const c = compare(v, data.version)
return { compare: c, origin: v, new: data.version, isNew: c === -1 ? true : false, ...data }
}
function compare(version1, version2) {
if (!version1) {
return -1
}
const parts1 = version1.split('.')
const parts2 = version2.split('.')
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
const part1 = parseInt(parts1[i] || 0)
const part2 = parseInt(parts2[i] || 0)
if (part1 < part2) {
return -1 // version1 < version2
}
if (part1 > part2) {
return 1 // version1 > version2
}
}
return 0 // version1 == version2
}
export default webwx(web, wx)
import Request from '../../request/index'
import webwx from './helper'
import { isMiniprogram } from '../../helper/index'
class Version {
constructor({ http, isMP = isMiniprogram, alert } = {}) {
this.request = new Request({ ...http, isMP, alert })
}
async get(data) {
const versionInfo = await this.request.get(data)
return webwx.getBody(versionInfo)
}
set(version) {
return webwx.setVersion(version)
}
}
export default Version
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @Author: limin * @Author: limin
* @Date: 2023-07-04 17:40:51 * @Date: 2023-07-04 17:40:51
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2023-07-05 08:48:32 * @LastEditTime: 2023-08-16 14:18:31
* @FilePath: \glsx-map-sdk\src\constants.js * @FilePath: \glsx-common-sdk\src\helper\constants.js
*/ */
export const MAP_OPTIONS = { domain: 'https://restapi.amap.com', KEY: '373bd88fa36ebc0247d60281386b6cec', SECRET: 'a2a93fa04721a36819d86b71cb31fe41' } export const REQUEST_OPTIONS = { BASE_URL: 'https://restapi.amap.com', APP_KEY: '373bd88fa36ebc0247d60281386b6cec', SECRET: 'a2a93fa04721a36819d86b71cb31fe41' }
export const isMiniprogram = !window
export const webwx = (wb, wx, isMP = isMiniprogram) => [wb, wx][+isMP]
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
* @Author: limin * @Author: limin
* @Date: 2023-07-04 17:37:45 * @Date: 2023-07-04 17:37:45
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2023-07-05 08:46:52 * @LastEditTime: 2023-08-17 19:29:42
* @FilePath: \glsx-map-sdk\src\helper.js * @FilePath: \glsx-common-sdk\src\helper\index.js
*/ */
export const isMiniprogram = !window export { isMiniprogram, webwx } from './f'
export { storage } from './storage/index'
import storage from './web'
export { storage }
/*
* @Author: limin
* @Date: 2018-06-23 11:13:44
* @Last Modified by: limin
* @Last Modified time: 2018-08-31 18:28:26
*/
const TYPE = {
LOCAL: 'localStorage',
SESSION: 'sessionStorage'
}
function isObject(val) {
return val !== null && typeof val === 'object'
}
function encrypt(val) {
if (!val) return val
return val
}
function decrypt(val) {
if (!val) return val
return val
}
function set(key, val, type = TYPE.LOCAL) {
if (isObject(val)) window[type].setItem(key, JSON.stringify(val))
else window[type].setItem(key, encrypt(val))
}
function get(key, type = TYPE.LOCAL) {
var val = window[type].getItem(key)
try {
if (val && val.startsWith('#')) {
return val
}
const value = isObject(val)?JSON.parse(decrypt(val)):decrypt(val)
return value
} catch (e) {
throw e
}
}
function remove(key, type = TYPE.LOCAL) {
window[type].removeItem(key)
}
function setSession(key, val, ex = 20) {
set(key, val, TYPE.SESSION)
}
function getSession(key) {
return get(key, TYPE.SESSION)
}
function removeSession(key) {
remove(key, TYPE.SESSION)
}
// 默认30minute
function setExpire(key, val, ex = 1.8e6) {
set(key, { v: val, t: Date.now() + ex })
}
function getExpire(key) {
var obj = get(key)
if (obj.t > Date.now()) return obj.v
else return null
}
export default {
set,
get,
remove,
setSession,
getSession,
removeSession,
setExpire,
getExpire
}
\ No newline at end of file \ No newline at end of file
File mode changed
/* /*
* @Descripttion: * @Descripttion:
* @version: 1.0.0 * @version: 1.0.0
* @Author: limin * @Author: limin
* @Date: 2023-08-15 16:37:55 * @Date: 2023-08-15 16:37:55
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2023-08-15 18:21:22 * @LastEditTime: 2023-08-17 15:22:04
* @FilePath: \glsx-common-sdk\src\index.js * @FilePath: \glsx-common-sdk\src\index.js
*/ */
import Request from './request/index' export { Version } from './function/index'
class GLCommon {
constructor(params = {}) {
const { key, secret } = params
this.request = new Request(key, secret)
}
}
export default GLCommon
import md5 from './md5'
import sha1 from './sha1'
import qs from './qs'
export { md5, sha1, qs }
(function() {
var crypt = require('crypt'),
utf8 = require('charenc').utf8,
bin = require('charenc').bin,
// The core
sha1 = function (message) {
// Convert to byte array
if (message.constructor == String)
message = utf8.stringToBytes(message);
else if (typeof Buffer !== 'undefined' && typeof Buffer.isBuffer == 'function' && Buffer.isBuffer(message))
message = Array.prototype.slice.call(message, 0);
else if (!Array.isArray(message))
message = message.toString();
// otherwise assume byte array
var m = crypt.bytesToWords(message),
l = message.length * 8,
w = [],
H0 = 1732584193,
H1 = -271733879,
H2 = -1732584194,
H3 = 271733878,
H4 = -1009589776;
// Padding
m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >>> 9) << 4) + 15] = l;
for (var i = 0; i < m.length; i += 16) {
var a = H0,
b = H1,
c = H2,
d = H3,
e = H4;
for (var j = 0; j < 80; j++) {
if (j < 16)
w[j] = m[i + j];
else {
var n = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16];
w[j] = (n << 1) | (n >>> 31);
}
var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (
j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 :
j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 :
j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 :
(H1 ^ H2 ^ H3) - 899497514);
H4 = H3;
H3 = H2;
H2 = (H1 << 30) | (H1 >>> 2);
H1 = H0;
H0 = t;
}
H0 += a;
H1 += b;
H2 += c;
H3 += d;
H4 += e;
}
return [H0, H1, H2, H3, H4];
},
// Public API
api = function (message, options) {
var digestbytes = crypt.wordsToBytes(sha1(message));
return options && options.asBytes ? digestbytes :
options && options.asString ? bin.bytesToString(digestbytes) :
crypt.bytesToHex(digestbytes);
};
api._blocksize = 16;
api._digestsize = 20;
module.exports = api;
})();
\ No newline at end of file \ No newline at end of file
const response = {
data_key: 'data',
message_key: 'message',
code_key: ['code', 'returnCode'],
code_success_value: '0',
errId_logout_value: '21',
logout_function: 'reLogin',
code_message_map: {}
}
const request = {
baseURL: '',
// 设置超时时间
timeout: 180000,
// 携带凭证
withCredentials: true,
// 返回数据类型
responseType: 'json'
}
const sign = {
appKey: '48e5e13229b82c1b4e6e8c96151f0637',
v: '1.0.0',
format: 'json',
source: 'scrm',
locale: 'zh_CN',
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b'
}
export { response, request, sign }
/* /*
* @Descripttion: 定义一个Request类,用于封装请求高德地图API的方法 * @Descripttion: 定义一个Request类,用于封装请求高德地图API的方法
* @version: 1.0.0 * @version: 1.0.0
* @Author: limin * @Author: limin
* @Date: 2023-07-04 17:25:31 * @Date: 2023-07-04 17:25:31
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2023-08-15 18:10:22 * @LastEditTime: 2023-08-17 15:10:36
* @FilePath: \glsx-common-sdk\src\request\index.js * @FilePath: \glsx-common-sdk\src\request\index.js
*/ */
import md5 from '../lib/md5'
import qs from '../lib/qs'
import wxRequest from './wx' import wxRequest from './wx'
import webRequest from './web' import webRequest from './web'
import { isMiniprogram } from '../helper/index' import createSign from './sign'
import RequestMethods from './requestMethods'
import { response as res } from './default'
class Request { class Request {
// 构造函数,接收key和secret作为参数,如果没有传入,则使用默认值 // 构造函数,接收key和secret作为参数,如果没有传入,则使用默认值
constructor(key = MAP_OPTIONS.KEY, secret = MAP_OPTIONS.SECRET) { constructor({ response = res, request = response, headers = {}, alert, isMP } = {}) {
// 将key和secret赋值给实例属性 this.response = response
this.key = key this.request = request
this.secret = secret this.headers = headers
} this.alert = alert
this.isMiniprogram = +isMP
/**对参数进行排序:按参数名升序 */
setLocaleCompare(params) {
// 将key添加到参数对象中
params.key = this.key
return Object.fromEntries(Object.entries(params).sort(([a], [b]) => a.localeCompare(b)))
}
/**签名计算(sig) */
getSign(params) {
return md5(`${decodeURIComponent(qs.stringify(this.setLocaleCompare(params)))}${this.secret}`)
} }
/**封装的GET方法 */ /**封装的GET方法 */
get(method, data) { get(data, noSignAttr) {
// 调用request方法,传入请求方式为GET,请求路径为method,请求数据为data
return this.fetch({ method: RequestMethods.GET, data, noSignAttr })
}
post(data, noSignAttr) {
// 调用request方法,传入请求方式为GET,请求路径为method,请求数据为data // 调用request方法,传入请求方式为GET,请求路径为method,请求数据为data
return this.request('GET', method, data) return this.fetch({ method: RequestMethods.POST, data, noSignAttr })
} }
/**封装的请求方法 */ /**封装的请求方法 */
async request(RequestMethods, method, data = {}) { fetch({ data, noSignAttr = [], method = RequestMethods.POST }) {
// 调用getSign方法,传入请求数据和请求路径,得到签名 // 调用getSign方法,传入请求数据和请求路径,得到签名
const sig = this.getSign(data, method), const signData = createSign(data, this.request.secret, noSignAttr, this.request.signWay)
obj = { const options = {
...this.setLocaleCompare(data), obj: signData,
sig method,
} baseUrl: this.request.baseUrl,
return await [webRequest,wxRequest][+isMiniprogram](RequestMethods, method, obj) headers: this.headers
}
return [webRequest, wxRequest][this.isMiniprogram](options)
} }
} }
export default Request export default Request
export default {
GET: 'GET',
POST: 'POST'
}
\ No newline at end of file \ No newline at end of file
import { sha1, md5, qs } from '../lib/index'
export default function (params, secret, noSignAttr = [], way = 'sha1') {
delete params.sign
params.timestamp = new Date().getTime()
var strQs = qs.stringify(params, { arrayFormat: 'indices', allowDots: true, encodeValuesOnly: true })
const objQs = strQs.split('&')
const collect = objQs.reduce((collect, item) => {
const [key, value] = item.split('=')
if (value === null) {
value = ''
} else if (typeof value === 'object') {
value = JSON.stringify(value)
}
collect[key] = decodeURIComponent(value)
return collect
}, {})
const keys = Object.keys(collect).sort()
const str = keys.reduce((col, key) => {
if (!noSignAttr.includes(key)) {
col.push(key, collect[key])
}
return col
}, [])
collect.sign = { sha1, md5 }[way](secret + str.join('') + secret).toUpperCase()
return collect
}
import { MAP_OPTIONS } from '../helper/constants' import { qs } from '../lib/index'
export default async (RequestMethods, method, obj = {}) => { import { response } from './default'
import RequestMethods from './requestMethods'
export default async ({ method, obj = {}, baseUrl, headers = {} }) => {
let requestAddrss = baseUrl
const settings = {
method
}
if (method.toUpperCase() === RequestMethods.GET) {
const params = [] const params = []
Object.keys(obj).map(key => { Object.keys(obj).map(key => params.push(`${key}=${encodeURIComponent(obj[key])}`))
params.push(`${key}=${encodeURIComponent(obj[key])}`) requestAddrss = `${baseUrl}?${params.join('&')}`
}) settings.headers = headers
try { } else {
const res = await window.fetch(`${MAP_OPTIONS.domain}${method}?${params.join('&')}`, { settings.headers = Object.assign({ 'Content-Type': 'application/json' }, headers)
method: RequestMethods settings.body = qs.stringify(obj)
}) }
const data = await res.json() try {
if (data.status == '1') return data const res = await window.fetch(requestAddrss, settings)
else throw data.info const data = await res.json()
} catch (error) { if (data.code == '0') return data.data
console.error(`接口异常:`, error) else throw data.info
throw error } catch (error) {
} console.error(`接口异常:`, error)
throw error
}
} }
import { MAP_OPTIONS } from '../helper/constants' import RequestMethods from './requestMethods'
export default async (RequestMethods, method, params = {}) => { export default async ({ method, obj = {}, baseUrl }) => {
wx.showNavigationBarLoading() wx.showNavigationBarLoading()
const header = method.toUpperCase() === RequestMethods.POST ? { 'content-type': 'application/json' } : {}
try { try {
const res = await new Promise((resolve, reject) => { const res = await new Promise((resolve, reject) => {
wx.request({ wx.request({
url: `${MAP_OPTIONS.domain}${method}`, url: baseUrl,
data:params, data: obj,
method: RequestMethods, method,
header: header,
RequestMethods === 'POST'
? {
'content-type': 'application/json'
}
: {},
dataType: 'json', dataType: 'json',
responseType: 'text', responseType: 'text',
success: resolve, success: resolve,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!