|
|
@@ -1,55 +1,111 @@
|
|
|
<template>
|
|
|
- <scroll-view class="main-container" scroll-y="true"
|
|
|
- :refresher-enabled="false">
|
|
|
- <view v-for="(item, index) in deviceListDataShow" :key="item.id" class="list-item" hover-class="list-item-hover"
|
|
|
- hover-start-time="0" hover-stay-time="100" @click="listViewTap(item.id)">
|
|
|
- <image v-if="item.manufacturer==='eciot'" src="/static/img/ecble.png" class="list-item-img"></image>
|
|
|
- <image v-else src="/static/img/ble.png" class="list-item-img"></image>
|
|
|
- <text class="list-item-name">{{item.name}}</text>
|
|
|
- <image v-if="item.rssi >= -41" src="/static/img/s5.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
- <image v-else-if="item.rssi >= -55" src="/static/img/s4.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
- <image v-else-if="item.rssi >= -65" src="/static/img/s3.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
- <image v-else-if="item.rssi >= -75" src="/static/img/s2.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
- <image v-else="item.rssi < -75" src="/static/img/s1.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
- <text class="list-item-rssi">{{item.rssi}}</text>
|
|
|
- <view class="list-item-line"></view>
|
|
|
- </view>
|
|
|
- <u-modal :show="showPwd" :confirmText="i18('确认')" :cancelText="i18('取消')" @confirm="inputPwd" @cancel="cancel" :showCancelButton="true" :title="$t('buletooth.pwdinput')" >
|
|
|
- <view class="slot-content">
|
|
|
- <view>
|
|
|
+ <view style="height: 100vh">
|
|
|
+ <view v-if="!connected">
|
|
|
+ <scroll-view class="main-container" scroll-y="true"
|
|
|
+ :refresher-enabled="false">
|
|
|
+ <view v-for="(item, index) in deviceListDataShow" :key="item.id" class="list-item" hover-class="list-item-hover"
|
|
|
+ hover-start-time="0" hover-stay-time="100" @click="listViewTap(item.id)">
|
|
|
+ <image v-if="item.manufacturer==='eciot'" src="/static/img/ecble.png" class="list-item-img"></image>
|
|
|
+ <image v-else src="/static/img/ble.png" class="list-item-img"></image>
|
|
|
+ <text class="list-item-name">{{item.name}}</text>
|
|
|
+ <image v-if="item.rssi >= -41" src="/static/img/s5.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
+ <image v-else-if="item.rssi >= -55" src="/static/img/s4.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
+ <image v-else-if="item.rssi >= -65" src="/static/img/s3.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
+ <image v-else-if="item.rssi >= -75" src="/static/img/s2.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
+ <image v-else="item.rssi < -75" src="/static/img/s1.png" mode="aspectFit" class="list-item-rssi-img"></image>
|
|
|
+ <text class="list-item-rssi">{{item.rssi}}</text>
|
|
|
+ <view class="list-item-line"></view>
|
|
|
+ </view>
|
|
|
+ <u-popup :show="showSendData" >
|
|
|
+ <view class="slot-content">
|
|
|
+ <view>
|
|
|
+ <u--input
|
|
|
+ :placeholder="i18('请输入值')"
|
|
|
+ border="surround"
|
|
|
+ v-model="sendData"
|
|
|
+ ></u--input>
|
|
|
+ </view>
|
|
|
+ <view style="margin:10px;text-decoration: underline;margin-bottom: 0px" @click="sendLanyaData">
|
|
|
+ <u-button>发送</u-button>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </u-popup>
|
|
|
+ <view v-if="deviceListDataShow.length==0" class="notice"> - {{ $t('buletooth.nodevice') }} -</view>
|
|
|
+ <view class="gap"></view>
|
|
|
+ </scroll-view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view v-if="connected">
|
|
|
+ <view class="text-area">
|
|
|
+ <u--form style="width: 100%;"
|
|
|
+ labelPosition="left"
|
|
|
+ ref="uForm"
|
|
|
+ >
|
|
|
+ <u-form-item
|
|
|
+ label="WIFI名称:"
|
|
|
+ borderBottom
|
|
|
+ labelWidth="auto"
|
|
|
+ @click="openChooseWifi"
|
|
|
+ ref="item1"
|
|
|
+ >
|
|
|
<u--input
|
|
|
- type="number"
|
|
|
- :placeholder="$t('buletooth.pwdtip')"
|
|
|
- border="surround"
|
|
|
- v-model="pwd"
|
|
|
+ v-model="SSID"
|
|
|
+ disabled
|
|
|
+ disabledColor="#ffffff"
|
|
|
+ placeholder="请选择wifi:"
|
|
|
+ border="none"
|
|
|
></u--input>
|
|
|
- </view>
|
|
|
+ <u-icon
|
|
|
+ slot="right"
|
|
|
+ name="arrow-right"
|
|
|
+ ></u-icon>
|
|
|
+ </u-form-item>
|
|
|
+ <u-form-item
|
|
|
+ label="密码:"
|
|
|
+ borderBottom
|
|
|
+ ref="item1"
|
|
|
+ >
|
|
|
+ <u--input
|
|
|
+ v-model="password"
|
|
|
+ border="none"
|
|
|
+ ></u--input>
|
|
|
+ </u-form-item>
|
|
|
+
|
|
|
+ <u-form-item
|
|
|
+ label="设备编号:"
|
|
|
+ borderBottom
|
|
|
+ ref="item1"
|
|
|
+ labelWidth="auto"
|
|
|
+ >
|
|
|
+ <u--input
|
|
|
+ v-model="deviceno"
|
|
|
+ border="none"
|
|
|
+ ></u--input>
|
|
|
+ </u-form-item>
|
|
|
|
|
|
- <view style="margin:10px;text-decoration: underline;margin-bottom: 0px" @click="forgetPwd">
|
|
|
- {{i18('忘记密码')}}?
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </u-modal>
|
|
|
|
|
|
- <u-popup :show="showSendData" >
|
|
|
- <view class="slot-content">
|
|
|
- <view>
|
|
|
+ <u-form-item
|
|
|
+ label="二维码ID:"
|
|
|
+ borderBottom
|
|
|
+ ref="item1"
|
|
|
+ labelWidth="auto"
|
|
|
+ >
|
|
|
<u--input
|
|
|
- :placeholder="i18('请输入值')"
|
|
|
- border="surround"
|
|
|
- v-model="sendData"
|
|
|
+ v-model="qrcodeid"
|
|
|
+ border="none"
|
|
|
></u--input>
|
|
|
- </view>
|
|
|
- <view style="margin:10px;text-decoration: underline;margin-bottom: 0px" @click="sendLanyaData">
|
|
|
- <u-button>发送</u-button>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </u-popup>
|
|
|
- <view v-if="deviceListDataShow.length==0" class="notice"> - {{ $t('buletooth.nodevice') }} -</view>
|
|
|
- <view class="gap"></view>
|
|
|
- </scroll-view>
|
|
|
+ </u-form-item>
|
|
|
|
|
|
+ </u--form>
|
|
|
|
|
|
+ </view>
|
|
|
+ <view style="margin:10px">
|
|
|
+ <u-button text="开始配网" @click="doConnect" size="small" type="primary"></u-button>
|
|
|
+
|
|
|
+ </view>
|
|
|
+ <u-picker @cancel="showWiftList=false" @confirm="chooseWifi" :show="showWiftList" :columns="wifiList"></u-picker>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
@@ -63,12 +119,9 @@ const ecUI = require('@/utils/ecUI.js')
|
|
|
const ecBLE = require('@/utils/ecBLE/ecBLE.js')
|
|
|
// #endif
|
|
|
import i18 from '@/utils/i18.js'
|
|
|
-import UButton from "../../../uni_modules/uview-ui/components/u-button/u-button";
|
|
|
-import UPopup from "../../../uni_modules/uview-ui/components/u-popup/u-popup";
|
|
|
let ctx
|
|
|
let deviceListData = []
|
|
|
export default {
|
|
|
- components: {UPopup, UButton},
|
|
|
data() {
|
|
|
return {
|
|
|
showPwd:false,
|
|
|
@@ -85,11 +138,20 @@ import UPopup from "../../../uni_modules/uview-ui/components/u-popup/u-popup";
|
|
|
commonCode:"",
|
|
|
showSendData:false,
|
|
|
sendData:"",
|
|
|
+ qrcodeid:"",
|
|
|
+ deviceno:"",
|
|
|
+ SSID:"",
|
|
|
+ password:"",
|
|
|
+ showWiftList:false,
|
|
|
+ wifiList: [
|
|
|
+ []
|
|
|
+ ],
|
|
|
+
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
uni.setNavigationBarTitle({
|
|
|
- title: "蓝牙控制"
|
|
|
+ title: "蓝牙配网"
|
|
|
})
|
|
|
ecUI.showLoading("正在初始化蓝牙模块")
|
|
|
ctx = this
|
|
|
@@ -112,6 +174,174 @@ import UPopup from "../../../uni_modules/uview-ui/components/u-popup/u-popup";
|
|
|
}, 100)
|
|
|
},
|
|
|
methods: {
|
|
|
+ getAuth(){
|
|
|
+ wx.getSetting({
|
|
|
+ success(res) {
|
|
|
+ if (!res.authSetting['scope.userLocation']) {
|
|
|
+ wx.authorize({
|
|
|
+ scope: 'scope.userLocation',
|
|
|
+ success () {
|
|
|
+ // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ chooseWifi(e){
|
|
|
+ this.SSID = e.value[0];
|
|
|
+ this.showWiftList= false;
|
|
|
+ },
|
|
|
+ openChooseWifi(){
|
|
|
+ if(this.wifiList[0].length == 0){
|
|
|
+ this.getWifiList();
|
|
|
+ }else{
|
|
|
+ this.showWiftList = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ openWifi(){
|
|
|
+ let self = this;
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ wx.startWifi({
|
|
|
+ success(res) {
|
|
|
+ console.log(res);
|
|
|
+ // self.getWifiList();
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res)
|
|
|
+ uni.showToast({
|
|
|
+ title: '请打开WIFI',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ },
|
|
|
+ getWifi(){
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ var that = this
|
|
|
+ wx.getConnectedWifi({
|
|
|
+ success(res) {
|
|
|
+ console.log(res)
|
|
|
+ that.BSSID = res.wifi.BSSID
|
|
|
+ that.WIFIName = res.wifi.SSID
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res)
|
|
|
+ //报错的相关处理
|
|
|
+ },
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ },
|
|
|
+ getWifiList(){
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ var that = this
|
|
|
+ uni.showLoading();
|
|
|
+ wx.getWifiList({
|
|
|
+ success(res) {
|
|
|
+ console.log(res)
|
|
|
+ wx.onGetWifiList(function(res) {
|
|
|
+ that.showWiftList = true;
|
|
|
+ uni.hideLoading();
|
|
|
+ console.log("获取wifi列表");
|
|
|
+ that.wifiList = [[]];
|
|
|
+ console.log(res.wifiList); //在这里提取列表数据
|
|
|
+ //通过遍历将WIFI名字存入集合,以便下卡框等组件使用
|
|
|
+ for (var i = 0; i < res.wifiList.length; i++) {
|
|
|
+ that.wifiList[0].push(res.wifiList[i].SSID)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res)
|
|
|
+ uni.showToast({
|
|
|
+ title: '获取wifi失败,请检查wifi',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ },
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ },
|
|
|
+ doConnect(){
|
|
|
+ if(this.SSID == ""){
|
|
|
+ uni.showToast({
|
|
|
+ title: '请选择WIFI',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(this.password == ""){
|
|
|
+ uni.showToast({
|
|
|
+ title: '请输入wifi密码',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(this.qrcodeid == ""){
|
|
|
+ uni.showToast({
|
|
|
+ title: '请输入二维码ID',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(this.deviceno == ""){
|
|
|
+ uni.showToast({
|
|
|
+ title: '请输入设备编号',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * ID:XXX+回车换行(设备编号)
|
|
|
+ * QR:XXXX+回车换行(二维码ID)
|
|
|
+ * ssid:WiFi名字+回车换行
|
|
|
+ * psd:wifi密码+回车换行
|
|
|
+ * 最后+OK
|
|
|
+ */
|
|
|
+ let self = this;
|
|
|
+ let endStr = "$$";
|
|
|
+ ecUI.showLoading("正在配置网络信息")
|
|
|
+ setTimeout(function(){
|
|
|
+ self.sendBlueData("ID:"+self.deviceno+endStr);
|
|
|
+ },200);
|
|
|
+ setTimeout(function(){
|
|
|
+ self.sendBlueData("QR:"+self.qrcodeid+endStr);
|
|
|
+ },400);
|
|
|
+
|
|
|
+ setTimeout(function(){
|
|
|
+ self.sendBlueData("ssid:"+self.SSID+endStr);
|
|
|
+ },600);
|
|
|
+
|
|
|
+ setTimeout(function(){
|
|
|
+ self.sendBlueData("psd:"+self.password+endStr);
|
|
|
+ },800);
|
|
|
+
|
|
|
+ setTimeout(function(){
|
|
|
+ self.sendBlueData("OK");
|
|
|
+ },1000);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ doByTime(func,time){
|
|
|
+ setTimeout(function (){
|
|
|
+ func();
|
|
|
+ },time);
|
|
|
+ },
|
|
|
sendLanyaData(){
|
|
|
this.$modal.showToast("正在发送");
|
|
|
this.sendBlueData(this.sendData);
|
|
|
@@ -209,21 +439,19 @@ import UPopup from "../../../uni_modules/uview-ui/components/u-popup/u-popup";
|
|
|
},
|
|
|
listViewTap(id){
|
|
|
let self = this;
|
|
|
- ecUI.showLoading(this.$t('buletooth.connecting'))
|
|
|
+ ecUI.showLoading("正在连接蓝牙")
|
|
|
ecBLE.onBLEConnectionStateChange(res => {
|
|
|
console.log(res);
|
|
|
if (res.ok) {
|
|
|
self.connected = true;
|
|
|
+ self.openWifi();
|
|
|
ecUI.hideLoading()
|
|
|
self.showSendData = true;
|
|
|
ecBLE.stopBluetoothDevicesDiscovery();
|
|
|
//
|
|
|
} else {
|
|
|
ecUI.hideLoading()
|
|
|
- ecUI.showModal(
|
|
|
- this.$t('buletooth.tip'),
|
|
|
- 'error,errCode=' + res.errCode + ',errMsg=' + res.errMsg
|
|
|
- )
|
|
|
+ this.$modal.showToast("请检查是否配置成功");
|
|
|
}
|
|
|
});
|
|
|
//receive data
|
|
|
@@ -235,22 +463,6 @@ import UPopup from "../../../uni_modules/uview-ui/components/u-popup/u-popup";
|
|
|
console.log(data)
|
|
|
self.$modal.closeLoading();
|
|
|
data = parseDataObj(data);
|
|
|
- console.log(data);
|
|
|
- let type = data.type;
|
|
|
- if(type == 253){
|
|
|
- self.messageCallback(data)
|
|
|
- }else{
|
|
|
- let pwd = data.real_data;
|
|
|
- let localPwd = self.getLocalPwd()
|
|
|
- console.log(pwd);
|
|
|
- console.log("localPwd:"+localPwd)
|
|
|
- self.rightPwd = pwd;
|
|
|
- if(pwd != localPwd){
|
|
|
- self.showInputPwd();
|
|
|
- }else{
|
|
|
- self.loginSuccess();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
})
|
|
|
self.connected = false;
|
|
|
@@ -410,4 +622,11 @@ import UPopup from "../../../uni_modules/uview-ui/components/u-popup/u-popup";
|
|
|
.gap {
|
|
|
height: 57px;
|
|
|
}
|
|
|
+ .text-area {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ background: white;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
</style>
|