|
| 1 | +<template> |
| 2 | + <div class="blog-container jobs-page"> |
| 3 | + <div class="page-header"> |
| 4 | + <h1 class="page-title">求职导航</h1> |
| 5 | + <p class="page-subtitle">求职经验、面试技巧、行业洞见</p> |
| 6 | + </div> |
| 7 | + |
| 8 | + <div v-if="loading" class="article-detail-loading">加载中...</div> |
| 9 | + |
| 10 | + <div v-else-if="articles.length === 0" class="card"> |
| 11 | + <div class="card-body" style="padding: 22px; color: var(--muted)">暂无内容</div> |
| 12 | + </div> |
| 13 | + |
| 14 | + <div v-else class="article-grid"> |
| 15 | + <ArticleCard v-for="a in articles" :key="a.id" :article="a" /> |
| 16 | + </div> |
| 17 | + |
| 18 | + <div v-if="total > size" class="pagination" style="margin-top: 24px; display: flex; justify-content: center; gap: 12px"> |
| 19 | + <button class="btn" :disabled="page <= 0" @click="goPage(page - 1)">上一页</button> |
| 20 | + <span style="line-height: 36px; color: var(--muted); font-size: 13px"> |
| 21 | + {{ page + 1 }} / {{ Math.ceil(total / size) }} |
| 22 | + </span> |
| 23 | + <button class="btn" :disabled="(page + 1) * size >= total" @click="goPage(page + 1)">下一页</button> |
| 24 | + </div> |
| 25 | + </div> |
| 26 | +</template> |
| 27 | + |
| 28 | +<script setup> |
| 29 | +import { onMounted, ref, watch } from 'vue' |
| 30 | +import { useRoute, useRouter } from 'vue-router' |
| 31 | +import { fetchArticlesByType } from '../api/article' |
| 32 | +import ArticleCard from '../components/ArticleCard.vue' |
| 33 | +
|
| 34 | +const route = useRoute() |
| 35 | +const router = useRouter() |
| 36 | +const loading = ref(true) |
| 37 | +const articles = ref([]) |
| 38 | +const page = ref(0) |
| 39 | +const size = 20 |
| 40 | +const total = ref(0) |
| 41 | +
|
| 42 | +async function load() { |
| 43 | + loading.value = true |
| 44 | + try { |
| 45 | + const p = Number(route.query.page) || 0 |
| 46 | + page.value = p |
| 47 | + const resp = await fetchArticlesByType('JOB_NAV', { page: p, size }) |
| 48 | + articles.value = resp?.items || [] |
| 49 | + total.value = resp?.total ?? 0 |
| 50 | + } finally { |
| 51 | + loading.value = false |
| 52 | + } |
| 53 | +} |
| 54 | +
|
| 55 | +function goPage(p) { |
| 56 | + router.push({ query: { page: String(p) } }) |
| 57 | +} |
| 58 | +
|
| 59 | +watch(() => route.query.page, () => load()) |
| 60 | +onMounted(() => load()) |
| 61 | +</script> |
| 62 | +
|
| 63 | +<style scoped> |
| 64 | +.page-header { |
| 65 | + margin-bottom: 24px; |
| 66 | +} |
| 67 | +.page-title { |
| 68 | + font-size: 28px; |
| 69 | + font-weight: 800; |
| 70 | + letter-spacing: -0.02em; |
| 71 | +} |
| 72 | +.page-subtitle { |
| 73 | + color: var(--muted); |
| 74 | + font-size: 14px; |
| 75 | + margin-top: 6px; |
| 76 | +} |
| 77 | +.article-grid { |
| 78 | + display: flex; |
| 79 | + flex-direction: column; |
| 80 | + gap: 16px; |
| 81 | +} |
| 82 | +</style> |
0 commit comments