YNUtdPlatform/pages/YNEduApp/user/myMsg.vue

161 lines
3.7 KiB
Vue
Raw Normal View History

2024-08-27 13:32:10 +08:00
<template>
<view>
2024-09-02 16:53:22 +08:00
<u-navbar title="消息通知" @leftClick="leftClick" placeholder />
<u-swipe-action class="swipe-wrapper">
<u-swipe-action-item
:options="options"
v-for="(item, index) in msgList"
:key="index"
class="swipe-item"
@click="handleOption(item)"
>
<div class="swipe-action" @click="handleItem(item)">
<div class="action-title">
<div class="tip" v-if="item.isRead == '0'"></div>
<div style="margin-right: 10px; font-size: 16px">{{ item.type == '1' ? '考试通知' : '其他通知' }}</div>
<div style="color: #919ca1">{{ item.updateTime }}</div>
</div>
<div>{{ item.content }}</div>
</div>
</u-swipe-action-item>
</u-swipe-action>
2024-08-27 13:32:10 +08:00
</view>
</template>
<script>
import config from '@/config'
export default {
data() {
return {
userId: uni.getStorageSync('userId'),
2024-08-28 09:51:05 +08:00
token: uni.getStorageSync('access_token'),
2024-09-02 16:53:22 +08:00
options: [
{
text: '删除',
style: {
backgroundColor: '#f56c6c'
}
}
],
2024-08-27 13:32:10 +08:00
// 消息列表
msgList: []
}
},
onLoad() {
2024-08-28 09:51:05 +08:00
this.getMsgList()
2024-08-27 13:32:10 +08:00
},
methods: {
// 获取消息列表
2024-09-02 16:53:22 +08:00
getMsgList() {
2024-09-06 14:53:49 +08:00
this.$verificationToken()
2024-08-27 13:32:10 +08:00
uni.request({
2024-09-02 16:53:22 +08:00
url: config.bmwUrl + '/users/getMsgInform',
method: 'get',
data: {
page: 1,
limit: 999
},
2024-08-27 13:32:10 +08:00
header: {
Authorization: this.token
},
success: res => {
2024-09-02 16:53:22 +08:00
res = res.data
2024-08-27 13:32:10 +08:00
console.log('🚀 ~ getMsgList ~ res:', res)
this.msgList = res.data
console.log('🚀 ~ getMsgList ~ this.msgList:', this.msgList)
}
})
},
2024-09-02 16:53:22 +08:00
// 操作-删除
handleOption(item) {
console.log('🚀 ~ handleOption ~ item:', item)
if (item.isRead == '0') {
this.markRead(item)
}
this.deleteMsg(item)
},
// 点击消息
handleItem(item) {
console.log('🚀 ~ handleItem ~ item:', item)
if (item.isRead == '0') {
this.markRead(item)
2024-08-27 13:32:10 +08:00
}
2024-09-02 16:53:22 +08:00
},
// 标记已读
markRead(item) {
const ids = [item.id]
console.log('🚀 ~ markRead ~ ids:', ids)
2024-09-06 14:53:49 +08:00
this.$verificationToken()
2024-09-02 16:53:22 +08:00
uni.request({
url: config.bmwUrl + '/users/markAsRead',
method: 'post',
data: { ids },
header: {
Authorization: this.token
},
success: res => {
console.log('🚀 ~ markRead ~ res:', res)
this.getMsgList()
}
})
},
// 删除消息
deleteMsg(item) {
const ids = [item.id]
console.log('🚀 ~ deleteMsg ~ ids:', ids)
2024-09-06 14:53:49 +08:00
this.$verificationToken()
2024-09-02 16:53:22 +08:00
uni.request({
url: config.bmwUrl + '/users/batchDelete',
method: 'post',
data: { ids },
header: {
Authorization: this.token
},
success: res => {
console.log('🚀 ~ deleteMsg ~ res:', res)
// 刷新页面
uni.reLaunch({
url: '/pages/YNEduApp/user/myMsg'
})
}
})
},
// 返回
leftClick() {
uni.reLaunch({
url: '/pages/YNEduApp/user/user'
2024-08-27 13:32:10 +08:00
})
}
}
}
</script>
<style lang="scss" scoped>
2024-09-02 16:53:22 +08:00
.swipe-wrapper {
2024-08-27 13:32:10 +08:00
padding: 10px;
2024-09-02 16:53:22 +08:00
.swipe-item {
border-radius: 5px;
margin: 10px 0;
.swipe-action {
padding: 10px;
border-radius: 5px;
word-break: break-all;
.action-title {
display: flex;
align-items: center;
.tip {
margin-right: 3px;
width: 5px;
height: 5px;
background-color: red;
border-radius: 50%;
}
}
}
2024-08-27 13:32:10 +08:00
}
}
</style>