-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.js
1 lines (1 loc) · 2.12 KB
/
dist.js
1
'use strict';var _keys=require('babel-runtime/core-js/object/keys'),_keys2=_interopRequireDefault(_keys),_typeof2=require('babel-runtime/helpers/typeof'),_typeof3=_interopRequireDefault(_typeof2),_assign=require('babel-runtime/core-js/object/assign'),_assign2=_interopRequireDefault(_assign);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var Axios=require('axios');module.exports=function(a){function b(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:'?',c='';return'object'===('undefined'==typeof a?'undefined':(0,_typeof3.default)(a))&&(0,_keys2.default)(a).forEach(function(d){'undefined'!=typeof a[d]&&'undefined'!==a[d]&&''!==a[d]&&('?'===b?c+='&'+d+'='+a[d]:c+='/'+d+'/'+a[d])}),c.replace(/^&/,'?')}function c(b){var c='',d='';b.response?(c=b.response.config.url,d='\u51FA\u9519\u4E86 \u9519\u8BEF\u4EE3\u7801: '+b.response.status+' \u9519\u8BEF\u4FE1\u606F: '+b.response.statusText):(c=b.config.url,d='\u8BF7\u6C42\u51FA\u9519\uFF0C\u8BF7\u68C0\u67E5\u60A8\u7684\u7F51\u7EDC\u914D\u7F6E '+b),a.think.logger.error('\u8BF7\u6C42\uFF1A'+c+' \u51FA\u9519'),a.think.logger.error(new Error(d));var e={};return b.response&&b.response.data&&(e=b.response.data),(0,_assign2.default)(g,{errmsg:d,data:e})}function d(a){var d=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},e=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{};return h.get(a+b(d),e).then(function(a){return(0,_assign2.default)(g,{errno:0,data:a.data})},function(a){return c(a)})}function e(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{};return h.post(a,b,d).then(function(a){return(0,_assign2.default)(g,{errno:0,data:a.data})},function(a){return c(a)})}var f=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},g={errno:1,errmsg:'',data:{}},h=Axios.create((0,_assign2.default)({timeout:3e4,responseType:'json',headers:{"X-Requested-With":'XMLHttpRequest',"Content-Type":'application/json'}},f));return{think:{axios:h,httpGet:d,httpPost:e},context:{axios:h,httpGet:d,httpPost:e},controller:{axios:h,httpGet:d,httpPost:e},service:{axios:h,httpGet:d,httpPost:e}}};