perf:优化权限

This commit is contained in:
Xwen
2023-12-23 19:05:51 +08:00
parent 58d90cc699
commit 04fb38757c
3 changed files with 54 additions and 48 deletions

View File

@@ -1,42 +1,52 @@
<template> <template>
<el-tree <el-tree
:data="props.data==''?[]:props.data" :data="props.data == '' ? [] : props.data"
:props="defaultProps" :props="defaultProps"
@node-click="handleNodeClick" @node-click="handleNodeClick"
:expand-on-click-node="false" :expand-on-click-node="false"
node-key="id" node-key="id"
:default-expand-all='true' :default-expand-all="true"
:highlight-current="true" :highlight-current="true"
:current-node-key="currentNodeKey" :current-node-key="currentNodeKey"
> >
<template #default="{ node, data }">
<template #default="{ node, data }"> <span class="custom-tree-node">
<span class="custom-tree-node"> <span>{{ data.name }}</span>
<span>{{data.name}}</span> <span>
<span> <a
style="color: #409eff; margin-left: 8px"
<a style="color: #409EFF; margin-left: 8px" @click="$emit('create',node, data)" v-hasPer="['bbs:article:add']" @click="$emit('create', node, data)"
v-if="isArticleUser && isAddArticle"
> + </a> >
<a style="color: #409EFF; margin-left: 8px" @click="$emit('update',node, data)" v-hasPer="['bbs:article:edit']" +
</a>
> 编辑 </a> <a
<a style="color: #f56c6c; margin-left: 8px" @click="$emit('remove',node, data)" v-hasPer="['bbs:article:remove']" style="color: #409eff; margin-left: 8px"
@click="$emit('update', node, data)"
> 删除 </a> v-if="isArticleUser && isEditArticle"
</span> >
编辑
</a>
<a
style="color: #f56c6c; margin-left: 8px"
@click="$emit('remove', node, data)"
v-if="isArticleUser && isRemoveArticle"
>
删除
</a>
</span> </span>
</template> </span>
</el-tree> </template>
</el-tree>
</template> </template>
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from "vue";
import { getPermission } from "@/utils/auth";
const props = defineProps(["data", "currentNodeKey", "isArticleUser"]);
const emits = defineEmits(["handleNodeClick"]);
const props = defineProps(['data',"currentNodeKey"]) const currentNodeKey = props.currentNodeKey;
const emits= defineEmits(["handleNodeClick"])
const currentNodeKey=props.currentNodeKey;
//数据定义 //数据定义
//子文章数据 //子文章数据
// const articleData =ref([]); // const articleData =ref([]);
@@ -52,8 +62,12 @@ const defaultProps = {
// } // }
//点击事件 //点击事件
const handleNodeClick = (data) => { const handleNodeClick = (data) => {
emits('handleNodeClick',data) emits("handleNodeClick", data);
}; };
const { isHasPermission: isAddArticle } = getPermission("bbs:article:add");
const { isHasPermission: isEditArticle } = getPermission("bbs:article:edit");
const { isHasPermission: isRemoveArticle } =
getPermission("bbs:article:remove");
</script> </script>
<style scoped> <style scoped>
.custom-tree-node { .custom-tree-node {
@@ -64,4 +78,4 @@ const handleNodeClick = (data) => {
font-size: 14px; font-size: 14px;
padding-right: 8px; padding-right: 8px;
} }
</style> </style>

View File

@@ -13,7 +13,7 @@ export function removeToken() {
return localStorage.removeItem(TokenKey); return localStorage.removeItem(TokenKey);
} }
export function getPermission(code, isDisabled) { export function getPermission(code, isDisabled = false) {
const all_permission = "*:*:*"; const all_permission = "*:*:*";
const isHasPermission = useUserStore().permissions.some((permission) => { const isHasPermission = useUserStore().permissions.some((permission) => {
if (all_permission === permission) { if (all_permission === permission) {

View File

@@ -26,6 +26,7 @@
@create="addNextArticle" @create="addNextArticle"
@handleNodeClick="handleNodeClick" @handleNodeClick="handleNodeClick"
:currentNodeKey="currentNodeKey" :currentNodeKey="currentNodeKey"
:isArticleUser="isArticleUser"
/> />
</template> </template>
</InfoCard> </InfoCard>
@@ -223,18 +224,9 @@ const loadArticleData = async () => {
//主题初始化 //主题初始化
const isDisabledCreateComment = ref(false); const isDisabledCreateComment = ref(false);
const isArticleUser = ref(false); const isArticleUser = ref(false);
const { isHasPermission: isAddArticle } = getPermission( const { isHasPermission: isAddArticle } = getPermission("bbs:article:add");
"bbs:article:add", const { isHasPermission: isEditTheme } = getPermission("bbs:discuss:edit");
isDisabledCreateComment.value const { isHasPermission: isRemoveTheme } = getPermission("bbs:discuss:remove");
);
const { isHasPermission: isEditTheme } = getPermission(
"bbs:discuss:edit",
isDisabledCreateComment.value
);
const { isHasPermission: isRemoveTheme } = getPermission(
"bbs:discuss:remove",
isDisabledCreateComment.value
);
const loadDiscuss = async (isRewrite) => { const loadDiscuss = async (isRewrite) => {
if (isRewrite) { if (isRewrite) {
//跳转路由 //跳转路由