<template>
|
<div class="ArticleManagement">
|
<el-row :gutter="20">
|
<el-col :span="24" :xs="24">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form-item label="文章标题" prop="title">
|
<el-input
|
v-model="queryParams.title"
|
placeholder="请输入文章标题"
|
clearable
|
style="width: 200px"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="文章分类" prop="category">
|
<el-select v-model="queryParams.category" placeholder="请选择分类" clearable style="width: 200px">
|
<el-option
|
v-for="item in categoryOptions"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="状态" prop="status">
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 200px">
|
<el-option
|
v-for="item in statusOptions"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery">搜索</el-button>
|
<el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-form>
|
|
<el-row :gutter="10" class="mb8">
|
<el-col :span="1.5">
|
<el-button
|
type="primary"
|
plain
|
icon="el-icon-plus"
|
size="medium"
|
@click="handleAdd"
|
>新增</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="danger"
|
plain
|
icon="el-icon-delete"
|
size="medium"
|
:disabled="multiple"
|
@click="handleDelete"
|
>删除</el-button>
|
</el-col>
|
</el-row>
|
|
<el-table v-loading="loading" :data="filteredArticleList" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="50" align="center" />
|
<el-table-column label="文章ID" align="center" prop="id" width="80" />
|
<el-table-column label="文章标题" align="center" prop="title" :show-overflow-tooltip="true" />
|
<el-table-column label="文章分类" align="center" prop="category" width="120">
|
<template slot-scope="scope">
|
<dict-tag :options="categoryOptions" :value="scope.row.category"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="封面图" align="center" prop="coverImage" width="120">
|
<template slot-scope="scope">
|
<el-image
|
v-if="scope.row.coverImage"
|
style="width: 80px; height: 60px"
|
:src="scope.row.coverImage"
|
:preview-src-list="[scope.row.coverImage]"
|
fit="cover"
|
/>
|
<span v-else>无封面</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="作者" align="center" prop="author" width="120" />
|
<el-table-column label="发布时间" align="center" prop="publishTime" width="160">
|
<template slot-scope="scope">
|
<span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d} {h}:{i}') }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="阅读量" align="center" prop="views" width="80" />
|
<el-table-column label="状态" align="center" prop="status" width="100">
|
<template slot-scope="scope">
|
<dict-tag :options="statusOptions" :value="scope.row.status"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
|
<template slot-scope="scope">
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-edit"
|
@click="handleUpdate(scope.row)"
|
>修改</el-button>
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-delete"
|
@click="handleDelete(scope.row)"
|
>删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<pagination
|
v-show="total>0"
|
:total="total"
|
:page.sync="queryParams.pageNum"
|
:limit.sync="queryParams.pageSize"
|
@pagination="getList"
|
/>
|
</el-col>
|
</el-row>
|
|
<!-- 添加或修改文章对话框 -->
|
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="文章标题" prop="title">
|
<el-input v-model="form.title" placeholder="请输入文章标题" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="文章分类" prop="category">
|
<el-select v-model="form.category" placeholder="请选择分类">
|
<el-option
|
v-for="item in categoryOptions"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="状态" prop="status">
|
<el-radio-group v-model="form.status">
|
<el-radio
|
v-for="dict in statusOptions"
|
:key="dict.value"
|
:label="dict.value"
|
>{{dict.label}}</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="封面图">
|
<el-upload
|
class="avatar-uploader"
|
action="#"
|
:show-file-list="false"
|
:on-change="handleCoverChange"
|
:auto-upload="false">
|
<img v-if="form.coverImage" :src="form.coverImage" class="avatar">
|
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
</el-upload>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="文章摘要" prop="summary">
|
<el-input
|
type="textarea"
|
:rows="3"
|
v-model="form.summary"
|
placeholder="请输入文章摘要"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="文章内容" prop="content">
|
<editor v-model="form.content" :min-height="300"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { parseTime } from '@/utils/ruoyi'
|
|
export default {
|
name: "ArticleManagement",
|
dicts: ['sys_normal_disable', 'sys_user_sex'],
|
data() {
|
return {
|
// 遮罩层
|
loading: false,
|
// 选中数组
|
ids: [],
|
// 非单个禁用
|
single: true,
|
// 非多个禁用
|
multiple: true,
|
// 显示搜索条件
|
showSearch: true,
|
// 总条数
|
total: 0,
|
// 文章表格数据
|
// 替换原有的articleList数据
|
articleList: [
|
{
|
id: 1,
|
title: "糖尿病管理新进展:个性化治疗方案的研究与应用",
|
category: "1",
|
coverImage: "https://example.com/images/diabetes-management.jpg",
|
author: "李成白",
|
publishTime: "2024-11-15 09:30:00",
|
views: 3250,
|
status: "1",
|
summary: "本文综述了近年来糖尿病个性化治疗的最新研究成果,重点分析了基于患者基因特征的定制化治疗方案。",
|
content: "<p>随着精准医疗的发展,糖尿病治疗正从标准化向个性化转变...</p>"
|
},
|
{
|
id: 2,
|
title: "心血管疾病预防:从风险评估到早期干预",
|
category: "2",
|
coverImage: "https://example.com/images/cardiovascular-prevention.jpg",
|
author: "刘翊惠",
|
publishTime: "2024-11-10 14:20:00",
|
views: 4280,
|
status: "1",
|
summary: "探讨心血管疾病的新型风险评估工具和早期干预策略,为临床实践提供指导。",
|
content: "<p>心血管疾病仍然是全球主要的死亡原因,早期预防至关重要...</p>"
|
},
|
{
|
id: 3,
|
title: "肿瘤免疫治疗的不良反应管理与应对策略",
|
category: "3",
|
coverImage: "https://example.com/images/immunotherapy-side-effects.jpg",
|
author: "张孟涵",
|
publishTime: "2024-11-05 10:15:00",
|
views: 2890,
|
status: "0",
|
summary: "系统分析免疫检查点抑制剂治疗中常见的不良反应及其临床管理方案。",
|
content: "<p>免疫治疗为肿瘤患者带来希望,但其独特的不良反应需要特别关注...</p>"
|
},
|
{
|
id: 4,
|
title: "人工智能在医学影像诊断中的应用与挑战",
|
category: "4",
|
coverImage: "https://example.com/images/ai-medical-imaging.jpg",
|
author: "吴思翰",
|
publishTime: "2024-10-28 16:45:00",
|
views: 5120,
|
status: "1",
|
summary: "回顾AI技术在CT、MRI等医学影像分析中的最新进展及临床应用价值。",
|
content: "<p>人工智能技术正在重塑医学影像诊断的格局...</p>"
|
},
|
{
|
id: 5,
|
title: "慢性疼痛的药物治疗与非药物干预综合管理",
|
category: "1",
|
coverImage: "https://example.com/images/chronic-pain-management.jpg",
|
author: "陈政倩",
|
publishTime: "2024-10-22 11:10:00",
|
views: 1950,
|
status: "1",
|
summary: "基于循证医学证据,提出慢性疼痛的综合管理方案,平衡疗效与安全性。",
|
content: "<p>慢性疼痛严重影响患者生活质量,需要多模式综合治疗...</p>"
|
},
|
{
|
id: 6,
|
title: "儿科呼吸道感染的诊疗规范更新解读",
|
category: "2",
|
coverImage: "https://example.com/images/pediatric-respiratory.jpg",
|
author: "邓诗涵",
|
publishTime: "2024-10-18 13:25:00",
|
views: 3670,
|
status: "1",
|
summary: "结合最新临床指南,详细解读儿童呼吸道感染的诊断标准和治疗原则。",
|
content: "<p>儿童呼吸道感染是儿科常见病,规范诊疗对预后至关重要...</p>"
|
},
|
{
|
id: 7,
|
title: "精神卫生数字疗法的现状与未来发展",
|
category: "3",
|
coverImage: "https://example.com/images/digital-mental-health.jpg",
|
author: "黄盛玫",
|
publishTime: "2024-10-12 15:30:00",
|
views: 2430,
|
status: "2",
|
summary: "探讨数字技术在精神心理疾病治疗中的应用前景和面临的挑战。",
|
content: "<p>数字疗法为精神卫生领域带来了新的治疗模式...</p>"
|
},
|
{
|
id: 8,
|
title: "老年综合评估在临床实践中的实施路径",
|
category: "4",
|
coverImage: "https://example.com/images/geriatric-assessment.jpg",
|
author: "王恩龙",
|
publishTime: "2024-10-05 08:45:00",
|
views: 1780,
|
status: "1",
|
summary: "系统介绍老年综合评估的多维度内容及其在老年患者管理中的价值。",
|
content: "<p>随着人口老龄化,老年综合评估成为老年医学的重要工具...</p>"
|
}
|
],
|
// 弹出层标题
|
title: "",
|
// 是否显示弹出层
|
open: false,
|
// 查询参数
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
title: undefined,
|
category: undefined,
|
status: undefined
|
},
|
// 表单参数
|
form: {},
|
// 表单校验
|
rules: {
|
title: [
|
{ required: true, message: "文章标题不能为空", trigger: "blur" }
|
],
|
category: [
|
{ required: true, message: "文章分类不能为空", trigger: "change" }
|
],
|
status: [
|
{ required: true, message: "状态不能为空", trigger: "change" }
|
],
|
summary: [
|
{ required: true, message: "文章摘要不能为空", trigger: "blur" }
|
],
|
content: [
|
{ required: true, message: "文章内容不能为空", trigger: "blur" }
|
]
|
},
|
// 文章分类选项
|
categoryOptions: [
|
{ value: "1", label: "临床研究" },
|
{ value: "2", label: "诊疗指南" },
|
{ value: "3", label: "药物进展" },
|
{ value: "4", label: "技术前沿" }
|
],
|
// 状态选项
|
statusOptions: [
|
{ value: "0", label: "草稿" },
|
{ value: "1", label: "已发布" },
|
{ value: "2", label: "已下架" }
|
]
|
};
|
},
|
computed: {
|
filteredArticleList() {
|
let list = [...this.articleList];
|
if (this.queryParams.title) {
|
list = list.filter(item =>
|
item.title.includes(this.queryParams.title)
|
);
|
}
|
if (this.queryParams.category) {
|
list = list.filter(item =>
|
item.category === this.queryParams.category
|
);
|
}
|
if (this.queryParams.status) {
|
list = list.filter(item =>
|
item.status === this.queryParams.status
|
);
|
}
|
return list;
|
}
|
},
|
created() {
|
this.total = this.articleList.length;
|
},
|
methods: {
|
// 解析时间
|
parseTime,
|
/** 查询文章列表 */
|
getList() {
|
this.loading = true;
|
setTimeout(() => {
|
this.loading = false;
|
}, 500);
|
},
|
/** 搜索按钮操作 */
|
handleQuery() {
|
this.queryParams.pageNum = 1;
|
},
|
/** 重置按钮操作 */
|
resetQuery() {
|
this.resetForm("queryForm");
|
this.handleQuery();
|
},
|
// 多选框选中数据
|
handleSelectionChange(selection) {
|
this.ids = selection.map(item => item.id);
|
this.single = selection.length !== 1;
|
this.multiple = !selection.length;
|
},
|
/** 新增按钮操作 */
|
handleAdd() {
|
this.reset();
|
this.open = true;
|
this.title = "添加文章";
|
},
|
/** 修改按钮操作 */
|
handleUpdate(row) {
|
this.reset();
|
const id = row.id || this.ids;
|
const article = this.articleList.find(item => item.id === id);
|
this.form = Object.assign({}, article);
|
this.open = true;
|
this.title = "修改文章";
|
},
|
/** 提交按钮 */
|
submitForm() {
|
this.$refs["form"].validate(valid => {
|
if (valid) {
|
if (this.form.id != null) {
|
// 模拟修改文章
|
const index = this.articleList.findIndex(item => item.id === this.form.id);
|
if (index !== -1) {
|
this.articleList.splice(index, 1, this.form);
|
}
|
this.$modal.msgSuccess("修改成功");
|
} else {
|
// 模拟新增文章
|
this.form.id = Math.max(...this.articleList.map(item => item.id)) + 1;
|
this.form.publishTime = new Date().toLocaleString();
|
this.form.views = 0;
|
this.articleList.unshift(this.form);
|
this.total = this.articleList.length;
|
this.$modal.msgSuccess("新增成功");
|
}
|
this.open = false;
|
}
|
});
|
},
|
/** 删除按钮操作 */
|
handleDelete(row) {
|
const articleIds = row.id || this.ids;
|
this.$modal.confirm('是否确认删除文章标题为"' + row.title + '"的数据项?').then(() => {
|
// 模拟删除文章
|
this.articleList = this.articleList.filter(item => item.id !== articleIds);
|
this.total = this.articleList.length;
|
this.$modal.msgSuccess("删除成功");
|
}).catch(() => {});
|
},
|
/** 取消按钮 */
|
cancel() {
|
this.open = false;
|
this.reset();
|
},
|
/** 表单重置 */
|
reset() {
|
this.form = {
|
id: undefined,
|
title: undefined,
|
category: undefined,
|
coverImage: undefined,
|
author: "管理员",
|
publishTime: undefined,
|
views: 0,
|
status: "1",
|
summary: undefined,
|
content: undefined
|
};
|
this.resetForm("form");
|
},
|
// 封面图上传处理
|
handleCoverChange(file) {
|
const reader = new FileReader();
|
reader.onload = (e) => {
|
this.form.coverImage = e.target.result;
|
};
|
reader.readAsDataURL(file.raw);
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.ArticleManagement {
|
padding: 20px;
|
}
|
|
.avatar-uploader ::v-deep .el-upload {
|
border: 1px dashed #d9d9d9;
|
border-radius: 6px;
|
cursor: pointer;
|
position: relative;
|
overflow: hidden;
|
}
|
|
.avatar-uploader ::v-deep .el-upload:hover {
|
border-color: #409EFF;
|
}
|
|
.avatar-uploader-icon {
|
font-size: 28px;
|
color: #8c939d;
|
width: 178px;
|
height: 178px;
|
line-height: 178px;
|
text-align: center;
|
}
|
|
.avatar {
|
width: 178px;
|
height: 178px;
|
display: block;
|
}
|
</style>
|