mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-08 03:37:28 +08:00
Add ArticleCategory component and update tag/category links
This commit is contained in:
58
open-isle-cli/src/components/ArticleCategory.vue
Normal file
58
open-isle-cli/src/components/ArticleCategory.vue
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<template>
|
||||||
|
<div class="article-category-container" v-if="category">
|
||||||
|
<div class="article-info-item" @click="gotoCategory">
|
||||||
|
<img
|
||||||
|
v-if="category.smallIcon"
|
||||||
|
class="article-info-item-img"
|
||||||
|
:src="category.smallIcon"
|
||||||
|
:alt="category.name"
|
||||||
|
/>
|
||||||
|
<div class="article-info-item-text">{{ category.name }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ArticleCategory',
|
||||||
|
props: {
|
||||||
|
category: { type: Object, default: null }
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
const router = useRouter()
|
||||||
|
const gotoCategory = () => {
|
||||||
|
if (!props.category) return
|
||||||
|
const value = encodeURIComponent(props.category.id ?? props.category.name)
|
||||||
|
router.push({ path: '/', query: { category: value } })
|
||||||
|
}
|
||||||
|
return { gotoCategory }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.article-category-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-info-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 2px 4px;
|
||||||
|
background-color: var(--article-info-background-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-info-item-img {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
class="article-info-item"
|
class="article-info-item"
|
||||||
v-for="tag in tags"
|
v-for="tag in tags"
|
||||||
:key="tag.id || tag.name"
|
:key="tag.id || tag.name"
|
||||||
|
@click="gotoTag(tag)"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
v-if="tag.smallIcon"
|
v-if="tag.smallIcon"
|
||||||
@@ -17,10 +18,20 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ArticleTags',
|
name: 'ArticleTags',
|
||||||
props: {
|
props: {
|
||||||
tags: { type: Array, default: () => [] }
|
tags: { type: Array, default: () => [] }
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
const router = useRouter()
|
||||||
|
const gotoTag = tag => {
|
||||||
|
const value = encodeURIComponent(tag.id ?? tag.name)
|
||||||
|
router.push({ path: '/', query: { tags: value } })
|
||||||
|
}
|
||||||
|
return { gotoTag }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -43,6 +54,7 @@ export default {
|
|||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
background-color: var(--article-info-background-color);
|
background-color: var(--article-info-background-color);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.article-info-item-img {
|
.article-info-item-img {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
</router-link>
|
</router-link>
|
||||||
<div class="article-item-description main-item">{{ sanitizeDescription(article.description) }}</div>
|
<div class="article-item-description main-item">{{ sanitizeDescription(article.description) }}</div>
|
||||||
<div class="article-info-container main-item">
|
<div class="article-info-container main-item">
|
||||||
<ArticleTags :tags="[article.category]" />
|
<ArticleCategory :category="article.category" />
|
||||||
<ArticleTags :tags="article.tags" />
|
<ArticleTags :tags="article.tags" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -104,6 +104,7 @@ import TimeManager from '../utils/time'
|
|||||||
import CategorySelect from '../components/CategorySelect.vue'
|
import CategorySelect from '../components/CategorySelect.vue'
|
||||||
import TagSelect from '../components/TagSelect.vue'
|
import TagSelect from '../components/TagSelect.vue'
|
||||||
import ArticleTags from '../components/ArticleTags.vue'
|
import ArticleTags from '../components/ArticleTags.vue'
|
||||||
|
import ArticleCategory from '../components/ArticleCategory.vue'
|
||||||
import SearchDropdown from '../components/SearchDropdown.vue'
|
import SearchDropdown from '../components/SearchDropdown.vue'
|
||||||
import { hatch } from 'ldrs'
|
import { hatch } from 'ldrs'
|
||||||
hatch.register()
|
hatch.register()
|
||||||
@@ -115,15 +116,20 @@ export default {
|
|||||||
CategorySelect,
|
CategorySelect,
|
||||||
TagSelect,
|
TagSelect,
|
||||||
ArticleTags,
|
ArticleTags,
|
||||||
|
ArticleCategory,
|
||||||
SearchDropdown
|
SearchDropdown
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const selectedCategory = ref(route.query.category || '')
|
const selectedCategory = ref(route.query.category ? decodeURIComponent(route.query.category) : '')
|
||||||
const selectedTags = ref([])
|
const selectedTags = ref([])
|
||||||
if (route.query.tags) {
|
if (route.query.tags) {
|
||||||
const t = Array.isArray(route.query.tags) ? route.query.tags.join(',') : route.query.tags
|
const t = Array.isArray(route.query.tags) ? route.query.tags.join(',') : route.query.tags
|
||||||
selectedTags.value = t.split(',').filter(v => v).map(v => isNaN(v) ? v : Number(v))
|
selectedTags.value = t
|
||||||
|
.split(',')
|
||||||
|
.filter(v => v)
|
||||||
|
.map(v => decodeURIComponent(v))
|
||||||
|
.map(v => (isNaN(v) ? v : Number(v)))
|
||||||
}
|
}
|
||||||
const isLoadingPosts = ref(false)
|
const isLoadingPosts = ref(false)
|
||||||
const topics = ref(['最新', '排行榜' /*, '热门', '类别'*/])
|
const topics = ref(['最新', '排行榜' /*, '热门', '类别'*/])
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<div class="article-title-container">
|
<div class="article-title-container">
|
||||||
<div class="article-title">{{ title }}</div>
|
<div class="article-title">{{ title }}</div>
|
||||||
<div class="article-info-container">
|
<div class="article-info-container">
|
||||||
<ArticleTags :tags="[category]" />
|
<ArticleCategory :category="category" />
|
||||||
<ArticleTags :tags="tags" />
|
<ArticleTags :tags="tags" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -78,6 +78,7 @@ import CommentItem from '../components/CommentItem.vue'
|
|||||||
import CommentEditor from '../components/CommentEditor.vue'
|
import CommentEditor from '../components/CommentEditor.vue'
|
||||||
import BaseTimeline from '../components/BaseTimeline.vue'
|
import BaseTimeline from '../components/BaseTimeline.vue'
|
||||||
import ArticleTags from '../components/ArticleTags.vue'
|
import ArticleTags from '../components/ArticleTags.vue'
|
||||||
|
import ArticleCategory from '../components/ArticleCategory.vue'
|
||||||
import ReactionsGroup from '../components/ReactionsGroup.vue'
|
import ReactionsGroup from '../components/ReactionsGroup.vue'
|
||||||
import { renderMarkdown } from '../utils/markdown'
|
import { renderMarkdown } from '../utils/markdown'
|
||||||
import { API_BASE_URL, toast } from '../main'
|
import { API_BASE_URL, toast } from '../main'
|
||||||
@@ -89,7 +90,7 @@ hatch.register()
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PostPageView',
|
name: 'PostPageView',
|
||||||
components: { CommentItem, CommentEditor, BaseTimeline, ArticleTags, ReactionsGroup },
|
components: { CommentItem, CommentEditor, BaseTimeline, ArticleTags, ArticleCategory, ReactionsGroup },
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const postId = route.params.id
|
const postId = route.params.id
|
||||||
|
|||||||
Reference in New Issue
Block a user