Files
Yi.Admin/Yi.BBS.Vue3/src/views/Article.vue

377 lines
9.9 KiB
Vue
Raw Normal View History

2023-03-05 20:30:44 +08:00
<template>
2023-03-12 19:49:08 +08:00
<div style="width: 90%; min-width: 1200px">
<!-- <div style="width: 1200px;"> -->
<el-row :gutter="20" class="top-div">
<el-col :span="5">
<el-row class="art-info-left">
<el-col :span="24">
<InfoCard header="主题信息" text="展开" hideDivider="true">
<template #content>
2023-03-16 21:34:52 +08:00
<el-button style="width: 100%; margin-bottom: 0.8rem" @click="loadDiscuss(true)">首页</el-button>
<el-button v-hasPer="['bbs:article:add']" @click="addArticle(0)" type="primary"
style="width: 100%; margin-bottom: 0.8rem; margin-left: 0">添加子文章</el-button>
<!--目录在这里 -->
<TreeArticleInfo :data="articleData" @remove="delArticle" @update="updateArticle" @create="addNextArticle"
@handleNodeClick="handleNodeClick" :currentNodeKey="currentNodeKey"/>
2023-03-12 19:49:08 +08:00
</template>
</InfoCard>
</el-col>
<el-col :span="24">
<InfoCard :items="items" header="推荐好友" text="更多">
<template #item="temp">
<AvatarInfo />
</template>
</InfoCard>
</el-col>
<el-col :span="24">
<InfoCard :items="items" header="推荐好友" text="更多">
<template #item="temp">
<AvatarInfo />
</template>
</InfoCard>
</el-col>
</el-row>
</el-col>
<el-col :span="14">
<el-row class="left-div">
<el-col :span="24">
<!-- {{ discuss.user }} -->
<AvatarInfo :size="50" :showWatching="true" :time="discuss.creationTime" :userInfo="discuss.user"></AvatarInfo>
<!-- :userInfo="{nick:'qwe'} -->
2023-03-12 19:49:08 +08:00
<el-divider />
<h2>{{ discuss.title }}</h2>
2023-03-17 00:30:26 +08:00
<ArticleContentInfo :code="discuss.content??''"></ArticleContentInfo>
2023-03-12 19:49:08 +08:00
<el-divider class="tab-divider" />
<el-space :size="10" :spacer="spacer">
<el-button icon="Pointer" text> 4</el-button>
<el-button icon="Star" text> 0</el-button>
<el-button icon="Share" text> 分享</el-button>
<el-button icon="Operation" text> 操作</el-button>
</el-space>
</el-col>
2023-03-23 18:15:30 +08:00
<el-col :span="24" class="comment">
<CommentInfo/>
</el-col>
2023-03-12 19:49:08 +08:00
</el-row>
</el-col>
<el-col :span="5">
<el-row class="right-div">
<el-col :span="24">
2023-03-16 21:34:52 +08:00
<InfoCard class="art-info-right" header="文章信息" text="更多" hideDivider="true">
2023-03-12 19:49:08 +08:00
<template #content>
<div>
<ul class="art-info-ul">
2023-03-16 21:34:52 +08:00
2023-03-12 19:49:08 +08:00
<li>
2023-03-16 21:34:52 +08:00
<el-button type="primary" size="default"
2023-03-19 00:42:18 +08:00
v-hasPer="['bbs:discuss:edit']"
2023-03-16 21:34:52 +08:00
@click="updateHander(route.params.discussId)">编辑</el-button>
<el-button style="margin-left: 1rem" type="danger"
2023-03-19 00:42:18 +08:00
v-hasPer="['bbs:discuss:remove']"
2023-03-16 21:34:52 +08:00
@click="delHander(route.params.discussId)">删除</el-button>
2023-03-12 19:49:08 +08:00
</li>
<li>分类 <span>文章</span></li>
标签
<el-tag type="success">文章</el-tag>
<el-tag type="info">资源</el-tag>
</ul>
</div>
</template>
</InfoCard>
</el-col>
<el-col :span="24">
<InfoCard class="art-info-right" header="目录" hideDivider="true">
<template #content>
<div>
<el-empty :image-size="100" style="padding: 20px 0;" v-if="catalogueData.length==0" description="无目录" />
<ul v-else class="art-info-ul">
2023-03-12 19:49:08 +08:00
<li v-for="(item, i) in catalogueData" :key="i">
2023-03-16 21:34:52 +08:00
<el-button style="width: 100%; justify-content: left" type="primary" text>{{ `${i + 1} ${item}`
}}</el-button>
2023-03-12 19:49:08 +08:00
</li>
</ul>
</div>
</template>
</InfoCard>
</el-col>
<el-col :span="24">
<InfoCard :items="items" header="推荐好友" text="更多">
<template #item="temp">
<AvatarInfo />
</template>
</InfoCard>
</el-col>
<el-col :span="24">
<InfoCard :items="items" header="推荐好友" text="更多">
<template #item="temp">
<AvatarInfo />
</template>
</InfoCard>
</el-col>
</el-row>
2023-03-12 19:49:08 +08:00
</el-col>
</el-row>
</div>
2023-03-05 20:30:44 +08:00
</template>
<script setup>
2023-03-12 19:49:08 +08:00
import { h, ref, onMounted } from "vue";
import AvatarInfo from "@/components/AvatarInfo.vue";
import InfoCard from "@/components/InfoCard.vue";
import ArticleContentInfo from "@/components/ArticleContentInfo.vue";
2023-03-23 18:15:30 +08:00
import CommentInfo from "@/components/CommentInfo.vue";
2023-03-11 17:00:36 +08:00
2023-03-12 19:49:08 +08:00
import TreeArticleInfo from "@/components/TreeArticleInfo.vue";
import { useRoute, useRouter } from "vue-router";
2023-03-11 17:00:36 +08:00
2023-03-12 19:49:08 +08:00
import { get as discussGet, del as discussDel } from "@/apis/discussApi.js";
2023-03-16 21:34:52 +08:00
import { all as articleall, del as articleDel, get as articleGet } from "@/apis/articleApi.js";
2023-03-11 17:00:36 +08:00
//数据定义
2023-03-12 19:49:08 +08:00
const route = useRoute();
const router = useRouter();
const spacer = h(ElDivider, { direction: "vertical" });
const items = [{ user: "用户1" }, { user: "用户2" }, { user: "用户3" }];
//子文章数据
2023-03-16 21:34:52 +08:00
const articleData = ref([]);
2023-03-11 17:00:36 +08:00
//主题内容
2023-03-12 19:49:08 +08:00
const discuss = ref({});
//当前默认选择的子文章
const currentNodeKey=route.params.articleId;
2023-03-12 01:50:11 +08:00
//目录数据
2023-03-12 19:49:08 +08:00
const catalogueData = ref([]);
2023-03-12 01:50:11 +08:00
2023-03-12 19:49:08 +08:00
//子文章初始化
2023-03-16 21:34:52 +08:00
const loadArticleData = async () => {
2023-03-20 19:46:47 +08:00
const response= await articleall(route.params.discussId)
articleData.value = response.data;
2023-03-11 17:00:36 +08:00
}
2023-03-12 19:49:08 +08:00
//主题初始化
2023-03-16 21:34:52 +08:00
const loadDiscuss = async (isRewrite) => {
2023-03-16 21:34:52 +08:00
if (isRewrite) {
//跳转路由
router.push(`/article/${route.params.discussId}`);
}
2023-03-20 19:46:47 +08:00
discuss.value = (await discussGet(route.params.discussId)).data;
if (route.params.articleId != "") {
2023-03-20 19:46:47 +08:00
const response = await articleGet(route.params.articleId);
discuss.value.content = response.data.content;
2023-03-16 21:34:52 +08:00
}
2023-03-15 13:38:05 +08:00
ContentHander();
};
//加载文章及目录
2023-03-16 21:34:52 +08:00
const ContentHander = () => {
//加载目录
var reg = /(#{1,6})\s(.*)/g;
if(discuss.value.content)
{
2023-03-12 19:49:08 +08:00
var myArray = discuss.value.content.match(reg);
if (myArray != null) {
catalogueData.value = myArray.map((x) => {
return x.replace(/#/g, "").replace(/\s/g, "");
});
}
2023-03-16 21:34:52 +08:00
}
2023-03-15 13:38:05 +08:00
}
2023-03-12 19:49:08 +08:00
//添加树型子文章
const addArticle = (parentArticleId) => {
//跳转路由
var routerPer = {
path: "/editArt",
query: {
operType: "create",
artType: "article",
discussId: route.params.discussId,
parentArticleId: parentArticleId,
},
};
router.push(routerPer);
};
//删除主题
const delHander = async (ids) => {
ElMessageBox.confirm(`确定是否删除编号[${ids}]的主题吗?`, "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "warning",
}).then(async () => {
const response = await discussDel(ids);
//删除成功后,跳转到主页
router.push("/index");
ElMessage({
type: "success",
message: "删除成功",
});
});
};
//更新操作
const updateHander = (discussId) => {
//跳转路由
var routerPer = {
path: "/editArt",
query: {
operType: "update",
artType: "discuss",
discussId: discussId,
},
};
router.push(routerPer);
};
2023-03-14 22:58:35 +08:00
//跳转添加子菜单
2023-03-16 21:34:52 +08:00
const addNextArticle = (node, data) => {
2023-03-14 22:58:35 +08:00
//跳转路由
var routerPer = {
path: "/editArt",
query: {
operType: "create",
artType: "article",
discussId: data.discussId,
parentArticleId: data.id,
},
};
router.push(routerPer);
}
//跳转更新子菜单
2023-03-16 21:34:52 +08:00
const updateArticle = (node, data) => {
2023-03-14 22:58:35 +08:00
//跳转路由
var routerPer = {
path: "/editArt",
query: {
operType: "update",
artType: "article",
discussId: data.discussId,
parentArticleId: data.parentId,
2023-03-16 21:34:52 +08:00
articleId: data.id
2023-03-14 22:58:35 +08:00
},
};
router.push(routerPer);
}
//单机节点
2023-03-16 21:34:52 +08:00
const handleNodeClick = (data) => {
//跳转路由
router.push(`/article/${route.params.discussId}/${data.id}`);
discuss.value.content = data.content;
2023-03-15 13:38:05 +08:00
ContentHander();
2023-03-14 22:58:35 +08:00
}
2023-03-12 19:49:08 +08:00
//删除子文章
2023-03-16 21:34:52 +08:00
const delArticle = (node, data) => {
ElMessageBox.confirm(`确定是否删除编号[${data.id}]的子文章吗?`, "警告", {
2023-03-12 19:49:08 +08:00
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "warning",
}).then(async () => {
2023-03-16 21:34:52 +08:00
await articleDel(data.id);
await loadArticleData();
2023-03-12 19:49:08 +08:00
ElMessage({
type: "success",
message: "删除成功",
});
});
2023-03-11 17:00:36 +08:00
2023-03-12 19:49:08 +08:00
}
onMounted(async () => {
await loadDiscuss();
await loadArticleData();
});
2023-03-05 20:30:44 +08:00
</script>
<style scoped >
2023-03-12 19:49:08 +08:00
.comment {
2023-03-23 23:12:26 +08:00
min-height: 40rem;
2023-03-11 17:00:36 +08:00
}
2023-03-16 21:34:52 +08:00
2023-03-12 01:50:11 +08:00
.art-info-left .el-col {
2023-03-12 19:49:08 +08:00
margin-bottom: 1rem;
}
2023-03-10 22:02:19 +08:00
.art-info-ul span {
2023-03-12 19:49:08 +08:00
margin-left: 1rem;
2023-03-10 22:02:19 +08:00
}
.art-info-ul .el-tag {
2023-03-12 19:49:08 +08:00
margin-left: 1rem;
2023-03-10 22:02:19 +08:00
}
.art-info-ul {
2023-03-12 19:49:08 +08:00
padding: 0;
margin: 0;
2023-03-10 22:02:19 +08:00
}
li {
2023-03-12 19:49:08 +08:00
list-style: none;
margin-bottom: 0.5rem;
2023-03-10 22:02:19 +08:00
}
.art-info-right {
2023-03-12 19:49:08 +08:00
height: 100%;
2023-03-10 22:02:19 +08:00
}
2023-03-05 20:30:44 +08:00
.left-div .el-col {
2023-03-12 19:49:08 +08:00
background-color: #ffffff;
min-height: 12rem;
margin-bottom: 1rem;
2023-03-05 20:30:44 +08:00
}
.right-div .el-col {
2023-03-12 19:49:08 +08:00
background-color: #ffffff;
min-height: 10rem;
margin-bottom: 1rem;
2023-03-05 20:30:44 +08:00
}
.left-top-div .el-col {
2023-03-12 19:49:08 +08:00
min-height: 2rem;
background-color: #fafafa;
margin-bottom: 1rem;
margin-left: 10px;
2023-03-05 20:30:44 +08:00
}
.top-div {
2023-03-12 19:49:08 +08:00
padding-top: 1rem;
2023-03-05 20:30:44 +08:00
}
.left-top-div {
2023-03-12 19:49:08 +08:00
font-size: small;
text-align: center;
line-height: 2rem;
2023-03-05 20:30:44 +08:00
}
h2 {
2023-03-12 19:49:08 +08:00
margin-bottom: 0.5em;
color: rgba(0, 0, 0, 0.85);
font-weight: 600;
font-size: 30px;
line-height: 1.35;
2023-03-05 20:30:44 +08:00
}
.left-div .el-col {
2023-03-12 19:49:08 +08:00
padding: 1.4rem 1.4rem 0.5rem 1.4rem;
2023-03-05 20:30:44 +08:00
}
2023-03-10 22:02:19 +08:00
2023-03-05 20:30:44 +08:00
.el-space {
2023-03-12 19:49:08 +08:00
display: flex;
vertical-align: top;
justify-content: space-evenly;
2023-03-05 20:30:44 +08:00
}
2023-03-10 22:02:19 +08:00
.tab-divider {
2023-03-12 19:49:08 +08:00
margin-bottom: 0.5rem;
2023-03-05 20:30:44 +08:00
}
</style>