diff --git a/manifest.json b/manifest.json index a223d22..f72a8c5 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "appid" : "__UNI__933D519", "description" : "", "versionName" : "1.0.0", - "versionCode" : "2", + "versionCode" : "7", "transformPx" : false, /* 小程序特有相关 */ "mp-weixin" : { diff --git a/pages/bindLock/bindLock.vue b/pages/bindLock/bindLock.vue index df25b3a..9aa85ee 100644 --- a/pages/bindLock/bindLock.vue +++ b/pages/bindLock/bindLock.vue @@ -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({ diff --git a/pages/home/home.vue b/pages/home/home.vue index 627264a..b8ec76c 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -22,12 +22,10 @@ {{group.groupName}} - + + lockIndex) in group.lockList" :key="lock.lockId" :threshold="50" @click="deleteLock(lock, + grounIndex, lockIndex)"> @@ -50,7 +48,8 @@ {{ getTimeLimit(lock.keyType) }} @@ -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; diff --git a/pages/keyList/keyList.vue b/pages/keyList/keyList.vue index 11a07a5..4aa2274 100644 --- a/pages/keyList/keyList.vue +++ b/pages/keyList/keyList.vue @@ -18,7 +18,8 @@ - + {{ key.keyName }} @@ -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; diff --git a/pages/lockDetail/lockDetail.vue b/pages/lockDetail/lockDetail.vue index d4befbc..901c600 100644 --- a/pages/lockDetail/lockDetail.vue +++ b/pages/lockDetail/lockDetail.vue @@ -51,6 +51,17 @@ 设置 + + + + + {{ currentLockInfo.lockAlias }} + {{ timeFormat('', 'mm/dd h:M') }} + + + @@ -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 {