From 96ea0266dd7c0da26341d8fea4d3bdb53361ffd0 Mon Sep 17 00:00:00 2001 From: zjx0905 <954270063@qq.com> Date: Sun, 4 Jun 2023 19:44:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=20uni=20=E9=80=82=E9=85=8D=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE : uni 不再内部支持, 可以参阅文档中的自定义适配器自行适配 uni #40 --- README.md | 3 -- example/src/pages/index/index.vue | 53 ++++---------------------- global.variables.d.ts | 1 - src/adpater/getDefaultAdapter.ts | 8 +--- src/core/createInstance.ts | 7 +++- test/adpater/getDefaultAdapter.test.ts | 1 - 6 files changed, 14 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 9bcbbae..af1dffe 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,3 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库 [提问点这里](https://github.com/zjx0905/axios-miniprogram/issues) -## 未来计划 - -2023 年 6 月 1 日 起该库将不再内部支持第三方框架,内置的 uni-app 即将移除,您依旧可以使用[适配器](https://axios-miniprogram.com/advanced/adapter)兼容 uni-app。 diff --git a/example/src/pages/index/index.vue b/example/src/pages/index/index.vue index 4815399..83fc560 100644 --- a/example/src/pages/index/index.vue +++ b/example/src/pages/index/index.vue @@ -24,54 +24,17 @@ function getRequest() { } function postRequest() { - axios.post('/users', { - name: 'Leanne Graham', - username: 'Bret', - email: 'Sincere@april.biz', - address: { - street: 'Kulas Light', - suite: 'Apt. 556', - city: 'Gwenborough', - zipcode: '92998-3874', - geo: { - lat: '-37.3159', - lng: '81.1496', - }, - }, - phone: '1-770-736-8031 x56442', - website: 'hildegard.org', - company: { - name: 'Romaguera-Crona', - catchPhrase: 'Multi-layered client-server neural-net', - bs: 'harness real-time e-markets', - }, - }); + axios.post( + '/users', + '{"name":"Leanne Graham","username":"Bret","email":"Sincere@april.biz","address":{"street":"Kulas Light","suite":"Apt. 556","city":"Gwenborough","zipcode":"92998-3874","geo":{"lat":"-37.3159","lng":"81.1496"}},"phone":"1-770-736-8031 x56442","website":"hildegard.org","company":{"name":"Romaguera-Crona","catchPhrase":"Multi-layered client-server neural-net","bs":"harness real-time e-markets"}}', + ); } function putRequest() { - axios.put('/users/:id', { - id: 1, - name: 'Leanne Graham', - username: 'Bret', - email: 'Sincere@april.biz', - address: { - street: 'Kulas Light', - suite: 'Apt. 556', - city: 'Gwenborough', - zipcode: '92998-3874', - geo: { - lat: '-37.3159', - lng: '81.1496', - }, - }, - phone: '1-770-736-8031 x56442', - website: 'hildegard.org', - company: { - name: 'Romaguera-Crona', - catchPhrase: 'Multi-layered client-server neural-net', - bs: 'harness real-time e-markets', - }, - }); + axios.put( + '/users/:id', + '{"id":1,"name":"Leanne Graham","username":"Bret","email":"Sincere@april.biz","address":{"street":"Kulas Light","suite":"Apt. 556","city":"Gwenborough","zipcode":"92998-3874","geo":{"lat":"-37.3159","lng":"81.1496"}},"phone":"1-770-736-8031 x56442","website":"hildegard.org","company":{"name":"Romaguera-Crona","catchPhrase":"Multi-layered client-server neural-net","bs":"harness real-time e-markets"}}', + ); } function deleteRequest() { diff --git a/global.variables.d.ts b/global.variables.d.ts index d659f10..96ae87f 100644 --- a/global.variables.d.ts +++ b/global.variables.d.ts @@ -1,4 +1,3 @@ -declare const uni: any; declare const wx: any; declare const my: any; declare const swan: any; diff --git a/src/adpater/getDefaultAdapter.ts b/src/adpater/getDefaultAdapter.ts index 174991e..63a5f86 100644 --- a/src/adpater/getDefaultAdapter.ts +++ b/src/adpater/getDefaultAdapter.ts @@ -13,13 +13,7 @@ export function getDefaultAdapter() { function getPlatform() { const undef = 'undefined'; - if (typeof uni !== undef) { - return { - request: uni.request, - downloadFile: uni.downloadFile, - uploadFile: uni.uploadFile, - }; - } else if (typeof wx !== undef) { + if (typeof wx !== undef) { return wx; } else if (typeof my !== undef) { return my; diff --git a/src/core/createInstance.ts b/src/core/createInstance.ts index 30f4f27..7a74720 100644 --- a/src/core/createInstance.ts +++ b/src/core/createInstance.ts @@ -54,8 +54,11 @@ export interface AxiosInstance extends AxiosRequest, Axios { fork(config: AxiosRequestConfig): AxiosInstance; } -export function createInstance(defaults: AxiosRequestConfig, parent?: Axios) { - const context = new Axios(defaults, parent); +export function createInstance( + defaults: AxiosRequestConfig, + parentContext?: Axios, +) { + const context = new Axios(defaults, parentContext); const instance = context.request as AxiosInstance; instance.getUri = function getUri(config) { diff --git a/test/adpater/getDefaultAdapter.test.ts b/test/adpater/getDefaultAdapter.test.ts index 9e18fa4..214edf6 100644 --- a/test/adpater/getDefaultAdapter.test.ts +++ b/test/adpater/getDefaultAdapter.test.ts @@ -2,7 +2,6 @@ import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest'; import { getDefaultAdapter } from '@/adpater/getDefaultAdapter'; const platforms = [ - 'uni', 'wx', 'my', 'swan',