添加博客文章相关功能(未完成)

This commit is contained in:
huangge1199 2024-08-28 15:14:38 +08:00
parent ecbb304fa6
commit 718834510c
8 changed files with 2643 additions and 0 deletions

View File

@ -7,6 +7,9 @@
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="icon" href="/favicon.ico">
<link rel="stylesheet" href="/katex.min.css" />
<script src="/katex.min.js"></script>
<script src="/mermaid.min.js"></script>
<title>Ruoyi-Flex管理系统</title>
<!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
<style>

1
public/katex.min.css vendored Normal file

File diff suppressed because one or more lines are too long

1
public/katex.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2151
public/mermaid.min.js vendored Normal file

File diff suppressed because one or more lines are too long

52
src/api/blog/posts.js Normal file
View File

@ -0,0 +1,52 @@
import request from '@/utils/request'
// 查询博客文章列表
export function listPosts(query) {
return request({
url: '/blog/posts/list',
method: 'get',
params: query
})
}
// 查询博客文章详细
export function getPosts(id) {
return request({
url: '/blog/posts/' + id,
method: 'get'
})
}
// 新增博客文章
export function addPosts(data) {
return request({
url: '/blog/posts',
method: 'post',
data: data
})
}
// 修改博客文章
export function updatePosts(data) {
return request({
url: '/blog/posts',
method: 'put',
data: data
})
}
// 删除博客文章
export function delPosts(id) {
return request({
url: '/blog/posts/' + id,
method: 'delete'
})
}
export function upload(data) {
return request({
url: '/resource/oss/upload',
method: 'post',
data: data
});
}

View File

