2024-10-31 09:56:55 +08:00
|
|
|
<template>
|
|
|
|
<div class="system-dept-container layout-padding">
|
|
|
|
<el-card shadow="hover" class="layout-padding-auto">
|
|
|
|
<div class="system-dept-search mb15">
|
|
|
|
<el-select @change="handleChangeModule" size="default" v-model="state.tableData.param.moduleName" placeholder="请选择模块" clearable style="max-width: 180px">
|
|
|
|
<el-option :data-op="item.id" v-for="(item,index) in moduleList" :key="index" :label="item.moduleName" :value="item.moduleName"></el-option>
|
|
|
|
</el-select>
|
|
|
|
<el-select size="default" v-model="state.tableData.param.labelName" placeholder="请选择标签" clearable class="ml10" style="max-width: 180px">
|
|
|
|
<el-option v-for="(item,index) in labelList" :key="index" :label="item.name" :value="item.name"></el-option>
|
|
|
|
</el-select>
|
|
|
|
<el-input size="default" placeholder="请输入标题" v-model="state.tableData.param.title" class="ml10" style="max-width: 180px"> </el-input>
|
|
|
|
<el-button @click="getTableData" size="default" type="primary" class="ml10">
|
|
|
|
<el-icon>
|
|
|
|
<ele-Search />
|
|
|
|
</el-icon>
|
|
|
|
查询
|
|
|
|
</el-button>
|
|
|
|
<el-button @click="reset" size="default" type="primary" class="ml10">
|
|
|
|
<el-icon>
|
|
|
|
<ele-RefreshRight />
|
|
|
|
</el-icon>
|
|
|
|
重置
|
|
|
|
</el-button>
|
|
|
|
<el-button @click="toAddArticle" size="default" type="success" class="ml10">
|
|
|
|
<el-icon>
|
|
|
|
<ele-FolderAdd />
|
|
|
|
</el-icon>
|
|
|
|
新增文章
|
|
|
|
</el-button>
|
|
|
|
</div>
|
|
|
|
<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
|
|
|
|
<el-table-column type="index" label="序号" width="100"/>
|
|
|
|
<el-table-column prop="title" label="标题" show-overflow-tooltip></el-table-column>
|
|
|
|
<el-table-column prop="articletype" label="文章类型" :formatter="typeFormatter" show-overflow-tooltip></el-table-column>
|
|
|
|
<el-table-column label="置顶" show-overflow-tooltip>
|
|
|
|
<template #default="scope">
|
|
|
|
<el-tag type="success" v-if="scope.row.top===1">是</el-tag>
|
|
|
|
<el-tag type="error" v-else>否</el-tag>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
2025-01-06 12:22:14 +08:00
|
|
|
<el-table-column prop="moduleName" label="模块名称" show-overflow-tooltip></el-table-column>
|
|
|
|
<el-table-column prop="labelName" label="标签名称" show-overflow-tooltip></el-table-column>
|
2024-12-05 16:21:58 +08:00
|
|
|
<el-table-column prop="htmlPath" label="链接" min-width="80">
|
|
|
|
<template #default="scope">
|
|
|
|
<el-button size="mini" style="border-radius: 10px;" @click="copyLink(scope.row)">复制</el-button>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
2024-10-31 09:56:55 +08:00
|
|
|
<el-table-column prop="createtime" label="创建时间" :formatter="dateFormatter" show-overflow-tooltip></el-table-column>
|
|
|
|
<el-table-column label="操作" width="200">
|
|
|
|
<template #default="scope">
|
|
|
|
<el-button size="small" text type="primary" @click="toShowDetail(scope.row)">查看详情</el-button>
|
2024-12-05 16:21:58 +08:00
|
|
|
<el-button size="small" text type="primary" @click="toPreview(scope.row)">预览</el-button>
|
2024-10-31 09:56:55 +08:00
|
|
|
<el-button size="small" text type="primary" @click="toEditArticle(scope.row)">修改</el-button>
|
|
|
|
<el-button size="small" text type="primary" @click="deleteArticle(scope.row.id)">删除</el-button>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
<el-pagination
|
|
|
|
@size-change="onHandleSizeChange"
|
|
|
|
@current-change="onHandleCurrentChange"
|
|
|
|
class="mt15"
|
|
|
|
:pager-count="5"
|
|
|
|
:page-sizes="[10, 20, 30]"
|
|
|
|
v-model:current-page="state.tableData.param.current"
|
|
|
|
background
|
|
|
|
v-model:page-size="state.tableData.param.size"
|
|
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
|
|
:total="state.tableData.total"
|
|
|
|
>
|
|
|
|
</el-pagination>
|
|
|
|
</el-card>
|
|
|
|
<!-- <DeptDialog ref="deptDialogRef" @refresh="getTableData()" /> -->
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-12-05 14:58:48 +08:00
|
|
|
<script setup lang="ts" name="article">
|
2025-01-14 17:43:50 +08:00
|
|
|
import { onActivated, onMounted, reactive, ref } from 'vue';
|
2024-10-31 09:56:55 +08:00
|
|
|
import { articleApi } from '/@/api/article';
|
|
|
|
import { ElMessage, ElMessageBox, TableColumnCtx } from 'element-plus';
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
// 表格数据
|
|
|
|
const state = reactive({
|
|
|
|
tableData: {
|
|
|
|
data: [],
|
|
|
|
total: 0,
|
|
|
|
loading: false,
|
|
|
|
param: {
|
|
|
|
labelName: '',
|
|
|
|
moduleName: '',
|
|
|
|
title: '',
|
|
|
|
current: 1,
|
|
|
|
size: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// 模块列表
|
|
|
|
const moduleList = ref([]);
|
|
|
|
|
|
|
|
// 标签列表
|
|
|
|
const labelList = ref([]);
|
|
|
|
|
2024-12-05 16:21:58 +08:00
|
|
|
// 基本路径
|
|
|
|
const viteUrl = import.meta.env.VITE_API_URL;
|
|
|
|
|
2024-10-31 09:56:55 +08:00
|
|
|
// 引入 api 请求接口
|
|
|
|
const artApi = articleApi();
|
|
|
|
|
|
|
|
// 获取表格数据
|
|
|
|
const getTableData = async() => {
|
|
|
|
try {
|
|
|
|
state.tableData.loading = true;
|
|
|
|
let res = await artApi.getArticleList(state.tableData.param);
|
|
|
|
if(res?.success){
|
2025-01-06 12:22:14 +08:00
|
|
|
state.tableData.data = res.data.records.map((item:any) => {
|
|
|
|
return{
|
|
|
|
...item,
|
|
|
|
moduleName:item.moduleName || '未设置',
|
|
|
|
labelName:item.labelName || '未设置',
|
|
|
|
}
|
|
|
|
});
|
2024-10-31 09:56:55 +08:00
|
|
|
state.tableData.total = res.data.total;
|
|
|
|
}else{
|
|
|
|
ElMessage.error('文章列表获取失败!');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} finally {
|
|
|
|
state.tableData.loading = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const getModuleList = async() => {
|
|
|
|
try {
|
|
|
|
let res = await artApi.getModuleList();
|
|
|
|
if(res?.success){
|
|
|
|
moduleList.value = res.data;
|
|
|
|
}else{
|
|
|
|
ElMessage.error('模块列表获取失败!');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
ElMessage.error('模块列表获取失败!');
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 模块选择
|
|
|
|
const handleChangeModule = async(val: any) => {
|
|
|
|
try {
|
|
|
|
state.tableData.param.labelName = '';
|
|
|
|
if(!val){labelList.value=[]; return;}
|
|
|
|
const op:any = event?.currentTarget;
|
|
|
|
let res = await artApi.getLabelList(op.dataset.op);
|
|
|
|
if(res?.success){
|
|
|
|
labelList.value = res.data;
|
|
|
|
}else{
|
|
|
|
ElMessage.error('标签列表获取失败!');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
ElMessage.error('标签列表获取失败!');
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重置
|
|
|
|
const reset = () =>{
|
|
|
|
state.tableData.param = {
|
|
|
|
labelName: '',
|
|
|
|
moduleName: '',
|
|
|
|
title: '',
|
|
|
|
current: 1,
|
|
|
|
size: 10,
|
|
|
|
}
|
|
|
|
getTableData();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 添加文章
|
|
|
|
const toAddArticle = () => {
|
|
|
|
router.push({ path: '/article/add' });
|
|
|
|
}
|
|
|
|
|
|
|
|
// 添加文章
|
|
|
|
const toEditArticle = (row: any) => {
|
2024-11-12 17:35:06 +08:00
|
|
|
router.push({ path: '/article/edit', query: { id:row.id, moduleName: row.moduleName, labelName: row.labelName } });
|
2024-10-31 09:56:55 +08:00
|
|
|
}
|
|
|
|
|
2024-12-05 16:21:58 +08:00
|
|
|
// 复制链接
|
|
|
|
const copyLink = (row: any) => {
|
|
|
|
if(row.id == null||row.id == ''){ ElMessage.warning('链接为空');return;}
|
|
|
|
var aux = document.createElement("input");
|
2024-12-10 10:24:23 +08:00
|
|
|
aux.setAttribute("value", `${viteUrl}vueAdmin/#article/content?id=${row.id}`);
|
2024-12-05 16:21:58 +08:00
|
|
|
document.body.appendChild(aux);
|
|
|
|
aux.select();
|
|
|
|
document.execCommand("copy");
|
|
|
|
document.body.removeChild(aux);
|
|
|
|
ElMessage.success('复制成功');
|
|
|
|
aux.remove();
|
|
|
|
}
|
|
|
|
|
2024-10-31 09:56:55 +08:00
|
|
|
// 文章详情
|
|
|
|
const toShowDetail = (row: any) => {
|
2024-11-12 17:35:06 +08:00
|
|
|
router.push({ path: '/article/detail' , query: { id:row.id, moduleName: row.moduleName, labelName: row.labelName } });
|
2024-10-31 09:56:55 +08:00
|
|
|
}
|
|
|
|
|
2024-12-05 16:21:58 +08:00
|
|
|
// 预览
|
|
|
|
const toPreview = (row: any) => {
|
2024-12-10 10:24:23 +08:00
|
|
|
window.open(`${viteUrl}vueAdmin/#article/content?id=${row.id}`);
|
2024-12-05 16:21:58 +08:00
|
|
|
}
|
|
|
|
|
2024-10-31 09:56:55 +08:00
|
|
|
// 文章删除
|
|
|
|
const deleteArticle = (id: number) => {
|
|
|
|
ElMessageBox.confirm('确定要删除该文章吗?', '提示', {
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning',
|
|
|
|
})
|
|
|
|
.then(async() => {
|
|
|
|
try {
|
|
|
|
state.tableData.loading = true;
|
|
|
|
let res = await artApi.deleteArticle(id);
|
|
|
|
if(res?.success){
|
|
|
|
await getTableData();
|
|
|
|
ElMessage.success('文章删除成功!');
|
|
|
|
} else ElMessage.error('文章删除失败!');
|
|
|
|
} catch(e) {
|
|
|
|
ElMessage.error('处理失败!');
|
|
|
|
} finally {
|
|
|
|
state.tableData.loading = false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 日期格式化
|
|
|
|
const dateFormatter = (row: any, column: TableColumnCtx<String>) => {
|
|
|
|
let date = new Date(row.createtime);
|
|
|
|
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 文章类型格式化
|
|
|
|
const typeFormatter = (row: any, column: TableColumnCtx<String>) => {
|
|
|
|
return row.articletype === 1 ? '外链' : '图文';
|
|
|
|
}
|
|
|
|
|
|
|
|
// 分页改变
|
|
|
|
const onHandleSizeChange = (val: number) => {
|
|
|
|
state.tableData.param.size = val;
|
|
|
|
getTableData();
|
|
|
|
};
|
|
|
|
|
|
|
|
// 分页改变
|
|
|
|
const onHandleCurrentChange = (val: number) => {
|
|
|
|
state.tableData.param.current = val;
|
|
|
|
getTableData();
|
|
|
|
};
|
|
|
|
|
2025-01-14 17:43:50 +08:00
|
|
|
onActivated(() => {
|
|
|
|
getTableData();
|
|
|
|
})
|
|
|
|
|
2024-10-31 09:56:55 +08:00
|
|
|
onMounted(() => {
|
|
|
|
getTableData();
|
|
|
|
getModuleList();
|
|
|
|
})
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.system-dept-container {
|
|
|
|
:deep(.el-card__body) {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex: 1;
|
|
|
|
overflow: auto;
|
|
|
|
.el-table {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|