347 lines
9.4 KiB
Vue
347 lines
9.4 KiB
Vue
<template>
|
||
<view class="notice-page">
|
||
<z-paging ref="noticePage" refresher-only
|
||
:show-empty="false" :show-footer="false" @onRefresh="getNoticeList">
|
||
<template #refresher="{refresherStatus}">
|
||
<!-- 此处的custom-refresh为demo中自定义的组件,非z-paging的内置组件,请在实际项目中自行创建。这里插入什么view,下拉刷新就显示什么view -->
|
||
<custom-refresher :status="refresherStatus" />
|
||
</template>
|
||
<!-- 未读/已读标签栏 -->
|
||
<view class="tab-bar">
|
||
<view
|
||
class="tab-item"
|
||
:class="{ active: currentTab === 0 }"
|
||
@click="switchTab(0)"
|
||
>
|
||
未读
|
||
</view>
|
||
<view
|
||
class="tab-item"
|
||
:class="{ active: currentTab === 1 }"
|
||
@click="switchTab(1)"
|
||
>
|
||
已读
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 公告列表 -->
|
||
<scroll-view :scroll-y="true" class="notice-list" v-if="noticeList.length>0">
|
||
<view
|
||
v-for="(item, index) in noticeList"
|
||
:key="index"
|
||
class="notice-item"
|
||
@click="handleClick(item)"
|
||
>
|
||
<!-- 状态点 + 标题 -->
|
||
<view class="notice-header">
|
||
<view class="status-dot" :style="{ borderColor: item.dotColor }">
|
||
<view class="dot-inner" :style="{ backgroundColor: item.dotColor }" v-if="Math.random() < 0.5"></view>
|
||
</view>
|
||
<text class="notice-title">{{ item.title }}</text>
|
||
</view>
|
||
|
||
<!-- 内容描述 -->
|
||
<view class="notice-content">
|
||
<text class="content-text">{{ item.content }}</text>
|
||
</view>
|
||
|
||
<!-- 底部:头像 + 作者 + 时间 -->
|
||
<view class="notice-footer">
|
||
<view class="author-info">
|
||
<image class="avatar" :src=" item.imgUrl || authorList[Math.round(Math.random())].imgUrl" mode="aspectFill"></image>
|
||
<text class="author-name">{{ item.createBy || authorList[Math.round(Math.random())].createBy }}</text>
|
||
</view>
|
||
<text class="notice-time">{{ formatTime(item.createTime) }}</text>
|
||
</view>
|
||
</view>
|
||
<!-- <uni-load-more v-if="noticeList.length>8" iconType="auto" :status="status" :content-text="contentText" />-->
|
||
|
||
<uni-divider-text margin="10rpx 0"
|
||
width="50%"
|
||
font-size="24rpx"
|
||
v-if="noticeList.length>0"
|
||
lineText="只展示最近7天的消息"/>
|
||
</scroll-view>
|
||
|
||
|
||
|
||
<view class="empty__item tn-margin-top empty__view" v-else>
|
||
<tn-empty icon="https://resource.tuniaokj.com/images/empty/alien/2.png"
|
||
text="近7天暂无公告" :imgWidth="200"
|
||
:imgHeight="200"></tn-empty>
|
||
</view>
|
||
|
||
<uni-popup ref="showNotice" mode="center" >
|
||
<!-- 新增:修改运行时间的弹窗 -->
|
||
<view class="modal-container">
|
||
<view class="modal-title">{{ notice.title }}</view>
|
||
<view class="modal-content"> {{ notice.content }}</view>
|
||
<view class="modal-remark">
|
||
<view class="remark">
|
||
发布人:{{ notice.createBy }}
|
||
</view>
|
||
<view class="remark">
|
||
发布时间:{{ notice.createTime }}
|
||
</view>
|
||
</view>
|
||
<view class="modal-btn-wrap">
|
||
<button class="modal-btn confirm" @click="closeShowNotice">确定</button>
|
||
</view>
|
||
</view>
|
||
</uni-popup>
|
||
</z-paging>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import {formatTime} from "@/utils/agri";
|
||
import UniDividerText from "@/components/uni-divider/uni-divider-text.vue";
|
||
import {listMessage, updateRead} from "@/api/warn/message";
|
||
|
||
export default {
|
||
components: {UniDividerText},
|
||
data() {
|
||
return {
|
||
currentTab: 0, // 0未读 1已读
|
||
authorList: [
|
||
{
|
||
createBy: '那只猪-图鸟人事部',
|
||
imgUrl: 'https://img.xiaoces.com/photos/profile.jpg'
|
||
},
|
||
{
|
||
createBy: '你的名字',
|
||
imgUrl: 'https://img.xiaoces.com/photos/logo200.png'
|
||
}
|
||
],
|
||
dotColorList: [
|
||
'#e53935',
|
||
'#007bff',
|
||
'#4caf50',
|
||
'#ff9800'
|
||
],
|
||
contentList: [
|
||
{
|
||
title: '2024年春节放假通知',
|
||
content: '各位同事:一年一度的春节又到啦,根据国家法定节假日规定,2024年春节放假安排如下:02月01日—...',
|
||
createBy: '那只猪-图鸟人事部',
|
||
createTime: '2024-01-26 10:12',
|
||
dotColor: '#e53935',
|
||
dotInner: true, // 实心红点
|
||
readStatus: 0,
|
||
imgUrl: 'https://img.xiaoces.com/photos/logo.png' // 替换为你的头像路径
|
||
},
|
||
{
|
||
title: '2024年春节放假通知',
|
||
content: '各位同事:一年一度的春节又到啦,根据国家法定节假日规定,2024年春节放假安排如下:02月01retrt345日—...',
|
||
createBy: '那只猪-图鸟人事部',
|
||
createTime: '2024-01-26 10:12',
|
||
dotColor: '#e53935',
|
||
dotInner: true, // 实心红点
|
||
readStatus: 0,
|
||
imgUrl: 'https://img.xiaoces.com/photos/logo.png' // 替换为你的头像路径
|
||
}
|
||
],
|
||
noticeList: [],
|
||
notice: {
|
||
title:null,
|
||
content:null,
|
||
createBy:null,
|
||
createTime:null
|
||
},
|
||
status: 'more',
|
||
contentText: {
|
||
contentdown: '查看更多',
|
||
contentrefresh: '加载中.....',
|
||
contentnomore: '没有更多数据了'
|
||
},
|
||
isHaveOldData: true
|
||
}
|
||
},
|
||
onLoad() {
|
||
// 系统通知按照最新时间升序排序
|
||
// 只允许查询七天以内消息默认展示今天
|
||
this.getNoticeList();
|
||
},
|
||
methods: {
|
||
formatTime,
|
||
switchTab(currentTab) {
|
||
this.currentTab = currentTab;
|
||
this.noticeList = this.contentList.filter(item =>
|
||
item.readStatus===currentTab);
|
||
},
|
||
handleClick(item) {
|
||
this.notice = item;
|
||
if (item.readStatus===0) {
|
||
updateRead({msgType: "notice",id:item.id}).then(response => {
|
||
if (response.code === 200) {
|
||
console.info("更新已读成功")
|
||
}
|
||
})
|
||
}
|
||
this.$refs.showNotice.open();
|
||
},
|
||
closeShowNotice() {
|
||
this.$refs.showNotice.close();
|
||
},
|
||
getNoticeList() {
|
||
this.status = 'loading'
|
||
// if (!this.isHaveOldData) {
|
||
// setTimeout(() => {
|
||
// this.$modal.msg("没有更早数据!");
|
||
// // 结束刷新状态
|
||
// this.status = 'nomore'
|
||
// }, 800);
|
||
// return;
|
||
// }
|
||
listMessage({msgType: "notice"}).then(response => {
|
||
if (response.code === 200) {
|
||
this.contentList = response.rows;
|
||
if (this.contentList.length === 0) {
|
||
this.$modal.showToast('没有更多数据~')
|
||
}
|
||
}
|
||
}).finally(()=>{
|
||
this.noticeList = this.contentList.filter(item =>
|
||
item.readStatus===0);
|
||
this.$refs.noticePage.complete();
|
||
// 结束刷新状态
|
||
this.status = 'nomore';
|
||
})
|
||
},
|
||
},
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
page {
|
||
box-sizing: border-box;
|
||
background-color: #f8f8f8;
|
||
}
|
||
|
||
/* 页面容器 */
|
||
.notice-page {
|
||
height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* 标签栏 */
|
||
.tab-bar {
|
||
display: flex;
|
||
height: 80rpx;
|
||
padding: 0 20rpx;
|
||
background-color: #fff;
|
||
border-bottom: 1rpx solid #eee;
|
||
}
|
||
.tab-item {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 32rpx;
|
||
color: #999;
|
||
position: relative;
|
||
}
|
||
.tab-item.active {
|
||
color: #007bff;
|
||
font-weight: 500;
|
||
}
|
||
.tab-item.active::after {
|
||
content: '';
|
||
position: absolute;
|
||
bottom: 0;
|
||
left: 50%;
|
||
transform: translateX(-50%);
|
||
width: 40rpx;
|
||
height: 4rpx;
|
||
background-color: #007bff;
|
||
border-radius: 2rpx;
|
||
}
|
||
|
||
/* 公告列表 */
|
||
.notice-list {
|
||
flex: 1;
|
||
padding: 20rpx;
|
||
background-color: transparent;
|
||
border-radius: 8rpx;
|
||
overflow: hidden;
|
||
/* 新增:H5端避免滚动条样式不一致 */
|
||
scrollbar-width: thin;
|
||
height: 100vh;
|
||
}
|
||
.notice-item {
|
||
background-color: #fff;
|
||
border-radius: 12rpx;
|
||
padding: 24rpx;
|
||
margin-bottom: 20rpx;
|
||
box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
|
||
}
|
||
|
||
/* 公告头部:状态点 + 标题 */
|
||
.notice-header {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-bottom: 16rpx;
|
||
}
|
||
.status-dot {
|
||
width: 24rpx;
|
||
height: 24rpx;
|
||
border: 2rpx solid;
|
||
border-radius: 50%;
|
||
margin-right: 16rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
.dot-inner {
|
||
width: 12rpx;
|
||
height: 12rpx;
|
||
border-radius: 50%;
|
||
}
|
||
.notice-title {
|
||
font-size: 32rpx;
|
||
color: #333;
|
||
font-weight: 500;
|
||
}
|
||
|
||
/* 公告内容 */
|
||
.notice-content {
|
||
margin-bottom: 20rpx;
|
||
}
|
||
.content-text {
|
||
font-size: 28rpx;
|
||
color: #666;
|
||
line-height: 1.5;
|
||
/* 超出两行隐藏(可按需调整) */
|
||
display: -webkit-box;
|
||
-webkit-line-clamp: 2;
|
||
-webkit-box-orient: vertical;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 公告底部:头像 + 作者 + 时间 */
|
||
.notice-footer {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
}
|
||
.author-info {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
.avatar {
|
||
width: 40rpx;
|
||
height: 40rpx;
|
||
border-radius: 50%;
|
||
margin-right: 12rpx;
|
||
}
|
||
.author-name {
|
||
font-size: 26rpx;
|
||
color: #999;
|
||
}
|
||
.notice-time {
|
||
font-size: 26rpx;
|
||
color: #999;
|
||
}
|
||
</style> |