perf:发布权限处理

This commit is contained in:
Xwen
2023-12-20 23:29:55 +08:00
parent 7f399d6854
commit 44b3a4e4f7
6 changed files with 78 additions and 59 deletions

View File

@@ -1,49 +1,46 @@
<template> <template>
<el-row> <el-row>
<el-col <el-col>
> <el-card :body-style="{ padding: '0px' }" shadow="never">
<el-card :body-style="{ padding: '0px' }" shadow="never"> <img src="" class="image" />
<img <div style="padding: 14px">
src="" <span>{{ props.name }}</span>
class="image" <div class="bottom">
/> <time class="remarks">{{ props.introduction }}</time>
<div style="padding: 14px"> <RouterLink :to="`/discuss/${props.id}/${props.isPublish}`">
<span>{{props.name}}</span> <el-button text class="button" type="primary"
<div class="bottom"> >进入<el-icon><CaretRight /></el-icon
<time class="remarks">{{ props.introduction }}</time> ></el-button>
<RouterLink :to="`/discuss/${props.id}`"> <el-button text class="button" type="primary">进入<el-icon><CaretRight /></el-icon></el-button> </RouterLink> </RouterLink>
</div>
</div> </div>
</el-card> </div>
</el-col> </el-card>
</el-row> </el-col>
</template> </el-row>
</template>
<script setup>
import { onMounted } from 'vue';
const props = defineProps(['name','introduction','id']) <script setup>
import { onMounted } from "vue";
</script> const props = defineProps(["name", "introduction", "id", "isPublish"]);
</script>
<style>
.remarks {
font-size: 12px;
color: #999;
}
.bottom {
margin-top: 13px;
line-height: 12px;
display: flex;
justify-content: space-between;
align-items: center;
}
<style>
.image { .remarks {
width: 100%; font-size: 12px;
display: block; color: #999;
} }
</style>
.bottom {
margin-top: 13px;
line-height: 12px;
display: flex;
justify-content: space-between;
align-items: center;
}
.image {
width: 100%;
display: block;
}
</style>

View File

@@ -117,7 +117,7 @@ export default function useAuths(opt) {
setToken(token); setToken(token);
try { try {
// 存储用户信息 // 存储用户信息
await getUserInfo(); // 用户信息 await useUserStore().getInfo(); // 用户信息
// 登录成功后 路由跳转 // 登录成功后 路由跳转
// 如果有记录当前跳转页面 // 如果有记录当前跳转页面
const currentPath = Session.get("currentPath"); const currentPath = Session.get("currentPath");

View File

@@ -54,7 +54,7 @@ const router = createRouter({
}, },
{ {
name: "discuss", name: "discuss",
path: "/discuss/:plateId?", path: "/discuss/:plateId?/:isPublish?",
component: () => import("../views/Discuss.vue"), component: () => import("../views/Discuss.vue"),
meta: { meta: {
title: "板块", title: "板块",

View File

@@ -121,5 +121,9 @@ const useUserStore = defineStore("user", {
this.id = ""; this.id = "";
}, },
}, },
persist: {
key: "userInfo",
storage: window.sessionStorage,
},
}); });
export default useUserStore; export default useUserStore;

View File

@@ -20,7 +20,10 @@
" "
>查询</el-button >查询</el-button
> >
<el-button @click="enterEditArticle" type="primary" <el-button
@click="enterEditArticle"
type="primary"
:class="[!isEditArticle ? 'el-button--disabled' : '']"
>发布主题</el-button >发布主题</el-button
> >
<el-dropdown> <el-dropdown>
@@ -99,9 +102,10 @@
<script setup> <script setup>
import DisscussCard from "@/components/DisscussCard.vue"; import DisscussCard from "@/components/DisscussCard.vue";
import { getList, getTopList } from "@/apis/discussApi.js"; import { getList, getTopList } from "@/apis/discussApi.js";
import { ref, reactive, watch } from "vue"; import { ref, reactive, watch, computed } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import BottomInfo from "@/components/BottomInfo.vue"; import BottomInfo from "@/components/BottomInfo.vue";
import useUserStore from "@/stores/user";
//数据定义 //数据定义
const route = useRoute(); const route = useRoute();
@@ -155,23 +159,31 @@ const loadDiscussList = async () => {
}; };
//进入添加主题页面 //进入添加主题页面
const isEditArticle = computed(
() =>
useUserStore().hasPermissions &&
!(route.params.isPublish === "false" ? false : true)
);
const enterEditArticle = () => { const enterEditArticle = () => {
//跳转路由 if (isEditArticle.value) {
var routerPer = { //跳转路由
path: "/editArt", var routerPer = {
query: { path: "/editArt",
operType: "create", query: {
artType: "discuss", operType: "create",
plateId: route.params.plateId, artType: "discuss",
}, plateId: route.params.plateId,
}; },
router.push(routerPer); };
router.push(routerPer);
} else {
ElMessage.warning("暂无发布权限!");
}
}; };
watch( watch(
() => route.query.q, () => route.query.q,
async (val) => { async (val) => {
console.log(val);
if (val) { if (val) {
query.title = val ?? ""; query.title = val ?? "";
} }
@@ -245,4 +257,9 @@ watch(
margin: 0.5rem 0; margin: 0.5rem 0;
} }
} }
/* 禁用状态下的样式 */
.el-button.el-button--disabled {
opacity: 0.6;
pointer-events: auto;
}
</style> </style>

View File

@@ -19,6 +19,7 @@
:name="i.name" :name="i.name"
:introduction="i.introduction" :introduction="i.introduction"
:id="i.id" :id="i.id"
:isPublish="i.isDisableCreateDiscuss"
/> />
</el-col> </el-col>