Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
qican777 authored Apr 17, 2024
2 parents 9751ca3 + b3e4a35 commit 85b2c6e
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@
}
},
"getTopStatus": false,
"getUpdateManager": false,
"getUpdateManager": true,
"getUserCryptoManager": false,
"getUserInfo": {
"object": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -1603,19 +1594,15 @@
}
},
"queryBookshelf": false,
"reLaunch": {
"object": {
"url": true
}
},
"reLaunch": false,
"readBLECharacteristicValue": {
"object": {
"characteristicId": true,
"deviceId": true,
"serviceId": true
}
},
"redirectTo": true,
"redirectTo": false,
"removeSavedFile": {
"object": {
"filePath": true
Expand Down Expand Up @@ -1754,7 +1741,11 @@
}
},
"setBackgroundColor": false,
"setBackgroundFetchToken": true,
"setBackgroundFetchToken": {
"object": {
"token": true
}
},
"setBackgroundTextStyle": false,
"setClipboardData": {
"object": {
Expand Down Expand Up @@ -1967,11 +1958,7 @@
"stopWifi": true,
"subscribeService": false,
"subscribeVoIPVideoMembers": false,
"switchTab": {
"object": {
"url": true
}
},
"switchTab": false,
"tradePay": false,
"unsubscribeMessage": false,
"updateBookshelfReadTime": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { NativeUpdateManager } from '../../interface/NativeUpdateManager'
* 获取全局唯一的版本更新管理器
*
* @canUse getUpdateManager
* @null_implementation
*/
export const getUpdateManager: typeof Taro.getUpdateManager = () => {
// 使用native方法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,12 +1036,6 @@
* @canNotUse onLocalServiceResolveFail
*/

/**
* 监听隐私接口需要用户授权事件。
*
* @canNotUse onNeedPrivacyAuthorization
*/

/**
* 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
* - 出现三次以上连接超时
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down
56 changes: 28 additions & 28 deletions packages/taro-platform-harmony-hybrid/src/api/apis/request.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand All @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}
}
34 changes: 0 additions & 34 deletions packages/taro-platform-harmony-hybrid/src/api/apis/route/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 12 additions & 2 deletions packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string, any> {
if (this?.pxTransformConfig) return this.pxTransformConfig
Expand Down Expand Up @@ -348,6 +356,7 @@ function loadChooseLocationStyle () {

loadChooseLocationStyle()

taro.requirePlugin = requirePlugin
taro.getApp = getApp
taro.pxTransform = pxTransform
taro.initPxTransform = initPxTransform
Expand Down Expand Up @@ -377,6 +386,7 @@ export {
options,
preload,
pxTransform,
requirePlugin,
useAddToFavorites,
useDidHide,
useDidShow,
Expand Down

0 comments on commit 85b2c6e

Please sign in to comment.