feat:增加配网接口和demo模块
This commit is contained in:
parent
690849af88
commit
d2071f2e88
@ -5,7 +5,8 @@
|
||||
"pages/lockDetail/lockDetail",
|
||||
"pages/card/card",
|
||||
"pages/fingerprint/fingerprint",
|
||||
"pages/password/password"
|
||||
"pages/password/password",
|
||||
"pages/configNetwork/configNetwork"
|
||||
],
|
||||
"window": {
|
||||
"backgroundTextStyle": "light",
|
||||
|
||||
131
miniprogram/miniprogram/pages/configNetwork/configNetwork.js
Normal file
131
miniprogram/miniprogram/pages/configNetwork/configNetwork.js
Normal file
@ -0,0 +1,131 @@
|
||||
const {
|
||||
Result,
|
||||
startSearchWiFi,
|
||||
selectLock,
|
||||
starEventOn,
|
||||
connectWiFi,
|
||||
starEventOff,
|
||||
} = requirePlugin('starCloud')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
lock: null, // 当前选中的锁
|
||||
accountInfo: {},
|
||||
loading: false,
|
||||
wifiList: [],
|
||||
showConnectDialog: false,
|
||||
connectSsid: '',
|
||||
connectPassword: '',
|
||||
},
|
||||
onLoad() {
|
||||
starEventOn('searchWiFiResult', async (data) => {
|
||||
if (data.code === 0) {
|
||||
console.log("收到wifi搜索列表的事件回调", data)
|
||||
this.setData({wifiList: data.wifiList || [], loading: false});
|
||||
}
|
||||
this.setData({loading: false});
|
||||
wx.hideLoading();
|
||||
});
|
||||
|
||||
|
||||
const app = getApp();
|
||||
|
||||
// 尝试获取全局数据
|
||||
const lock = app.globalData.lock;
|
||||
const accountInfo = app.globalData.accountInfo;
|
||||
|
||||
console.log('lockDetail onLoad:', {lock, accountInfo});
|
||||
|
||||
if (!lock || !accountInfo) {
|
||||
wx.showToast({
|
||||
title: '获取设备信息失败',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置数据到页面
|
||||
this.setData({
|
||||
lock,
|
||||
accountInfo
|
||||
});
|
||||
this.searchWifi();
|
||||
},
|
||||
async searchWifi() {
|
||||
console.log('启动搜索WiFi...');
|
||||
this.setData({loading: true});
|
||||
wx.showLoading({title: '正在搜索WiFi...', mask: true});
|
||||
try {
|
||||
await selectLock({
|
||||
accountInfo: this.data.accountInfo,
|
||||
lockId: this.data.lock.lockId
|
||||
});
|
||||
const result = await startSearchWiFi({
|
||||
disconnect: false
|
||||
});
|
||||
console.log('searchWifi result', result);
|
||||
if (result.code === 0) {
|
||||
// 已经开始搜索,loading状态保持,等待事件回调结束loading
|
||||
} else {
|
||||
this.setData({loading: false});
|
||||
wx.hideLoading();
|
||||
wx.showModal({
|
||||
title: '搜索失败',
|
||||
content: result.message || '启动WiFi搜索失败',
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.setData({loading: false});
|
||||
wx.hideLoading();
|
||||
wx.showModal({
|
||||
title: '异常',
|
||||
content: error.message || 'WiFi搜索异常',
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
},
|
||||
onWifiItemTap(e) {
|
||||
const ssid = e.currentTarget.dataset.ssid;
|
||||
this.setData({
|
||||
showConnectDialog: true,
|
||||
connectSsid: ssid,
|
||||
connectPassword: ''
|
||||
});
|
||||
},
|
||||
onInputSsid(e) {
|
||||
this.setData({connectSsid: e.detail.value});
|
||||
},
|
||||
onInputPassword(e) {
|
||||
this.setData({connectPassword: e.detail.value});
|
||||
},
|
||||
onDialogCancel() {
|
||||
this.setData({showConnectDialog: false});
|
||||
},
|
||||
async onDialogConfirm() {
|
||||
const ssid = this.data.connectSsid;
|
||||
const password = this.data.connectPassword;
|
||||
this.setData({loading: true});
|
||||
wx.showLoading({title: '正在连接WiFi...', mask: true});
|
||||
await selectLock({
|
||||
accountInfo: this.data.accountInfo,
|
||||
lockId: this.data.lock.lockId
|
||||
});
|
||||
// 这里可以进行连接WiFi的逻辑
|
||||
const result = await connectWiFi({
|
||||
ssid: ssid,
|
||||
password: password,
|
||||
});
|
||||
console.log('connectWiFi result', result);
|
||||
this.setData({loading: false, showConnectDialog: false});
|
||||
wx.hideLoading();
|
||||
},
|
||||
onUnload() {
|
||||
if (typeof starEventOff === 'function') {
|
||||
starEventOff('searchWiFiResult');
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "配置网络"
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
<view class="container">
|
||||
<view class="header">配置网络</view>
|
||||
<view class="content">
|
||||
<view class="tip-text">
|
||||
<text>• 确保搜索WiFi时锁板处于亮屏状态</text>
|
||||
<text>\n</text>
|
||||
<text>• 确保连接的WiFi是2.4GHz的WiFi</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="wifi-list" wx:if="{{wifiList.length}}">
|
||||
<view class="wifi-item" wx:for="{{wifiList}}" wx:key="ssid" data-ssid="{{item.ssid}}" bindtap="onWifiItemTap">
|
||||
<text class="ssid">{{item.ssid}}</text>
|
||||
<text class="rssi">信号: {{item.rssi}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{showConnectDialog}}" class="dialog-mask">
|
||||
<view class="dialog-box">
|
||||
<view class="dialog-title">连接WiFi</view>
|
||||
<view class="dialog-content">
|
||||
<input class="dialog-input" placeholder="WiFi昵称" value="{{connectSsid}}" disabled />
|
||||
<input class="dialog-input" placeholder="WiFi密码" password value="{{connectPassword}}" bindinput="onInputPassword" />
|
||||
</view>
|
||||
<view class="dialog-actions">
|
||||
<button class="dialog-btn cancel" bindtap="onDialogCancel">取消</button>
|
||||
<button class="dialog-btn confirm" bindtap="onDialogConfirm">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
111
miniprogram/miniprogram/pages/configNetwork/configNetwork.wxss
Normal file
111
miniprogram/miniprogram/pages/configNetwork/configNetwork.wxss
Normal file
@ -0,0 +1,111 @@
|
||||
.container {
|
||||
padding: 32rpx;
|
||||
min-height: 100vh;
|
||||
background: #f7f7f7;
|
||||
}
|
||||
.header {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 32rpx;
|
||||
color: #007AFF;
|
||||
}
|
||||
.content {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
.wifi-list {
|
||||
margin-top: 32rpx;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
}
|
||||
.wifi-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
.wifi-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.ssid {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
.rssi {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
.loading-bar {
|
||||
margin: 24rpx 0;
|
||||
padding: 20rpx;
|
||||
background: #fffbe6;
|
||||
color: #faad14;
|
||||
border-radius: 8rpx;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
.dialog-mask {
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0,0,0,0.4);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.dialog-box {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
width: 80vw;
|
||||
max-width: 600rpx;
|
||||
padding: 40rpx 32rpx 24rpx 32rpx;
|
||||
box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.15);
|
||||
}
|
||||
.dialog-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 32rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.dialog-content {
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
.dialog-input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
border: 2rpx solid #eee;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 24rpx;
|
||||
padding: 0 20rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 24rpx;
|
||||
}
|
||||
.dialog-btn {
|
||||
flex: 1;
|
||||
height: 72rpx;
|
||||
border-radius: 36rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
.dialog-btn.cancel {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
.dialog-btn.confirm {
|
||||
background: linear-gradient(135deg, #007AFF, #40a9ff);
|
||||
color: #fff;
|
||||
}
|
||||
.tip-text {
|
||||
color: #faad14;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.8;
|
||||
margin-bottom: 12rpx;
|
||||
white-space: pre-line;
|
||||
}
|
||||
@ -401,5 +401,12 @@ Page({
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 配置网络
|
||||
configNetwork() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/configNetwork/configNetwork'
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -67,6 +67,11 @@
|
||||
<text class="feature-name">功能设置</text>
|
||||
<text class="feature-desc">查看所有配置</text>
|
||||
</button>
|
||||
<button class="feature-btn" bind:tap="configNetwork">
|
||||
<view class="feature-icon network-icon"></view>
|
||||
<text class="feature-name">配置网络</text>
|
||||
<text class="feature-desc">WiFi网络设置</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<button class="main-btn danger" bind:tap="deleteLock">删除设备</button>
|
||||
|
||||
@ -278,3 +278,7 @@
|
||||
transform: scale(0.98);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.network-icon {
|
||||
background-image: url("data:image/svg+xml,%3Csvg t='1710000000000' class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M512 832a64 64 0 1 0 0-128 64 64 0 0 0 0 128zm0-704C300.3 128 128 300.3 128 512h64c0-176.7 143.3-320 320-320s320 143.3 320 320h64c0-211.7-172.3-384-384-384zm0 192c-123.7 0-224 100.3-224 224h64c0-88.2 71.8-160 160-160s160 71.8 160 160h64c0-123.7-100.3-224-224-224z' fill='%23007AFF'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@ -24,7 +24,7 @@
|
||||
"@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
|
||||
"@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
|
||||
"pinia": "^2.2.8",
|
||||
"star-cloud-uni": "^1.0.14",
|
||||
"star-cloud-uni": "^1.0.16",
|
||||
"vue": "^3.5.13",
|
||||
"vue-i18n": "^9.1.9"
|
||||
},
|
||||
@ -10046,9 +10046,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/star-cloud-uni": {
|
||||
"version": "1.0.14",
|
||||
"resolved": "https://registry.npmjs.org/star-cloud-uni/-/star-cloud-uni-1.0.14.tgz",
|
||||
"integrity": "sha512-8KnuxvqiyvDcodaue0t0ofYuMNYqXv2HLw5P1HglEWZqiQyMCMwB8dcx9UxV4X1mdRlgj0/JbxdT5vE/eRT4Og==",
|
||||
"version": "1.0.16",
|
||||
"resolved": "https://registry.npmjs.org/star-cloud-uni/-/star-cloud-uni-1.0.16.tgz",
|
||||
"integrity": "sha512-Q9KF7C41WD5KH3EePgkFTIxaLnbc/uL4N0iu6qzmZ+6N8bJIHQaJAcnJPho+TQVsnyv9fkTOR4bF0oOqqg/dGg==",
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"crc": "^4.3.2",
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
"@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
|
||||
"@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
|
||||
"pinia": "^2.2.8",
|
||||
"star-cloud-uni": "^1.0.14",
|
||||
"star-cloud-uni": "^1.0.16",
|
||||
"vue": "^3.5.13",
|
||||
"vue-i18n": "^9.1.9"
|
||||
},
|
||||
|
||||
24
src/index.js
24
src/index.js
@ -24,7 +24,10 @@ import {
|
||||
remoteUnLock,
|
||||
readSupportFunctionsSetting,
|
||||
getLockList,
|
||||
startSearchWiFi,
|
||||
connectWiFi
|
||||
} from 'star-cloud-uni'
|
||||
|
||||
// 用于存储事件监听器的Map
|
||||
const eventListeners = new Map();
|
||||
module.exports = {
|
||||
@ -260,7 +263,7 @@ module.exports = {
|
||||
|
||||
// 存储监听器
|
||||
eventListeners.set(eventName, listener);
|
||||
|
||||
|
||||
// 注册事件监听
|
||||
uni.$on(eventName, listener);
|
||||
},
|
||||
@ -317,7 +320,7 @@ module.exports = {
|
||||
* @param params
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
async remoteUnLock(params){
|
||||
async remoteUnLock(params) {
|
||||
return await remoteUnLock(params)
|
||||
},
|
||||
|
||||
@ -326,7 +329,22 @@ module.exports = {
|
||||
* @param params
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
async getLockList(params){
|
||||
async getLockList(params) {
|
||||
return await getLockList(params);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 启动搜索wifi
|
||||
* @param params
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
async startSearchWiFi(params) {
|
||||
return await startSearchWiFi(params);
|
||||
},
|
||||
|
||||
|
||||
async connectWiFi(params){
|
||||
return await connectWiFi(params);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user