Merge branch 'fanpeng' into 'master'

1. 在部分蓝牙操作后断开蓝牙连接

See merge request StarlockTeam/wx-starlock!6
This commit is contained in:
范鹏 2024-09-06 06:22:06 +00:00
commit 99d98cd08d
21 changed files with 338 additions and 111 deletions

View File

@ -3,7 +3,7 @@
"appid" : "__UNI__933D519",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "2",
"versionCode" : "7",
"transformPx" : false,
/* */
"mp-weixin" : {

View File

@ -33,7 +33,8 @@ export default {
console.log(this.name)
},
methods: {
...mapActions(useBluetoothStore, ['addLockUser']),
...mapActions(useBluetoothStore, ['addLockUser', 'closeBluetoothConnection', 'updateBindedDeviceName',
'closeAllBluetooth', 'initAndListenBluetooth']),
...mapActions(useLockStore, ['getLockList', 'updateLockSearch']),
...mapActions(useBasicStore, ['backAndToast']),
uopdateName(data) {
@ -73,6 +74,10 @@ export default {
password
})
if(addUserCode === 0) {
this.closeBluetoothConnection()
this.updateBindedDeviceName(this.currentLockInfo.name)
this.closeAllBluetooth()
this.initAndListenBluetooth()
} else if(addUserCode === -1) {
uni.hideLoading()
this.backAndToast('添加失败,请重试')
@ -120,8 +125,10 @@ export default {
pageNo: 1
})
this.getLockList(this.lockSearch)
uni.hideLoading()
this.backAndToast('添加成功')
setTimeout(() => {
uni.hideLoading()
this.backAndToast('添加成功')
}, 1000)
} else {
uni.hideLoading()
uni.showToast({

View File

@ -22,12 +22,10 @@
<view class="group-name-text">{{group.groupName}}</view>
<view class="group-name-line"></view>
</view>
<up-swipe-action class="lock">
<up-swipe-action>
<up-swipe-action-item class="lock" :ref="'swipeItem' + grounIndex" :options="options" v-for="(lock,
lockIndex)
in
group.lockList"
:key="lock.lockId" :threshold="50" @click="deleteLock(lock, grounIndex, lockIndex)">
lockIndex) in group.lockList" :key="lock.lockId" :threshold="50" @click="deleteLock(lock,
grounIndex, lockIndex)">
<view class="lock" @click="toLockDeatil(lock)">
<view class="lock-top">
<image class="lock-image-lock" src="/static/images/icon_lock.png"></image>
@ -50,7 +48,8 @@
</view>
</view>
<view class="lock-time"
:style="{padding: lock.keyStatus === 110401 && !lock.days ? '12rpx 24rpx 0 24rpx'
:style="{padding: lock.keyStatus === 110401 && !lock.days &&
lock.lockSetting.remoteUnlock === 0 ? '12rpx 24rpx 0 24rpx'
:'6rpx 24rpx 0 24rpx'}">
<view v-if="lock.keyType === 1 || lock.keyType === 3" style="font-size: 32rpx">{{
getTimeLimit(lock.keyType) }}</view>
@ -129,25 +128,39 @@
mask: true
})
const accountInfo = uni.getAccountInfoSync()
console.log(accountInfo)
getApp().globalData.appid = accountInfo.miniProgram.appId
getApp().globalData.envVersion = accountInfo.miniProgram.envVersion
this.deviceInfo = await this.getDeviceInfo()
const token = uni.getStorageSync('token')
if(token) {
this.getLockList(this.lockSearch)
await this.getUserInfo()
await Promise.all([
this.getLockList(this.lockSearch),
this.getUserInfo()
]).then((res) => {
this.penging = false
uni.hideLoading()
const list = uni.getStorageSync('lockList')
const userInfo = uni.getStorageSync('userInfo')
if(res[0].code === -1 && res[1] === -1 && list && userInfo) {
uni.showToast({
title: '网络访问失败,请检查网络是否正常',
icon: 'none'
})
this.updateLockList(list)
this.updateUserInfo(userInfo)
this.updateLoginStatus(true)
}
})
} else {
await this.homeLogin()
this.penging = false
uni.hideLoading()
}
this.penging = false
uni.hideLoading()
},
methods: {
timeFormat,
...mapActions(useUserStore, ['updateUserInfo', 'updateLoginStatus', 'phoneLogin', 'getUserInfo']),
...mapActions(useLockStore, ['getLockList', 'getRole', 'getTimeLimit', 'updateLockSearch', 'getPowerIcon']),
...mapActions(useLockStore, ['getLockList', 'updateLockList', 'getRole', 'getTimeLimit', 'updateLockSearch', 'getPowerIcon']),
...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo',
'checkSetting', 'updateKeyId', 'resetDevice']),
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
@ -186,7 +199,7 @@
authUid: that.userInfo.uid.toString(),
keyId: that.keyId.toString()
})
if(resetDeviceCode === 0) {
if(resetDeviceCode === 0 || resetDeviceCode === -2) {
const { code, message } = await deleteLockRequest({
lockId: that.currentLockInfo.lockId
})
@ -208,14 +221,12 @@
icon: 'none'
})
}
} else if(code === -1) {
} else if(resetDeviceCode === -1) {
uni.hideLoading()
uni.showToast({
title: '删除失败,请保持在锁附近',
icon: 'none'
})
} else {
uni.hideLoading()
}
} else {
const { code } = await deleteKeyRequest({
@ -343,21 +354,33 @@
}
const { code } = await this.getLockList(search)
if(code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
this.updateLockSearch(search)
}
}
},
async refresherList() {
this.refresherTriggered = true
this.getUserInfo()
this.updateLockSearch({
...this.lockSearch,
pageNo: 1
})
await this.getLockList(this.lockSearch)
uni.showToast({
title: '刷新成功',
icon: 'none'
})
const { code, message } = await this.getLockList(this.lockSearch)
if(code === 0) {
uni.showToast({
title: '刷新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
this.refresherTriggered = false
},
async changeSearch(data) {
@ -391,7 +414,7 @@
}
},
async toLockDeatil(lock) {
if(this.bluetoothStatus !== 0) {
if(!(this.bluetoothStatus === 0 || this.bluetoothStatus === -1)) {
this.getBluetoothStatus()
return
}
@ -442,6 +465,11 @@ page {
.u-swipe-action {
overflow: inherit !important;
padding-bottom: 32rpx;
width: 672rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.u-swipe-action-item {
@ -607,6 +635,7 @@ page {
}
.lock-status {
margin-top: 5rpx;
margin-left: 24rpx;
color: #FFFFFF;
border-radius: 8rpx;

View File

@ -18,7 +18,8 @@
<up-swipe-action-item ref="swipeItem" :options="options" v-for="(key, index) in keyList"
:key="key.keyboardPwdId" :threshold="50" @click="deleteKey(key)">
<view class="key" @click="toKeyDetail(key)">
<image class="key-left" :src="key.headUrl" mode="aspectFill"></image>
<image class="key-left" :src="key.headUrl === '' ? '/static/images/icon_user.png' : key.headUrl"
mode="aspectFill"></image>
<view class="key-right">
<view style="display: flex;">
<view class="key-right-top">{{ key.keyName }}</view>
@ -95,13 +96,22 @@ export default {
...this.keySearch,
lockId: this.currentLockInfo.lockId
})
const { code, meesage } = await this.getKeyList(this.keySearch)
this.requestFinished = true
const { code, message } = await this.getKeyList(this.keySearch)
uni.hideLoading()
this.requestFinished = true
if(code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
}
},
onUnload() {
this.clearList('key')
},
methods: {
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
...mapActions(useLockStore, ['getKeyList', 'updateCurrentKeyInfo', 'updateKeySearch', 'getKeyStatus']),
...mapActions(useLockStore, ['getKeyList', 'updateCurrentKeyInfo', 'updateKeySearch', 'getKeyStatus', 'clearList']),
changeRadio() {
this.checked = !this.checked
},
@ -238,12 +248,17 @@ export default {
...this.keySearch,
pageNo: 1
})
const { code, meesage } = await this.getKeyList(this.keySearch)
const { code, message } = await this.getKeyList(this.keySearch)
if(code === 0) {
uni.showToast({
title: '刷新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
this.refresherTriggered = false
},
@ -256,12 +271,17 @@ export default {
...this.keySearch,
pageNo
}
const { code, meesage } = await this.getKeyList(params)
const { code, message } = await this.getKeyList(params)
if(code === 0) {
this.updateKeySearch({
...this.keySearch,
pageNo
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
},
async changeSearch(data) {
@ -269,7 +289,13 @@ export default {
...this.keySearch,
searchStr: data
})
const { code, meesage } = await this.getKeyList(this.keySearch)
const { code, message } = await this.getKeyList(this.keySearch)
if(code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
}
},
},
}
@ -338,7 +364,7 @@ page {
width: 574rpx;
.key-right-top {
max-width: 450rpx;
max-width: 400rpx;
font-size: 32rpx;
font-weight: bold;
padding-bottom: 6rpx;

View File

@ -51,6 +51,17 @@
<view class="setting-text">设置</view>
<image class="setting-arrow" mode="aspectFill" src="/static/images/icon_arrow.png"></image>
</view>
<up-popup :show="show" @close="closePopup" mode="center" :closeOnClickOverlay="true" bgColor="transparent">
<view class="popup" @click="closePopup">
<image class="popup-background" :src="type === 'close' ? '/static/images/background_close_door.png' :
'/static/images/background_open_door.png'"
mode="aspectFill"></image>
<view>
<view class="popup-name">{{ currentLockInfo.lockAlias }}</view>
<view class="popup-time">{{ timeFormat('', 'mm/dd h:M') }}</view>
</view>
</view>
</up-popup>
</view>
</template>
@ -70,7 +81,9 @@ export default {
return {
time: 0,
onlineToken: '0',
pending: false
pending: false,
show: false,
type: ''
}
},
computed: {
@ -85,9 +98,13 @@ export default {
this.getServeTime()
},
methods: {
timeFormat,
...mapActions(useLockStore, ['getRole', 'updateLockSearch', 'getLockList', 'getPowerIcon']),
...mapActions(useBluetoothStore, ['openDoor', 'updateServerTimestamp']),
...mapActions(useBasicStore, ['routeJump', 'backAndToast']),
...mapActions(useBluetoothStore, ['openDoor', 'updateServerTimestamp', 'closeBluetoothConnection']),
...mapActions(useBasicStore, ['routeJump', 'backAndToast', 'getNetworkType']),
closePopup() {
this.show = false
},
powerTip() {
const that = this
const time = timeFormat(that.currentLockInfo.electricQuantityDate, 'yyyy-mm-dd h:M')
@ -123,13 +140,25 @@ export default {
if(this.pending) {
return
}
if(this.currentLockInfo.lockSetting.appUnlockOnline) {
const netWork = await this.getNetworkType()
if(!netWork) {
uni.showToast({
title: '网络访问失败,请检查网络是否正常',
icon: 'none'
})
return
}
}
uni.vibrateLong()
this.pending = true
this.$refs.loading.open()
uni.showToast({
title: `正在尝试${type === 'close' ? '关' : '开'}锁……`,
icon: 'none'
})
if(type === 'close') {
uni.showToast({
title: `正在尝试闭锁……`,
icon: 'none'
})
}
if(this.currentLockInfo.lockSetting.appUnlockOnline) {
const result = await this.getNetToken()
if(!result) {
@ -151,11 +180,13 @@ export default {
openTime: parseInt(new Date().getTime() / 1000) + this.time,
onlineToken: this.onlineToken
})
this.closeBluetoothConnection()
if(code === 0) {
uni.showToast({
title: `${type === 'close' ? '关' : '开'}锁成功`,
icon: 'none'
})
this.show = true
this.type = type
setTimeout(() => {
this.show = false
}, 3000)
if(this.currentLockInfo.keyType === 3) {
const { code: deleteKeyCode } = await deleteKeyRequest({
keyId: this.keyId
@ -188,6 +219,45 @@ export default {
</script>
<style lang="scss" scoped>
.popup {
display: flex;
position: relative;
width: 400rpx;
height: 389rpx;
text-align: center;
flex-wrap: wrap;
.popup-background {
z-index: -1;
width: 400rpx;
height: 389rpx;
position: absolute;
}
.popup-name {
margin-left: 30rpx;
z-index: 9;
margin-top: 180rpx;
color: #676b6d;
width: 340rpx;
max-height: 80rpx;
line-height: 40rpx;
word-break: break-all;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
white-space: normal;
}
.popup-time {
margin-top: 10rpx;
width: 400rpx;
}
}
.days {
line-height: 60rpx;
background: #faecc9;

View File

@ -102,6 +102,8 @@
uni.setStorageSync('envVersion', env.key)
uni.removeStorageSync('token')
uni.removeStorageSync('openid')
uni.removeStorageSync('userInfo')
uni.removeStorageSync('lockList')
uni.reLaunch({
url: '/pages/home/home'
})
@ -126,6 +128,8 @@
openid
})
if(code === 0) {
uni.removeStorageSync('userInfo')
uni.removeStorageSync('lockList')
uni.setStorageSync('token', data.accessToken)
this.updateLockSearch({
...this.lockSearch,

View File

@ -52,7 +52,7 @@ export default {
},
methods: {
timeFormat,
...mapActions(useBluetoothStore, ['setLockPassword']),
...mapActions(useBluetoothStore, ['setLockPassword', 'closeBluetoothConnection']),
...mapActions(useLockStore, ['updatePasswordSearch', 'getPasswordList']),
...mapActions(useBasicStore, ['backAndToast']),
async deletePassword () {
@ -78,6 +78,7 @@ export default {
startTime: timestamp,
endTime: timestamp
})
that.closeBluetoothConnection()
if(code === 0) {
const { code: requestCode, message } = await deletePsaawordRequest({
lockId: that.currentLockInfo.lockId,
@ -105,8 +106,6 @@ export default {
title: '删除失败,请保持在锁附近',
icon: 'none'
})
} else {
uni.hideLoading()
}
}
}

View File

@ -18,7 +18,7 @@
<up-swipe-action-item ref="swipeItem" :options="options" v-for="(password, index) in passwordList"
:key="password.keyboardPwdId" :threshold="50" @click="deletePassword(password)">
<view class="password" @click="toPasswordDetail(password)">
<image class="password-left" src="/static/images/icon_lock_transparent.png" mode="aspectFill"></image>
<image class="password-left" src="/static/images/icon_password.png" mode="aspectFill"></image>
<view class="password-right">
<view style="display: flex; align-items: center">
<view class="password-right-top">{{ password.keyboardPwdName }}</view>
@ -80,14 +80,23 @@ export default {
lockId: this.currentLockInfo.lockId,
lockStatus: this.currentLockInfo.lockStatus
})
const { code, meesage } = await this.getPasswordList(this.passwordSearch)
const { code, message } = await this.getPasswordList(this.passwordSearch)
this.requestFinished = true
uni.hideLoading()
if(code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
}
},
onUnload() {
this.clearList('password')
},
methods: {
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
...mapActions(useLockStore, ['getPasswordList', 'updateCurrentPasswordInfo', 'updatePasswordSearch', 'getPasswordStatus']),
...mapActions(useBluetoothStore, ['resetLockPassword', 'setLockPassword']),
...mapActions(useBluetoothStore, ['resetLockPassword', 'setLockPassword', 'closeBluetoothConnection']),
toPasswordDetail(password) {
this.updateCurrentPasswordInfo(password)
this.routeJump({
@ -120,6 +129,7 @@ export default {
startTime: timestamp,
endTime: timestamp
})
that.closeBluetoothConnection()
if(code === 0) {
const { code: requestCode, message } = await deletePsaawordRequest({
lockId: that.currentLockInfo.lockId,
@ -150,8 +160,6 @@ export default {
title: '删除失败,请保持在锁附近',
icon: 'none'
})
} else {
uni.hideLoading()
}
}
}
@ -159,13 +167,6 @@ export default {
},
async resetPassword() {
const that = this
if(this.passwordList.length === 0) {
uni.showToast({
title: '暂无密码,无需重置',
icon: 'none'
})
return
}
uni.showModal({
title: '提示',
content: '确定要重置密码,该锁的所有密码都将被删除',
@ -179,6 +180,7 @@ export default {
uid: that.userInfo.uid.toString(),
keyId: that.currentLockInfo.keyId.toString()
})
that.closeBluetoothConnection()
if(code === 0) {
const { code: requestCode, message } = await resetPsaawordListRequest({
lockId: that.currentLockInfo.lockId,
@ -209,8 +211,6 @@ export default {
title: '重置密码失败,请保持在锁附近',
icon: 'none'
})
} else {
uni.hideLoading()
}
}
}
@ -227,12 +227,17 @@ export default {
...this.passwordSearch,
pageNo: 1
})
const { code, meesage } = await this.getPasswordList(this.passwordSearch)
const { code, message } = await this.getPasswordList(this.passwordSearch)
if(code === 0) {
uni.showToast({
title: '刷新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
this.refresherTriggered = false
},
@ -245,12 +250,17 @@ export default {
...this.passwordSearch,
pageNo
}
const { code, meesage } = await this.getPasswordList(params)
const { code, message } = await this.getPasswordList(params)
if(code === 0) {
that.updatePasswordSearch({
...that.passwordSearch,
pageNo
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
},
async changeSearch(data) {
@ -258,7 +268,13 @@ export default {
...this.passwordSearch,
searchStr: data
})
const { code, meesage } = await this.getPasswordList(this.passwordSearch)
const { code, message } = await this.getPasswordList(this.passwordSearch)
if(code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
}
},
},
}
@ -326,6 +342,7 @@ page {
width: 574rpx;
.password-right-top {
max-width: 400rpx;
font-size: 32rpx;
font-weight: bold;
padding-bottom: 6rpx;

View File

@ -137,6 +137,7 @@ export default {
}
},
fail (res) {
console.log('获取地理位置信息失败', res)
if(res.errMsg === 'getLocation:fail auth deny') {
uni.showModal({
title: '提示',
@ -154,6 +155,23 @@ export default {
}
}
})
} else if(res.errMsg === 'getLocation:fail system permission denied') {
uni.showModal({
title: '提示',
content: '定位失败,请打开微信的位置权限',
confirmText: '去打开',
cancelText: '跳过',
success (res) {
if (res.confirm) {
uni.openAppAuthorizeSetting()
} else {
that.routeJump({
type: 'redirectTo',
name: 'bindLock'
})
}
}
})
} else {
uni.showModal({
title: '提示',

View File

@ -38,16 +38,7 @@
</view>
</view>
</view>
<view class="view" v-if="currentLockInfo.keyType === 2 || currentLockInfo.keyType === 4">
<view v-if="currentLockInfo.keyType === 2">
<view class="view-button">
<view>有效期</view>
<view class="view-button" style="padding: 0">
<view class="info">{{ timeFormat(currentLockInfo.startDate, 'yyyy-mm-dd h:M') }}{{
timeFormat(currentLockInfo.endDate, 'yyyy-mm-dd h:M') }}</view>
</view>
</view>
</view>
<view class="view">
<view v-if="currentLockInfo.keyType === 4">
<view class="view-button">
<view>有效期</view>
@ -71,6 +62,19 @@
</view>
</view>
</view>
<view v-else>
<view class="view-button">
<view>有效期</view>
<view class="view-button" style="padding: 10rpx 0">
<view class="info" v-if="currentLockInfo.keyType === 2" style="line-height: 40rpx">
<view>{{ timeFormat(currentLockInfo.startDate, 'yyyy-mm-dd h:M') }}</view>
<view>{{ timeFormat(currentLockInfo.endDate, 'yyyy-mm-dd h:M') }}</view>
</view>
<view class="info" v-if="currentLockInfo.keyType === 3">单次</view>
<view class="info" v-if="currentLockInfo.keyType === 1">永久</view>
</view>
</view>
</view>
</view>
<view class="button-logout" @click="deleteLock">删除</view>
<up-modal :show="showModal" title="是否删除授权管理员钥匙?" :showCancelButton="true" width="600rpx" @cancel="cancelModal"
@ -200,7 +204,7 @@ export default {
authUid: that.userInfo.uid.toString(),
keyId: that.keyId.toString()
})
if(resetDeviceCode === 0) {
if(resetDeviceCode === 0 || resetDeviceCode === -2) {
const { code, message } = await deleteLockRequest({
lockId: that.currentLockInfo.lockId
})
@ -212,7 +216,6 @@ export default {
})
that.getLockList(that.lockSearch)
that.backAndToast('删除成功', 2)
uni.navigateBack()
} else {
uni.hideLoading()
uni.showToast({
@ -220,14 +223,12 @@ export default {
icon: 'none'
})
}
} else if(code === -1) {
} else if(resetDeviceCode === -1) {
uni.hideLoading()
uni.showToast({
title: '删除失败,请保持在锁附近',
icon: 'none'
})
} else {
uni.hideLoading()
}
} else {
const { code } = await deleteKeyRequest({

View File

@ -81,9 +81,12 @@ export default {
...mapState(useUserStore, ['userInfo'])
},
methods: {
...mapActions(useBasicStore, ['routeJump']),
...mapActions(useBasicStore, ['routeJump', 'getNetworkType']),
...mapActions(useUserStore, ['updateUserInfo', 'checkSession', 'getUserInfo']),
async rebindPhone(detail) {
if(!(detail.detail.encryptedData && detail.detail.iv)) {
return
}
if(detail.detail.errMsg === 'getPhoneNumber:fail user deny') {
return
}
@ -99,10 +102,6 @@ export default {
})
if(code === 0) {
this.getUserInfo()
// this.updateUserInfo({
// ...this.userInfo,
// mobile: data.mobile
// })
uni.showToast({
title: '更换成功',
icon: 'none'
@ -266,9 +265,8 @@ page {
.name-info {
line-height: 40rpx;
font-size: 30rpx;
text-align: right;
width: 500rpx;
width: 520rpx;
overflow: hidden;
word-break: break-all;
margin-right: 20rpx;

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
static/images/icon_password.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
static/images/icon_user.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
static/images/img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -134,6 +134,23 @@ export const useBasicStore = defineStore('basic', {
})
}
},
// 获取当前网络状态
getNetworkType() {
return new Promise((resolve) => {
uni.getNetworkType({
success: function (res) {
if(res.networkType === 'none') {
resolve(false)
return
}
resolve(true)
},
fail: function () {
resolve(false)
}
})
})
},
// 获取设备信息
getDeviceInfo() {
const that = this

View File

@ -71,10 +71,20 @@ export const useBluetoothStore = defineStore('ble', {
// 服务器时间
serverTimestamp: 0,
// 设备keyID
keyId: '0'
keyId: '0',
// 刚绑定的设备名称
bindedDeviceName: ''
}
},
actions: {
// 保存刚绑定的设备名称
updateBindedDeviceName(name) {
this.bindedDeviceName = name
setTimeout(() => {
this.bindedDeviceName = ''
console.log('清空设备名称')
}, 15000)
},
// 更新keyId
updateKeyId(keyId) {
this.keyId = keyId
@ -97,6 +107,15 @@ export const useBluetoothStore = defineStore('ble', {
}
return { code, data, message }
},
// 关闭全部蓝牙监听并关闭蓝牙模拟
closeAllBluetooth() {
uni.offBluetoothAdapterStateChange()
uni.closeBluetoothAdapter({
success(res) {
console.log('关闭蓝牙模块', res)
}
})
},
// 初始化并监听
async initAndListenBluetooth(tipFlag) {
// 初始化蓝牙
@ -590,7 +609,7 @@ export const useBluetoothStore = defineStore('ble', {
})
},
// 连接蓝牙设备+获取设备服务+获取设备特征值
connectBluetoothDevice() {
connectBluetoothDevice(number = 0) {
const that = this
return new Promise((resolve) => {
if(that.bluetoothStatus !== 0) {
@ -662,11 +681,15 @@ export const useBluetoothStore = defineStore('ble', {
}
})
},
fail(res) {
async fail(res) {
if(res.errno === 1509007) {
resolve(true)
return
}
if(res.errno === 1509001 && number < 1) {
// 重新连接
resolve(await that.connectBluetoothDevice(number + 1))
}
uni.showToast({
title: '连接失败,请靠近设备并保持设备处于唤醒状态',
icon: 'none'
@ -733,7 +756,7 @@ export const useBluetoothStore = defineStore('ble', {
let timer2
return new Promise((resolve) => {
uni.startBluetoothDevicesDiscovery({
success: function (res) {
success: function () {
timer2 = setTimeout(() => {
uni.stopBluetoothDevicesDiscovery()
clearInterval(timer1)
@ -746,7 +769,8 @@ export const useBluetoothStore = defineStore('ble', {
for(let i = 0; i < deviceList.length; i++) {
if(deviceList[i]?.name === that.currentLockInfo.name) {
const uuid = deviceList[i]?.advertisServiceUUIDs[0]
if(uuid && uuid.slice(2,8)==='758824' && uuid.slice(30,32)==='01') {
console.log('设备UUID', uuid, uuid.slice(2,8), uuid.slice(30,32))
if(uuid && uuid.slice(2,8)==='758824' && (uuid.slice(30,32)==='01' || that.bindedDeviceName === that.currentLockInfo.name)) {
uni.stopBluetoothDevicesDiscovery()
clearTimeout(timer2)
clearInterval(timer1)
@ -761,6 +785,7 @@ export const useBluetoothStore = defineStore('ble', {
uni.stopBluetoothDevicesDiscovery()
clearTimeout(timer2)
clearInterval(timer1)
uni.hideLoading()
uni.showToast({
title: '锁已被重置,请重新绑定',
icon: 'none'
@ -769,6 +794,14 @@ export const useBluetoothStore = defineStore('ble', {
code: -2
})
break
} else {
uni.stopBluetoothDevicesDiscovery()
clearTimeout(timer2)
clearInterval(timer1)
resolve({
code: -3
})
break
}
}
}

View File

@ -51,6 +51,14 @@ export const useLockStore = defineStore('lock', {
}
},
actions: {
// 更新锁列表
updateLockList(list) {
this.lockList = list
},
// 清空列表
clearList(type) {
this[type + 'List'] = []
},
// 获取电量icon
getPowerIcon(power) {
if(power >= 80) {
@ -107,7 +115,7 @@ export const useLockStore = defineStore('lock', {
},
getKeyStatus(keyStatus) {
if(keyStatus === 110401) {
return '正常'
return ''
} else if(keyStatus === 110403) {
return '未生效'
} else if(keyStatus === 110402) {
@ -162,12 +170,9 @@ export const useLockStore = defineStore('lock', {
} else {
this.lockList = this.lockList.concat(data.groupList)
}
uni.setStorageSync('lockList', this.lockList)
return { code }
} else {
uni.showToast({
title: message,
icon: 'none'
})
return { code, message }
}
},
@ -220,10 +225,6 @@ export const useLockStore = defineStore('lock', {
}
return { code }
} else {
uni.showToast({
title: message,
icon: 'none'
})
return { code, message }
}
},
@ -232,7 +233,6 @@ export const useLockStore = defineStore('lock', {
if(code === 0) {
this.keyTotal = data.total
for(let i = 0; i < data.list.length; i++) {
console.log(data.list[i].keyType)
if(data.list[i].keyType === 1) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].sendDate), 'yyyy-mm-dd h:M')} 永久`
} else if(data.list[i].keyType === 2) {
@ -250,10 +250,6 @@ export const useLockStore = defineStore('lock', {
}
return { code }
} else {
uni.showToast({
title: message,
icon: 'none'
})
return { code, message }
}
}

View File

@ -25,6 +25,7 @@ export const useUserStore = defineStore('user', {
async getUserInfo() {
const { code, data } = await getUserInfoRequest()
if(code === 0) {
uni.setStorageSync('userInfo', data)
this.updateUserInfo(data)
this.updateLoginStatus(true)
}

View File

@ -11,6 +11,7 @@ import env from '@/config/env'
* */
const request = (config) => {
let timer
return new Promise((resolve) => {
const baseConfig = env[getApp().globalData.getEnvConfig()]
@ -25,14 +26,20 @@ const request = (config) => {
const header = config.header || headerDefault
const data = config.data || {}
const timestamp = new Date().getTime()
timer = setTimeout(() => {
resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' })
}, 3200)
uni.request({
url: URL,
method,
header,
data,
timeout: 7000,
timeout: 3000,
async success(res) {
const { statusCode, data } = res
if(timer) {
clearTimeout(timer)
}
if (statusCode === 200) {
const code = data.errorCode
const message = data.errorMsg
@ -58,11 +65,15 @@ const request = (config) => {
})
}
} else {
resolve({ code: -1, data, message: '网络不太好哦,请稍后再试' })
resolve({ code: -1, data, message: '网络访问失败,请检查网络是否正常' })
}
},
async fail() {
resolve({ code: -1, data, message: '网络不太好哦,请稍后再试' })
async fail(res) {
console.log('网络访问失败', res)
if(timer) {
clearTimeout(timer)
}
resolve({ code: -1, message: '网络访问失败,请检查网络是否正常' })
},
async complete(res) {
console.log(URL.substring(baseConfig.baseUrl.length + 1), {