Commit a0dd9d1b by liimin

0.0.6

1 parent 1059f5f5
......@@ -47,5 +47,5 @@ var t="function"==typeof Map&&Map.prototype,e=Object.getOwnPropertyDescriptor&&t
},{}],"zMBz":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=o(require("md5")),e=o(require("qs")),r=require("./constants"),n=require("./helper");function o(t){return t&&t.__esModule?t:{default:t}}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(){a=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},c=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(T){l=function(t,e,r){return t[e]=r}}function f(t,e,r,o){var i=e&&e.prototype instanceof y?e:y,a=Object.create(i.prototype),c=new S(o||[]);return n(a,"_invoke",{value:j(t,r,c)}),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(T){return{type:"throw",arg:T}}}t.wrap=f;var p={};function y(){}function v(){}function d(){}var g={};l(g,c,function(){return this});var m=Object.getPrototypeOf,b=m&&m(m(k([])));b&&b!==e&&r.call(b,c)&&(g=b);var w=d.prototype=y.prototype=Object.create(g);function x(t){["next","throw","return"].forEach(function(e){l(t,e,function(t){return this._invoke(e,t)})})}function O(t,e){var o;n(this,"_invoke",{value:function(n,a){function c(){return new e(function(o,c){!function n(o,a,c,u){var s=h(t[o],t,a);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==i(f)&&r.call(f,"__await")?e.resolve(f.__await).then(function(t){n("next",t,c,u)},function(t){n("throw",t,c,u)}):e.resolve(f).then(function(t){l.value=t,c(l)},function(t){return n("throw",t,c,u)})}u(s.arg)}(n,a,o,c)})}return o=o?o.then(c,c):c()}})}function j(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return _()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=L(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=h(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function k(t){if(t){var e=t[c];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:_}}function _(){return{value:void 0,done:!0}}return v.prototype=d,n(w,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:v,configurable:!0}),v.displayName=l(d,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,l(t,s,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(O.prototype),l(O.prototype,u,function(){return this}),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then(function(t){return t.done?t.value:a.next()})},x(w),l(w,s,"Generator"),l(w,c,function(){return this}),l(w,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=k,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function c(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?c(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=x(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(s){return void r(s)}c.done?e(u):Promise.resolve(u).then(n,o)}function f(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){l(i,n,o,a,c,"next",t)}function c(t){l(i,n,o,a,c,"throw",t)}a(void 0)})}}function h(t,e){return g(t)||d(t,e)||y(t,e)||p()}function p(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function y(t,e){if(t){if("string"==typeof t)return v(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,e):void 0}}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function d(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(l){s=!0,o=l}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}function g(t){if(Array.isArray(t))return t}function m(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function b(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,x(n.key),n)}}function w(t,e,r){return e&&b(t.prototype,e),r&&b(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function x(t){var e=O(t,"string");return"symbol"===i(e)?e:String(e)}function O(t,e){if("object"!==i(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var j=function(){function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r.MAP_OPTIONS.KEY,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r.MAP_OPTIONS.SECRET;m(this,o),this.key=t,this.secret=e}return w(o,[{key:"setLocaleCompare",value:function(t){return t.key=this.key,Object.fromEntries(Object.entries(t).sort(function(t,e){var r=h(t,1)[0],n=h(e,1)[0];return r.localeCompare(n)}))}},{key:"getSign",value:function(r){return(0,t.default)("".concat(decodeURIComponent(e.default.stringify(this.setLocaleCompare(r)))).concat(this.secret))}},{key:"get",value:function(t,e){return this.request("GET",t,e)}},{key:"request",value:function(){var t=f(a().mark(function t(e,o){var i,c,s,l,f,h,p,y,v,d,g=arguments;return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=g.length>2&&void 0!==g[2]?g[2]:{},c=this.getSign(i,o),s=u(u({},this.setLocaleCompare(i)),{},{sig:c}),!n.isMiniprogram){t.next=31;break}return wx.showNavigationBarLoading(),t.prev=4,t.next=7,new Promise(function(t,n){wx.request({url:"".concat(r.MAP_OPTIONS.domain).concat(o),data:s,method:e,header:"POST"===e?{"content-type":"application/json"}:{},dataType:"json",responseType:"text",success:t,fail:n})});case 7:if(l=t.sent,f=l.statusCode,h=l.data,p=l.errMsg,"200"!=f){t.next=17;break}if("1"!=h.status){t.next=14;break}return t.abrupt("return",h);case 14:wx.showToast({title:h.info,icon:"none"});case 15:t.next=18;break;case 17:wx.showToast({title:p,icon:"error"});case 18:t.next=26;break;case 20:throw t.prev=20,t.t0=t.catch(4),wx.hideLoading(),console.error("接口异常:",t.t0),wx.showToast({title:"系统异常",icon:"error"}),t.t0;case 26:return t.prev=26,wx.hideNavigationBarLoading(),t.finish(26);case 29:t.next=51;break;case 31:return y=[],Object.keys(s).map(function(t){y.push("".concat(t,"=").concat(encodeURIComponent(s[t])))}),t.prev=33,t.next=36,window.fetch("".concat(r.MAP_OPTIONS.domain).concat(o,"?").concat(y.join("&")),{method:e});case 36:return v=t.sent,t.next=39,v.json();case 39:if("1"!=(d=t.sent).status){t.next=44;break}return t.abrupt("return",d);case 44:throw d.info;case 45:t.next=51;break;case 47:throw t.prev=47,t.t1=t.catch(33),console.error("接口异常:",t.t1),t.t1;case 51:case"end":return t.stop()}},t,this,[[4,20,26,29],[33,47]])}));return function(e,r){return t.apply(this,arguments)}}()}]),o}(),L=j;exports.default=L;
},{"md5":"pMqz","qs":"OFf3","./constants":"iJA9","./helper":"YaYI"}],"Focm":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=e(require("./request"));function e(t){return t&&t.__esModule?t:{default:t}}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function o(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach(function(e){i(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function i(t,e,r){return(e=m(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t,e){return f(t)||l(t,e)||u(t,e)||c()}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(t,e){if(t){if("string"==typeof t)return s(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function l(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(l){s=!0,o=l}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}function f(t){if(Array.isArray(t))return t}function p(){p=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(k){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=e&&e.prototype instanceof v?e:v,a=Object.create(i.prototype),c=new _(n||[]);return o(a,"_invoke",{value:x(t,r,c)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(k){return{type:"throw",arg:k}}}t.wrap=l;var h={};function v(){}function y(){}function d(){}var g={};s(g,a,function(){return this});var m=Object.getPrototypeOf,b=m&&m(m(E([])));b&&b!==e&&n.call(b,a)&&(g=b);var w=d.prototype=v.prototype=Object.create(g);function O(t){["next","throw","return"].forEach(function(e){s(t,e,function(t){return this._invoke(e,t)})})}function j(t,e){var i;o(this,"_invoke",{value:function(o,a){function c(){return new e(function(i,c){!function o(i,a,c,u){var s=f(t[i],t,a);if("throw"!==s.type){var l=s.arg,p=l.value;return p&&"object"==r(p)&&n.call(p,"__await")?e.resolve(p.__await).then(function(t){o("next",t,c,u)},function(t){o("throw",t,c,u)}):e.resolve(p).then(function(t){l.value=t,c(l)},function(t){return o("throw",t,c,u)})}u(s.arg)}(o,a,i,c)})}return i=i?i.then(c,c):c()}})}function x(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return N()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=S(a,r);if(c){if(c===h)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,S(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function L(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function E(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:N}}function N(){return{value:void 0,done:!0}}return y.prototype=d,o(w,"constructor",{value:d,configurable:!0}),o(d,"constructor",{value:y,configurable:!0}),y.displayName=s(d,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,u,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},O(j.prototype),s(j.prototype,c,function(){return this}),t.AsyncIterator=j,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new j(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then(function(t){return t.done?t.value:a.next()})},O(w),s(w,u,"Generator"),s(w,a,function(){return this}),s(w,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=E,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function h(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(s){return void r(s)}c.done?e(u):Promise.resolve(u).then(n,o)}function v(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){h(i,n,o,a,c,"next",t)}function c(t){h(i,n,o,a,c,"throw",t)}a(void 0)})}}function y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,m(n.key),n)}}function g(t,e,r){return e&&d(t.prototype,e),r&&d(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(t){var e=b(t,"string");return"symbol"===r(e)?e:String(e)}function b(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var w=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};y(this,e);var n=r.key,o=r.secret;this.request=new t.default(n,o)}return g(e,[{key:"calculateDistance",value:function(){var t=v(p().mark(function t(e,r){var n,o,i,a,c,u,s=arguments;return p().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=s.length>2&&void 0!==s[2]?s[2]:1,t.prev=1,o=JSON.parse(JSON.stringify(e)).reverse().join(","),i=JSON.parse(JSON.stringify(r)).reverse().join(","),t.next=6,this.request.get("/v3/distance",{destination:o,origins:i,type:n});case 6:return a=t.sent,c=a.results,u={elements:c},t.abrupt("return",Promise.resolve(u));case 12:return t.prev=12,t.t0=t.catch(1),t.abrupt("return",Promise.reject(t.t0));case 15:case"end":return t.stop()}},t,this,[[1,12]])}));return function(e,r){return t.apply(this,arguments)}}()},{key:"calculateDistanceMatrix",value:function(){var t=v(p().mark(function t(e,r){var n,o,i,a,c,u,s=arguments;return p().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=s.length>2&&void 0!==s[2]?s[2]:1,t.prev=1,o=JSON.parse(JSON.stringify(e)).reverse().join(","),i=JSON.parse(JSON.stringify(r)).map(function(t){return t.reverse()}).join("|"),t.next=6,this.request.get("/v3/distance",{destination:o,origins:i,type:n});case 6:return a=t.sent,c=a.results,u={rows:[{elements:c}]},t.abrupt("return",Promise.resolve(u));case 12:return t.prev=12,t.t0=t.catch(1),t.abrupt("return",Promise.reject(t.t0));case 15:case"end":return t.stop()}},t,this,[[1,12]])}));return function(e,r){return t.apply(this,arguments)}}()},{key:"geocoder",value:function(t){return this.request.get("/v3/geocode/geo",{address:t})}},{key:"detailedAdrress",value:function(){var t=v(p().mark(function t(e){var r,n,i,c,u,s,l,f,h;return p().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,r=a(e,2),n=r[0],i=r[1],t.next=4,this.request.get("/v3/geocode/regeo",{location:JSON.parse(JSON.stringify(e)).reverse().join(",")});case 4:return c=t.sent,u=c.regeocode,s=u.addressComponent,l=u.formatted_address,f="".concat(s.province||"").concat(s.city||"").concat(s.district||"").concat(s.township||""),h=o(o({},u),{},{address:f,formatted_addresses:{recommend:l,rough:l,standard_address:l},address_component:{city:s.city,district:s.district,nation:s.country,province:s.province,street:s.township},ad_info:{adcode:s.adcode,city:s.city,city_code:s.citycode,district:s.district,location:{lat:n,lng:i},name:"".concat(s.country+","||"").concat(s.province+","||"").concat(s.city+","||"").concat(s.district||""),nation:s.country,nation_code:"",phone_area_code:s.citycode,province:s.province},location:{lat:n,lng:i}}),t.abrupt("return",Promise.resolve(h));case 13:return t.prev=13,t.t0=t.catch(0),t.abrupt("return",Promise.reject(t.t0));case 16:case"end":return t.stop()}},t,this,[[0,13]])}));return function(e){return t.apply(this,arguments)}}()},{key:"getLocationByIp",value:function(){return this.request.get("/v3/ip")}},{key:"translate",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"autonavi",r=JSON.parse(JSON.stringify(t)).map(function(t){return t.reverse()}).join("|");return this.request.get("/v3/assistant/coordinate/convert",{locations:r,coordsys:e})}}]),e}(),O=w;exports.default=O;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=e(require("./request"));function e(t){return t&&t.__esModule?t:{default:t}}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function o(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach(function(e){i(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function i(t,e,r){return(e=m(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(){a=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},c=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(N){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof v?e:v,a=Object.create(i.prototype),c=new S(n||[]);return o(a,"_invoke",{value:x(t,r,c)}),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(N){return{type:"throw",arg:N}}}t.wrap=f;var p={};function v(){}function y(){}function d(){}var g={};l(g,c,function(){return this});var m=Object.getPrototypeOf,b=m&&m(m(P([])));b&&b!==e&&n.call(b,c)&&(g=b);var w=d.prototype=v.prototype=Object.create(g);function O(t){["next","throw","return"].forEach(function(e){l(t,e,function(t){return this._invoke(e,t)})})}function j(t,e){var i;o(this,"_invoke",{value:function(o,a){function c(){return new e(function(i,c){!function o(i,a,c,u){var s=h(t[i],t,a);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==r(f)&&n.call(f,"__await")?e.resolve(f.__await).then(function(t){o("next",t,c,u)},function(t){o("throw",t,c,u)}):e.resolve(f).then(function(t){l.value=t,c(l)},function(t){return o("throw",t,c,u)})}u(s.arg)}(o,a,i,c)})}return i=i?i.then(c,c):c()}})}function x(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=L(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=h(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function P(t){if(t){var e=t[c];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return y.prototype=d,o(w,"constructor",{value:d,configurable:!0}),o(d,"constructor",{value:y,configurable:!0}),y.displayName=l(d,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,l(t,s,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},O(j.prototype),l(j.prototype,u,function(){return this}),t.AsyncIterator=j,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new j(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then(function(t){return t.done?t.value:a.next()})},O(w),l(w,s,"Generator"),l(w,c,function(){return this}),l(w,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=P,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function c(t,e){return h(t)||f(t,e)||s(t,e)||u()}function u(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function s(t,e){if(t){if("string"==typeof t)return l(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,e):void 0}}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function f(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(l){s=!0,o=l}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}function h(t){if(Array.isArray(t))return t}function p(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(s){return void r(s)}c.done?e(u):Promise.resolve(u).then(n,o)}function v(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){p(i,n,o,a,c,"next",t)}function c(t){p(i,n,o,a,c,"throw",t)}a(void 0)})}}function y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,m(n.key),n)}}function g(t,e,r){return e&&d(t.prototype,e),r&&d(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(t){var e=b(t,"string");return"symbol"===r(e)?e:String(e)}function b(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var w=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};y(this,e);var n=r.key,o=r.secret;this.request=new t.default(n,o)}return g(e,[{key:"calculateDistance",value:function(){var t=v(a().mark(function t(e,r){var n,o,i,u,s,l,f,h=arguments;return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=h.length>2&&void 0!==h[2]?h[2]:1,t.prev=1,o=[e,r].map(function(t){return JSON.stringify(t).reverse().join(",")}),i=c(o,2),u=i[0],s=i[1],t.next=5,this.request.get("/v3/distance",{destination:u,origins:s,type:n});case 5:return l=t.sent,f=l.results,t.abrupt("return",{elements:f});case 10:throw t.prev=10,t.t0=t.catch(1),t.t0;case 13:case"end":return t.stop()}},t,this,[[1,10]])}));return function(e,r){return t.apply(this,arguments)}}()},{key:"calculateDistanceMatrix",value:function(){var t=v(a().mark(function t(e,r){var n,o,i,u,s,l,f,h=arguments;return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=h.length>2&&void 0!==h[2]?h[2]:1,t.prev=1,o=[e,r].map(function(t){return JSON.stringify(t).reverse().join(t===e?",":"|")}),i=c(o,2),u=i[0],s=i[1],t.next=5,this.request.get("/v3/distance",{destination:u,origins:s,type:n});case 5:return l=t.sent,f=l.results,t.abrupt("return",{rows:[{elements:f}]});case 10:throw t.prev=10,t.t0=t.catch(1),t.t0;case 13:case"end":return t.stop()}},t,this,[[1,10]])}));return function(e,r){return t.apply(this,arguments)}}()},{key:"geocoder",value:function(t){return this.request.get("/v3/geocode/geo",{address:t})}},{key:"detailedAdrress",value:function(){var t=v(a().mark(function t(e){var r,n,i,u,s,l,f,h,p;return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,r=c(e,2),n=r[0],i=r[1],t.next=4,this.request.get("/v3/geocode/regeo",{location:JSON.stringify(e).reverse().join(",")});case 4:return u=t.sent,s=u.regeocode,l=s.addressComponent,f=s.formatted_address,h="".concat(l.province||"").concat(l.city||"").concat(l.district||"").concat(l.township||""),p=o(o({},s),{},{address:h,formatted_addresses:{recommend:f,rough:f,standard_address:f},address_component:{city:l.city,district:l.district,nation:l.country,province:l.province,street:l.township},ad_info:{adcode:l.adcode,city:l.city,city_code:l.citycode,district:l.district,location:{lat:n,lng:i},name:"".concat(l.country+","||"").concat(l.province+","||"").concat(l.city+","||"").concat(l.district||""),nation:l.country,nation_code:"",phone_area_code:l.citycode,province:l.province},location:{lat:n,lng:i}}),t.abrupt("return",p);case 13:throw t.prev=13,t.t0=t.catch(0),t.t0;case 16:case"end":return t.stop()}},t,this,[[0,13]])}));return function(e){return t.apply(this,arguments)}}()},{key:"getLocationByIp",value:function(){return this.request.get("/v3/ip")}},{key:"translate",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"autonavi",r=c([t].map(function(t){return JSON.stringify(t).reverse().join("|")}),1)[0];return this.request.get("/v3/assistant/coordinate/convert",{locations:r,coordsys:e})}}]),e}(),O=w;exports.default=O;
},{"./request":"zMBz"}]},{},["Focm"], null)
\ No newline at end of file
{
"name": "glsx-map-sdk",
"version": "0.0.5",
"version": "0.0.6",
"description": "glsx-map-sdk",
"main": "dist/glsx-map-sdk.js",
"scripts": {
......@@ -11,9 +11,5 @@
"license": "ISC",
"devDependencies": {
"parcel-bundler": "^1.12.5"
},
"dependencies": {
"md5": "^2.3.0",
"qs": "^6.11.2"
}
}
......@@ -4,26 +4,26 @@ class GlMapApi {
const { key, secret } = params
this.request = new Request(key, secret)
}
/**计算距离
/** 定义一个异步方法,用于计算两个坐标之间的距离
* from 起始位置 [lat,lng]
* to 结束位置 [lat,lng]
* type 0:直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
*/
async calculateDistance(from, to, type = 1) {
try {
const destination = JSON.parse(JSON.stringify(from)).reverse().join(','),
origins = JSON.parse(JSON.stringify(to)).reverse().join(','),
{ results } = await this.request.get('/v3/distance', {
destination,
origins,
type
}),
res = {
elements: results
}
return Promise.resolve(res)
// 使用数组解构和map方法,将from和to参数转换为字符串,并反转数组顺序,然后用逗号连接,得到目的地坐标和出发地坐标
const [destination, origins] = [from, to].map(coord => JSON.stringify(coord).reverse().join(','))
// 调用request对象的get方法,传入请求路径为/v3/distance,请求数据为目的地坐标,出发地坐标和距离类型(默认为1),并等待异步结果,并解构响应数据中的results属性
const { results } = await this.request.get('/v3/distance', {
destination,
origins,
type
})
// 返回一个包含elements属性的对象,值为results
return { elements: results }
} catch (error) {
return Promise.reject(error)
// 如果发生异常,则抛出错误对象
throw error
}
}
/** 批量距离计算(矩阵)
......@@ -33,26 +33,23 @@ class GlMapApi {
*/
async calculateDistanceMatrix(from, toList, type = 1) {
try {
const destination = JSON.parse(JSON.stringify(from)).reverse().join(','),
origins = JSON.parse(JSON.stringify(toList))
.map(e => (e = e.reverse()))
.join('|'),
{ results } = await this.request.get('/v3/distance', {
destination,
origins,
type
}),
res = {
rows: [
{
elements: results
}
]
}
return Promise.resolve(res)
// 使用数组解构和map方法,将from和toList参数转换为字符串,并反转数组顺序,然后用逗号或竖线连接,得到目的地坐标和出发地坐标
const [destination, origins] = [from, toList].map(coord =>
JSON.stringify(coord)
.reverse()
.join(coord === from ? ',' : '|')
)
// 调用request对象的get方法,传入请求路径为/v3/distance,请求数据为目的地坐标,出发地坐标和距离类型(默认为1),并等待异步结果,并解构响应数据中的results属性
const { results } = await this.request.get('/v3/distance', {
destination,
origins,
type
})
// 返回一个包含rows属性的对象,值为一个包含elements属性的对象数组,值为results
return { rows: [{ elements: results }] }
} catch (error) {
return Promise.reject(error)
// 如果发生异常,则抛出错误对象
throw error
}
}
/**地址解析(地址转坐标)
......@@ -67,12 +64,17 @@ class GlMapApi {
* location [lat<纬度>,lng<经度>] */
async detailedAdrress(location) {
try {
// 使用数组解构,将location参数分解为纬度和经度
const [lat, lng] = location
// 调用request对象的get方法,传入请求路径为/v3/geocode/regeo,请求数据为坐标字符串(反转数组顺序并用逗号连接),并等待异步结果,并解构响应数据中的regeocode属性
const { regeocode } = await this.request.get('/v3/geocode/regeo', {
location: JSON.parse(JSON.stringify(location)).reverse().join(',')
location: JSON.stringify(location).reverse().join(',')
}),
// 解构regeocode对象中的addressComponent和formatted_address属性
{ addressComponent, formatted_address } = regeocode,
// 拼接省市区乡镇作为地址
address = `${addressComponent.province || ''}${addressComponent.city || ''}${addressComponent.district || ''}${addressComponent.township || ''}`,
// 定义一个返回数据对象,包含regeocode对象中的所有属性,以及一些格式化后的地址信息和坐标信息
data = {
...regeocode,
address,
......@@ -109,9 +111,11 @@ class GlMapApi {
}
}
return Promise.resolve(data)
// 返回一个成功的Promise对象,值为返回数据对象
return data
} catch (error) {
return Promise.reject(error)
// 如果发生异常,则抛出错误对象
throw error
}
}
/**IP定位 */
......@@ -127,10 +131,11 @@ class GlMapApi {
autonavi(不进行转换))
*
*/
// 定义一个方法,用于将一组坐标转换为不同的坐标系
translate(locationsList, coordsys = 'autonavi') {
const locations = JSON.parse(JSON.stringify(locationsList))
.map(e => (e = e.reverse()))
.join('|')
// 使用数组解构和map方法,将locationsList参数转换为字符串,并反转数组顺序,然后用竖线连接,得到locations字符串
const [locations] = [locationsList].map(coord => JSON.stringify(coord).reverse().join('|'))
// 调用request对象的get方法,传入请求路径为/v3/assistant/coordinate/convert,请求数据为locations字符串和coordsys参数(默认为autonavi),并返回结果
return this.request.get('/v3/assistant/coordinate/convert', {
locations,
coordsys
......
......@@ -2,15 +2,18 @@ import md5 from 'md5'
import qs from 'qs'
import { MAP_OPTIONS } from './constants'
import { isMiniprogram } from './helper'
//注释
// 定义一个Request类,用于封装请求高德地图API的方法
class Request {
// 构造函数,接收key和secret作为参数,如果没有传入,则使用默认值
constructor(key = MAP_OPTIONS.KEY, secret = MAP_OPTIONS.SECRET) {
// 将key和secret赋值给实例属性
this.key = key
this.secret = secret
}
/**对参数进行排序:按参数名升序 */
setLocaleCompare(params) {
// 将key添加到参数对象中
params.key = this.key
return Object.fromEntries(Object.entries(params).sort(([a], [b]) => a.localeCompare(b)))
}
......@@ -20,10 +23,12 @@ class Request {
}
/**封装的GET方法 */
get(method, data) {
// 调用request方法,传入请求方式为GET,请求路径为method,请求数据为data
return this.request('GET', method, data)
}
/**封装的请求方法 */
async request(RequestMethods, method, data = {}) {
// 调用getSign方法,传入请求数据和请求路径,得到签名
const sig = this.getSign(data, method),
obj = {
...this.setLocaleCompare(data),
......@@ -77,6 +82,7 @@ class Request {
wx.hideNavigationBarLoading()
}
} else {
// 如果不是小程序环境,则使用window.fetch方法发送请求,并传入完整的请求地址和请求方式
const params = []
Object.keys(obj).map(key => {
params.push(`${key}=${encodeURIComponent(obj[key])}`)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!