Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
a95f99c1
U
uni-api
项目概览
DCloud
/
uni-api
通知
699
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看板
提交
a95f99c1
编写于
3月 28, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev_autotest' into dev
上级
8558a49b
98ad8603
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
569 addition
and
354 deletion
+569
-354
jest.config.js
jest.config.js
+11
-0
pages.json
pages.json
+8
-1
pages/index/index.vue
pages/index/index.vue
+30
-8
uni_modules/uni-wifi/utssdk/app-android/index.uts
uni_modules/uni-wifi/utssdk/app-android/index.uts
+345
-277
uni_modules/uni-wifi/utssdk/app-ios/index.uts
uni_modules/uni-wifi/utssdk/app-ios/index.uts
+15
-68
uni_modules/uni-wifi/utssdk/interface.uts
uni_modules/uni-wifi/utssdk/interface.uts
+125
-0
uni_modules/uni-wifi/utssdk/uni.autotest.js
uni_modules/uni-wifi/utssdk/uni.autotest.js
+35
-0
未找到文件。
jest.config.js
0 → 100644
浏览文件 @
a95f99c1
module
.
exports
=
{
testTimeout
:
10000
,
reporters
:
[
'
default
'
],
watchPathIgnorePatterns
:
[
'
/node_modules/
'
,
'
/dist/
'
,
'
/.git/
'
],
moduleFileExtensions
:
[
'
js
'
,
'
json
'
],
rootDir
:
__dirname
,
testMatch
:
[
"
<rootDir>/pages/**/*test.[jt]s?(x)
"
],
testPathIgnorePatterns
:
[
'
/node_modules/
'
]
}
pages.json
浏览文件 @
a95f99c1
...
...
@@ -5,7 +5,14 @@
"style"
:
{
"navigationBarTitleText"
:
"uni-app"
}
}
},
{
"path"
:
"pages/autotest/uni-wifi/uni-wifi"
,
"style"
:
{
"navigationBarTitleText"
:
"uni-wifi"
,
"enablePullDownRefresh"
:
false
}
}
],
"globalStyle"
:
{
"navigationBarTextStyle"
:
"black"
,
...
...
pages/index/index.vue
浏览文件 @
a95f99c1
...
...
@@ -14,6 +14,7 @@
<button
@
tap=
"testStartWifi"
>
初始化wifi模块
</button>
<button
@
tap=
"testGetWifiList"
>
获取当前wifi列表
</button>
<button
@
tap=
"testOffGetWifiList"
>
移除wifi列表监听
</button>
<button
@
tap=
"testGetConnnectWifi"
>
获取当前连接的wifi
</button>
<button
@
tap=
"testConnnectWifi"
>
链接wifi
</button>
<button
@
tap=
"testStopWifi"
>
关闭wifi模块
</button>
...
...
@@ -39,15 +40,26 @@
console
.
log
(
res
);
},
testConnnectWifi
(){
uni
.
connectWifi
({
maunal
:
false
,
SSID
:
"
Xiaomi_20D0
"
,
password
:
"
BBBB
"
,
complete
:(
res
)
=>
{
console
.
log
(
res
);
uni
.
startWifi
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
uni
.
connectWifi
({
maunal
:
false
,
SSID
:
"
Xiaomi_20D0
"
,
password
:
"
BBB111
"
,
complete
:(
res
)
=>
{
console
.
log
(
res
);
}
});
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
});
})
},
testGetConnnectWifi
(){
...
...
@@ -96,6 +108,9 @@
})
},
testStopWifi
()
{
uni
.
offWifiConnected
()
uni
.
offWifiConnectedWithPartialInfo
()
uni
.
stopWifi
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
...
...
@@ -119,6 +134,13 @@
})
},
testOffGetWifiList
(){
uni
.
offGetWifiList
()
},
testonMemoryWarning
()
{
uni
.
onMemoryWarning
(
this
.
onMemoryWarning
)
uni
.
showToast
({
...
...
uni_modules/uni-wifi/utssdk/app-android/index.uts
浏览文件 @
a95f99c1
此差异已折叠。
点击以展开。
uni_modules/uni-wifi/utssdk/app-ios/index.uts
浏览文件 @
a95f99c1
...
...
@@ -3,60 +3,7 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S
import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit';
/**
* Wifi 函数通用入参封装
*/
type WifiOption = {
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
};
/**
* Wifi 链接参数封装
*/
type WifiConnectOption = {
SSID?: string;
BSSID?: string;
password?: string;
maunal?: boolean;
partialInfo?: boolean; //ios不生效
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
}
/**
* 获取当前链接的wifi信息
*/
type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UniWifiResult) => void
fail?: (res: UniWifiResult) => void
complete?: (res: UniWifiResult) => void
}
/*
* 对外暴露的wifi信息
*/
type UniWifiInfo = {
SSID: string;
BSSID: string;
secure: boolean;
signalStrength: number;
frequency: number;
}
type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
type UniWifiCallback = () => void
import { WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OnOffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
/*
* 系统定位权限获取类
...
...
@@ -135,7 +82,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
let list = arr! as NSArray
let index = 0
while (index < list.count) {
let item = list[index]
let item = list[index]
let interfaceName = item as string
let dic = CNCopyCurrentNetworkInfo(interfaceName as CFString)
if (dic != null) {
...
...
@@ -157,7 +104,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
index++
}
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) {
if (wifiInfo.BSSID
!
.length > 0 && wifiInfo.SSID.length > 0) {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
errCode: 0,
...
...
@@ -204,7 +151,7 @@ class UniWiFiModuleGloabInfo {
/*
* 初始化wifi模块
*/
export
function startWifi
(option: WifiOption) {
export
const startWifi: StartWifi = function
(option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res: UniWifiResult = {
errSubject: "uni-startWifi",
...
...
@@ -219,7 +166,7 @@ export function startWifi(option: WifiOption) {
/*
* 停止wifi模块
*/
export
function stopWifi
(option: WifiOption) {
export
const stopWifi: StopWifi = function
(option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = []
let res: UniWifiResult = {
...
...
@@ -235,7 +182,7 @@ export function stopWifi(option: WifiOption) {
/*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/
export
function getWifiList
(option: WifiOption) {
export
const getWifiList: GetWifiList = function
(option: WifiOption) {
let res: UniWifiResult = {
errSubject: "uni-getWifiList",
errCode: 12001,
...
...
@@ -249,14 +196,14 @@ export function getWifiList(option: WifiOption) {
/* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法
*/
export
function onGetWifiList
(callback: UniWifiCallback) {
export
const onGetWifiList: OnGetWifiList = function
(callback: UniWifiCallback) {
}
/*
* 注销获取wifi列表的回调
*/
export
function offGetWifiList
(callback: UniWifiCallback) {
export
const offGetWifiList: OffGetWifiList = function
(callback: UniWifiCallback) {
}
...
...
@@ -264,7 +211,7 @@ export function offGetWifiList(callback: UniWifiCallback) {
/*
* 获取当前连接的wifi信息
*/
export
function getConnectedWifi
(option: GetConnectedWifiOptions) {
export
const getConnectedWifi: GetConnectedWifi = function
(option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
...
...
@@ -299,7 +246,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
/*
* 连接wifi
*/
export
function connectWifi
(option: WifiConnectOption) {
export
const connectWifi: ConnectWifi = function
(option: WifiConnectOption) {
let res: UniWifiResult = {
errSubject: "uni-connectWifi",
errCode: 12001,
...
...
@@ -314,35 +261,35 @@ export function connectWifi(option: WifiConnectOption) {
/*
* 连上wifi事件的监听函数
*/
export
function onWifiConnected
(callback: UniWifiCallback) {
export
const onWifiConnected: OnWifiConnected = function
(callback: UniWifiCallback) {
}
/*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/
export
function onWifiConnectedWithPartialInfo
(callback: UniWifiCallback) {
export
const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function
(callback: UniWifiCallback) {
}
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export
function offWifiConnected
(callback: UniWifiCallback | null) {
export
const offWifiConnected: OffWifiConnected = function
(callback: UniWifiCallback | null) {
}
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export
function onOffWifiConnectedWithPartialInfo
(callback: UniWifiCallback | null) {
export
const onOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInfo = function
(callback: UniWifiCallback | null) {
}
/*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/
export
function setWifiList
(option: WifiOption) {
export
const setWifiList: SetWifiList = function
(option: WifiOption) {
let res: UniWifiResult = {
errSubject: "uni-setWifiList",
errCode: 12001,
...
...
uni_modules/uni-wifi/utssdk/interface.uts
0 → 100644
浏览文件 @
a95f99c1
/**
* Wifi 函数通用入参封装
*/
export type WifiOption = {
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
};
/**
* Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID?: string;
BSSID?: string;
password?: string;
maunal?: boolean;
partialInfo?: boolean; //ios不生效
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
}
/**
* 获取当前链接的wifi信息
*/
export type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UniWifiResult) => void
fail?: (res: UniWifiResult) => void
complete?: (res: UniWifiResult) => void
}
/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
SSID: string;
BSSID?: string;
secure?: boolean;
signalStrength?: number;
frequency?: number;
}
export type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
export type UniWifiCallback = () => void
export type StartWifi = (option: WifiOption) => void
export type StopWifi = (option: WifiOption) => void
export type GetWifiList = (option: WifiOption) => void
export type OnGetWifiList = (callback: UniWifiCallback) => void
export type OffGetWifiList = (callback: UniWifiCallback) => void
export type GetConnectedWifi = (option: GetConnectedWifiOptions) => void
export type ConnectWifi = (option: WifiConnectOption) => void
export type OnWifiConnected = (callback: UniWifiCallback) => void
export type OnWifiConnectedWithPartialInfo = (callback: UniWifiCallback) => void
export type OffWifiConnected = (callback: UniWifiCallback | null) => void
export type OnOffWifiConnectedWithPartialInfo = (callback: UniWifiCallback | null) => void
export type SetWifiList = (option: WifiOption) => void
interface Uni {
startWifi : StartWifi,
stopWifi : StopWifi,
/**
* @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: ConnectWifi,
/**
* @autotest {
generated: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi'
}
]
}
*/
getWifiList : GetWifiList,
onGetWifiList : OnGetWifiList,
offGetWifiList : OffGetWifiList,
getConnectedWifi : GetConnectedWifi,
onWifiConnected : OnWifiConnected,
onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo,
offWifiConnected : OffWifiConnected,
onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo,
setWifiList : SetWifiList,
}
uni_modules/uni-wifi/utssdk/uni.autotest.js
0 → 100644
浏览文件 @
a95f99c1
function
startWifi
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
startWifi
({
success
:
()
=>
{
console
.
log
(
'
startWifi success
'
);
resolve
()
},
fail
:
()
=>
{
console
.
log
(
'
startWifi fail
'
);
reject
()
}
})
})
}
function
stopWifi
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
stopWifi
({
success
:
()
=>
{
console
.
log
(
'
stopWifi success
'
);
resolve
()
},
fail
:
()
=>
{
console
.
log
(
'
stopWifi success
'
);
fail
()
}
})
})
}
module
.
exports
=
{
startWifi
,
stopWifi
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录