Commit 60cae9e1 authored by rockyl's avatar rockyl

init

parent 66d1a76e
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
......@@ -66,7 +70,7 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
break;
case 'form':
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
options.body = querystringify_1.stringify(params);
options.body = (0, querystringify_1.stringify)(params);
break;
case 'json':
options.headers['Content-Type'] = 'application/json';
......@@ -76,7 +80,7 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
}
else {
url += url.indexOf('?') < 0 ? '?' : '';
url += (url.endsWith('?') ? '' : '&') + querystringify_1.stringify(params);
url += (url.endsWith('?') ? '' : '&') + (0, querystringify_1.stringify)(params);
}
}
try {
......@@ -84,12 +88,18 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
const response = await fetchMethod(url, options);
const respText = await response.text();
if (response.status === 310) {
console.log('重定向到:' + respText);
try {
location.href = respText;
}
catch (e) {
}
}
let jsonObj = JSON.parse(respText);
if (_options.successfullyJudge(jsonObj)) {
return jsonObj.data;
}
console.log(jsonObj);
return Promise.reject(new ApiError('call api failed', jsonObj.code, errMessage || jsonObj[_options.messageField]));
}
catch (e) {
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAMA,oCAAiC;AACjC,mDAAyC;AACzC,+EAA0D;AAE1D,gEAA8C;AAK9C,MAAM,QAAS,SAAQ,KAAK;IAI3B,YAAY,IAAY,EAAE,IAAa,EAAE,OAAgB;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AC3F,CAAC;KACF;IAAC,OAAO,CAAC,EAAE;QACX,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACzB;AACF,CAAC;AA/ED,4BA+EC"}
\ No newline at end of file
......@@ -10,6 +10,7 @@
},
"scripts": {
"dev": "tsc -w",
"build": "tsc"
"build": "tsc",
"release": "npm version patch && npm publish"
}
}
......@@ -160,7 +160,12 @@ export async function fetchApi(
if (response.status === 310) {
//客户端重定向,用于跨域重定向
console.log('重定向到:' + respText)
try {
location.href = respText;
} catch (e) {
}
}
let jsonObj = JSON.parse(respText);
......@@ -168,6 +173,8 @@ export async function fetchApi(
return jsonObj.data;
}
console.log(jsonObj)
return Promise.reject(
new ApiError('call api failed', jsonObj.code, errMessage || jsonObj[_options.messageField]),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment