feat: 【消息通知】点击查看更多按钮,即加载所有数据,滚动显示。此时查看更多按钮隐藏,无需再次点击

pull/7/head
刘释隆 1 year ago
parent 34937aeabf
commit 9c137112f2

@ -1,32 +1,32 @@
<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue'
import { format } from 'date-fns'
import { useRoute, useRouter } from 'vue-router'
import { getMessageList, readAllMsg, readMsg } from '@/api/message/message'
import iconApproveActive from '@/assets/images/message/approve-active.png'
import iconApprove from '@/assets/images/message/approve.png'
import iconSystemActive from '@/assets/images/message/system-active.png'
import iconSystem from '@/assets/images/message/system.png'
import iconArrowActive from '@/assets/images/message/arrow-active.png'
import iconArrow from '@/assets/images/message/arrow.png'
import iconClear from '@/assets/images/message/clear.png'
import iconArrowDown from '@/assets/images/message/arrow-down.png'
const emit = defineEmits(['goDetail'])
const router = useRouter()
const route = useRoute()
const hasNextPage = ref(false)
import { reactive, ref, toRefs } from "vue";
import { format } from "date-fns";
import { useRoute, useRouter } from "vue-router";
import { getMessageList, readAllMsg, readMsg } from "@/api/message/message";
import iconApproveActive from "@/assets/images/message/approve-active.png";
import iconApprove from "@/assets/images/message/approve.png";
import iconSystemActive from "@/assets/images/message/system-active.png";
import iconSystem from "@/assets/images/message/system.png";
import iconArrowActive from "@/assets/images/message/arrow-active.png";
import iconArrow from "@/assets/images/message/arrow.png";
import iconClear from "@/assets/images/message/clear.png";
import iconArrowDown from "@/assets/images/message/arrow-down.png";
const emit = defineEmits(["goDetail"]);
const router = useRouter();
const route = useRoute();
const hasNextPage = ref(false);
const state = reactive({
tabList: [
{
name: '审批通知',
name: "审批通知",
icon: iconApprove,
activeIcon: iconApproveActive,
value: 1,
},
{
name: '系统消息',
name: "系统消息",
icon: iconSystem,
activeIcon: iconSystemActive,
value: 2,
@ -34,112 +34,147 @@ const state = reactive({
],
list: [] as any,
pageNo: 1,
})
});
const { list, tabList } = toRefs(state)
const { list, tabList } = toRefs(state);
const tab = ref(1)
const tab = ref(1);
async function getList() {
const res = await getMessageList({
async function getList(type = "") {
let res = await getMessageList({
pageNo: state.pageNo,
pageSize: '7',
pageSize: "7",
msgCategory: tab.value,
})
if (res.code === 'OK') {
hasNextPage.value = res.data.hasNextPage
if (tab.value === 1) {
res.data.list.forEach((item) => {
item.tag = JSON.parse(item.busJson)
})
});
if (type == "more") {
while (res.data.endRow > 0) {
if (res.code == "OK") {
if (tab.value === 1) {
res.data.list.forEach((item) => {
item.tag = JSON.parse(item.busJson);
});
}
state.list = state.list.concat(res.data.list);
state.pageNo++;
res = await getMessageList({
pageNo: state.pageNo,
pageSize: "7",
msgCategory: tab.value,
});
}
}
hasNextPage.value = res.data.hasNextPage;
} else {
if (res.code === "OK") {
hasNextPage.value = res.data.hasNextPage;
if (tab.value === 1) {
res.data.list.forEach((item) => {
item.tag = JSON.parse(item.busJson);
});
}
state.list = state.list.concat(res.data.list);
}
console.log(res.data.list)
state.list = state.list.concat(res.data.list)
}
}
getList()
getList();
async function clearMsg() {
const res = await readAllMsg({ msgCategory: tab.value })
if (res.code === 'OK') {
state.list = []
state.pageNo = 1
getList()
const res = await readAllMsg({ msgCategory: tab.value });
if (res.code === "OK") {
state.list = [];
state.pageNo = 1;
getList();
}
}
function switchTab(type: number) {
tab.value = type
state.list = []
state.pageNo = 1
getList()
tab.value = type;
state.list = [];
state.pageNo = 1;
getList();
}
function goFinalDetail(row) {
console.log(row)
router.push({ name: 'final-detail', query: { id: row.tag.taskId, packageid: row.packageid } })
console.log(row);
router.push({
name: "final-detail",
query: { id: row.tag.taskId, packageid: row.packageid },
});
}
function goDetail(item) {
if (tab.value === 1) {
clearMsgOne(item.id)
goFinalDetail(item)
clearMsgOne(item.id);
goFinalDetail(item);
}
else
// emit('goDetail', item.id)
{ router.push({ name: 'message-detail', query: { id: item.id } }) }
else {
router.push({ name: "message-detail", query: { id: item.id } });
}
}
async function clearMsgOne(id) {
const res = await readMsg({ msgid: id })
const res = await readMsg({ msgid: id });
}
function getMore() {
state.pageNo += 1
getList()
state.pageNo += 1;
getList("more");
}
</script>
<template>
<div class="wrapper-message">
<div class="flex justify-between header">
<div class="header-title">
消息通知
</div>
<div class="header-title">消息通知</div>
<div class="clear" @click="clearMsg">
<img class="icon-clear" :src="iconClear" alt="">
<img class="icon-clear" :src="iconClear" alt="" />
清除未读
</div>
</div>
<div class="content">
<div class="slider">
<div
v-for="(item) in tabList"
v-for="item in tabList"
:key="item.value"
:class="{ 'item-active': tab === item.value }"
class="flex item"
@click="switchTab(item.value)"
>
<div class="flex item-left align-center">
<img class="icon" :src="tab === item.value ? item.activeIcon : item.icon" alt="">
<img
class="icon"
:src="tab === item.value ? item.activeIcon : item.icon"
alt=""
/>
<div :class="{ 'text-active': tab === item.value }" class="text">
{{ item.name }}
</div>
</div>
<img class="icon-arrow" :src="tab === item.value ? iconArrowActive : iconArrow" alt="">
<img
class="icon-arrow"
:src="tab === item.value ? iconArrowActive : iconArrow"
alt=""
/>
<div v-if="tab === item.value" class="line" />
</div>
</div>
<div class="list">
<div v-for="(item, index) in list" :key="item.id" :class="{ 'pt0': index === 0, 'item-disabled': item.readFlag }" class="item" @click="goDetail(item)">
<div
v-for="(item, index) in list"
:key="item.id"
:class="{ pt0: index === 0, 'item-disabled': item.readFlag }"
class="item"
@click="goDetail(item)"
>
<div class="left">
<div class="num">
{{ format(item.sendTime, 'dd') }}
{{ format(item.sendTime, "dd") }}
<div v-if="!item.readFlag" class="point" />
</div>
<div class="date">
{{ format(item.sendTime, 'yyyy-MM') }}
{{ format(item.sendTime, "yyyy-MM") }}
</div>
</div>
<div class="middle">
@ -150,29 +185,25 @@ function getMore() {
{{ item.titile }}
</div>
<div v-if="tab === 1" class="status">
<div class="tag tag-blue">
审批节点{{ item.tag.nodeName }}
</div>
<div class="tag tag-blue">审批节点{{ item.tag.nodeName }}</div>
<div :class="item.tag.states === 5 ? 'tag-red' : 'tag-green'" class="tag">
审批状态{{ item.tag.states }}
</div>
</div>
<div v-if="tab === 1" class="subtitle">
<span class="name">{{ item.tag.sendUserName }}</span>
<span class="time">{{ format(item.sendTime, 'yyyy-MM-dd HH:mm:ss') }}</span>
<span class="time">{{ format(item.sendTime, "yyyy-MM-dd HH:mm:ss") }}</span>
</div>
<div v-else class="subtitle">
<span class="name">{{ item.userName }}</span>
<span class="time">{{ format(item.sendTime, 'yyyy-MM-dd HH:mm:ss') }}</span>
<span class="time">{{ format(item.sendTime, "yyyy-MM-dd HH:mm:ss") }}</span>
</div>
</div>
<div class="look">
查看
</div>
<div class="look">查看</div>
</div>
<div v-if="hasNextPage" class="more" @click="getMore">
查看更多<img class="icon-more" :src="iconArrowDown" alt="">
查看更多<img class="icon-more" :src="iconArrowDown" alt="" />
</div>
</div>
</div>
@ -185,15 +216,15 @@ function getMore() {
flex: 1;
flex-direction: column;
box-sizing: border-box;
background: #FFF;
background: #fff;
border-radius: 3px;
height: calc(100vh - 88px);
position: relative;
.header{
.header {
padding: 24px;
&-title{
&-title {
font-size: 20px;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 600;
@ -201,7 +232,7 @@ function getMore() {
line-height: 28px;
}
.clear{
.clear {
font-size: 14px;
font-family: PingFang SC, PingFang SC-Regular;
color: #666666;
@ -210,7 +241,7 @@ function getMore() {
display: flex;
align-items: center;
.icon-clear{
.icon-clear {
width: 16px;
height: 16px;
margin-right: 6px;
@ -218,20 +249,20 @@ function getMore() {
}
}
.content{
.content {
display: flex;
.slider{
.icon{
.slider {
.icon {
width: 17px;
height: 17px;
}
.icon-arrow{
.icon-arrow {
width: 14px;
height: 14px;
}
.item{
.item {
width: 200px;
height: 44px;
position: relative;
@ -240,32 +271,32 @@ function getMore() {
align-items: center;
justify-content: space-between;
cursor: pointer;
&-active{
background: rgba(80,122,253,.1);
&-active {
background: rgba(80, 122, 253, 0.1);
}
}
.item-left{
.item-left {
align-items: center;
}
.text{
.text {
font-size: 14px;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 600;
color: #333333;
margin-left: 12px;
&-active{
color: #507AFD;
&-active {
color: #507afd;
}
}
.icon-arrow{
.icon-arrow {
width: 14px;
height: 14px;
}
.line{
.line {
position: absolute;
width: 3px;
height: 44px;
@ -275,7 +306,7 @@ function getMore() {
}
}
.list{
.list {
margin-left: 24px;
flex: 1;
overflow-y: auto;
@ -284,7 +315,7 @@ function getMore() {
height: calc(100vh - 88px - 76px);
padding-right: 24px;
.more{
.more {
display: flex;
align-items: center;
justify-content: center;
@ -298,14 +329,14 @@ function getMore() {
background: #fff;
cursor: pointer;
.icon-more{
.icon-more {
width: 14px;
height: 14px;
margin-left: 6px;
}
}
.item{
.item {
display: flex;
align-items: center;
justify-content: space-between;
@ -313,16 +344,16 @@ function getMore() {
padding: 16px 0 8px 25px;
border-bottom: 1px solid #eeeeee;
&-disabled{
&-disabled {
opacity: 0.5;
}
}
.pt0{
.pt0 {
padding-top: 0;
}
.num{
.num {
font-size: 32px;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC-Medium;
font-weight: 600;
@ -332,7 +363,7 @@ function getMore() {
position: relative;
}
.date{
.date {
font-size: 12px;
font-family: PingFang SC, PingFang SC-Regular;
text-align: left;
@ -340,7 +371,7 @@ function getMore() {
line-height: 17px;
}
.point{
.point {
position: absolute;
right: -2px;
top: 5px;
@ -350,7 +381,7 @@ function getMore() {
background: #ff4e4f;
}
.left{
.left {
width: 80px;
height: 64px;
border-right: 1px solid #e8e8e8;
@ -360,18 +391,18 @@ function getMore() {
justify-content: center;
}
.middle{
.middle {
flex: 1;
padding-left: 20px;
}
.status{
.status {
display: flex;
align-items: center;
// margin-top: 8px;
}
.tag{
.tag {
padding: 0 8px;
height: 24px;
border-radius: 2px;
@ -384,22 +415,22 @@ function getMore() {
align-items: center;
}
.tag-blue{
background: rgba(80,122,253,0.10);
.tag-blue {
background: rgba(80, 122, 253, 0.1);
color: #507afd;
}
.tag-red{
.tag-red {
color: #ff4e4f;
background: rgba(255,78,79,0.10);
background: rgba(255, 78, 79, 0.1);
}
.tag-green{
color: #3EE199;
background: rgba(62,225,153,0.10);
.tag-green {
color: #3ee199;
background: rgba(62, 225, 153, 0.1);
}
.title{
.title {
font-size: 16px;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 600;
@ -408,7 +439,7 @@ function getMore() {
line-height: 25px;
}
.subtitle{
.subtitle {
font-size: 12px;
font-family: PingFang SC, PingFang SC-Regular;
text-align: left;
@ -417,11 +448,11 @@ function getMore() {
// margin-top: 8px;
}
.name{
.name {
margin-right: 16px;
}
.look{
.look {
font-size: 14px;
font-family: PingFang SC, PingFang SC-Regular;
text-align: left;
@ -430,7 +461,6 @@ function getMore() {
cursor: pointer;
}
}
}
}

Loading…
Cancel
Save