完成绑定设备全部功能
This commit is contained in:
parent
921f9607a3
commit
e3a54bd1e6
12
api/check.js
Normal file
12
api/check.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import request from '../utils/request'
|
||||||
|
|
||||||
|
// check 检查模块
|
||||||
|
|
||||||
|
// 获取服务器时间
|
||||||
|
export function getServerDatetime(data) {
|
||||||
|
return request({
|
||||||
|
url: '/check/getServerDatetime',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
12
api/geocode.js
Normal file
12
api/geocode.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import request from '../utils/request'
|
||||||
|
|
||||||
|
// geocode 地理编码模块
|
||||||
|
|
||||||
|
// 获取地址信息
|
||||||
|
export function getGeocodeAddress(data) {
|
||||||
|
return request({
|
||||||
|
url: '/geocode/getAddress',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -10,3 +10,12 @@ export function getLockListRequest(data) {
|
|||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 绑定锁管理员
|
||||||
|
export function bindLockAdmin(data) {
|
||||||
|
return request({
|
||||||
|
url: '/v2/lock/bindAdmin',
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -5,49 +5,6 @@
|
|||||||
"versionName" : "1.0.0",
|
"versionName" : "1.0.0",
|
||||||
"versionCode" : "100",
|
"versionCode" : "100",
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
|
||||||
"app-plus" : {
|
|
||||||
"usingComponents" : true,
|
|
||||||
"nvueStyleCompiler" : "uni-app",
|
|
||||||
"compilerVersion" : 3,
|
|
||||||
"splashscreen" : {
|
|
||||||
"alwaysShowBeforeRender" : true,
|
|
||||||
"waiting" : true,
|
|
||||||
"autoclose" : true,
|
|
||||||
"delay" : 0
|
|
||||||
},
|
|
||||||
/* 模块配置 */
|
|
||||||
"modules" : {},
|
|
||||||
/* 应用发布信息 */
|
|
||||||
"distribute" : {
|
|
||||||
/* android打包配置 */
|
|
||||||
"android" : {
|
|
||||||
"permissions" : [
|
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
|
||||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
|
||||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
|
||||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
/* ios打包配置 */
|
|
||||||
"ios" : {},
|
|
||||||
/* SDK配置 */
|
|
||||||
"sdkConfigs" : {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/* 快应用特有相关 */
|
|
||||||
"quickapp" : {},
|
|
||||||
/* 小程序特有相关 */
|
/* 小程序特有相关 */
|
||||||
"mp-weixin" : {
|
"mp-weixin" : {
|
||||||
"appid" : "wx9829a39e65550757",
|
"appid" : "wx9829a39e65550757",
|
||||||
@ -55,20 +12,17 @@
|
|||||||
"urlCheck" : true,
|
"urlCheck" : true,
|
||||||
"minified" : true
|
"minified" : true
|
||||||
},
|
},
|
||||||
|
"permission": {
|
||||||
|
"scope.bluetooth": {
|
||||||
|
"desc": "蓝牙将用于控制和管理您的智能门锁"
|
||||||
|
},
|
||||||
|
"scope.userLocation": {
|
||||||
|
"desc": "获取您的位置信息将用于智能门锁的位置服务"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"requiredPrivateInfos": ["getLocation"],
|
||||||
"usingComponents" : true,
|
"usingComponents" : true,
|
||||||
"lazyCodeLoading" : "requiredComponents"
|
"lazyCodeLoading" : "requiredComponents"
|
||||||
},
|
},
|
||||||
"mp-alipay" : {
|
|
||||||
"usingComponents" : true
|
|
||||||
},
|
|
||||||
"mp-baidu" : {
|
|
||||||
"usingComponents" : true
|
|
||||||
},
|
|
||||||
"mp-toutiao" : {
|
|
||||||
"usingComponents" : true
|
|
||||||
},
|
|
||||||
"uniStatistics" : {
|
|
||||||
"enable" : false
|
|
||||||
},
|
|
||||||
"vueVersion" : "3"
|
"vueVersion" : "3"
|
||||||
}
|
}
|
||||||
|
|||||||
22
pages.json
22
pages.json
@ -17,6 +17,16 @@
|
|||||||
"navigationStyle": "default"
|
"navigationStyle": "default"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/selectAddress/selectAddress",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "锁地址",
|
||||||
|
"navigationBarTextStyle": "white",
|
||||||
|
"navigationBarBackgroundColor": "#63b8af",
|
||||||
|
"navigationStyle": "default",
|
||||||
|
"disableScroll": true
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/mine/mine",
|
"path": "pages/mine/mine",
|
||||||
"style": {
|
"style": {
|
||||||
@ -110,10 +120,20 @@
|
|||||||
"navigationStyle": "default"
|
"navigationStyle": "default"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/bindLock/bindLock",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "添加锁",
|
||||||
|
"navigationBarTextStyle": "white",
|
||||||
|
"navigationBarBackgroundColor": "#63b8af",
|
||||||
|
"navigationStyle": "default"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/searchDevice/searchDevice",
|
"path": "pages/searchDevice/searchDevice",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "搜索",
|
"disableScroll": true,
|
||||||
|
"navigationBarTitleText": "附近设备",
|
||||||
"navigationBarTextStyle": "white",
|
"navigationBarTextStyle": "white",
|
||||||
"navigationBarBackgroundColor": "#63b8af",
|
"navigationBarBackgroundColor": "#63b8af",
|
||||||
"navigationStyle": "default"
|
"navigationStyle": "default"
|
||||||
|
|||||||
186
pages/bindLock/bindLock.vue
Normal file
186
pages/bindLock/bindLock.vue
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<view class="text">如需修改名字请重新命名,点击确定添加锁</view>
|
||||||
|
<input class="input" :value="name" maxlength="32" placeholder="请输入名称" placeholder-class="input-placeholder"
|
||||||
|
@input="uopdateName"
|
||||||
|
></input>
|
||||||
|
<view class="button" @click="bindLock">确定</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
|
import { mapActions, mapState } from 'pinia'
|
||||||
|
import { bindLockAdmin } from '@/api/lock'
|
||||||
|
import { useLockStore } from '@/stores/lock'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
name: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(useBluetoothStore, ['currentLockInfo', 'keyId']),
|
||||||
|
...mapState(useUserStore, ['userInfo']),
|
||||||
|
},
|
||||||
|
onLoad() {
|
||||||
|
this.name = this.currentLockInfo.name
|
||||||
|
console.log(this.currentLockInfo)
|
||||||
|
console.log(this.name)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(useBluetoothStore, ['addLockUser']),
|
||||||
|
...mapActions(useLockStore, ['getLockList']),
|
||||||
|
uopdateName(data) {
|
||||||
|
this.name = data.detail.value
|
||||||
|
},
|
||||||
|
async bindLock() {
|
||||||
|
if(this.name === '') {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入名称',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uni.showLoading({
|
||||||
|
title: '添加中'
|
||||||
|
})
|
||||||
|
const timestamp = parseInt(new Date().getTime() / 1000)
|
||||||
|
const password = (Math.floor(Math.random() * 900000) + 100000).toString()
|
||||||
|
const { code: addUserCode } = await this.addLockUser({
|
||||||
|
name: this.currentLockInfo.name,
|
||||||
|
keyId: this.keyId,
|
||||||
|
authUid: this.userInfo.uid.toString(),
|
||||||
|
uid: this.userInfo.uid.toString(),
|
||||||
|
openMode: 1,
|
||||||
|
keyType: 1,
|
||||||
|
startDate: timestamp,
|
||||||
|
expireDate: 0xffffffff,
|
||||||
|
useCountLimit: 0xffff,
|
||||||
|
isRound: 0,
|
||||||
|
weekRound: 0,
|
||||||
|
startHour: 0,
|
||||||
|
startMin: 0,
|
||||||
|
endHour: 0,
|
||||||
|
endMin: 0,
|
||||||
|
role: 0xff,
|
||||||
|
password
|
||||||
|
})
|
||||||
|
if(addUserCode !== 0) {
|
||||||
|
uni.navigateBack({
|
||||||
|
complete() {
|
||||||
|
uni.showToast({
|
||||||
|
title: '添加失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
uni.hideLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const params = {
|
||||||
|
lockAlias: this.name,
|
||||||
|
lockInfo: {
|
||||||
|
...this.currentLockInfo.lockConfig,
|
||||||
|
adminPwd: password
|
||||||
|
},
|
||||||
|
bluetooth: {
|
||||||
|
bluetoothDeviceName: this.currentLockInfo.name,
|
||||||
|
bluetoothDeviceId: this.currentLockInfo.deviceId,
|
||||||
|
publicKey: this.currentLockInfo.publicKey,
|
||||||
|
privateKey: this.currentLockInfo.commKey,
|
||||||
|
signKey: this.currentLockInfo.signKey,
|
||||||
|
},
|
||||||
|
lockUserNo: this.currentLockInfo.lockUserNo,
|
||||||
|
pwdTimestamp: this.currentLockInfo.pwdTimestamp,
|
||||||
|
featureValue: this.currentLockInfo.featureValue,
|
||||||
|
featureSettingValue: this.currentLockInfo.featureSettingValue,
|
||||||
|
featureSettingParams: this.currentLockInfo.featureSettingParams
|
||||||
|
}
|
||||||
|
if(this.currentLockInfo.position) {
|
||||||
|
params.position = {
|
||||||
|
latitude: this.currentLockInfo.position.latitude,
|
||||||
|
longitude: this.currentLockInfo.position.longitude,
|
||||||
|
province: this.currentLockInfo.position.province,
|
||||||
|
city: this.currentLockInfo.position.city,
|
||||||
|
district: this.currentLockInfo.position.district,
|
||||||
|
country: this.currentLockInfo.position.country,
|
||||||
|
township: this.currentLockInfo.position.township,
|
||||||
|
address: this.currentLockInfo.position.address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const { code, message } = await bindLockAdmin(params)
|
||||||
|
console.log('添加锁返回', code, message)
|
||||||
|
if(code === 0) {
|
||||||
|
this.getLockList({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 50
|
||||||
|
})
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.navigateBack({
|
||||||
|
complete() {
|
||||||
|
uni.showToast({
|
||||||
|
title: '添加成功',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({
|
||||||
|
title: message,
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
page {
|
||||||
|
background-color: $uni-bg-color-grey;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.text {
|
||||||
|
color: #2b2a28;
|
||||||
|
padding: 100rpx 0;
|
||||||
|
font-size: 34rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
border-radius: 16rpx;
|
||||||
|
background: #FFFFFF;
|
||||||
|
margin-left: 35rpx;
|
||||||
|
margin-top: 24rpx;
|
||||||
|
height: 108rpx;
|
||||||
|
width: 616rpx;
|
||||||
|
padding-left: 32rpx;
|
||||||
|
padding-right: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-placeholder {
|
||||||
|
height: 108rpx;
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
line-height: 108rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
margin-top: 160rpx;
|
||||||
|
margin-left: 35rpx;
|
||||||
|
width: 680rpx;
|
||||||
|
height: 96rpx;
|
||||||
|
background: #63b8af;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
line-height: 96rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 32rpx;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -2,8 +2,8 @@
|
|||||||
<view>
|
<view>
|
||||||
<view v-if="!penging">
|
<view v-if="!penging">
|
||||||
<view v-if="isLogin">
|
<view v-if="isLogin">
|
||||||
<scroll-view scroll-y="true" :style="{ height: 'calc(100vh)' }" lower-threshold="100"
|
<scroll-view v-if="deviceInfo" scroll-y="true" :style="{ height: deviceInfo.windowHeight + 'px' }"
|
||||||
@refresherrefresh="refresherList" :refresher-enabled="true" @scrolltolower="nextPage"
|
lower-threshold="100" @refresherrefresh="refresherList" :refresher-enabled="true" @scrolltolower="nextPage"
|
||||||
:refresher-triggered="refresherTriggered">
|
:refresher-triggered="refresherTriggered">
|
||||||
<view class="search">
|
<view class="search">
|
||||||
<up-search :searchIconSize="48" :inputStyle="{ fontSize: '32rpx' }" @focus="getFocus" @blur="getBlur"
|
<up-search :searchIconSize="48" :inputStyle="{ fontSize: '32rpx' }" @focus="getFocus" @blur="getBlur"
|
||||||
@ -12,7 +12,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="lock-list" v-if="!penging">
|
<view class="lock-list" v-if="!penging">
|
||||||
<view v-if="lockList.length === 0 && search.searchStr === '' && !focus">
|
<view v-if="lockList.length === 0 && search.searchStr === '' && !focus">
|
||||||
<image src="/static/images/icon_add.png" mode="aspectFill" class="button-add-big" @click="toSearchDevice"></image>
|
<image src="/static/images/icon_add_round.png" mode="aspectFill" class="button-add-big"
|
||||||
|
@click="toSearchDevice"></image>
|
||||||
<view class="text">填加锁时,手机必须在锁旁边</view>
|
<view class="text">填加锁时,手机必须在锁旁边</view>
|
||||||
</view>
|
</view>
|
||||||
<view v-else>
|
<view v-else>
|
||||||
@ -32,9 +33,9 @@
|
|||||||
<view>{{getRole(lock.userType)}}</view>
|
<view>{{getRole(lock.userType)}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="lock-name">{{lock.lockName}}</view>
|
<view class="lock-name">{{lock.lockAlias}}</view>
|
||||||
<view class="lock-time">
|
<view class="lock-time">
|
||||||
<view v-if="lock.keyType !== 1" style="font-size: 32rpx">{{ getTimeLimit(lock.keyType) }}</view>
|
<view v-if="lock.keyType === 1" style="font-size: 32rpx">{{ getTimeLimit(lock.keyType) }}</view>
|
||||||
<view v-else>
|
<view v-else>
|
||||||
<view>{{ timeFormat(lock.startDate, 'yyyy-mm-dd h:M') }}</view>
|
<view>{{ timeFormat(lock.startDate, 'yyyy-mm-dd h:M') }}</view>
|
||||||
<view>{{ timeFormat(lock.endDate, 'yyyy-mm-dd h:M ') + getTimeLimit(lock.keyType) }}</view>
|
<view>{{ timeFormat(lock.endDate, 'yyyy-mm-dd h:M ') + getTimeLimit(lock.keyType) }}</view>
|
||||||
@ -45,7 +46,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
<image v-if="lockList.length !== 0" src="/static/images/icon_add.png" mode="aspectFill"
|
<image v-if="lockList.length !== 0" src="/static/images/icon_add_round.png" mode="aspectFill"
|
||||||
class="button-add" @click="toSearchDevice"></image>
|
class="button-add" @click="toSearchDevice"></image>
|
||||||
</view>
|
</view>
|
||||||
<view v-else>
|
<view v-else>
|
||||||
@ -63,6 +64,7 @@
|
|||||||
import { useBluetoothStore } from '@/stores/bluetooth'
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
||||||
import { useBasicStore } from '@/stores/basic'
|
import { useBasicStore } from '@/stores/basic'
|
||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
|
import { getServerDatetime } from '@/api/check'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -74,7 +76,8 @@
|
|||||||
},
|
},
|
||||||
refresherTriggered: false,
|
refresherTriggered: false,
|
||||||
focus: false,
|
focus: false,
|
||||||
penging: true
|
penging: true,
|
||||||
|
deviceInfo: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -86,6 +89,8 @@
|
|||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '加载中'
|
title: '加载中'
|
||||||
})
|
})
|
||||||
|
this.deviceInfo = await this.getDeviceInfo()
|
||||||
|
console.log(this.deviceInfo)
|
||||||
const token = uni.getStorageSync('token')
|
const token = uni.getStorageSync('token')
|
||||||
if(token) {
|
if(token) {
|
||||||
this.updateLoginStatus(true)
|
this.updateLoginStatus(true)
|
||||||
@ -102,7 +107,7 @@
|
|||||||
...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'login']),
|
...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'login']),
|
||||||
...mapActions(useLockStore, ['getLockList', 'getRole', 'getTimeLimit']),
|
...mapActions(useLockStore, ['getLockList', 'getRole', 'getTimeLimit']),
|
||||||
...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo', 'checkSetting']),
|
...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo', 'checkSetting']),
|
||||||
...mapActions(useBasicStore, ['routeJump']),
|
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
|
||||||
async nextPage() {
|
async nextPage() {
|
||||||
if(this.lockList.length < this.lockTotal) {
|
if(this.lockList.length < this.lockTotal) {
|
||||||
this.search.pageNo++
|
this.search.pageNo++
|
||||||
@ -116,6 +121,10 @@
|
|||||||
this.refresherTriggered = true
|
this.refresherTriggered = true
|
||||||
this.search.pageNo = 1
|
this.search.pageNo = 1
|
||||||
await this.getLockList(this.search)
|
await this.getLockList(this.search)
|
||||||
|
uni.showToast({
|
||||||
|
title: '刷新成功',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
this.refresherTriggered = false
|
this.refresherTriggered = false
|
||||||
},
|
},
|
||||||
async changeSearch(data) {
|
async changeSearch(data) {
|
||||||
|
|||||||
@ -164,12 +164,12 @@
|
|||||||
console.log('添加用户返回', addUserCode)
|
console.log('添加用户返回', addUserCode)
|
||||||
},
|
},
|
||||||
getLockStatusResult() {
|
getLockStatusResult() {
|
||||||
const timnestamp = parseInt(new Date().getTime() / 1000)
|
const timestamp = parseInt(new Date().getTime() / 1000)
|
||||||
this.getLockStatus({
|
this.getLockStatus({
|
||||||
name: this.currentLockInfo.name,
|
name: this.currentLockInfo.name,
|
||||||
uid: this.authUid,
|
uid: this.authUid,
|
||||||
nowTime: timnestamp,
|
nowTime: timestamp,
|
||||||
localTime: timnestamp
|
localTime: timestamp
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,161 @@
|
|||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
|
<scroll-view v-if="deviceInfo" class="scroll-view" scroll-y="true" :style="{ height: deviceInfo.screenHeight - deviceInfo.statusBarHeight + 'px' }">
|
||||||
|
<view style="padding-bottom: calc(env(safe-area-inset-bottom) + 300rpx)">
|
||||||
|
<view class="device" v-for="device in deviceList" @click="connect(device)">
|
||||||
|
<view class="device" style="justify-content:flex-start;">
|
||||||
|
<image class="device-lock" src="/static/images/icon_door_lock.png"></image>
|
||||||
|
<view class="device-name">{{device.name}}</view>
|
||||||
|
</view>
|
||||||
|
<image class="device-add" src="/static/images/icon_add.png"></image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
<view class="loading">
|
||||||
|
<up-loading-icon size="80rpx" text="搜索中" :vertical="true" textSize="32rpx"></up-loading-icon>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState, mapActions } from 'pinia'
|
||||||
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
||||||
|
import { useBasicStore } from '@/stores/basic'
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {}
|
return {
|
||||||
|
deviceInfo: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(useBluetoothStore, ['deviceList', 'currentLockInfo', 'serverTimestamp', 'keyId']),
|
||||||
|
...mapState(useUserStore, ['userInfo'])
|
||||||
|
},
|
||||||
|
async onLoad() {
|
||||||
|
this.deviceInfo = await this.getDeviceInfo()
|
||||||
|
this.getBluetoothDevices()
|
||||||
|
},
|
||||||
|
onUnload() {
|
||||||
|
this.stopGetBluetoothDevices()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(useBluetoothStore, ['getBluetoothDevices', 'stopGetBluetoothDevices', 'updateCurrentLockInfo',
|
||||||
|
'getPublicKey', 'getCommKey', 'connectBluetoothDevice', 'updateServerTimestamp', 'getLockStatus']),
|
||||||
|
...mapActions(useBasicStore, ['getDeviceInfo', 'routeJump']),
|
||||||
|
async connect(device) {
|
||||||
|
uni.showLoading({
|
||||||
|
title: '连接中',
|
||||||
|
// mask: true
|
||||||
|
})
|
||||||
|
const { code: serverTimestampCode, message } = await this.updateServerTimestamp()
|
||||||
|
if(serverTimestampCode !== 0) {
|
||||||
|
uni.showToast({
|
||||||
|
title: message,
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
uni.hideLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.updateCurrentLockInfo({
|
||||||
|
name: device.name,
|
||||||
|
deviceId: device.deviceId
|
||||||
|
})
|
||||||
|
const result = await this.connectBluetoothDevice()
|
||||||
|
this.stopGetBluetoothDevices()
|
||||||
|
if(result) {
|
||||||
|
const { code: getPublicKeyCode } = await this.getPublicKey(this.currentLockInfo.name)
|
||||||
|
console.log('获取公钥返回', getPublicKeyCode, [...this.currentLockInfo.publicKey])
|
||||||
|
if(getPublicKeyCode !== 0) {
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({
|
||||||
|
title: '连接失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { code: getCommKeyCode } = await this.getCommKey(this.currentLockInfo.name, this.keyId,
|
||||||
|
this.userInfo.uid.toString(), this.serverTimestamp)
|
||||||
|
console.log('获取私钥返回', getCommKeyCode)
|
||||||
|
if(getCommKeyCode !== 0) {
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({
|
||||||
|
title: '连接失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const timestamp = parseInt(new Date().getTime() / 1000)
|
||||||
|
const { code } = await this.getLockStatus({
|
||||||
|
name: this.currentLockInfo.name,
|
||||||
|
uid: this.userInfo.uid,
|
||||||
|
nowTime: this.serverTimestamp,
|
||||||
|
localTime: timestamp
|
||||||
|
})
|
||||||
|
if (code !== 0) {
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({
|
||||||
|
title: '连接失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.routeJump({
|
||||||
|
type: 'redirectTo',
|
||||||
|
name: 'selectAddress'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.getBluetoothDevices()
|
||||||
|
uni.showToast({
|
||||||
|
title: '连接失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
uni.hideLoading()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
page {
|
||||||
|
background-color: $uni-bg-color-grey;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.loading {
|
||||||
|
position: fixed;
|
||||||
|
bottom: calc(env(safe-area-inset-bottom) + 50rpx) ;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.device {
|
||||||
|
background: #ffffff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
height: 100rpx;
|
||||||
|
|
||||||
|
.device-lock {
|
||||||
|
margin-left: 24rpx;
|
||||||
|
width: 72rpx;
|
||||||
|
height: 72rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-name {
|
||||||
|
margin-left: 24rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-add {
|
||||||
|
float: right;
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
margin-right: 24rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
256
pages/selectAddress/selectAddress.vue
Normal file
256
pages/selectAddress/selectAddress.vue
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<view class="title">地理位置</view>
|
||||||
|
<view v-if="show">
|
||||||
|
<map class="map" :longitude="longitude" :latitude="latitude" :scale="16" :markers="markers"
|
||||||
|
:enable-zoom="false" :enable-scroll="false"></map>
|
||||||
|
</view>
|
||||||
|
<view v-else class="map"></view>
|
||||||
|
<view class="explain">检查以确保以下地址是正确的</view>
|
||||||
|
<view class="view-address" :style="{height: calculateStringTotalWidth(address) > 44 ? '120rpx' : '80rpx'}">
|
||||||
|
<view class="address">{{ address }}</view>
|
||||||
|
</view>
|
||||||
|
<view class="bottom">
|
||||||
|
<view class="skip" @click="skipAddress">跳过</view>
|
||||||
|
<view class="confirm" @click="toBindLock">下一步</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { test } from 'uview-plus'
|
||||||
|
import { useBasicStore } from '@/stores/basic'
|
||||||
|
import { mapState, mapActions } from 'pinia'
|
||||||
|
import { getGeocodeAddress } from '@/api/geocode'
|
||||||
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
latitude: null,
|
||||||
|
longitude: null,
|
||||||
|
show: false,
|
||||||
|
markers: [],
|
||||||
|
address: '',
|
||||||
|
first: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(useBluetoothStore, ['currentLockInfo'])
|
||||||
|
},
|
||||||
|
onLoad() {
|
||||||
|
this.getLocation()
|
||||||
|
},
|
||||||
|
onShow() {
|
||||||
|
if(this.first) {
|
||||||
|
this.first = false
|
||||||
|
} else {
|
||||||
|
if(!this.show) {
|
||||||
|
this.getLocation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(useBasicStore, ['routeJump', 'calculateStringTotalWidth']),
|
||||||
|
...mapActions(useBluetoothStore, ['updateCurrentLockInfo']),
|
||||||
|
toBindLock() {
|
||||||
|
const that = this
|
||||||
|
if(this.address === '') {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '暂未获取到地理位置信息,请重试',
|
||||||
|
confirmText: '重试',
|
||||||
|
success: (res) => {
|
||||||
|
if(res.confirm) {
|
||||||
|
that.getLocation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.routeJump({
|
||||||
|
type: 'redirectTo',
|
||||||
|
name: 'bindLock'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
skipAddress() {
|
||||||
|
const that = this
|
||||||
|
if(this.address !== '') {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '已获取当前地理位置,确定跳过吗',
|
||||||
|
confirmText: '跳过',
|
||||||
|
cancelText: '取消',
|
||||||
|
success: (res) => {
|
||||||
|
if(res.confirm) {
|
||||||
|
const lockInfo = that.currentLockInfo
|
||||||
|
delete lockInfo.position
|
||||||
|
that.updateCurrentLockInfo(lockInfo)
|
||||||
|
this.routeJump({
|
||||||
|
type: 'redirectTo',
|
||||||
|
name: 'bindLock'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.routeJump({
|
||||||
|
type: 'redirectTo',
|
||||||
|
name: 'bindLock'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async getLocation() {
|
||||||
|
const that = this
|
||||||
|
uni.getLocation({
|
||||||
|
isHighAccuracy: true,
|
||||||
|
type: 'gcj02',
|
||||||
|
async success (res) {
|
||||||
|
that.latitude = res.latitude
|
||||||
|
that.longitude = res.longitude
|
||||||
|
that.markers = [{
|
||||||
|
id: 1,
|
||||||
|
latitude: res.latitude,
|
||||||
|
longitude: res.longitude,
|
||||||
|
iconPath: '/static/images/icon_address.png',
|
||||||
|
width: '48rpx',
|
||||||
|
height: '48rpx'
|
||||||
|
}]
|
||||||
|
that.show = true
|
||||||
|
const { code, data: result } = await getGeocodeAddress({
|
||||||
|
latitude: that.latitude,
|
||||||
|
longitude: that.longitude
|
||||||
|
})
|
||||||
|
if(code === 0) {
|
||||||
|
that.address = result.addr
|
||||||
|
const position = {
|
||||||
|
...result,
|
||||||
|
latitude: that.latitude,
|
||||||
|
longitude: that.longitude
|
||||||
|
}
|
||||||
|
console.log('获取地理位置信息', that.currentLockInfo)
|
||||||
|
that.updateCurrentLockInfo({
|
||||||
|
...that.currentLockInfo,
|
||||||
|
position
|
||||||
|
})
|
||||||
|
console.log('获取地理位置信息', that.currentLockInfo)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail (res) {
|
||||||
|
if(res.errMsg === 'getLocation:fail auth deny') {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '拒绝授权将无法使用定位功能',
|
||||||
|
confirmText: '去授权',
|
||||||
|
cancelText: '跳过',
|
||||||
|
success (res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
uni.openSetting()
|
||||||
|
} else {
|
||||||
|
that.routeJump({
|
||||||
|
type: 'redirectTo',
|
||||||
|
name: 'bindLock'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '获取地理位置信息失败',
|
||||||
|
confirmText: '重试',
|
||||||
|
cancelText: '跳过',
|
||||||
|
success (res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
that.getLocation()
|
||||||
|
} else {
|
||||||
|
that.routeJump({
|
||||||
|
type: 'redirectTo',
|
||||||
|
name: 'bindLock'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
page {
|
||||||
|
background-color: $uni-bg-color-grey;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.map {
|
||||||
|
width: 750rpx;
|
||||||
|
height: 650rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
padding: 40rpx 30rpx;
|
||||||
|
font-size: 80rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.explain {
|
||||||
|
padding: 20rpx 30rpx 0 30rpx;
|
||||||
|
font-size: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-address {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 690rpx;
|
||||||
|
color: #c4c4c4;
|
||||||
|
font-size: 32rpx;
|
||||||
|
margin: 0 30rpx;
|
||||||
|
border-bottom: #63b8af 3rpx solid;
|
||||||
|
|
||||||
|
.address {
|
||||||
|
width: 690rpx;
|
||||||
|
text-align: left;
|
||||||
|
word-break: break-all;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom {
|
||||||
|
width: 600rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0 75rpx;
|
||||||
|
position: fixed;
|
||||||
|
bottom: calc(30rpx + env(safe-area-inset-bottom));
|
||||||
|
|
||||||
|
.skip {
|
||||||
|
width: 225rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
line-height: 80rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 36rpx;
|
||||||
|
border-radius: 64rpx;
|
||||||
|
border: 3rpx solid #63b8af;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm {
|
||||||
|
border-radius: 64rpx;
|
||||||
|
color: #FFFFFF;
|
||||||
|
background-color: #63b8af;
|
||||||
|
width: 225rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
line-height: 80rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 36rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 880 B |
BIN
static/images/icon_add_round.png
Normal file
BIN
static/images/icon_add_round.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
BIN
static/images/icon_address.png
Normal file
BIN
static/images/icon_address.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
static/images/icon_door_lock.png
Executable file
BIN
static/images/icon_door_lock.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@ -61,6 +61,16 @@ const pages = [
|
|||||||
name: 'searchDevice',
|
name: 'searchDevice',
|
||||||
path: '/pages/searchDevice/searchDevice',
|
path: '/pages/searchDevice/searchDevice',
|
||||||
tabBar: false
|
tabBar: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'selectAddress',
|
||||||
|
path: '/pages/selectAddress/selectAddress',
|
||||||
|
tabBar: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'bindLock',
|
||||||
|
path: '/pages/bindLock/bindLock',
|
||||||
|
tabBar: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -120,5 +130,22 @@ export const useBasicStore = defineStore('basic', {
|
|||||||
return
|
return
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
// 计算字符串长度
|
||||||
|
calculateStringTotalWidth(str) {
|
||||||
|
let totalWidth = 0
|
||||||
|
// 遍历字符串中的每一个字符
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
const char = str[i]
|
||||||
|
// 判断当前字符是全角字符还是半角字符
|
||||||
|
if (/[\uFF01-\uFF60\uFFE0-\uFFE6\u4E00-\u9FFF\u3000-\u303F]/.test(char)) {
|
||||||
|
// 全角字符宽度为 2
|
||||||
|
totalWidth += 2
|
||||||
|
} else {
|
||||||
|
// 半角字符宽度为 1
|
||||||
|
totalWidth += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalWidth
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { defineStore } from 'pinia'
|
|||||||
import crc from 'crc'
|
import crc from 'crc'
|
||||||
import { sm4 } from 'sm-crypto'
|
import { sm4 } from 'sm-crypto'
|
||||||
import { md5 } from 'js-md5'
|
import { md5 } from 'js-md5'
|
||||||
|
import { getServerDatetime } from '@/api/check'
|
||||||
|
|
||||||
// 定时器
|
// 定时器
|
||||||
let timer
|
let timer
|
||||||
@ -58,10 +59,32 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
// 消息序号
|
// 消息序号
|
||||||
messageCount: 1,
|
messageCount: 1,
|
||||||
// 是否初始化蓝牙
|
// 是否初始化蓝牙
|
||||||
isInitBluetooth: false
|
isInitBluetooth: false,
|
||||||
|
// 服务器时间
|
||||||
|
serverTimestamp: 0,
|
||||||
|
// 设备keyID
|
||||||
|
keyId: '0'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
// 二进制转字符串
|
||||||
|
uint8ArrayToString(uint8Array) {
|
||||||
|
let str = ''
|
||||||
|
for (let i = 0; i < uint8Array.length; i++) {
|
||||||
|
if (uint8Array[i] !== 0) {
|
||||||
|
str += String.fromCharCode(uint8Array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
},
|
||||||
|
// 更新服务端时间戳
|
||||||
|
async updateServerTimestamp() {
|
||||||
|
const { code, data, message } = await getServerDatetime({})
|
||||||
|
if(code === 0) {
|
||||||
|
this.serverTimestamp = parseInt(data.date / 1000)
|
||||||
|
}
|
||||||
|
return { code, data, message }
|
||||||
|
},
|
||||||
// 初始化并监听
|
// 初始化并监听
|
||||||
async initAndListenBluetooth() {
|
async initAndListenBluetooth() {
|
||||||
// 初始化蓝牙
|
// 初始化蓝牙
|
||||||
@ -168,7 +191,7 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
if(binaryData[14] === 0) {
|
if(binaryData[14] === 0) {
|
||||||
that.updateCurrentLockInfo({
|
that.updateCurrentLockInfo({
|
||||||
...that.currentLockInfo,
|
...that.currentLockInfo,
|
||||||
publicKey: binaryData.slice(15, 31)
|
publicKey: [...binaryData.slice(15, 31)]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
characteristicValueCallback({
|
characteristicValueCallback({
|
||||||
@ -191,7 +214,8 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
that.updateCurrentLockInfo({
|
that.updateCurrentLockInfo({
|
||||||
...that.currentLockInfo,
|
...that.currentLockInfo,
|
||||||
commKey: decrypted.slice(3, 19),
|
commKey: decrypted.slice(3, 19),
|
||||||
signKey: decrypted.slice(19, 35)
|
signKey: decrypted.slice(19, 35),
|
||||||
|
pwdTimestamp: this.arrayToTimestamp(decrypted.slice(35, 39)) * 1000
|
||||||
})
|
})
|
||||||
console.log('commKey', Array.from(that.currentLockInfo.commKey))
|
console.log('commKey', Array.from(that.currentLockInfo.commKey))
|
||||||
console.log('signKey', Array.from(that.currentLockInfo.signKey))
|
console.log('signKey', Array.from(that.currentLockInfo.signKey))
|
||||||
@ -211,28 +235,28 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
case cmdIds.getLockStatus:
|
case cmdIds.getLockStatus:
|
||||||
if (decrypted[2] === 0) {
|
if (decrypted[2] === 0) {
|
||||||
const lockConfig = {
|
const lockConfig = {
|
||||||
vendor: decrypted.slice(3, 23),
|
vendor: that.uint8ArrayToString(decrypted.slice(3, 23)),
|
||||||
product: decrypted[23],
|
product: decrypted[23],
|
||||||
model: decrypted.slice(24, 44),
|
model: that.uint8ArrayToString(decrypted.slice(24, 44)),
|
||||||
fwVersion: decrypted.slice(44, 64),
|
fwVersion: that.uint8ArrayToString(decrypted.slice(44, 64)),
|
||||||
hwVersion: decrypted.slice(64, 84),
|
hwVersion: that.uint8ArrayToString(decrypted.slice(64, 84)),
|
||||||
serialNum0: decrypted.slice(84, 100),
|
serialNum0: that.uint8ArrayToString(decrypted.slice(84, 100)),
|
||||||
serialNum1: decrypted.slice(100, 116),
|
serialNum1: that.uint8ArrayToString(decrypted.slice(100, 116)),
|
||||||
btDeviceName: decrypted.slice(116, 132),
|
btDeviceName: that.uint8ArrayToString(decrypted.slice(116, 132)),
|
||||||
battRemCap: decrypted[132],
|
electricQuantity: decrypted[132],
|
||||||
battRemCapStandby: decrypted[133],
|
electricQuantityStandby: decrypted[133],
|
||||||
restoreCounter: decrypted.slice(134, 136),
|
restoreCount: decrypted[134] * 256 + decrypted[135],
|
||||||
restoreDate: decrypted.slice(136, 140),
|
restoreDate: this.arrayToTimestamp(decrypted.slice(136, 140)),
|
||||||
icPartNo: decrypted.slice(140, 150),
|
icPartNo: that.uint8ArrayToString(decrypted.slice(140, 150)),
|
||||||
inDate: decrypted.slice(150, 154),
|
indate: this.arrayToTimestamp(decrypted.slice(150, 154)),
|
||||||
mac: decrypted.slice(154, 174),
|
mac: that.uint8ArrayToString(decrypted.slice(154, 174)),
|
||||||
featurevalueLength: decrypted[174],
|
timezoneOffset: new Date().getTimezoneOffset() * 60
|
||||||
featureValue: decrypted.slice(175, 175 + decrypted[174]),
|
|
||||||
featureEnValLength: decrypted[175 + decrypted[174]],
|
|
||||||
featureEnVal: decrypted.slice(176 + decrypted[174], 176 + decrypted[174] + decrypted[175 + decrypted[174]]),
|
|
||||||
}
|
}
|
||||||
that.updateCurrentLockInfo({
|
that.updateCurrentLockInfo({
|
||||||
...that.currentLockInfo,
|
...that.currentLockInfo,
|
||||||
|
featureValue: that.uint8ArrayToString(decrypted.slice(175, 175 + decrypted[174])),
|
||||||
|
featureSettingValue: that.uint8ArrayToString(decrypted.slice(176 + decrypted[174], 176 + decrypted[174] + decrypted[175 + decrypted[174]])),
|
||||||
|
featureSettingParams: Array.from(decrypted.slice(176 + decrypted[174] + decrypted[175 + decrypted[174]])),
|
||||||
lockConfig
|
lockConfig
|
||||||
})
|
})
|
||||||
console.log('获取锁状态成功', that.currentLockInfo.lockConfig)
|
console.log('获取锁状态成功', that.currentLockInfo.lockConfig)
|
||||||
@ -244,7 +268,8 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
case cmdIds.addUser:
|
case cmdIds.addUser:
|
||||||
that.updateCurrentLockInfo({
|
that.updateCurrentLockInfo({
|
||||||
...that.currentLockInfo,
|
...that.currentLockInfo,
|
||||||
token: decrypted.slice(42,46)
|
token: decrypted.slice(42,46),
|
||||||
|
lockUserNo: decrypted[47] * 256 + decrypted[48]
|
||||||
})
|
})
|
||||||
characteristicValueCallback({
|
characteristicValueCallback({
|
||||||
code: decrypted[46]
|
code: decrypted[46]
|
||||||
@ -769,10 +794,15 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
array[3] = (timestamp & 0xff)
|
array[3] = (timestamp & 0xff)
|
||||||
return array
|
return array
|
||||||
},
|
},
|
||||||
|
// 二进制转时间戳
|
||||||
|
arrayToTimestamp(array) {
|
||||||
|
const timestamp = (array[0] << 24) | (array[1] << 16) | (array[2] << 8) | array[3]
|
||||||
|
return timestamp >>> 0
|
||||||
|
},
|
||||||
// 添加用户
|
// 添加用户
|
||||||
async addLockUser(data) {
|
async addLockUser(data) {
|
||||||
const { name, authUid, uid, keyId, openMode, keyType, startDate, expireDate, useCountLimit, isRound, weekRound,
|
const { name, authUid, uid, keyId, openMode, keyType, startDate, expireDate, useCountLimit, isRound, weekRound,
|
||||||
startHour, startMin, endHour, endMin, role, password, publicKey, commKey } = data
|
startHour, startMin, endHour, endMin, role, password } = data
|
||||||
const length = 2 + 40 + 20 + 40 + 20 + 1 + 1 + 4 + 4 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 20 + 4 + 1 + 16
|
const length = 2 + 40 + 20 + 40 + 20 + 1 + 1 + 4 + 4 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 20 + 4 + 1 + 16
|
||||||
const headArray = this.createPackageHeader(3, length)
|
const headArray = this.createPackageHeader(3, length)
|
||||||
const conentArray = new Uint8Array(length)
|
const conentArray = new Uint8Array(length)
|
||||||
@ -825,7 +855,7 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
|
|
||||||
conentArray.set(md5Array, 166)
|
conentArray.set(md5Array, 166)
|
||||||
|
|
||||||
const cebArray = sm4.encrypt(conentArray, commKey, { mode: 'ecb', output: 'array' })
|
const cebArray = sm4.encrypt(conentArray, this.currentLockInfo.commKey, { mode: 'ecb', output: 'array' })
|
||||||
|
|
||||||
const packageArray = this.createPackageEnd(headArray, cebArray)
|
const packageArray = this.createPackageEnd(headArray, cebArray)
|
||||||
await this.writeBLECharacteristicValue(packageArray)
|
await this.writeBLECharacteristicValue(packageArray)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export const useUserStore = defineStore('user', {
|
|||||||
this.isLogin = status
|
this.isLogin = status
|
||||||
},
|
},
|
||||||
async login() {
|
async login() {
|
||||||
uni.setStorageSync('token', '3021|MZv7iEf0NwjCPSGx4QWs37zOjeVN3GrSJ2v7D56L7db1fcc5')
|
uni.setStorageSync('token', '3023|pZ1aoVlMKJBTBTGWlsZPpbLvxc8txcHbrJx2ljrf49c7efe0')
|
||||||
const { code, data } = await getUserInfoRequest()
|
const { code, data } = await getUserInfoRequest()
|
||||||
await useLockStore().getLockList({
|
await useLockStore().getLockList({
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
|
|||||||
@ -74,6 +74,7 @@ const request = (config) => {
|
|||||||
code: res?.data?.errorCode,
|
code: res?.data?.errorCode,
|
||||||
res: res?.data?.data,
|
res: res?.data?.data,
|
||||||
token: header?.authorization || '',
|
token: header?.authorization || '',
|
||||||
|
message: res?.data?.errorMsg,
|
||||||
duration: new Date().getTime() - timestamp
|
duration: new Date().getTime() - timestamp
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user