web-资源修改

This commit is contained in:
2025-10-20 15:08:41 +08:00
parent 16824537d1
commit 6f9244eade
6 changed files with 171 additions and 73 deletions

View File

@@ -15,7 +15,7 @@
<el-table-column prop="title" label="文章标题" min-width="200" />
<el-table-column prop="category" label="分类" width="120" />
<el-table-column prop="author" label="作者" width="120" />
<el-table-column prop="publishDate" label="发布日期" width="120" />
<el-table-column prop="publishTime" label="发布日期" width="120" />
<el-table-column prop="views" label="阅读量" width="100" />
<el-table-column prop="status" label="状态" width="100">
<template #default="{ row }">
@@ -26,20 +26,34 @@
</el-table-column>
<el-table-column label="操作" width="200" fixed="right">
<template #default="{ row }">
<el-button size="small" @click="viewArticle(row)">查看</el-button>
<el-button size="small" @click="editArticle(row)">编辑</el-button>
<el-button size="small" type="danger" @click="deleteArticle(row)">删除</el-button>
<el-button size="small" type="danger" @click="deleteArticle()">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
v-model:current-page="currentPage"
v-model:page-size="pageSize"
v-model:current-page="pageParam.page"
v-model:page-size="pageParam.size"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
<!-- 文章查看弹窗 -->
<ArticleShowView
v-model="showViewDialog"
:as-dialog="true"
title="文章详情"
width="900px"
:article-data="currentArticle"
:category-list="categoryList"
:show-edit-button="true"
@edit="handleEditFromView"
@close="showViewDialog = false"
/>
</div>
</template>
@@ -47,20 +61,47 @@
import { ref, onMounted } from 'vue';
import { ElButton, ElInput, ElTable, ElTableColumn, ElTag, ElPagination, ElMessage } from 'element-plus';
import { useRouter } from 'vue-router';
import { resourceApi, resourceCategoryApi } from '@/apis/resource'
import type { PageParam, ResourceSearchParams, Resource, ResourceCategory } from '@/types';
import { ArticleShowView } from '@/views/article';
const router = useRouter();
const searchKeyword = ref('');
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const articles = ref<any[]>([]);
const pageParam = ref<PageParam>({
page: 1,
size: 10
});
const filter = ref<ResourceSearchParams>({
keyword: searchKeyword.value
});
const total = ref<number>(0);
const articles = ref<Resource[]>([]);
const showViewDialog = ref(false);
const currentArticle = ref<any>(null);
const categoryList = ref<ResourceCategory[]>([]);
onMounted(() => {
loadArticles();
loadCategories();
});
function loadArticles() {
// TODO: 加载文章数据
async function loadCategories() {
try {
const res = await resourceCategoryApi.getCategoryList();
if (res.success && res.dataList) {
categoryList.value = res.dataList;
}
} catch (error) {
console.error('加载分类列表失败:', error);
}
}
async function loadArticles() {
const res = await resourceApi.getResourcePage(pageParam.value, filter.value);
if (res.success) {
articles.value = res.pageDomain?.dataList || [];
total.value = res.pageDomain?.total || 0;
}
}
function showCreateDialog() {
@@ -80,12 +121,40 @@ function handleDataCollection() {
ElMessage.info('数据采集功能开发中');
}
function editArticle(row: any) {
// TODO: 编辑文章
async function viewArticle(row: any) {
try {
const res = await resourceApi.getResourceById(row.resourceID);
if (res.success && res.data) {
// 将 ResourceVO 转换为 ArticleShowView 期望的格式
const resourceVO = res.data;
currentArticle.value = {
...resourceVO.resource,
tags: resourceVO.tags || []
};
showViewDialog.value = true;
} else {
ElMessage.error('获取文章详情失败');
}
} catch (error) {
ElMessage.error('获取文章详情失败');
console.error(error);
}
}
function deleteArticle(row: any) {
function editArticle(row: any) {
router.push('/article/add?id=' + row.resourceID);
}
function handleEditFromView() {
if (currentArticle.value?.resourceID) {
showViewDialog.value = false;
router.push('/article/add?id=' + currentArticle.value.resourceID);
}
}
function deleteArticle() {
// TODO: 删除文章
ElMessage.info('删除功能开发中');
}
function getStatusType(status: string) {
@@ -107,12 +176,12 @@ function getStatusText(status: string) {
}
function handleSizeChange(val: number) {
pageSize.value = val;
pageParam.value.size = val;
loadArticles();
}
function handleCurrentChange(val: number) {
currentPage.value = val;
pageParam.value.page = val;
loadArticles();
}
</script>