Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
4ce655e2
U
uni-api
项目概览
DCloud
/
uni-api
通知
697
Star
23
Fork
13
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4ce655e2
编写于
11月 10, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wifi 适配 uni error.
上级
dcfa32bb
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
647 addition
and
219 deletion
+647
-219
uni_modules/uni-wifi/utssdk/app-android/index.uts
uni_modules/uni-wifi/utssdk/app-android/index.uts
+159
-196
uni_modules/uni-wifi/utssdk/index.d.ts
uni_modules/uni-wifi/utssdk/index.d.ts
+377
-0
uni_modules/uni-wifi/utssdk/interface.uts
uni_modules/uni-wifi/utssdk/interface.uts
+52
-23
uni_modules/uni-wifi/utssdk/unierror.uts
uni_modules/uni-wifi/utssdk/unierror.uts
+59
-0
未找到文件。
uni_modules/uni-wifi/utssdk/app-android/index.uts
浏览文件 @
4ce655e2
此差异已折叠。
点击以展开。
uni_modules/uni-wifi/utssdk/index.d.ts
0 → 100644
浏览文件 @
4ce655e2
declare
namespace
UniNamespace
{
type
UniWifiComplete
=
any
type
WifiSuccessCallback
=
(
res
:
UniWifiResult
)
=>
void
type
WifiFailCallback
=
(
err
:
UniWifiFail
)
=>
void
type
WifiCompleteCallback
=
(
res
:
UniWifiComplete
)
=>
void
type
UniWifiCallback
=
()
=>
void
type
WifiErrorCode
=
1300002
interface
UniWifiInfo
{
SSID
:
string
;
BSSID
?:
string
;
secure
?:
boolean
;
signalStrength
?:
number
;
frequency
?:
number
;
}
interface
UniWifiResult
{
errCode
:
number
,
errSubject
:
string
,
errMsg
:
string
,
wifi
:
UniWifiInfo
|
null
}
interface
UniWifiFail
{
errCode
:
WifiErrorCode
}
interface
WifiConnectOption
{
SSID
:
string
|
null
;
BSSID
:
string
|
null
;
password
:
string
|
null
;
maunal
:
boolean
|
null
;
partialInfo
:
boolean
|
null
;
//ios不生效
success
?:
WifiSuccessCallback
|
null
;
fail
?:
WifiFailCallback
|
null
;
complete
?:
WifiCompleteCallback
|
null
;
}
interface
GetConnectedWifiOptions
{
partialInfo
:
boolean
|
null
;
success
?:
WifiSuccessCallback
|
null
;
fail
?:
WifiFailCallback
|
null
;
complete
?:
WifiCompleteCallback
|
null
;
}
interface
WifiOption
{
success
?:
WifiSuccessCallback
|
null
,
fail
?:
WifiFailCallback
|
null
,
complete
?:
InstallApkCompleteCallback
|
null
}
}
declare
interface
Uni
{
/**
* 初始化Wi-Fi模块
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { after: 'stopWifi' }
*/
startWifi
(
option
:
UniNamespace
.
WifiOption
):
void
,
/**
* 关闭 Wi-Fi 模块
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi' }
*/
stopWifi
(
option
:
UniNamespace
.
WifiOption
)
:
void
,
/**
* @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": ">=4.4 && <10.0",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest {
generated: false,
pollution: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi',
input: [{
maunal:false,
SSID:"Xiaomi_20D0",
password:"streamApp!2016",
}],
output:{
callbackType: 'success',
value: { errCode: 12013 ,errMsg: "connectWifi:wifi config may be expired",errSubject: "uni-connectWifi"}
}
}
]
}
*/
connectWifi
(
option
:
UniNamespace
.
WifiConnectOption
)
:
void
,
/**
* 请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/
getWifiList
(
option
:
UniNamespace
.
WifiOption
)
:
void
,
/**
* 监听获取到 Wi-Fi 列表数据事件。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
* @autotest {
generated: false,
pollution: false,
expectCallback: true,
before: 'startWifi',
after: 'onGetWifiListAfter',
cases: [
{
output: {
value: 0,
returnKey: '.wifiList.length',
jestExpectSyntax: 'toBeGreaterThan'
},
}
]
}
*/
onGetWifiList
(
callback
:
UniNamespace
.
UniWifiCallback
)
:
void
,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offGetWifiList
(
callback
:
UniNamespace
.
UniWifiCallback
)
:
void
,
/**
* 获取已连接的 Wi-Fi 信息
*
* @param {GetConnectedWifiOptions} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { before: 'startWifi', after: 'stopWifi' }
*/
getConnectedWifi
(
option
:
UniNamespace
.
GetConnectedWifiOptions
)
:
void
,
/**
* 监听连接上 Wi-Fi 的事件
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnected
(
callback
:
UniNamespace
.
UniWifiCallback
)
:
void
,
/**
* 监听连接上 Wi-Fi 的事件。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnectedWithPartialInfo
(
callback
:
UniNamespace
.
UniWifiCallback
)
:
void
,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offWifiConnected
(
callback
?:
UniNamespace
.
UniWifiCallback
)
:
void
,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onOffWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onOffWifiConnectedWithPartialInfo
(
callback
?:
UniNamespace
.
UniWifiCallback
)
:
void
,
/**
* SetWifiList 暂未实现
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
*/
setWifiList
(
option
:
UniNamespace
.
WifiOption
)
:
void
,
}
uni_modules/uni-wifi/utssdk/interface.uts
浏览文件 @
4ce655e2
...
...
@@ -8,7 +8,7 @@ export type WifiOption = {
};
/**
* Wifi 链接参数封装
* Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID ?: string;
...
...
@@ -31,7 +31,7 @@ export type GetConnectedWifiOptions = {
complete ?: (res : any) => void
}
/*
/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
...
...
@@ -42,6 +42,10 @@ export type UniWifiInfo = {
frequency ?: number;
}
export type UniWifiInfoWithPartialInfo = {
SSID : string;
}
export type UniWifiResult = {
errCode : number,
...
...
@@ -52,6 +56,12 @@ export type UniWifiResult = {
export type UniWifiCallback = () => void
export type UniGetWifiListCallback = (wifiInfo:UTSJSONObject) => void
export type UniWifiResultCallback = (wifiInfo:UniWifiResult) => void
export type UniWifiResultCallbackWithPartialInfo = (wifiInfo:UniWifiInfoWithPartialInfo) => void
export type StartWifi = (option : WifiOption) => void
...
...
@@ -77,11 +87,30 @@ export type OnOffWifiConnectedWithPartialInfo = (callback : UniWifiCallback | nu
export type SetWifiList = (option : WifiOption) => void
/**
* 错误码
* - 12000 尚未初始化
* - 12001 当前系统不支持相关能力
* - 12002 密码错误
* - 12005 Android 特有,未打开 Wi-Fi 开关
* - 12007 用户拒绝授权链接 Wi-Fi
* - 12010 系统其他错误
* - 12013 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
*/
export type WifiErrorCode = 12000 |12001 | 12002 | 12005 | 12007 | 12010 | 12013;
export interface WifiFail extends IUniError{
errCode: WifiErrorCode
};
interface Uni {
/**
* 初始化Wi-Fi模块
*
* @param {WifiOption} option
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
* @uniPlatform {
* "app": {
...
...
@@ -104,8 +133,8 @@ interface Uni {
startWifi(option : WifiOption): void,
/**
* 关闭 Wi-Fi 模块
*
* @param {WifiOption} option
*
* @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
* @uniPlatform {
* "app": {
...
...
@@ -127,7 +156,7 @@ interface Uni {
*/
stopWifi(option : WifiOption) : void,
/**
* @param {WifiConnectOption} option
* @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform {
* "app": {
...
...
@@ -191,8 +220,8 @@ interface Uni {
getWifiList(option : WifiOption) : void,
/**
* 监听获取到 Wi-Fi 列表数据事件。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
* @uniPlatform {
* "app": {
...
...
@@ -231,8 +260,8 @@ interface Uni {
onGetWifiList(callback : UniWifiCallback) : void,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
* @uniPlatform {
* "app": {
...
...
@@ -255,8 +284,8 @@ interface Uni {
offGetWifiList(callback : UniWifiCallback) : void,
/**
* 获取已连接的 Wi-Fi 信息
*
* @param {GetConnectedWifiOptions} option
*
* @param {GetConnectedWifiOptions} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
* @uniPlatform {
* "app": {
...
...
@@ -279,8 +308,8 @@ interface Uni {
getConnectedWifi(option : GetConnectedWifiOptions) : void,
/**
* 监听连接上 Wi-Fi 的事件
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
* @uniPlatform {
* "app": {
...
...
@@ -303,8 +332,8 @@ interface Uni {
onWifiConnected(callback : UniWifiCallback) : void,
/**
* 监听连接上 Wi-Fi 的事件。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
...
...
@@ -327,8 +356,8 @@ interface Uni {
onWifiConnectedWithPartialInfo(callback : UniWifiCallback) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
* @uniPlatform {
* "app": {
...
...
@@ -351,8 +380,8 @@ interface Uni {
offWifiConnected(callback : UniWifiCallback | null) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onOffWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
...
...
@@ -375,7 +404,7 @@ interface Uni {
onOffWifiConnectedWithPartialInfo(callback : UniWifiCallback | null) : void,
/**
* SetWifiList 暂未实现
*
*
* @uniPlatform {
* "app": {
* "android": {
...
...
@@ -392,4 +421,4 @@ interface Uni {
* }
*/
setWifiList(option : WifiOption) : void,
}
\ No newline at end of file
}
uni_modules/uni-wifi/utssdk/unierror.uts
0 → 100644
浏览文件 @
4ce655e2
import { WifiErrorCode, WifiFail} from "./interface.uts"
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-wifi';
/**
* 错误码
* @UniError
*/
export const WifiUniErrors : Map<WifiErrorCode, string> = new Map([
/**
* 未先调用 startWifi 接口
*/
[12000, 'not init.'],
/**
* 当前系统不支持相关能力
*/
[12001, 'system not support'],
/**
* 密码错误
*/
[12002, 'password error Wi-Fi'],
/**
* Android 特有,未打开 Wi-Fi 开关
*/
[12005, 'wifi not turned on'],
/**
* 用户拒绝授权链接 Wi-Fi
*/
[12007, 'user denied'],
/**
* 系统其他错误,需要在 errmsg 打印具体的错误原因
*/
[12010, 'unknown error'],
/**
* 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
*/
[12013, 'wifi config may be expired'],
]);
export function getErrcode(errCode : number) : WifiErrorCode {
const res = WifiUniErrors[errCode];
return res == null ? 12000 : errCode;
}
export class WifiFailImpl extends UniError implements WifiFail {
constructor(errCode : WifiErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = WifiUniErrors[errCode] ?? "";
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录