@ -4,6 +4,7 @@
transition: margin-left 0.28s;
margin-left: $base-sidebar-width;
position: relative;
background-color: #ecf5fc;
}
.sidebarHide {

View File

@ -0,0 +1,334 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="标题" prop="title">
<el-input
v-model="queryParams.title"
placeholder="请输入标题"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @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="Plus"
@click="handleAdd"
v-hasPermi="['blog:posts:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="Edit"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['blog:posts:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['blog:posts:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['blog:posts:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="postsList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="主键" align="center" prop="id" />
<el-table-column label="状态" align="center" prop="status" />
<el-table-column label="标题" align="center" prop="title" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['blog:posts:edit']">修改</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['blog:posts:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改博客文章对话框 -->
<el-dialog :title="title" v-model="open" width="780px" append-to-body>
<el-form ref="postsRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="是否可评论01不能" prop="disallowComment">
<el-input v-model="form.disallowComment" placeholder="请输入是否可评论01不能" />
</el-form-item>
<el-form-item label="关键字" prop="keywords">
<el-input v-model="form.keywords" type="textarea" placeholder="请输入内容" />
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="form.password" placeholder="请输入密码" />
</el-form-item>
<el-form-item label="固定链接地址" prop="slug">
<el-input v-model="form.slug" placeholder="请输入固定链接地址" />
</el-form-item>
<el-form-item label="总览" prop="summary">
<el-input v-model="form.summary" type="textarea" placeholder="请输入内容" />
</el-form-item>
<el-form-item label="标题" prop="title">
<el-input v-model="form.title" placeholder="请输入标题" />
</el-form-item>
<el-form-item label="置顶" prop="topPriority">
<el-input v-model="form.topPriority" placeholder="请输入置顶" />
</el-form-item>
<el-divider content-position="center">博客文章内容信息</el-divider>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="Plus" @click="handleAddBlogContents">添加</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="Delete" @click="handleDeleteBlogContents">删除</el-button>
</el-col>
</el-row>
<el-table :data="blogContentsList" :row-class-name="rowBlogContentsIndex" @selection-change="handleBlogContentsSelectionChange" ref="blogContents">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="序号" align="center" prop="index" width="50"/>
</el-table>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="Posts">
import { listPosts, getPosts, delPosts, addPosts, updatePosts } from "@/api/blog/posts";
const { proxy } = getCurrentInstance();
//
const postsList = ref([]);
//
const blogContentsList = ref([]);
//
const open = ref(false);
//
const loading = ref(true);
//
const showSearch = ref(true);
//
const ids = ref([]);
//
const checkedBlogContents = ref([]);
//
const single = ref(true);
//
const multiple = ref(true);
//
const total = ref(0);
//
const title = ref("");
const data = reactive({
form: {},
queryParams: {
pageNum: 1,
pageSize: 10,
slug: null,
type: null,
status: null,
title: null,
},
rules: {
id: [
{ required: true, message: "主键不能为空", trigger: "blur" }
],
slug: [
{ required: true, message: "固定链接地址不能为空", trigger: "blur" }
],
type: [
{ required: true, message: "类型0文章1自定义页面不能为空", trigger: "change" }
],
title: [
{ required: true, message: "标题不能为空", trigger: "blur" }
],
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询博客文章列表 */
function getList() {
loading.value = true;
listPosts(queryParams.value).then(response => {
postsList.value = response.rows;
total.value = response.total;
loading.value = false;
});
}
//
function cancel() {
open.value = false;
reset();
}
//
function reset() {
form.value = {
id: null,
disallowComment: null,
keywords: null,
password: null,
slug: null,
type: null,
status: null,
summary: null,
title: null,
topPriority: null,
visits: null,
wordCount: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null
};
blogContentsList.value = [];
proxy.resetForm("postsRef");
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
//
function handleSelectionChange(selection) {
ids.value = selection.map(item => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
reset();
open.value = true;
title.value = "添加博客文章";
}
/** 修改按钮操作 */
function handleUpdate(row) {
reset();
const _id = row.id || ids.value
getPosts(_id).then(response => {
form.value = response.data;
blogContentsList.value = response.data.blogContentsList;
open.value = true;
title.value = "修改博客文章";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["postsRef"].validate(valid => {
if (valid) {
form.value.blogContentsList = blogContentsList.value;
if (form.value.id != null) {
updatePosts(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
});
} else {
addPosts(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
const _ids = row.id || ids.value;
proxy.$modal.confirm('是否确认删除博客文章编号为"' + _ids + '"的数据项?').then(function() {
return delPosts(_ids);
}).then(() => {
getList();
proxy.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
/** 博客文章内容序号 */
function rowBlogContentsIndex({ row, rowIndex }) {
row.index = rowIndex + 1;
}
/** 博客文章内容添加按钮操作 */
function handleAddBlogContents() {
let obj = {};
obj.originalContent = "";
blogContentsList.value.push(obj);
}
/** 博客文章内容删除按钮操作 */
function handleDeleteBlogContents() {
if (checkedBlogContents.value.length == 0) {
proxy.$modal.msgError("请先选择要删除的博客文章内容数据");
} else {
const blogContentss = blogContentsList.value;
const checkedBlogContentss = checkedBlogContents.value;
blogContentsList.value = blogContentss.filter(function(item) {
return checkedBlogContentss.indexOf(item.index) == -1
});
}
}
/** 复选框选中数据 */
function handleBlogContentsSelectionChange(selection) {
checkedBlogContents.value = selection.map(item => item.index)
}
/** 导出按钮操作 */
function handleExport() {
proxy.download('blog/posts/export', {
...queryParams.value
}, `posts_${new Date().getTime()}.xlsx`)
}
getList();
</script>

View File

@ -0,0 +1,100 @@
<template>
<div class="content">
<el-form ref="postsRef" :model="form" :rules="rules" label-width="0%" style="width: 100%;padding: 0 10%">
<el-row style="margin-top: 20px">
<el-col :span="24">
<el-form-item prop="title">
<el-input v-model="form.title" placeholder="请输入文章标题"/>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item prop="md" v-loading="textLoading">
<v-md-editor
v-model="form.blogContents.originalContent"
left-toolbar="undo redo clear
| h bold italic strikethrough quote
| ul ol table hr
| link image code | emoji"
height="650px"
@upload-image="handleUploadImage"
></v-md-editor>
</el-form-item>
</el-col>
<el-col :span="24" style="text-align: center">
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="close">返回</el-button>
</el-col>
</el-row>
</el-form>
</div>
</template>
<script setup name="write">
import VMdEditor from '@kangc/v-md-editor';
import {xss} from '@kangc/v-md-editor';
import {addPosts, updatePosts, upload} from "@/api/blog/posts";
const route = useRoute();
const { proxy } = getCurrentInstance();
const textLoading = ref(false);
const data = reactive({
form: {
id: undefined,
title: undefined,
keywords: undefined,
summary: undefined,
blogContents: {
originalContent: '',
content: undefined
}
},
rules: {
title: [
{required: true, message: "标题不能为空", trigger: "blur"}
],
}
});
const {form, rules} = toRefs(data);
/** 上传图片 */
function handleUploadImage(event, insertImage, files) {
textLoading.value = true;
let formData = new FormData();
formData.append('file', files[0]);
upload(formData).then(res => {
insertImage({
url: res.data.url
});
textLoading.value = false;
});
}
/** 提交按钮 */
function submitForm() {
// console.log('text:::' + form.value.md);
// console.log('html:::' + form.value.html);
proxy.$refs["postsRef"].validate(valid => {
if (valid) {
form.blogContents.content = xss.process(VMdEditor.vMdParser.themeConfig.markdownParser.render(form.blogContents.originalContent));
if (form.value.id != null) {
updatePosts(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
});
} else {
addPosts(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
});
}
}
});
}
function close() {
const obj = { path: "/blog/posts" };
proxy.$tab.closeOpenPage(obj);
}
</script>