消息列表:已读消息更改

This commit is contained in:
guoyue 2022-09-08 09:44:12 +08:00
parent 7f3c5c0921
commit 5eefd4d306
1 changed files with 309 additions and 302 deletions

View File

@ -79,7 +79,11 @@
<a-list-item>
<a-list-item-meta description="">
<template #title>
<div class="left" @click="read(item)">
<div
class="left"
@click="read(item)"
:class="item.readStatus === 1 ? '' : 'pointer'"
>
{{ item.content }}
</div>
<div class="right">{{ '发布时间:' + item.senderDate }}</div>
@ -111,337 +115,340 @@
</div>
</template>
<script setup>
// import { SearchOutlined } from '@ant-design/icons-vue'
import { ref, reactive, onBeforeUnmount } from 'vue'
import mybus from '@/myplugins/mybus'
import { message } from 'ant-design-vue'
import { mynotice, mynoticeRead } from '@/api/home'
import { useRouter } from 'vue-router'
const router = useRouter()
const total = ref(0)
const pageSize = ref(8)
const pageNum = ref(1)
const value = ref('全部消息')
const obj = reactive({ page: pageNum.value, limit: pageSize.value })
const navList = reactive([
{
title: '全部',
key: 'all',
num: 0,
},
{
title: '通知',
key: 'notice',
num: 0,
},
{
title: '评论',
key: 'comment',
num: 0,
},
{
title: '其它',
key: 'other',
num: 0,
},
])
const selectNav = ref('all')
const selectData = ref([])
const data = ref([])
const changeNav = (nav) => {
selectNav.value = nav.key
if (nav.key === 'all') {
delete obj.from
} else {
obj.from = nav.title
}
value.value = '全部消息'
delete obj.readStatus
init()
// import { SearchOutlined } from '@ant-design/icons-vue'
import { ref, reactive, onBeforeUnmount } from 'vue'
import mybus from '@/myplugins/mybus'
import { message } from 'ant-design-vue'
import { mynotice, mynoticeRead } from '@/api/home'
import { useRouter } from 'vue-router'
const router = useRouter()
const total = ref(0)
const pageSize = ref(8)
const pageNum = ref(1)
const value = ref('全部消息')
const obj = reactive({ page: pageNum.value, limit: pageSize.value })
const navList = reactive([
{
title: '全部',
key: 'all',
num: 0,
},
{
title: '通知',
key: 'notice',
num: 0,
},
{
title: '评论',
key: 'comment',
num: 0,
},
{
title: '其它',
key: 'other',
num: 0,
},
])
const selectNav = ref('all')
const selectData = ref([])
const data = ref([])
const changeNav = (nav) => {
selectNav.value = nav.key
if (nav.key === 'all') {
delete obj.from
} else {
obj.from = nav.title
}
const changeCheckBox = (item) => {
item.checked = !item.checked
if (item.checked) {
selectData.value.push(item.id)
} else {
selectData.value = selectData.value.filter((val) => val !== item.id)
}
value.value = '全部消息'
delete obj.readStatus
init()
}
const changeCheckBox = (item) => {
item.checked = !item.checked
if (item.checked) {
selectData.value.push(item.id)
} else {
selectData.value = selectData.value.filter((val) => val !== item.id)
}
const changeCheckAll = () => {
if (selectData.value.length == data.value.length) {
selectData.value = []
data.value.forEach((val) => {
val.checked = false
})
} else {
selectData.value = []
data.value.forEach((val) => {
val.checked = true
selectData.value.push(val.id)
})
}
}
const changePageNum = (page) => {
pageNum.value = page
obj.page = pageNum.value
init()
}
const handleChange = () => {
pageNum.value = 1
obj.page = pageNum.value
switch (value.value) {
case '全部消息':
delete obj.readStatus
break
case '已读消息':
obj.readStatus = 1
break
case '未读消息':
obj.readStatus = 0
break
default:
delete obj.readStatus
break
}
init()
}
const goBack = (url) => {
router.push({
path: url,
}
const changeCheckAll = () => {
if (selectData.value.length == data.value.length) {
selectData.value = []
data.value.forEach((val) => {
val.checked = false
})
} else {
selectData.value = []
data.value.forEach((val) => {
val.checked = true
selectData.value.push(val.id)
})
}
const read = (item) => {
// console.log(item)
if (selectData.value.length === 0 && !item) {
message.error('未选择消息!')
}
const changePageNum = (page) => {
pageNum.value = page
obj.page = pageNum.value
init()
}
const handleChange = () => {
pageNum.value = 1
obj.page = pageNum.value
switch (value.value) {
case '全部消息':
delete obj.readStatus
break
case '已读消息':
obj.readStatus = 1
break
case '未读消息':
obj.readStatus = 0
break
default:
delete obj.readStatus
break
}
init()
}
const goBack = (url) => {
router.push({
path: url,
})
}
const read = (item) => {
// console.log(item)
if (selectData.value.length === 0 && !item) {
message.error('未选择消息!')
return
}
console.log(selectData.value)
if (item) {
//
if (item.readStatus === 1) {
return
}
console.log(selectData.value)
// let str = ''
// selectData.value.forEach((val, index) => {
// str += val
// if (index < selectData.value.length - 1) {
// str += ';'
// }
// })
if (item) {
mynoticeRead(item.id).then((res) => {
mynoticeRead(item.id).then((res) => {
if (res.data.code == 0) {
message.success('操作成功!')
mybus.emit('getMynotice')
init()
} else {
message.error('操作失败!')
}
})
} else {
console.log('提交')
selectData.value.map((val) => {
mynoticeRead(val).then((res) => {
if (res.data.code == 0) {
message.success('操作成功!')
// message.success('')
mybus.emit('getMynotice')
init()
} else {
message.error('操作失败!')
}
})
} else {
console.log('提交')
selectData.value.map((val) => {
mynoticeRead(val).then((res) => {
if (res.data.code == 0) {
// message.success('')
mybus.emit('getMynotice')
init()
} else {
message.error('操作失败!')
}
})
})
}
}
const init = () => {
// from readStatus 0 1
mynotice(obj).then((res) => {
console.log('消息=============>', res.data.data)
res.data.data.list.forEach((val) => {
if (val.from === '通知') {
val.src = require('@/assets/mynoticeView/notice.png')
} else if (val.from === '评论') {
val.src = require('@/assets/mynoticeView/comment.png')
} else if (val.from === '其它') {
val.src = require('@/assets/mynoticeView/other.png')
}
val.checked = false
})
data.value = res.data.data.list
total.value = res.data.data.total
selectData.value = []
})
}
navList.forEach((val) => {
if (val.title === '全部') {
mynotice({ page: pageNum.value, limit: pageSize.value }).then((res) => {
val.num = res.data.data.total
})
} else {
mynotice({
page: pageNum.value,
limit: pageSize.value,
from: val.title,
}).then((res) => {
val.num = res.data.data.total
})
}
}
const init = () => {
// from readStatus 0 1
mynotice(obj).then((res) => {
console.log('消息=============>', res.data.data)
res.data.data.list.forEach((val) => {
if (val.from === '通知') {
val.src = require('@/assets/mynoticeView/notice.png')
} else if (val.from === '评论') {
val.src = require('@/assets/mynoticeView/comment.png')
} else if (val.from === '其它') {
val.src = require('@/assets/mynoticeView/other.png')
}
val.checked = false
})
data.value = res.data.data.list
total.value = res.data.data.total
selectData.value = []
})
}
navList.forEach((val) => {
if (val.title === '全部') {
mynotice({ page: pageNum.value, limit: pageSize.value }).then((res) => {
val.num = res.data.data.total
})
} else {
mynotice({
page: pageNum.value,
limit: pageSize.value,
from: val.title,
}).then((res) => {
val.num = res.data.data.total
})
}
})
init()
mybus.on('noticeListInit', () => {
init()
mybus.on('noticeListInit', () => {
init()
})
onBeforeUnmount(() => {
mybus.off('noticeListInit')
})
})
onBeforeUnmount(() => {
mybus.off('noticeListInit')
})
</script>
<style lang="less" scoped>
.notice-list {
padding: 0.64rem 0 0;
background: #f4f5f8;
.ant-breadcrumb {
padding: 0.1rem 3.1rem;
}
.top {
background: #fff;
padding: 0.18rem 3.1rem 0;
display: flex;
justify-content: space-between;
align-items: center;
.left {
display: flex;
.item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-left: 1.28rem;
margin-bottom: 0.16rem;
border-bottom: 3px solid #fff;
i {
display: inline-block;
width: 0.48rem;
height: 0.48rem;
margin-bottom: 0.15rem;
cursor: pointer;
}
.all {
background: url('~@/assets/mynoticeView/all.png') no-repeat;
background-size: 100%;
}
.notice {
background: url('~@/assets/mynoticeView/notice.png') no-repeat;
background-size: 100%;
}
.comment {
background: url('~@/assets/mynoticeView/comment.png') no-repeat;
background-size: 100%;
}
.other {
background: url('~@/assets/mynoticeView/other.png') no-repeat;
background-size: 100%;
}
}
.item:nth-of-type(1) {
margin-left: 0;
}
.select {
border-bottom: 3px solid #0058e1;
color: #0058e1;
}
}
.right {
display: flex;
align-items: center;
height: 0.32rem;
div {
width: 0.5rem;
}
.reset {
color: #0058e1;
cursor: pointer;
}
}
}
.btn {
background: #fff;
margin-top: 0.16rem;
padding: 0.14rem 3.1rem 0;
display: flex;
justify-content: space-between;
.left {
display: flex;
align-items: center;
.ant-select {
margin-right: 0.24rem;
}
.check {
display: flex;
align-items: center;
div {
margin-left: 0.24rem;
span {
font-size: 18px;
color: #0058e1;
}
}
div:nth-of-type(1) {
margin-left: 0.12rem;
}
}
}
.right {
display: flex;
justify-content: space-around;
align-items: center;
div {
margin: 0 0.1rem;
}
span {
cursor: pointer;
color: #0058e1;
text-align: center;
align-self: center;
padding: 0.05rem 0.1rem;
}
.notice-list {
padding: 0.64rem 0 0;
background: #f4f5f8;
.ant-breadcrumb {
padding: 0.1rem 3.1rem;
}
.top {
background: #fff;
padding: 0.18rem 3.1rem 0;
display: flex;
justify-content: space-between;
align-items: center;
span:hover {
background: rgba(0, 88, 225, 0.1);
.left {
display: flex;
.item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-left: 1.28rem;
margin-bottom: 0.16rem;
border-bottom: 3px solid #fff;
i {
display: inline-block;
width: 0.48rem;
height: 0.48rem;
margin-bottom: 0.15rem;
cursor: pointer;
}
.all {
background: url('~@/assets/mynoticeView/all.png') no-repeat;
background-size: 100%;
}
.notice {
background: url('~@/assets/mynoticeView/notice.png') no-repeat;
background-size: 100%;
}
.comment {
background: url('~@/assets/mynoticeView/comment.png') no-repeat;
background-size: 100%;
}
.other {
background: url('~@/assets/mynoticeView/other.png') no-repeat;
background-size: 100%;
}
}
.item:nth-of-type(1) {
margin-left: 0;
}
.select {
border-bottom: 3px solid #0058e1;
color: #0058e1;
}
}
.main {
background: #fff;
padding: 0 3.1rem;
height: 4.75rem;
overflow-y: scroll;
:deep(.ant-list-item-meta) {
.right {
display: flex;
align-items: center;
height: 0.32rem;
div {
width: 0.5rem;
}
.reset {
color: #0058e1;
cursor: pointer;
}
}
}
.btn {
background: #fff;
margin-top: 0.16rem;
padding: 0.14rem 3.1rem 0;
display: flex;
justify-content: space-between;
.left {
display: flex;
align-items: center;
.ant-select {
margin-right: 0.24rem;
}
.check {
display: flex;
align-items: center;
.ant-checkbox-wrapper {
margin-right: 0.3rem;
}
.ant-list-item-meta-title {
display: flex;
justify-content: space-between;
align-items: center;
.left {
cursor: pointer;
width: 9.2rem;
max-height: 0.43rem;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
word-break: break-all;
}
.left:hover {
div {
margin-left: 0.24rem;
span {
font-size: 18px;
color: #0058e1;
}
}
div:nth-of-type(1) {
margin-left: 0.12rem;
}
}
}
.ant-pagination {
background: #fff;
margin-top: 0;
padding: 0.2rem 0 0.2rem;
.right {
display: flex;
justify-content: space-around;
align-items: center;
div {
margin: 0 0.1rem;
}
span {
cursor: pointer;
color: #0058e1;
text-align: center;
align-self: center;
padding: 0.05rem 0.1rem;
}
span:hover {
background: rgba(0, 88, 225, 0.1);
}
}
}
.main {
background: #fff;
padding: 0 3.1rem;
height: 4.75rem;
overflow-y: scroll;
:deep(.ant-list-item-meta) {
display: flex;
align-items: center;
.ant-checkbox-wrapper {
margin-right: 0.3rem;
}
.ant-list-item-meta-title {
display: flex;
justify-content: space-between;
align-items: center;
.left {
width: 9.2rem;
max-height: 0.43rem;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
word-break: break-all;
}
.pointer {
cursor: pointer;
}
.left:hover {
color: #0058e1;
}
}
}
}
.ant-pagination {
background: #fff;
margin-top: 0;
padding: 0.2rem 0 0.2rem;
}
}
</style>