feat: 添加子文章crud

This commit is contained in:
橙子
2023-03-14 22:58:35 +08:00
parent 2824e1325d
commit 295cf5e066
10 changed files with 75 additions and 24 deletions

View File

@@ -15,7 +15,6 @@ import { ref,watch } from 'vue';
const outputHtml=ref("") const outputHtml=ref("")
const props = defineProps(['code']) const props = defineProps(['code'])
watch(props,(n,o)=>{ watch(props,(n,o)=>{
marked.setOptions({ marked.setOptions({
renderer: new marked.Renderer(), renderer: new marked.Renderer(),
highlight: function(code) { highlight: function(code) {

View File

@@ -38,7 +38,6 @@ onMounted(() => {
//使用传入值 //使用传入值
if(props.userInfo!= undefined) if(props.userInfo!= undefined)
{ {
console.log(props.userInfo,"props.userInfo333");
userInfo.icon=props.userInfo.icon; userInfo.icon=props.userInfo.icon;
userInfo.name=props.userInfo.name; userInfo.name=props.userInfo.name;
userInfo.role=props.userInfo.role; userInfo.role=props.userInfo.role;

View File

@@ -1,7 +1,7 @@
<template> <template>
<el-tree <el-tree
:data="props.data" :data="data"
:props="defaultProps" :props="props.defaultProps"
@node-click="handleNodeClick" @node-click="handleNodeClick"
:expand-on-click-node="false" :expand-on-click-node="false"
node-key="id" node-key="id"
@@ -9,8 +9,15 @@
<template #default="{ node, data }"> <template #default="{ node, data }">
<span class="custom-tree-node"> <span class="custom-tree-node">
<span>{{ node.label }}</span> <span>{{data.name}}</span>
<span> <span>
<a style="color: #409EFF; margin-left: 8px" @click="$emit('create',node, data)"
> + </a>
<a style="color: #409EFF; margin-left: 8px" @click="$emit('update',node, data)"
> 编辑 </a>
<a style="color: #f56c6c; margin-left: 8px" @click="$emit('remove',node, data)" <a style="color: #f56c6c; margin-left: 8px" @click="$emit('remove',node, data)"
> 删除 </a> > 删除 </a>
@@ -22,6 +29,7 @@
<script setup> <script setup>
const props = defineProps(['data']) const props = defineProps(['data'])
const emits= defineEmits(["handleNodeClick"])
//数据定义 //数据定义
//子文章数据 //子文章数据
// const articleData =ref([]); // const articleData =ref([]);
@@ -37,6 +45,6 @@ const defaultProps = {
// } // }
//点击事件 //点击事件
const handleNodeClick = (data) => { const handleNodeClick = (data) => {
console.log(data); emits('handleNodeClick',data)
}; };
</script> </script>

View File

@@ -8,17 +8,19 @@
<InfoCard header="主题信息" text="展开" hideDivider="true"> <InfoCard header="主题信息" text="展开" hideDivider="true">
<template #content> <template #content>
<el-button style="width: 100%; margin-bottom: 0.8rem" <el-button style="width: 100%; margin-bottom: 0.8rem"
@click="loadDiscuss"
>首页</el-button >首页</el-button
> >
<el-button <el-button
v-hasPer="['bbs:acticle:add']" v-hasPer="['bbs:article:add']"
@click="addArticle(0)" @click="addArticle(0)"
type="primary" type="primary"
style="width: 100%; margin-bottom: 0.8rem; margin-left: 0" style="width: 100%; margin-bottom: 0.8rem; margin-left: 0"
>添加子文章</el-button >添加子文章</el-button
> >
<!--目录在这里 --> <!--目录在这里 -->
<TreeArticleInfo :data="articleData" @remove="delArticle" /> <TreeArticleInfo :data="articleData" @remove="delArticle" @update="updateArticle"
@create="addNextArticle" @handleNodeClick="handleNodeClick" />
</template> </template>
</InfoCard> </InfoCard>
</el-col> </el-col>
@@ -78,6 +80,7 @@
<template #content> <template #content>
<div> <div>
<ul class="art-info-ul"> <ul class="art-info-ul">
<li> <li>
<el-button <el-button
type="primary" type="primary"
@@ -227,6 +230,48 @@ const updateHander = (discussId) => {
router.push(routerPer); router.push(routerPer);
}; };
//跳转添加子菜单
const addNextArticle=(node,data)=>{
//跳转路由
var routerPer = {
path: "/editArt",
query: {
operType: "create",
artType: "article",
discussId: data.discussId,
parentArticleId: data.id,
},
};
router.push(routerPer);
}
//跳转更新子菜单
const updateArticle=(node,data)=>{
//跳转路由
var routerPer = {
path: "/editArt",
query: {
operType: "update",
artType: "article",
discussId: data.discussId,
parentArticleId: data.parentId,
articleId:data.id
},
};
router.push(routerPer);
}
//单机节点
const handleNodeClick=(data)=>{
//加载目录
var reg = /(#{1,6})\s(.*)/g;
discuss.value.content=data.content;
var myArray = discuss.value.content.match(reg);
if (myArray != null) {
catalogueData.value = myArray.map((x) => {
return x.replace(/#/g, "").replace(/\s/g, "");
});
}
}
//删除子文章 //删除子文章
const delArticle=( node,data)=>{ const delArticle=( node,data)=>{
ElMessageBox.confirm(`确定是否删除编号[${data.id}]的子文章吗?`, "警告", { ElMessageBox.confirm(`确定是否删除编号[${data.id}]的子文章吗?`, "警告", {

View File

@@ -23,7 +23,7 @@
> >
<el-input placeholder="请输入" v-model="editForm.name" /> <el-input placeholder="请输入" v-model="editForm.name" />
</el-form-item> </el-form-item>
<el-form-item label="标题:" prop="title"> <el-form-item v-else label="标题:" prop="title">
<el-input placeholder="请输入" v-model="editForm.title" /> <el-input placeholder="请输入" v-model="editForm.title" />
</el-form-item> </el-form-item>
<el-form-item label="描述:" prop="introduction"> <el-form-item label="描述:" prop="introduction">
@@ -67,9 +67,9 @@ import {
} from "@/apis/discussApi.js"; } from "@/apis/discussApi.js";
import { import {
add as acticleAdd, add as articleAdd,
update as acticleUpdate, update as articleUpdate,
get as acticleGet, get as articleGet,
} from "@/apis/articleApi.js"; } from "@/apis/articleApi.js";
//数据定义 //数据定义
@@ -136,20 +136,19 @@ const submit = async (formEl) => {
//artcle文章处理 //artcle文章处理
else if (route.query.artType == "article") { else if (route.query.artType == "article") {
//组装文章内容:需要添加的文章信息 //组装文章内容:需要添加的文章信息
article.content= editForm.content;
article. content= editForm.content;
article.name= editForm.name; article.name= editForm.name;
article.discussId=route.query.discussId; article.discussId=route.query.discussId;
article.parentId=route.query.parentArticleId
//文章创建 //文章创建
if (route.query.operType == "create") { if (route.query.operType == "create") {
await acticleAdd(article); await articleAdd(article);
} }
//文章更新 //文章更新
else if (route.query.operType == "update") { else if (route.query.operType == "update") {
await articleUpdate(route.query.articleId, article); await articleUpdate(route.query.articleId, article);
} }
} }
//添加成功后跳转到该页面 //添加成功后跳转到该页面
var routerPer = { path: `/discuss/${discuss.plateId}` }; var routerPer = { path: `/discuss/${discuss.plateId}` };
router.push(routerPer); router.push(routerPer);
@@ -168,8 +167,8 @@ onMounted(async () => {
await loadDiscuss(); await loadDiscuss();
//更新文章 //更新文章
} else if (route.query.artType == "acticle") { } else if (route.query.artType == "article") {
await loadActicle(); await loadArticle();
} }
} }
}); });
@@ -183,11 +182,11 @@ const loadDiscuss = async () => {
discuss.plateId=response.plateId; discuss.plateId=response.plateId;
}; };
//加载文章 //加载文章
const loadActicle = async () => { const loadArticle = async () => {
const response = await acticleGet(route.query.acticleId); const response = await articleGet(route.query.articleId);
editForm.content = response.content; editForm.content = response.content;
editForm.name = response.name; editForm.name = response.name;
// editForm.discussId = response.discussId; editForm.discussId = response.discussId;
}; };
</script> </script>
<style scoped> <style scoped>

View File

@@ -14,5 +14,7 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
public string Name { get; set; } public string Name { get; set; }
public long DiscussId { get; set; } public long DiscussId { get; set; }
public long ParentId { get; set; } public long ParentId { get; set; }
public List<ArticleAllOutputDto> Children { get; set; }
} }
} }

View File

@@ -8,7 +8,6 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
{ {
public class ArticleUpdateInputVo public class ArticleUpdateInputVo
{ {
public long Id { get; set; }
public string Content { get; set; } public string Content { get; set; }
public string Name { get; set; } public string Name { get; set; }
public long DiscussId { get; set; } public long DiscussId { get; set; }

View File

@@ -41,8 +41,8 @@ namespace Yi.BBS.Application.Forum
} }
var entities = await _articleRepository.GetTreeAsync(x => x.DiscussId == discussId); var entities = await _articleRepository.GetTreeAsync(x => x.DiscussId == discussId);
var result = entities.Tile(); //var result = entities.Tile();
var items = _mapper.Map<List<ArticleAllOutputDto>>(result); var items = _mapper.Map<List<ArticleAllOutputDto>>(entities);
return items; return items;
} }