6 changed files with 137 additions and 63 deletions
-
2src/apis/voteDetail.js
-
31src/components/home/AsideMenu.vue
-
50src/router/index.js
-
8src/stores/voteDetail.js
-
73src/views/ArticleList/ArticleList.vue
-
6src/views/Vote/Vote.vue
@ -1,46 +1,50 @@ |
|||
import { createRouter, createWebHistory } from 'vue-router' |
|||
import HomeView from '../views/HomeView.vue' |
|||
import { createRouter, createWebHistory } from "vue-router"; |
|||
import HomeView from "../views/HomeView.vue"; |
|||
|
|||
const router = createRouter({ |
|||
history: createWebHistory(import.meta.env.BASE_URL), |
|||
routes: [ |
|||
{ |
|||
path: '/', |
|||
name: 'home', |
|||
path: "/", |
|||
name: "home", |
|||
component: HomeView, |
|||
children: [ |
|||
{ |
|||
path: 'article', |
|||
name: 'article', |
|||
path: "article", |
|||
name: "article", |
|||
// route level code-splitting
|
|||
// this generates a separate chunk (About.[hash].js) for this route
|
|||
// which is lazy-loaded when the route is visited.
|
|||
component: () => import('@/views/Article/Article.vue'), |
|||
component: () => import("@/views/Article/Article.vue"), |
|||
}, |
|||
{ |
|||
path: 'vote', |
|||
name: 'vote', |
|||
component: () => import('@/views/Vote/Vote.vue'), |
|||
path: "vote", |
|||
name: "vote", |
|||
component: () => import("@/views/Vote/Vote.vue"), |
|||
}, |
|||
{ |
|||
path: 'voteRecord', |
|||
name: 'voteRecord', |
|||
component: () => import('@/views/VoteRecord/VoteRecord.vue'), |
|||
path: "voteRecord", |
|||
name: "voteRecord", |
|||
component: () => import("@/views/VoteRecord/VoteRecord.vue"), |
|||
}, |
|||
{ |
|||
path: 'voteDetail', |
|||
name: 'voteDetail', |
|||
component: () => import('@/views/VoteDetail/VoteDetail.vue'), |
|||
path: "voteDetail", |
|||
name: "voteDetail", |
|||
component: () => import("@/views/VoteDetail/VoteDetail.vue"), |
|||
}, |
|||
{ |
|||
path: 'test', |
|||
name: 'test', |
|||
component: () => import('@/views/test/test.vue'), |
|||
path: "articleList", |
|||
name: "articleList", |
|||
component: () => import("@/views/ArticleList/ArticleList.vue") |
|||
}, |
|||
] |
|||
{ |
|||
path: "test", |
|||
name: "test", |
|||
component: () => import("@/views/test/test.vue"), |
|||
}, |
|||
], |
|||
}, |
|||
|
|||
], |
|||
}) |
|||
}); |
|||
|
|||
export default router |
|||
export default router; |
@ -0,0 +1,73 @@ |
|||
<!-- ArticleList.vue --> |
|||
<template> |
|||
<div> |
|||
<el-table :data="tableData" style="width: 100%"> |
|||
<el-table-column label="文章标题" prop="articleTitle" /> |
|||
<el-table-column label="是否开启投票"> |
|||
<template #default="{ row }"> |
|||
<span>{{ row.voteStatus === 1 ? '是' : '否' }}</span> |
|||
</template> |
|||
</el-table-column> |
|||
<el-table-column label="发布时间" prop="createTime" /> |
|||
<el-table-column label="操作"> |
|||
<template #default="{ row }"> |
|||
<el-button @click="viewArticle(row)" type="primary">查看</el-button> |
|||
</template> |
|||
</el-table-column> |
|||
</el-table> |
|||
<el-dialog v-model="centerDialogVisible" title="提示" width="500" align-center> |
|||
<span>该文章未开启投票活动</span> |
|||
<template #footer> |
|||
<div class="dialog-footer"> |
|||
<el-button type="primary" @click="centerDialogVisible = false"> |
|||
确认 |
|||
</el-button> |
|||
</div> |
|||
</template> |
|||
</el-dialog> |
|||
</div> |
|||
</template> |
|||
|
|||
<script setup> |
|||
import { useVoteDetailStore } from '@/stores/voteDetail' |
|||
import { ref, onMounted } from 'vue'; |
|||
import { useRouter } from 'vue-router' |
|||
import { ElTable, ElTableColumn, ElButton } from 'element-plus'; |
|||
const tableData = ref([]) |
|||
// 获取投票数据函数 |
|||
const fetchVoteData = async () => { |
|||
try { |
|||
const res = await useVoteDetailStore().getArticleList() |
|||
console.log(res) |
|||
tableData.value = res.data.data.articleList |
|||
} catch (err) { |
|||
console.error('请求失败', err) |
|||
} |
|||
} |
|||
onMounted(async () => { |
|||
fetchVoteData() |
|||
}) |
|||
const router = useRouter() |
|||
const centerDialogVisible = ref(false) |
|||
|
|||
|
|||
const viewArticle = (article) => { |
|||
if (article.voteStatus == 0) { |
|||
centerDialogVisible.value = true |
|||
return |
|||
} |
|||
|
|||
router.push({ |
|||
path: '/vote', |
|||
query: { |
|||
articleId: article.articleId |
|||
} |
|||
}) |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.el-button { |
|||
margin-right: 10px; |
|||
} |
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue