From 9243917876095350b248e59cd545c8923524e6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=98=B3?= Date: Tue, 16 Apr 2024 20:09:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?switchTab=E3=80=81navigateTo=E7=AD=89?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=87=BD=E6=95=B0=E5=8F=AF=E4=BB=A5=E8=A2=AB?= =?UTF-8?q?hook=20=E6=94=AF=E6=8C=81requriePlugin=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build/config/harmony-definition.json | 27 +++------------ .../src/api/apis/comments.ts | 6 ---- .../src/api/apis/index.ts | 2 +- .../src/api/apis/route/index.ts | 34 ------------------- .../src/api/apis/taro.ts | 14 ++++++-- 5 files changed, 18 insertions(+), 65 deletions(-) delete mode 100644 packages/taro-platform-harmony-hybrid/src/api/apis/route/index.ts diff --git a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json index 671d0b834da1..5e49f1177414 100644 --- a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json +++ b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json @@ -1296,18 +1296,9 @@ "phoneNumber": true } }, - "navigateBack": { - "object": { - "delta": true - } - }, + "navigateBack": false, "navigateBackMiniProgram": false, - "navigateTo": { - "object": { - "url": true, - "events": true - } - }, + "navigateTo": false, "navigateToBookshelf": false, "navigateToMiniProgram": { "object": { @@ -1603,11 +1594,7 @@ } }, "queryBookshelf": false, - "reLaunch": { - "object": { - "url": true - } - }, + "reLaunch": false, "readBLECharacteristicValue": { "object": { "characteristicId": true, @@ -1615,7 +1602,7 @@ "serviceId": true } }, - "redirectTo": true, + "redirectTo": false, "removeSavedFile": { "object": { "filePath": true @@ -1967,11 +1954,7 @@ "stopWifi": true, "subscribeService": false, "subscribeVoIPVideoMembers": false, - "switchTab": { - "object": { - "url": true - } - }, + "switchTab": false, "tradePay": false, "unsubscribeMessage": false, "updateBookshelfReadTime": false, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts index 9cda511f937b..c43312be399d 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts @@ -1036,12 +1036,6 @@ * @canNotUse onLocalServiceResolveFail */ -/** - * 监听隐私接口需要用户授权事件。 - * - * @canNotUse onNeedPrivacyAuthorization - */ - /** * 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。 * - 出现三次以上连接超时 diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts index db92527b4fb9..673b616c10a3 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts @@ -20,7 +20,7 @@ export * from './network' export * from './open-api' export * from './payment' export * from './qq' -export * from './route' +// export * from './route' export * from './share' export * from './storage' export * from './swan' diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/route/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/route/index.ts deleted file mode 100644 index ac02367fd795..000000000000 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/route/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @canUse navigateBack - * @__object [delta] - */ - -/** - * @canUse navigateTo - * @__object [url, events] - */ - -/** - * @canUse redirectTo - * @object [url] - */ - -/** - * @canUse reLaunch - * @__object [url] - */ - -/** - * @canUse switchTab - * @__object [url] - */ - -export { navigateBack, navigateTo, redirectTo, reLaunch, switchTab } from '@tarojs/router' - -// FIXME 方法导出类型未对齐,后续修复 - -/** - * 页面间事件通信通道 - * - * @canNotUse EventChannel - */ diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts index 146041e50923..51621da68bab 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts @@ -16,7 +16,7 @@ import { switchTab, } from './index' import native from './NativeApi' -import { permanentlyNotSupport } from './utils' +// import { permanentlyNotSupport } from './utils' // @ts-ignore window.base64ToArrayBuffer = (base64: string) => toByteArray(base64).buffer @@ -105,7 +105,15 @@ const taro: typeof Taro = { useUnload } -export const requirePlugin = permanentlyNotSupport('requirePlugin') +// export const requirePlugin = permanentlyNotSupport('requirePlugin') +const requirePlugin = () => { + return { + world: '', + hello: function () { + + } + } +} function getConfig (): Record { if (this?.pxTransformConfig) return this.pxTransformConfig @@ -348,6 +356,7 @@ function loadChooseLocationStyle () { loadChooseLocationStyle() +taro.requirePlugin = requirePlugin taro.getApp = getApp taro.pxTransform = pxTransform taro.initPxTransform = initPxTransform @@ -377,6 +386,7 @@ export { options, preload, pxTransform, + requirePlugin, useAddToFavorites, useDidHide, useDidShow, From 198b7bd87e5adef153f789df0dc294bad2a76962 Mon Sep 17 00:00:00 2001 From: ZXDSAX <2998227853@qq.com> Date: Wed, 17 Apr 2024 11:45:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BF=AE=E4=BB=A5=E5=8F=8Arequest=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3js=E5=AE=9E=E7=8E=B0=E6=B7=BB=E5=8A=A0onHeadersReceive?= =?UTF-8?q?d=E5=92=8CoffHeadersReceived=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build/config/harmony-definition.json | 8 ++- .../src/api/apis/NativeApi.ts | 2 + .../api/apis/base/update/getUpdateManager.ts | 1 - .../src/api/apis/network/request/index.ts | 4 +- .../src/api/apis/request.ts | 56 +++++++++---------- .../apis/storage/setBackgroundFetchToken.ts | 2 +- 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json index 671d0b834da1..09255dddc6d6 100644 --- a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json +++ b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json @@ -1178,7 +1178,7 @@ } }, "getTopStatus": false, - "getUpdateManager": false, + "getUpdateManager": true, "getUserCryptoManager": false, "getUserInfo": { "object": { @@ -1754,7 +1754,11 @@ } }, "setBackgroundColor": false, - "setBackgroundFetchToken": true, + "setBackgroundFetchToken": { + "object": { + "token": true + } + }, "setBackgroundTextStyle": false, "setClipboardData": { "object": { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts index b747444770f3..43b4fc0978b9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts @@ -10,6 +10,7 @@ const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMod // @ts-ignore const asyncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: false }) || (target => target) +export let judgeUseAxios = false class NativeApi { // @ts-ignore @(syncAndRelease) @@ -893,6 +894,7 @@ class HybridProxy { get (_target: any, prop: string) { return (...args: any) => { if (this.useAxios && prop === this.requestApi) { + judgeUseAxios = this.useAxios // @ts-ignore return new RequestTask(...args) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/base/update/getUpdateManager.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/base/update/getUpdateManager.ts index 8a2b6bf1831f..f5aee3cd9651 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/base/update/getUpdateManager.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/base/update/getUpdateManager.ts @@ -6,7 +6,6 @@ import { NativeUpdateManager } from '../../interface/NativeUpdateManager' * 获取全局唯一的版本更新管理器 * * @canUse getUpdateManager - * @null_implementation */ export const getUpdateManager: typeof Taro.getUpdateManager = () => { // 使用native方法 diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/network/request/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/network/request/index.ts index ec627dae335c..ffbea80fc08a 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/network/request/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/network/request/index.ts @@ -2,7 +2,7 @@ import Taro from '@tarojs/api' import { isFunction } from '@tarojs/shared' import { NativeRequest } from '../../interface/NativeRequest' -import native from '../../NativeApi' +import native, { judgeUseAxios } from '../../NativeApi' import { getParameterError, shouldBeObject } from '../../utils' export const _request = (options) => { @@ -46,7 +46,7 @@ export const _request = (options) => { reject(res) }, }) - task = NativeRequest.getRequestTask(taskID) + task = judgeUseAxios ? taskID : NativeRequest.getRequestTask(taskID) }) as any result.onHeadersReceived = task.onHeadersReceived.bind(task) diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/request.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/request.ts index b6ee87ce5fc6..e4284cb294ca 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/request.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/request.ts @@ -1,7 +1,12 @@ +import { CallbackManager } from './utils/handler' + const axios = require('axios').default const CancelToken = axios.CancelToken const source = CancelToken.source() +const callbackManager = { + headersReceived: new CallbackManager() +} const errMsgMap = new Map([ [401, 'Parameter error'], @@ -17,12 +22,11 @@ const errMsgMap = new Map([ [999, 'Unknown Other Error'], ]) +let isHeaderReceived = false export class RequestTask { - public responseHeader public abortFlag public fail public complete - public headersCallback public result public res public interceptor @@ -33,11 +37,9 @@ export class RequestTask { let { data } = object || {} const { success, fail, complete, dataType } = object || {} - this.responseHeader = null this.abortFlag = false this.fail = fail this.complete = complete - this.headersCallback = new Set() // 使用axios.create来创建axios实例 this.httpRequest = axios.create({ responseType: responseType || 'text', @@ -75,6 +77,9 @@ export class RequestTask { if (response.config.enableCache === false) { localStorage.setItem(response.config.url, JSON.stringify(response.data)) } + callbackManager.headersReceived.trigger({ + header: response.headers + }) return response }, (error) => { @@ -122,7 +127,6 @@ export class RequestTask { }) .then((response) => { if (success && !this.abortFlag) { - this.responseHeader = response.headers let result = response.result if (response.config.responseType === 'text') { if (dataType === 'text') { @@ -186,22 +190,20 @@ export class RequestTask { } onHeadersReceived (callback) { - if (!callback) { - console.error('[AdvancedAPI] Invalid, callback is null') - return - } - const taskCallback = (header) => { - !this.abortFlag && callback({ header }) - } - if (!this.headersCallback.has(callback)) { - this.headersCallback.add(taskCallback) - if (this.httpRequest) { - this.interceptor = this.httpRequest.interceptors.response.use((response) => { - taskCallback(this.responseHeader) - return response - }) + if (isHeaderReceived === false) { + const taskCallback = (header) => { + !this.abortFlag && callback({ header }) } - taskCallback(this.responseHeader) + if (!callback) { + console.error('[AdvancedAPI] Invalid, callback is null') + return + } + if (callbackManager) { + isHeaderReceived = true + callbackManager.headersReceived.addUnique(taskCallback) + } + } else { + callbackManager.headersReceived.remove(callback) } } @@ -210,14 +212,12 @@ export class RequestTask { * remove all if callback is null, otherwise remove the specialized callback */ offHeadersReceived (callback) { - if (this.headersCallback.has(callback)) { - if (this.httpRequest) { - this.httpRequest.interceptors.eject(this.interceptor) - } - this.headersCallback.delete(callback) - } else { - // eslint-disable-next-line no-console - console.debug('offHeadersReceived callback invalid') + if (!callback) { + console.error('Invalid, callback is null') + return + } + if (callbackManager && isHeaderReceived) { + callbackManager.headersReceived.remove(callback) } } } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/storage/setBackgroundFetchToken.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/storage/setBackgroundFetchToken.ts index 0649393c4149..60f2bcf8726f 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/storage/setBackgroundFetchToken.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/storage/setBackgroundFetchToken.ts @@ -8,7 +8,7 @@ import native from '../NativeApi' * 拉取 backgroundFetch 客户端缓存数据 * * @canUse setBackgroundFetchToken - * @null_implementation + * @__object [token] */ export const setBackgroundFetchToken: typeof Taro.setBackgroundFetchToken = function (options) { const name = 'setBackgroundFetchToken'