Match-id-a5f10cc817b40592611e27bb36f7d7e40bbdc80d

This commit is contained in:
* 2023-09-04 15:51:34 +08:00
commit ff9eba84c1
8 changed files with 380 additions and 318 deletions

File diff suppressed because it is too large Load Diff

View File

@ -24,9 +24,9 @@
sendRequestButton.addEventListener('click', function() { sendRequestButton.addEventListener('click', function() {
message.innerHTML = ''; message.innerHTML = '';
cancelTokenSource = horizonRequest.CancelToken.source(); cancelTokenSource = inulaRequest.CancelToken.source();
horizonRequest.get('http://localhost:3001/data', { inulaRequest.get('http://localhost:3001/data', {
cancelToken: cancelTokenSource.token cancelToken: cancelTokenSource.token
}).then(function(response) { }).then(function(response) {
message.innerHTML = '请求成功: ' + JSON.stringify(response.data, null, 2); message.innerHTML = '请求成功: ' + JSON.stringify(response.data, null, 2);
@ -36,15 +36,15 @@
}); });
cancelRequestButton.addEventListener('click', function () { cancelRequestButton.addEventListener('click', function () {
const CancelToken = horizonRequest.CancelToken; const CancelToken = inulaRequest.CancelToken;
const source = CancelToken.source(); const source = CancelToken.source();
horizonRequest.get('http://localhost:3001/data', { inulaRequest.get('http://localhost:3001/data', {
cancelToken: source.token cancelToken: source.token
}).then(function(response) { }).then(function(response) {
console.log(response.data); console.log(response.data);
}).catch(function(error) { }).catch(function(error) {
if (horizonRequest.isCancel(error)) { if (inulaRequest.isCancel(error)) {
message.innerHTML = '请求已被取消:' + error.message; message.innerHTML = '请求已被取消:' + error.message;
} else { } else {
message.innerHTML = '请求出错:' + error.message; message.innerHTML = '请求出错:' + error.message;

View File

@ -3,11 +3,11 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Horizon Request Interceptor Test</title> <title>Inula Request Interceptor Test</title>
<link rel="stylesheet" type="text/css" href="interceptorStyles.css"> <link rel="stylesheet" type="text/css" href="interceptorStyles.css">
</head> </head>
<body> <body>
<header>Horizon Request interceptor Test</header> <header>Inula Request interceptor Test</header>
<h2>使用拦截器:</h2> <h2>使用拦截器:</h2>
<div class="response-container"> <div class="response-container">
<h3>响应状态码:</h3> <h3>响应状态码:</h3>
@ -89,7 +89,7 @@
// 不使用拦截器的请求 // 不使用拦截器的请求
document.getElementById('sendRequestWithoutInterceptor').addEventListener('click', function () { document.getElementById('sendRequestWithoutInterceptor').addEventListener('click', function () {
horizonRequest.get('http://localhost:3001/') inulaRequest.get('http://localhost:3001/')
.then(function (response) { .then(function (response) {
document.getElementById('responseStatusWithoutInterceptor').textContent = response.status; document.getElementById('responseStatusWithoutInterceptor').textContent = response.status;
document.getElementById('responseDataWithoutInterceptor').textContent = JSON.stringify(response.data, null, 2); document.getElementById('responseDataWithoutInterceptor').textContent = JSON.stringify(response.data, null, 2);

View File

@ -2,11 +2,11 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Horizon Request API Test</title> <title>Inula Request API Test</title>
<link rel="stylesheet" type="text/css" href="requestStyles.css"> <link rel="stylesheet" type="text/css" href="requestStyles.css">
</head> </head>
<body> <body>
<header>Horizon Request API Test</header> <header>Inula Request API Test</header>
<div class="container"> <div class="container">
<div class="card"> <div class="card">
<h2>Request</h2> <h2>Request</h2>
@ -85,8 +85,8 @@
const resetButton = document.getElementById('resetButton'); const resetButton = document.getElementById('resetButton');
queryButton.addEventListener('click', function () { queryButton.addEventListener('click', function () {
const inulaRequest = inulaRequest.create(); const irInstance = inulaRequest.create();
inulaRequest.request('http://localhost:3001/', {method: 'GET', data: {}}) irInstance.request('http://localhost:3001/', {method: 'GET', data: {}})
.then(function (response) { .then(function (response) {
requestResult.innerHTML = JSON.stringify(response.data, null, 2); requestResult.innerHTML = JSON.stringify(response.data, null, 2);
}) })
@ -189,7 +189,7 @@
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
horizonRequest.post('http://localhost:3001/', formData, { inulaRequest.post('http://localhost:3001/', formData, {
onUploadProgress: function (progressEvent) { onUploadProgress: function (progressEvent) {
const loaded = progressEvent.loaded; const loaded = progressEvent.loaded;
const total = progressEvent.total; const total = progressEvent.total;

View File

@ -23,12 +23,12 @@ app.use(cors(corsOptions));
// 处理 GET 请求 // 处理 GET 请求
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.send('Hello Horizon Request!'); res.send('Hello Inula Request!');
}) })
app.get('/data', (req, res) => { app.get('/data', (req, res) => {
const data = { const data = {
message: 'Hello Horizon Request!', message: 'Hello Inula Request!',
}; };
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
@ -37,7 +37,7 @@ app.get('/data', (req, res) => {
}); });
app.get('/download', (req, res) => { app.get('/download', (req, res) => {
const filePath = 'D:\\code\\MRcode\\Horizon-Request\\examples\\request\\downloadTest.html'; const filePath = 'D:\\code\\MRcode\\inula-Request\\examples\\request\\downloadTest.html';
const fileName = 'downloadTest.html'; const fileName = 'downloadTest.html';
const fileSize = fs.statSync(filePath).size; const fileSize = fs.statSync(filePath).size;

View File

@ -7,10 +7,10 @@ import { babel } from '@rollup/plugin-babel';
export default { export default {
input: './index.ts', input: './index.ts',
output: { output: {
file: 'dist/horizonRequest.js', file: 'dist/inulaRequest.js',
format: 'umd', format: 'umd',
exports: 'named', exports: 'named',
name: 'horizonRequest', name: 'inulaRequest',
sourcemap: false, sourcemap: false,
}, },
plugins: [ plugins: [

View File

@ -12,11 +12,17 @@ function processUploadProgress(
) { ) {
if (onUploadProgress) { if (onUploadProgress) {
let totalBytesToUpload = 0; // 上传的总字节数 let totalBytesToUpload = 0; // 上传的总字节数
if (data instanceof File) {
totalBytesToUpload = data.size;
}
if (data instanceof FormData) {
data.forEach(value => { data.forEach(value => {
if (value instanceof Blob) { if (value instanceof Blob) {
totalBytesToUpload += value.size; totalBytesToUpload += value.size;
} }
}); });
}
const handleUploadProgress = () => { const handleUploadProgress = () => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();

View File

@ -4,7 +4,7 @@ const path = require('path');
// webpack配置信息 // webpack配置信息
module.exports = { module.exports = {
// 指定入口文件 // 指定入口文件
entry: './src/horizonRequest.ts', entry: './src/inulaRequest.ts',
// 指定打包文件信息 // 指定打包文件信息
output: { output: {
@ -12,7 +12,7 @@ module.exports = {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
library: 'myLibrary', library: 'myLibrary',
libraryTarget: 'umd', libraryTarget: 'umd',
filename: 'horizonRequest.js', filename: 'inulaRequest.js',
}, },
// 指定打包时使用的模块 // 指定打包时使用的模块