Skip to content

Commit

Permalink
Merge pull request #15590 from handsomeliuyang/main
Browse files Browse the repository at this point in the history
Harmony-hybird的request的实现优化,request的h5版本复用taro-h5的实现,同时通过接口参数,业务可以灵活选择实现机制
  • Loading branch information
qican777 committed Apr 28, 2024
2 parents df0abee + 9da7364 commit 6c930de
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 310 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ common/autoinstallers/*/.npmrc

target/
debug/
!packages/taro-platform-harmony-hybrid/src/api/apis/base/debug

# Binding artifacts
artifacts
Expand All @@ -84,4 +85,4 @@ artifacts
*.node

# harmony-hybrid extend-h5-apis file
packages/taro-platform-harmony-hybrid/src/api/apis/extend-h5-apis.ts
packages/taro-platform-harmony-hybrid/src/api/apis/extend-h5-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@
"verticalAccuracy": true
}
},
"getLogManager": false,
"getLogManager": true,
"getMenuButtonBoundingClientRect": {
"return": {
"left": true,
Expand Down Expand Up @@ -958,7 +958,7 @@
"getPrivacySetting": false,
"getQQRunData": false,
"getRandomValues": false,
"getRealtimeLogManager": false,
"getRealtimeLogManager": true,
"getRecorderManager": true,
"getRendererUserAgent": false,
"getSavedFileInfo": {
Expand Down Expand Up @@ -1755,7 +1755,7 @@
"setCustomDress": false,
"setDocumentTitle": false,
"setEnable1v1Chat": false,
"setEnableDebug": false,
"setEnableDebug": true,
"setInnerAudioOption": false,
"setKeepScreenOn": {
"object": {
Expand Down
24 changes: 12 additions & 12 deletions packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import osChannelApi from './osChannelApi'
import { RequestTask } from './request'
// import { RequestTask } from './request'

// @ts-ignore
const syncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations

Check warning on line 5 in packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Unexpected mix of '&&' and '||'. Use parentheses to clarify the intended order of operations
Expand All @@ -10,7 +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
// export let judgeUseAxios = false
class NativeApi {
// @ts-ignore
@(syncAndRelease)
Expand Down Expand Up @@ -880,24 +880,24 @@ class AsyncToSyncProxy {
}

class HybridProxy {
private readonly useAxios: boolean
// private readonly useAxios: boolean
private readonly useOsChannel: boolean
private readonly cacheProxy: any
private readonly requestApi = 'request'
// private readonly requestApi = 'request'

constructor (useAxios: boolean, useOsChannel: boolean, nativeApi: NativeApi) {
this.useAxios = useAxios
constructor (useOsChannel: boolean, nativeApi: NativeApi) {
// this.useAxios = useAxios
this.useOsChannel = useOsChannel
this.cacheProxy = new Proxy(nativeApi, new CacheStorageProxy(nativeApi))
}

get (_target: any, prop: string) {
return (...args: any) => {
if (this.useAxios && prop === this.requestApi) {
judgeUseAxios = this.useAxios
// @ts-ignore
return new RequestTask(...args)
}
// if (this.useAxios && prop === this.requestApi) {
// judgeUseAxios = this.useAxios
// // @ts-ignore
// return new RequestTask(...args)
// }
if (this.useOsChannel && osChannelApi.hasOwnProperty(prop)) {
return osChannelApi[prop](...args)
}
Expand All @@ -907,5 +907,5 @@ class HybridProxy {
}

const nativeApi = new NativeApi()
const native = new Proxy(nativeApi, new HybridProxy(false, false, nativeApi)) // 第一个false是默认走jsb,true是走纯js, 第二个false是不走osChannel
const native = new Proxy(nativeApi, new HybridProxy(false, nativeApi)) // 第一个false是默认走jsb,true是走纯js, 第二个false是不走osChannel
export default native
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Taro from '@tarojs/api'

/**
* 获取日志管理器对象
*
* @canUse getLogManager
* @null_implementation
*/
export const getLogManager: typeof Taro.getLogManager = () => {
return new LogManager()
}

/**
* 日志管理器
*
* @canUse LogManager
* @null_implementation
*/
class LogManager implements Taro.LogManager {
debug (): void {

}

info (): void {

}

log (): void {

}

warn (): void {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Taro from '@tarojs/api'

/**
* 获取实时日志管理器对象
*
* @canUse getRealtimeLogManager
* @null_implementation
*/
export const getRealtimeLogManager: typeof Taro.getRealtimeLogManager = () => {
return new RealtimeLogManager()
}

/**
* 实时日志管理器
*
* @canUse RealtimeLogManager
* @null_implementation
*/
class RealtimeLogManager implements Taro.RealtimeLogManager {
addFilterMsg (): void {

}

error (): void {

}

in (): void {

}

info (): void {

}

setFilterMsg (): void {

}

tag (tagName: string): RealtimeTagLogManager {
return new RealtimeTagLogManager(tagName)
}

warn (): void {

}
}

/**
* 给定标签的实时日志管理器
*
* @canUse RealtimeTagLogManager
* @null_implementation
*/
class RealtimeTagLogManager implements Taro.RealtimeTagLogManager {
_tagName: string

constructor (tagName: string) {
this._tagName = tagName
}

addFilterMsg (_msg): void {

}

error (_key, _value): void {

}

info (_key, _value): void {

}

setFilterMsg (_msg): void {

}

warn (_key, _value): void {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 设置是否打开调试开关
export * from './setEnableDebug'

// 获取实时日志管理器对象
export * from './getRealtimeLogManager'

// 获取日志管理器对象
export * from './getLogManager'

/**
* 向调试面板中打印日志。console 是一个全局对象,可以直接访问。
*
* @canUse console
* @__class [debug, error, group, groupEnd, info, log, warn]
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Taro from '@tarojs/api'

import { shouldBeObject } from '../../utils'
import { MethodHandler } from '../../utils/handler'

/**
* 设置是否打开调试开关
*
* @canUse setEnableDebug
* @null_implementation
*/
export const setEnableDebug: typeof Taro.setEnableDebug = (options) => {
const name = 'setEnableDebug'

return new Promise((resolve, reject) => {
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${name}:fail ${isObject.msg}` }
console.error(res.errMsg)
return reject(res)
}
const { success, fail, complete } = options as Exclude<typeof options, undefined>
const handle = new MethodHandler<{
errMsg?: string
}>({ name, success, fail, complete })
try {
handle.success({
errMsg: 'ok'
}, { resolve, reject })
} catch (error) {
handle.fail({
errMsg: 'fail'
}, { resolve, reject })
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const env = {
* @__class [debug, error, group, groupEnd, info, log, warn]
*/

export * from './debug/index'
export * from './system'
export * from './update'
export * from './weapp/life-cycle'
18 changes: 0 additions & 18 deletions packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1478,30 +1478,12 @@
* @canNotUse updateWeChatApp
*/

/**
* 获取日志管理器对象
*
* @canNotUse getLogManager
*/

/**
* 程序测速上报
*
* @canNotUse getPerformance
*/

/**
* 获取实时日志管理器对象
*
* @canNotUse getRealtimeLogManager
*/

/**
* 设置是否打开调试开关
*
* @canNotUse setEnableDebug
*/

/**
* 插屏广告组件类
*
Expand Down

0 comments on commit 6c930de

Please sign in to comment.