fix: 修复通知列表页面无登录功能的bug

This commit is contained in:
范鹏 2024-10-07 14:16:26 +08:00
parent c340a52c35
commit 6d3274c183
3 changed files with 84 additions and 26 deletions

View File

@ -77,7 +77,7 @@
</view>
</view>
<button open-type="getPhoneNumber" style="display:none" id="phone" @getphonenumber="getphonenumber"></button>
<up-modal :show="showModal" title="是否删除授权管理员钥匙?" :showCancelButton="true" width="600rpx" @cancel="cancelModal"
<up-modal :show="showModal" title="是否删除授权管理员钥匙?" :showCancelButton="true" width="600rpx" @cancel="cancelModal"
@confirm="confirmModal">
<view class="slot-content" @click="changeRadio">
<view style="display: flex;align-items: center;">
@ -622,7 +622,7 @@ page {
.button-add-big {
width: 400rpx;
height: 400rpx;
margin-top: 250rpx;
margin-top: 300rpx;
margin-left: 136rpx;
}

View File

@ -1,8 +1,8 @@
<template>
<view>
<scroll-view v-if="deviceInfo" scroll-y="true" :style="{ height: deviceInfo.windowHeight + 'px' }"
lower-threshold="100" @refresherrefresh="refresherList" :refresher-enabled="true" @scrolltolower="nextPage"
:refresher-triggered="refresherTriggered" @scroll="scroll">
<scroll-view v-if="deviceInfo" scroll-y="true" :style="{ height: deviceInfo.windowHeight + 'px' }"
lower-threshold="100" @refresherrefresh="refresherList" :refresher-enabled="true" @scrolltolower="nextPage"
:refresher-triggered="refresherTriggered" @scroll="scroll">
<view v-if="isLogin">
<view class="list" v-if="requestFinished">
<view v-if="notificationList.length === 0">
<image class="empty-list" src="/static/images/background_empty_list.png" mode="aspectFill"></image>
@ -28,19 +28,28 @@
</up-swipe-action-item>
</up-swipe-action>
</view>
</scroll-view>
<view class="delete" @click="deleteAllNotification">
<image class="delete-image" src="/static/images/icon_delete.png" mode="aspectFill"></image>
</view>
<view v-else>
<view class="tips">因智能门锁与账号绑定登录为手机号登录</view>
<label for="phone">
<view class="button-login">登录</view>
</label>
</view>
</scroll-view>
<view class="delete" @click="deleteAllNotification" v-if="isLogin && requestFinished && notificationList.length !==
0">
<image class="delete-image" src="/static/images/icon_delete.png" mode="aspectFill"></image>
</view>
<button open-type="getPhoneNumber" style="display:none" id="phone" @getphonenumber="getphonenumber"></button>
</template>
<script>
import { mapActions, mapState } from 'pinia'
import { useNotificationStore } from '../../stores/notification'
import { useBasicStore } from '../../stores/basic'
import { useNotificationStore } from '@/stores/notification'
import { useBasicStore } from '@/stores/basic'
import { timeFormat } from 'uview-plus'
import { deleteAllNotification, deleteNotification, markAsReadNotification } from '../../api/notification'
import { deleteAllNotification, deleteNotification, markAsReadNotification } from '@/api/notification'
import { useUserStore } from '@/stores/user'
export default {
data () {
@ -58,28 +67,50 @@ export default {
},
computed: {
...mapState(useNotificationStore, ['notificationTotal', 'notificationList', 'notificationSearch']),
...mapState(useUserStore, ['isLogin']),
},
async onLoad () {
uni.showLoading({
title: '加载中',
mask: true
})
this.deviceInfo = await this.getDeviceInfo()
const { code, message } = await this.getNotificationList(this.notificationSearch)
uni.hideLoading()
this.requestFinished = true
if (code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
if(this.isLogin) {
await this.getList()
}
this.requestFinished = true
},
methods: {
timeFormat,
...mapActions(useNotificationStore, ['getNotificationList', 'updateNotificationSearch', 'updateNotificationItem','deleteNotificationItem']),
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo', 'getNetworkType']),
scroll(e) {
...mapActions(useUserStore, ['phoneLogin']),
async getList() {
uni.showLoading({
title: '加载中',
mask: true
})
const { code, message } = await this.getNotificationList(this.notificationSearch)
uni.hideLoading()
if (code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
}
},
async getphonenumber(data) {
if(data.detail.errMsg === 'getPhoneNumber:fail user deny') {
return
}
const result = await this.phoneLogin({
encryptedData: data.detail.encryptedData,
iv: data.detail.iv
})
if(!result) {
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
})
}
},
scroll() {
this.$refs.swipeItem.forEach(item => {
if(item.show) {
item.closeHandler()
@ -316,4 +347,25 @@ page {
font-size: 32rpx;
color: #999999;
}
.tips {
margin-top: 40vh;
padding: 32rpx 0;
text-align: center;
font-size: 28rpx;
color: #999999;
}
.button-login {
border-radius: 46rpx;
width: 650rpx;
height: 120rpx;
line-height: 120rpx;
text-align: center;
margin-left: 50rpx;
background: #63b8af;
color: #ffffff;
font-size: 48rpx;
font-weight: bold;
}
</style>

View File

@ -5,6 +5,7 @@ import { defineStore } from 'pinia'
import { getUserInfoRequest, loginRequest, phoneLoginRequest } from '@/api/user'
import { useLockStore } from '@/stores/lock'
import { setStorage, getStorage } from '@/utils/storage'
import { useNotificationStore } from '@/stores/notification'
export const useUserStore = defineStore('user', {
state() {
@ -35,7 +36,7 @@ export const useUserStore = defineStore('user', {
async phoneLogin(params) {
const { iv, encryptedData } = params
const openid = getStorage('openid')
const { code, data, message } = await phoneLoginRequest({ iv, encryptedData, openid })
const { code, data } = await phoneLoginRequest({ iv, encryptedData, openid })
if(code === 0) {
setStorage('token', data.accessToken)
this.getUserInfo()
@ -44,6 +45,11 @@ export const useUserStore = defineStore('user', {
pageNo: 1
})
useLockStore().getLockList(useLockStore().lockSearch)
useNotificationStore().updateNotificationSearch({
...useNotificationStore().notificationSearch,
pageNo: 1
})
useNotificationStore().getNotificationList(useNotificationStore().notificationSearch)
return true
} else {
return false