kana-bbs/components/PostList.vue

140 lines
3.3 KiB
Vue
Raw Normal View History

2022-01-30 13:34:10 +08:00
<template lang="pug">
.post-list
ul(v-if="data.length")
li(v-for="item in data", :key="item._id")
2022-01-31 02:34:36 +08:00
NuxtLink(:to="`/user/${item.user._id}`")
2024-04-16 20:06:06 +08:00
img.avatar(:src="item.user.avatar" onerror="this.src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'")
2022-01-30 13:34:10 +08:00
.content
2022-02-08 03:37:22 +08:00
.name(:class="{ adminname: item.user.gid === 1 }") {{ item.user.name }}
2022-01-30 13:34:10 +08:00
.info
span {{ rwdate(item.updatedAt) }}
2022-02-07 22:27:54 +08:00
div(v-html="markdown(item.data)")
2022-02-08 03:37:22 +08:00
.options
2022-02-24 16:45:45 +08:00
i.fas.fa-eraser(
2024-04-16 19:25:19 +08:00
v-if="account.gid === 1 || account.uid === item.uid"
2022-02-24 16:45:45 +08:00
@click="remove(item._id)"
2024-04-16 19:25:19 +08:00
title="删除"
2022-02-24 16:45:45 +08:00
)
i.fas.fa-marker(
2024-04-16 19:25:19 +08:00
v-if="account.gid === 1 || account.uid === item.uid"
2022-02-24 16:45:45 +08:00
@click="remove(item._id)"
2024-04-16 19:25:19 +08:00
title="编辑"
2022-02-24 16:45:45 +08:00
)
i.fas.fa-heart(
:class="{ like: item.like }",
@click="like(item._id, item.like)"
2024-04-16 19:25:19 +08:00
title="点赞"
2022-02-24 16:45:45 +08:00
)
2022-01-30 13:34:10 +08:00
.post-none(v-else) 没有评论~
</template>
<style lang="sass">
.post-none
display: flex
justify-content: center
align-items: center
justify-items: center
text-align: center
min-height: 24rem
.post-list
ul
list-style: none
padding: 0
margin: 0
li
display: flex
border-radius: .5rem
margin: 0
padding: 8px 0
color: #222222
.avatar
width: 48px
height: 48px
background: rgba(0, 0, 0, .05)
border-radius: 50%
overflow: hidden
.content
padding-left: 1rem
2022-02-08 03:37:22 +08:00
.name
2022-01-30 13:34:10 +08:00
font-size: 1.1rem
font-weight: 600
2022-02-08 03:37:22 +08:00
.name.adminname
color: #ff5599
2022-01-30 13:34:10 +08:00
.info
span
margin-right: .5rem
2022-02-08 03:37:22 +08:00
.options
margin-left: auto
i
cursor: pointer
padding: 0
margin: 0 .5rem
color: #888888
//display: none
i:hover
color: #cc1414
i.like
color: #cc1414
//display: inline
//li:hover
// .options
// i
// display: inline
2022-01-30 13:34:10 +08:00
</style>
<script>
2022-02-07 22:27:54 +08:00
import { marked } from "marked";
2022-01-30 13:34:10 +08:00
export default {
props: ["data"],
2022-02-08 03:37:22 +08:00
computed: {
account() {
return this.$store.state.account;
},
},
2022-01-30 13:34:10 +08:00
methods: {
rwdate(utc) {
let t = new Date(utc);
return t.getMonth() + 1 + "月 " + t.getDate() + ", " + t.getFullYear();
},
2022-02-07 22:27:54 +08:00
markdown(data) {
return marked.parse(data);
},
2022-02-24 16:45:45 +08:00
like(_id, en) {
if (en) {
return this.$axios
.delete("/api/like?attach=post&aid=" + _id)
.then((res) => {
if (res.status === 200) {
this.data.forEach((item) => {
if (item._id === _id) {
item.like = false;
}
});
}
});
}
2022-02-08 03:37:22 +08:00
let data = { attach: "post", aid: _id };
this.$axios.post("/api/like", data).then((res) => {
if (res.status === 200) {
this.data.forEach((item) => {
if (item._id === _id) {
item.like = true;
}
});
}
});
},
2022-02-24 16:45:45 +08:00
remove(_id) {
this.$axios.delete("/api/post/" + _id).then((res) => {
if (res.status === 200) {
this.$emit(
"update:data",
this.data.filter((item) => item._id !== _id)
);
}
});
2024-04-16 20:06:06 +08:00
}
2022-01-30 13:34:10 +08:00
},
};
</script>