Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 部分API不支持,修改为继承h5 #15925

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class Index extends React.Component {
password: 'lwh123456',
},
func: (apiIndex, data) => {
TestConsole.consoleTest('connectWifi')
Taro.connectWifi({
...data,
success: (res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,7 @@
"tcpNoDelay": true
}
},
"connectWifi": {
"object": {
"SSID": true,
"password": true,
"BSSID": true
}
},
"connectWifi": false,
"console": {
"debug": true,
"error": true,
Expand Down Expand Up @@ -1237,7 +1231,7 @@
}
},
"getWeRunData": false,
"getWifiList": true,
"getWifiList": false,
"getWindowInfo": {
"return": {
"pixelRatio": true,
Expand Down Expand Up @@ -1979,7 +1973,7 @@
"resultJSONSignature": true
}
},
"startWifi": true,
"startWifi": false,
"stopAccelerometer": true,
"stopBackgroundAudio": false,
"stopBeaconDiscovery": false,
Expand All @@ -1994,7 +1988,7 @@
"stopPullDownRefresh": true,
"stopRecord": false,
"stopVoice": false,
"stopWifi": true,
"stopWifi": false,
"subscribeService": false,
"subscribeVoIPVideoMembers": false,
"switchTab": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,6 @@
import Taro from '@tarojs/taro'
import { getParameterError, shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 连接 Wi-Fi
*
* @canUse connectWifi
* @__object [SSID, password, BSSID]
* @canNotUse connectWifi
*/
export const connectWifi: typeof Taro.connectWifi = (options) => {
const name = 'connectWifi'

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 { SSID, password, BSSID, success, fail, complete } = options as Exclude<typeof options, undefined>

const handle = new MethodHandler({ name, success, fail, complete })

// options.SSID must be string
if (typeof SSID !== 'string') {
return handle.fail(
{
errMsg: getParameterError({
para: 'SSID',
correct: 'string',
wrong: SSID,
}),
},
{ resolve, reject }
)
}

if (typeof password !== 'string') {
return handle.fail(
{
errMsg: getParameterError({
para: 'password',
correct: 'string',
wrong: password,
}),
},
{ resolve, reject }
)
}

if (typeof BSSID !== 'string') {
return handle.fail(
{
errMsg: getParameterError({
para: 'BSSID',
correct: 'string',
wrong: BSSID,
}),
},
{ resolve, reject }
)
}

nativeWifi.connectWifi({
SSID: SSID,
password: password,
BSSID: BSSID,
success: (res: any) => {
handle.success(res, { resolve, reject })
},
fail: (err: any) => {
handle.fail(err, { resolve, reject })
},
})
})
}
export { connectWifi } from '@tarojs/taro-h5'
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 请求获取 Wi-Fi 列表
*
* @canUse getWifiList
* @canNotUse getWifiList
*/
export const getWifiList: typeof Taro.getWifiList = (options) => {
const name = 'getWifiList'
const isValid = shouldBeObject(options).flag || typeof options === 'undefined'
if (!isValid) {
const res = { errMsg: `${name}:fail invalid params` }
console.error(res.errMsg)
return Promise.reject(res)
}
const { success, fail, complete } = options || {}
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
nativeWifi.getWifiList({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
fail: (err: any) => {
handle.fail(err, { resolve, reject })
},
})
})
}
export { getWifiList } from '@tarojs/taro-h5'
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 初始化 Wi-Fi 模块
*
* @canUse startWifi
* @canNotUse startWifi
*/
export const startWifi: typeof Taro.startWifi = (options) => {
const name = 'startWifi'
const isValid = shouldBeObject(options).flag || typeof options === 'undefined'
if (!isValid) {
const res = { errMsg: `${name}:fail invalid params` }
console.error(res.errMsg)
return Promise.reject(res)
}
const { success, fail, complete } = options || {}
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
nativeWifi.startWifi({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
fail: (err: any) => {
handle.fail(err, { resolve, reject })
},
})
})
}
export { startWifi } from '@tarojs/taro-h5'
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 关闭 Wi-Fi 模块
*
* @canUse stopWifi
* @canNotUse stopWifi
*/
export const stopWifi: typeof Taro.stopWifi = (options) => {
const name = 'stopWifi'
const isValid = shouldBeObject(options).flag || typeof options === 'undefined'
if (!isValid) {
const res = { errMsg: `${name}:fail invalid params` }
console.error(res.errMsg)
return Promise.reject(res)
}
const { success, fail, complete } = options || {}
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
nativeWifi.stopWifi({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
fail: (err: any) => {
handle.fail(err, { resolve, reject })
},
})
})
}
export { stopWifi } from '@tarojs/taro-h5'