|
|
|
@ -1,31 +1,43 @@ |
|
|
|
|
<template> |
|
|
|
|
<div v-for="article in articles" :key="article.url" id="articles"> |
|
|
|
|
<div class="grid" :style="gridStyle(article)"> |
|
|
|
|
<div class="image-container"> |
|
|
|
|
<img :src="imageIfExists(article)" alt="" class="image" /> |
|
|
|
|
<div v-for="article in articles" :key="article.url" id="articles"> |
|
|
|
|
<div class="grid" :style="gridStyle()"> |
|
|
|
|
<div class="image-container"> |
|
|
|
|
<img |
|
|
|
|
:src="imageIfExists(article)" |
|
|
|
|
alt="" |
|
|
|
|
class="image" |
|
|
|
|
v-if="imageIfExists(article) !== null" |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<router-link |
|
|
|
|
:to="{ name: 'detail', params: { id: article.id } }" |
|
|
|
|
class="article-info" |
|
|
|
|
> |
|
|
|
|
<span v-if="article.category !== null" class="category"> |
|
|
|
|
{{ article.category.title }} |
|
|
|
|
</span> |
|
|
|
|
|
|
|
|
|
<span |
|
|
|
|
v-for="tag in article.tags" |
|
|
|
|
v-bind:key="tag" |
|
|
|
|
class="tag" |
|
|
|
|
> |
|
|
|
|
{{ tag }} |
|
|
|
|
</span> |
|
|
|
|
<!-- 路由链接:to的两个参数分别是: 路由名称和传入的id --> |
|
|
|
|
<router-link |
|
|
|
|
:to="{ name: 'detail', params: { id: article.id } }" |
|
|
|
|
> |
|
|
|
|
<div class="article-title">{{ article.title }}</div> |
|
|
|
|
</router-link> |
|
|
|
|
|
|
|
|
|
<div> |
|
|
|
|
{{ formatted_time(article.created) }} |
|
|
|
|
</div> |
|
|
|
|
</router-link> |
|
|
|
|
</div> |
|
|
|
|
<div> |
|
|
|
|
</div> |
|
|
|
|
<div> |
|
|
|
|
<span v-if="article.category !== null" class="category"> |
|
|
|
|
{{ article.category.title }} |
|
|
|
|
</span> |
|
|
|
|
|
|
|
|
|
<span v-for="tag in article.tags" v-bind:key="tag" class="tag"> |
|
|
|
|
{{ tag }} |
|
|
|
|
</span> |
|
|
|
|
<!-- 路由链接:to的两个参数分别是: 路由名称和传入的id --> |
|
|
|
|
<router-link :to="{ name: 'detail', params: { id: article.id } }"> |
|
|
|
|
<div class="article-title">{{ article.title }}</div> |
|
|
|
|
</router-link> |
|
|
|
|
|
|
|
|
|
<div> |
|
|
|
|
{{ formatted_time(article.created) }} |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<!-- 实现分页 --> |
|
|
|
|
<!-- 实现分页 --> |
|
|
|
|
<div id="paginator"> |
|
|
|
|
<span v-if="is_page_exists('previous')"> |
|
|
|
|
<router-link :to="get_path('previous')"> Prev </router-link> |
|
|
|
@ -41,7 +53,7 @@ |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import $ from "jquery"; |
|
|
|
|
import { onMounted, ref, watch} from "vue"; |
|
|
|
|
import { onMounted, ref, watch } from "vue"; |
|
|
|
|
import { useRoute } from "vue-router"; |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
@ -141,31 +153,31 @@ export default { |
|
|
|
|
return url; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const imageIfExists = (article) => { |
|
|
|
|
if (article.avatar) { |
|
|
|
|
return article.avatar.content; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const gridStyle = (article) => { |
|
|
|
|
if(article.avatar) { |
|
|
|
|
return { |
|
|
|
|
display: 'grid', |
|
|
|
|
gridTemplateColumns: '1fr 1fr 8fr', |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
const imageIfExists = (article) => { |
|
|
|
|
if (article.avatar) { |
|
|
|
|
return article.avatar.content; |
|
|
|
|
} else { |
|
|
|
|
// 默认头像 |
|
|
|
|
return "http://127.0.0.1:6789/media/avatar/20221002/Blog.jpg"; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const gridStyle = () => { |
|
|
|
|
return { |
|
|
|
|
display: "grid", |
|
|
|
|
gridTemplateColumns: "1fr 10fr", |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
onMounted(get_article_data); |
|
|
|
|
|
|
|
|
|
// watch(()=>router.fullPath, () => { |
|
|
|
|
// console.log("路由变化了!"); |
|
|
|
|
// get_article_data(); |
|
|
|
|
// }) |
|
|
|
|
|
|
|
|
|
// watch(()=>router.fullPath, () => { |
|
|
|
|
// console.log("路由变化了!"); |
|
|
|
|
// get_article_data(); |
|
|
|
|
// }) |
|
|
|
|
|
|
|
|
|
// 和上面的功能等价 |
|
|
|
|
watch(router,get_article_data); |
|
|
|
|
// 和上面的功能等价 |
|
|
|
|
watch(router, get_article_data); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
articles, |
|
|
|
@ -173,8 +185,8 @@ export default { |
|
|
|
|
is_page_exists, |
|
|
|
|
get_page_param, |
|
|
|
|
get_article_data, |
|
|
|
|
imageIfExists, |
|
|
|
|
gridStyle, |
|
|
|
|
imageIfExists, |
|
|
|
|
gridStyle, |
|
|
|
|
get_path, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
@ -188,38 +200,65 @@ export default { |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
|
|
|
|
|
|
#articles { |
|
|
|
|
padding: 1rem; |
|
|
|
|
padding: 0.4rem; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.image { |
|
|
|
|
width: 100px; |
|
|
|
|
width: 100%; |
|
|
|
|
border-radius: 10px; |
|
|
|
|
box-shadow: darkslategrey 0 0 12px; |
|
|
|
|
user-select: none; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
.image-container { |
|
|
|
|
width: 100px; |
|
|
|
|
width: 100%; |
|
|
|
|
display: grid; |
|
|
|
|
place-items: center; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.article-info { |
|
|
|
|
width:90%; |
|
|
|
|
border-radius: 10px; |
|
|
|
|
background-color: lightgray; |
|
|
|
|
display: grid; |
|
|
|
|
place-items: start start; |
|
|
|
|
padding-left: 10px; |
|
|
|
|
user-select: none; |
|
|
|
|
position: relative; |
|
|
|
|
left: 20px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.article-info:hover { |
|
|
|
|
cursor: pointer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.grid { |
|
|
|
|
padding-bottom: 10px; |
|
|
|
|
padding-bottom: 5px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
a { |
|
|
|
|
text-decoration: none; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.article-title { |
|
|
|
|
font-size: 1.5rem; |
|
|
|
|
font-weight: bolder; |
|
|
|
|
text-decoration: none; |
|
|
|
|
color: blue; |
|
|
|
|
padding: 15px 0 15px 0; |
|
|
|
|
color: blueviolet; |
|
|
|
|
padding: 5px 0 5px 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.tag { |
|
|
|
|
padding: 2px 5px 2px 5px; |
|
|
|
|
padding: 5px 10px 5px 10px; |
|
|
|
|
margin: 5px 5px 5px 0; |
|
|
|
|
font-family: Georgia, Arial, sans-serif; |
|
|
|
|
font-size: small; |
|
|
|
|
background-color: #4e4e4e; |
|
|
|
|
color: whitesmoke; |
|
|
|
|
border-radius: 5px; |
|
|
|
|
border-radius: 15px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#paginator { |
|
|
|
@ -237,7 +276,6 @@ export default { |
|
|
|
|
font-weight: bold; |
|
|
|
|
padding-left: 10px; |
|
|
|
|
padding-right: 10px; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.category { |
|
|
|
|