kana-bbs/components/PostList.vue

106 lines
2.4 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}`")
img.avatar(:src="item.user.avatar")
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
i.fas.fa-eraser(v-if="account.gid === 1 || account.uid === item.uid")
i.fas.fa-marker(v-if="account.gid === 1 || account.uid === item.uid")
i.fas.fa-heart(:class="{ like: item.like }", @click="like(item._id)")
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-08 03:37:22 +08:00
like(_id) {
let data = { attach: "post", aid: _id };
console.log(data);
this.$axios.post("/api/like", data).then((res) => {
if (res.status === 200) {
this.data.forEach((item) => {
if (item._id === _id) {
item.like = true;
}
});
}
});
},
2022-01-30 13:34:10 +08:00
},
};
</script>