lanan-repair-app/pages-home/msg/message.vue

273 lines
6.6 KiB
Vue
Raw Normal View History

2024-10-24 18:14:26 +08:00
<template>
2025-08-11 17:42:50 +08:00
<view class="container">
<VNavigationBar style="position: relative;z-index: 99;" backgroundColor="#fff" title-color="#000" title="消息中心"
:showClear="showClear" @clearNoRead="clearNoReadFun"></VNavigationBar>
<!-- <VNavigationBar background-color="#fff" title-color="#333" title="消息中心" :showClear="showClear" @clearNoRead="clearNoReadFun"></VNavigationBar>-->
<view class="body">
<view class="messageList">
<scroll-view style="height: 100%;" scroll-y="true" class="itemContent" @scrolltolower="onReachBottomCus"
refresher-enabled @refresherrefresh="onRefresherrefresh" :refresher-triggered="isTriggered">
<view v-for="(item, index) in messageList" :key="index" class="messageItem"
@click="readNotice(item)">
<image class="messageIcon" src="../../static/icons/message-icon1.png" mode="aspectFit"></image>
<view class="messageContent">
<view :class="{'messageTitle':item.readStatus,'noReadTitle':!item.readStatus}">系统通知</view>
<view class="messageContent_content">{{item.templateContent}}</view>
<view class="messageContent_content" style="text-align: right">
{{formatTime(item.createTime)}}</view>
</view>
</view>
<view style="text-align: center" v-if="messageList.length==0">
<image class="" src="@/static/images/nothing.png"></image>
</view>
</scroll-view>
</view>
</view>
<!-- 提示窗示例 -->
<uni-popup ref="alertDialog" type="dialog">
<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="我知道了" title="系统通知"
:content="nowReadItem.templateContent" @confirm="dialogToggle" @close="dialogToggle"></uni-popup-dialog>
</uni-popup>
<!-- &lt;!&ndash; 普通弹窗 &ndash;&gt;-->
<!-- <uni-popup ref="popup" background-color="#fff" >-->
<!-- <view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">-->
<!-- <text class="text popup-content-text">{{ nowReadItem.templateContent }}</text>-->
<!-- <button class="button popup-info" @click="dialogToggle"><text-->
<!-- class="button-text info-text">知道了</text></button>-->
<!-- </view>-->
<!-- </uni-popup>-->
</view>
2024-10-24 18:14:26 +08:00
</template>
<script>
import VNavigationBar from '@/components/VNavigationBar.vue'
2025-08-11 17:42:50 +08:00
import request from "@/utils/request";
import {
formatTimestamp
} from "@/utils/utils";
2024-10-24 18:14:26 +08:00
export default {
components: {
VNavigationBar,
},
data() {
return {
2025-08-11 17:42:50 +08:00
msgType: 'success',
2024-10-24 18:14:26 +08:00
messageList: [],
2025-08-11 17:42:50 +08:00
pageNo: 1,
pageSize: 15,
total: 0,
//下来刷新状态
isTriggered: false,
//是否显示一键清空
showClear: true,
nowReadItem: {},
2024-10-24 18:14:26 +08:00
};
},
2025-08-11 17:42:50 +08:00
onLoad() {
},
onShow() {
this.getList()
},
methods: {
/**
* 点击阅读消息
*/
async readNotice(item) {
this.nowReadItem = item
// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
this.$refs.alertDialog.open()
//直接请求后台已读
await request({
url: "/admin-api/system/notify-message/update-read",
method: "PUT",
params: {
ids: this.nowReadItem.id
},
tenantIdFlag: false
}).then((res) => {
if (res.code == 200) {
this.onRefresherrefresh()
}
})
},
/**
* 消息设置为已读
*/
dialogToggle() {
},
/**
* 一键清空未读消息
*/
async clearNoReadFun() {
console.log("清空了")
await request({
url: "/admin-api/system/notify-message/update-all-read",
method: "PUT",
tenantIdFlag: false
}).then((res) => {
if (res.code == 200) {
uni.showToast({
title: '操作成功',
icon: 'none'
})
setTimeout(() => {
this.onRefresherrefresh()
}, 500)
}
})
},
formatTime(value) {
return formatTimestamp(value)
},
/**
* 上滑加载数据
*/
onReachBottomCus() {
//判断 如果页码*页容量大于等于总条数,提示该页数据加载完毕
if (this.pageNo * this.pageSize >= this.total) {
uni.$u.toast('没有更多数据了')
return
}
//页码+1,调用获取数据的方法获取第二页数据
this.pageNo++
//此处调用自己获取数据列表的方法
this.getList()
},
/**
* 下拉刷新数据
*/
onRefresherrefresh() {
this.isTriggered = true
this.pageNo = 1
this.total = 0
this.messageList = []
this.getList()
},
/**
* 分页查询
*/
async getList() {
await request({
url: "/admin-api/system/notify-message/my-page",
method: "GET",
params: {
pageNo: this.pageNo,
pageSize: this.pageSize,
systemCode: 'weixiu'
}
}).then((res) => {
//判断 如果获取的数据的页码不是第一页,就让之前赋值获取过的数组数据 concat连接 刚获取的第n页数据
if (this.pageNo != 1) {
this.messageList = this.messageList.concat(res.data.list)
} else {
this.messageList = res.data.list
}
//将获取的总条数赋值
this.total = res.data.total
this.isTriggered = false
})
},
}
2024-10-24 18:14:26 +08:00
}
</script>
<style lang="less" scoped>
2025-08-11 17:42:50 +08:00
.container {
height: 100%;
2024-10-24 18:14:26 +08:00
display: flex;
2025-08-11 17:42:50 +08:00
flex-direction: column;
2024-10-24 18:14:26 +08:00
2025-08-11 17:42:50 +08:00
.body {
2024-10-24 18:14:26 +08:00
flex: 1;
2025-08-11 17:42:50 +08:00
height: calc(100vh - env(safe-area-inset-top));
overflow: auto;
}
.messageList {
padding: 0 32rpx;
height: 100%;
}
.messageItem {
padding: 30rpx 0;
display: flex;
align-items: center;
column-gap: 20rpx;
border-bottom: 1rpx solid #EEEEEE;
.messageIcon {
width: 80rpx;
height: 80rpx;
}
.noReadTitle {
font-weight: bold;
font-size: 32rpx;
color: #333333;
}
.noReadTitle:after {
content: "*";
color: red;
display: block;
/* 或者其他的块级显示类型,比如 inline-block, table 等 */
position: absolute;
/* 或者 absolute 或者 fixed取决于你的布局需求 */
z-index: 1;
/* 确保它在元素的上方 */
right: 0;
}
.messageContent {
flex: 1;
width: 0;
}
.messageTitle {
font-size: 32rpx;
color: #333333;
}
.messageContent_content {
font-weight: 500;
font-size: 28rpx;
color: #858BA0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
.popup-content {
padding: 15px;
height: auto;
margin: auto;
width: 80%;
background-color: #fff;
2024-10-24 18:14:26 +08:00
}
2025-08-11 17:42:50 +08:00
.popup-content-text {
display: flex;
align-items: center;
justify-content: center;
}
.text {
color: #333;
2024-10-24 18:14:26 +08:00
}
2025-08-11 17:42:50 +08:00
.popup-info {
margin-top: 30rpx;
color: #fff;
background-color: #f2f6fc;
2024-10-24 18:14:26 +08:00
}
2025-08-11 17:42:50 +08:00
.info-text {
color: #909399;
}
}
</style>