feat: 消息通知相关页面
This commit is contained in:
parent
6c19cbc0e0
commit
fcf3297f5d
39
api/notification.js
Normal file
39
api/notification.js
Normal file
@ -0,0 +1,39 @@
|
||||
import request from '../utils/request'
|
||||
|
||||
// Notification 通知模块
|
||||
|
||||
// 获取通知列表
|
||||
export function getNotificationList(data) {
|
||||
return request({
|
||||
url: '/notifications/list',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 标记消息为已读
|
||||
export function markAsReadNotification(data) {
|
||||
return request({
|
||||
url: '/notifications/markAsRead',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除所有通知
|
||||
export function deleteAllNotification(data) {
|
||||
return request({
|
||||
url: '/notifications/deleteAll',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除通知
|
||||
export function deleteNotification(data) {
|
||||
return request({
|
||||
url: '/notifications/delete',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
"name" : "wx-starlock",
|
||||
"appid" : "__UNI__933D519",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.2",
|
||||
"versionCode" : "22",
|
||||
"versionName" : "1.1.0",
|
||||
"versionCode" : "23",
|
||||
"transformPx" : false,
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
|
||||
18
pages.json
18
pages.json
@ -122,6 +122,18 @@
|
||||
"disableScroll": true,
|
||||
"navigationBarTitleText": "钥匙详情"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/notificationList/notificationList",
|
||||
"style": {
|
||||
"navigationBarTitleText": "通知列表"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/notificationDetail/notificationDetail",
|
||||
"style": {
|
||||
"navigationBarTitleText": "消息详情"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
@ -144,6 +156,12 @@
|
||||
"selectedIconPath": "static/images/tabbar_key_select.png",
|
||||
"text": "设备"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/notificationList/notificationList",
|
||||
"iconPath": "static/images/tabbar_notification_no_select.png",
|
||||
"selectedIconPath": "static/images/tabbar_notification_select.png",
|
||||
"text": "消息"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/mine/mine",
|
||||
"iconPath": "static/images/tabbar_mine_no_select.png",
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
...mapState(useLockStore, ['lockList', 'lockTotal', 'lockSearch']),
|
||||
...mapState(useBluetoothStore, ['bluetoothStatus', 'isInitBluetooth', 'keyId', 'currentLockInfo']),
|
||||
},
|
||||
async onLoad() {
|
||||
async onLoad(data) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
@ -158,6 +158,8 @@
|
||||
this.penging = false
|
||||
uni.hideLoading()
|
||||
}
|
||||
const _data = JSON.parse(JSON.stringify(data))
|
||||
this.shareJump(_data)
|
||||
},
|
||||
methods: {
|
||||
timeFormat,
|
||||
@ -165,7 +167,7 @@
|
||||
...mapActions(useLockStore, ['getLockList', 'updateLockList', 'getRole', 'getTimeLimit', 'updateLockSearch', 'getPowerIcon']),
|
||||
...mapActions(useBluetoothStore, ['getBluetoothStatus', 'initAndListenBluetooth', 'updateCurrentLockInfo',
|
||||
'checkSetting', 'updateKeyId', 'resetDevice']),
|
||||
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo', 'getNetworkType']),
|
||||
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo', 'getNetworkType', 'shareJump']),
|
||||
async deleteLock(lock, groupIndex, lockIndex) {
|
||||
const that = this
|
||||
const netWork = await this.getNetworkType()
|
||||
|
||||
56
pages/notificationDetail/notificationDetail.vue
Normal file
56
pages/notificationDetail/notificationDetail.vue
Normal file
@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<view v-if="notification">
|
||||
<view class="time">创建时间:{{ timeFormat(notification.createdAt, 'yyyy-mm-dd h:M') }}</view>
|
||||
<view class="content">{{notification.data}}</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { timeFormat } from 'uview-plus'
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
notification: null
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
this.notification = JSON.parse(options.notification)
|
||||
console.log(this.notification)
|
||||
},
|
||||
methods: {
|
||||
timeFormat,
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
background-color: $uni-bg-color-grey;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.time {
|
||||
margin-top: 24rpx;
|
||||
margin-left: 25rpx;
|
||||
color: #6c6c6c;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.content {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #6c6c6c;
|
||||
width: 652rpx;
|
||||
margin-left: 25rpx;
|
||||
margin-top: 20rpx;
|
||||
border-radius: 24rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 24rpx;
|
||||
box-shadow: 2rpx 2rpx 10rpx rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
</style>
|
||||
311
pages/notificationList/notificationList.vue
Normal file
311
pages/notificationList/notificationList.vue
Normal file
@ -0,0 +1,311 @@
|
||||
<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">
|
||||
<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>
|
||||
<view class="empty-list-text">暂无数据</view>
|
||||
</view>
|
||||
<up-swipe-action v-else>
|
||||
<up-swipe-action-item class="item" ref="swipeItem" :options="options"
|
||||
v-for="(notification,index) in notificationList" :key="notification.id"
|
||||
:threshold="50" @click="deleteNotification(notification, index)">
|
||||
<view class="notification" @click="toDetail(index,notification)">
|
||||
<view v-if="notification.readAt === 0">
|
||||
<image class="icon" src="/static/images/icon_notification_unread.png" mode="aspectFill"></image>
|
||||
<view class="point"></view>
|
||||
</view>
|
||||
<image v-else class="icon" src="/static/images/icon_notification_read.png" mode="aspectFill"></image>
|
||||
<view>
|
||||
<view class="content" :style="{color:notification.readAt === 0?'#000000':'#6c6c6c'}">{{ notification.data
|
||||
}}</view>
|
||||
<view class="time" :style="{color:notification.readAt === 0?'#000000':'#6c6c6c'}">{{ timeFormat(notification.createdAt, 'yyyy-mm-dd h:M') }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions, mapState } from 'pinia'
|
||||
import { useNotificationStore } from '../../stores/notification'
|
||||
import { useBasicStore } from '../../stores/basic'
|
||||
import { timeFormat } from 'uview-plus'
|
||||
import { deleteAllNotification, deleteNotification, markAsReadNotification } from '../../api/notification'
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
refresherTriggered: false,
|
||||
requestFinished: false,
|
||||
deviceInfo: null,
|
||||
options: [{
|
||||
text: '删除',
|
||||
style: {
|
||||
backgroundColor: '#f56c6c'
|
||||
}
|
||||
}],
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(useNotificationStore, ['notificationTotal', 'notificationList', 'notificationSearch']),
|
||||
},
|
||||
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'
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
timeFormat,
|
||||
...mapActions(useNotificationStore, ['getNotificationList', 'updateNotificationSearch', 'updateNotificationItem','deleteNotificationItem']),
|
||||
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo', 'getNetworkType']),
|
||||
async deleteNotification (notification, index) {
|
||||
const netWork = await this.getNetworkType()
|
||||
if (!netWork) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$refs.swipeItem[index].closeHandler()
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该通知吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const { code, message } = await deleteNotification({
|
||||
id: notification.id
|
||||
})
|
||||
if (code === 0) {
|
||||
this.deleteNotificationItem(index)
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'none'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
deleteAllNotification() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除所有通知吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const { code, message } = await deleteAllNotification()
|
||||
if (code === 0) {
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'none'
|
||||
})
|
||||
this.updateNotificationSearch({
|
||||
pageNo: 1
|
||||
})
|
||||
await this.getNotificationList(this.notificationSearch)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
toDetail(index, notification) {
|
||||
if(notification.readAt === 0) {
|
||||
notification.readAt = 1
|
||||
this.updateNotificationItem(index,notification)
|
||||
markAsReadNotification({
|
||||
id: notification.id
|
||||
})
|
||||
}
|
||||
this.routeJump({
|
||||
name: 'notificationDetail',
|
||||
params: {
|
||||
notification: JSON.stringify(notification)
|
||||
}
|
||||
})
|
||||
},
|
||||
async refresherList() {
|
||||
this.refresherTriggered = true
|
||||
this.updateNotificationSearch({
|
||||
pageNo: 1
|
||||
})
|
||||
const { code, message } = await this.getNotificationList(this.notificationSearch)
|
||||
if(code === 0) {
|
||||
uni.showToast({
|
||||
title: '刷新成功',
|
||||
icon: 'none'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
this.refresherTriggered = false
|
||||
},
|
||||
async nextPage() {
|
||||
if(this.notificationTotal <= this.notificationSearch.pageNo * this.notificationSearch.pageSize) {
|
||||
return
|
||||
}
|
||||
const pageNo = this.notificationSearch.pageNo + 1
|
||||
const params = {
|
||||
...this.notificationSearch,
|
||||
pageNo
|
||||
}
|
||||
const { code, message } = await this.getNotificationList(params)
|
||||
if(code === 0) {
|
||||
this.updateNotificationSearch({
|
||||
pageNo
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
background-color: $uni-bg-color-grey;
|
||||
}
|
||||
|
||||
.u-swipe-action {
|
||||
overflow: inherit !important;
|
||||
width: 700rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
padding-bottom: 140rpx !important;
|
||||
}
|
||||
|
||||
.u-swipe-action-item {
|
||||
overflow: inherit !important;
|
||||
border-radius: 32rpx !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.u-swipe-action-item__right {
|
||||
margin-top: 32rpx;
|
||||
border-radius: 32rpx !important;
|
||||
}
|
||||
|
||||
.u-swipe-action-item__content {
|
||||
border-radius: 32rpx !important;
|
||||
margin-left: 25rpx;
|
||||
}
|
||||
|
||||
.u-swipe-action-item__right__button {
|
||||
border-radius: 32rpx !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.item {
|
||||
border-radius: 32rpx;
|
||||
}
|
||||
|
||||
.notification {
|
||||
border-radius: 32rpx;
|
||||
margin-top: 32rpx;
|
||||
display: flex;
|
||||
width: 636rpx;
|
||||
padding: 32rpx;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
box-shadow: 2rpx 2rpx 10rpx rgba(0, 0, 0, 0.3);
|
||||
|
||||
.icon {
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
}
|
||||
|
||||
.point {
|
||||
width: 16rpx;
|
||||
height: 16rpx;
|
||||
background-color: #ff0000;
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
top: 41rpx;
|
||||
left: 72rpx;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 550rpx;
|
||||
font-size: 28rpx;
|
||||
color: #6c6c6c;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 24rpx;
|
||||
color: #6c6c6c;
|
||||
margin-top: 5rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.delete {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
background-color: #5db5aa;
|
||||
position: fixed;
|
||||
bottom: 80rpx;
|
||||
right: 30rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.delete-image {
|
||||
width: 45rpx;
|
||||
height: 45rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-list {
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
margin: 400rpx auto 20rpx 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.empty-list-text {
|
||||
text-align: center;
|
||||
font-size: 32rpx;
|
||||
color: #999999;
|
||||
}
|
||||
</style>
|
||||
BIN
static/images/icon_delete.png
Normal file
BIN
static/images/icon_delete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
static/images/icon_notification_read.png
Executable file
BIN
static/images/icon_notification_read.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
static/images/icon_notification_unread.png
Executable file
BIN
static/images/icon_notification_unread.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
static/images/tabbar_notification_no_select.png
Normal file
BIN
static/images/tabbar_notification_no_select.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
static/images/tabbar_notification_select.png
Normal file
BIN
static/images/tabbar_notification_select.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@ -96,6 +96,16 @@ const pages = [
|
||||
name: 'keyDetail',
|
||||
path: '/pages/keyDetail/keyDetail',
|
||||
tabBar: false
|
||||
},
|
||||
{
|
||||
name: 'notificationList',
|
||||
path: '/pages/notificationList/notificationList',
|
||||
tabBar: true
|
||||
},
|
||||
{
|
||||
name: 'notificationDetail',
|
||||
path: '/pages/notificationDetail/notificationDetail',
|
||||
tabBar: false
|
||||
}
|
||||
]
|
||||
|
||||
@ -106,7 +116,9 @@ export const useBasicStore = defineStore('basic', {
|
||||
// 设备信息
|
||||
deviceInfo: null,
|
||||
// 胶囊按钮的位置信息
|
||||
buttonInfo: null
|
||||
buttonInfo: null,
|
||||
// 分享配置
|
||||
shareConfig: {}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@ -207,6 +219,47 @@ export const useBasicStore = defineStore('basic', {
|
||||
}, 300)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
// 分享跳转
|
||||
shareJump(data = this.shareConfig) {
|
||||
if (data.path) {
|
||||
const target = data.path.split('/')
|
||||
if (target.length > 1) {
|
||||
data.path = data.path.slice(target[0].length + 1, data.path.length)
|
||||
} else {
|
||||
delete data.path
|
||||
}
|
||||
const page = pages.find((page) => {
|
||||
return page.name === target[0]
|
||||
})
|
||||
if (page) {
|
||||
if (page.tabBar) {
|
||||
wx.switchTab({
|
||||
url: page.path
|
||||
})
|
||||
} else {
|
||||
const url = page.path + '?' + getParams(data)
|
||||
wx.navigateTo({ url })
|
||||
}
|
||||
} else {
|
||||
delete data.path
|
||||
}
|
||||
} else {
|
||||
delete data.path
|
||||
}
|
||||
this.shareConfig = data
|
||||
|
||||
function getParams(params) {
|
||||
let paramStr = ''
|
||||
Object.keys(params).forEach((item) => {
|
||||
if (paramStr === '') {
|
||||
paramStr = `${item}=${params[item]}`
|
||||
} else {
|
||||
paramStr = `${paramStr}&${item}=${params[item]}`
|
||||
}
|
||||
})
|
||||
return paramStr
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
47
stores/notification.js
Normal file
47
stores/notification.js
Normal file
@ -0,0 +1,47 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { getNotificationList } from '../api/notification'
|
||||
|
||||
export const useNotificationStore = defineStore('notification', {
|
||||
state() {
|
||||
return {
|
||||
// 通知列表
|
||||
notificationList: [],
|
||||
// 通知总数
|
||||
notificationTotal: 0,
|
||||
// 通知列表搜索数据
|
||||
notificationSearch: {
|
||||
pageNo: 1,
|
||||
pageSize: 50,
|
||||
},
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 删除通知列表某一项数据
|
||||
deleteNotificationItem (index) {
|
||||
this.notificationList.splice(index, 1)
|
||||
},
|
||||
// 更新某一项通知列表数据
|
||||
updateNotificationItem (index, params) {
|
||||
this.notificationList[index] = { ...this.notificationList[index], ...params }
|
||||
},
|
||||
// 更新通知列表搜索数据
|
||||
updateNotificationSearch (params) {
|
||||
this.notificationSearch = { ...this.notificationSearch, ...params }
|
||||
},
|
||||
// 获取通知列表
|
||||
async getNotificationList (params) {
|
||||
const { code, data, message } = await getNotificationList({ pageNo: params.pageNo, pageSize: params.pageSize })
|
||||
if(code === 0) {
|
||||
this.notificationTotal = data.total
|
||||
if(params.pageNo === 1) {
|
||||
this.notificationList = data.list
|
||||
} else {
|
||||
this.notificationList = this.notificationList.concat(data.list)
|
||||
}
|
||||
return { code }
|
||||
} else {
|
||||
return { code, message }
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user