Skip to content

Commit

Permalink
fix: 解决 reqeust 生成文件流的问题 (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt authored Mar 28, 2024
1 parent 0f672af commit c369572
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
74 changes: 37 additions & 37 deletions packages/fes-plugin-request/package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"name": "@fesjs/plugin-request",
"version": "4.0.0-rc.1",
"description": "@fesjs/plugin-request",
"main": "lib/index.js",
"files": [
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/WeBankFinTech/fes.js.git",
"directory": "packages/fes-plugin-request"
},
"keywords": [
"fes"
],
"author": "qlin",
"license": "MIT",
"bugs": {
"url": "https://github.com/WeBankFinTech/fes.js/issues"
},
"homepage": "https://github.com/WeBankFinTech/fes.js#readme",
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"@fesjs/fes": "^3.1.4",
"vue": "^3.2.37"
},
"dependencies": {
"@fesjs/utils": "^3.0.1",
"@qlin/request": "^0.1.2"
},
"typings": "./types.d.ts"
"name": "@fesjs/plugin-request",
"version": "4.0.0-rc.1",
"description": "@fesjs/plugin-request",
"author": "qlin",
"license": "MIT",
"homepage": "https://github.com/WeBankFinTech/fes.js#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/WeBankFinTech/fes.js.git",
"directory": "packages/fes-plugin-request"
},
"bugs": {
"url": "https://github.com/WeBankFinTech/fes.js/issues"
},
"keywords": [
"fes"
],
"main": "lib/index.js",
"files": [
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"@fesjs/fes": "^3.1.4",
"vue": "^3.2.37"
},
"dependencies": {
"@fesjs/utils": "^3.0.1",
"@qlin/request": "^0.2.0"
},
"typings": "./types.d.ts"
}
6 changes: 4 additions & 2 deletions packages/fes-plugin-request/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'path';
import { join } from 'node:path';
import { name } from '../package.json';

export default (api) => {
Expand All @@ -9,7 +9,9 @@ export default (api) => {

let generatedOnce = false;
api.onGenerateFiles(() => {
if (generatedOnce) return;
if (generatedOnce) {
return;
}
generatedOnce = true;
api.copyTmpFiles({
namespace,
Expand Down
16 changes: 8 additions & 8 deletions packages/fes-plugin-request/src/template/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function getRequestInstance() {
type: ApplyPluginsType.modify,
initialValue: {
timeout: 10000,
responseType: 'json',
},
});

Expand All @@ -18,7 +17,7 @@ function getRequestInstance() {

let currentRequest;

export const rawRequest = (url, data, options = {}) => {
export function rawRequest(url, data, options = {}) {
if (typeof options === 'string') {
options = {
method: options,
Expand All @@ -28,27 +27,28 @@ export const rawRequest = (url, data, options = {}) => {
currentRequest = getRequestInstance();
}
return currentRequest(url, data, options);
};
}

export const request = async (url, data, options = {}) => {
export async function request(url, data, options = {}) {
const response = await rawRequest(url, data, options);
return response.data;
};
}

request.version = '4.0.0';

function isPromiseLike(obj) {
return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
}

export const useRequest = (url, data, options = {}) => {
export function useRequest(url, data, options = {}) {
const loadingRef = ref(true);
const errorRef = ref(null);
const dataRef = shallowRef(null);
let promise;
if (isPromiseLike(url)) {
promise = url;
} else {
}
else {
promise = request(url, data, options);
}
promise
Expand All @@ -66,4 +66,4 @@ export const useRequest = (url, data, options = {}) => {
error: errorRef,
data: dataRef,
};
};
}

0 comments on commit c369572

Please sign in to comment.