mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
perf: Setting menu permission
This commit is contained in:
@@ -77,8 +77,10 @@ async def pager(
|
||||
keyword: Optional[str] = Query(None, description="搜索关键字(可选)"),
|
||||
oid: Optional[int] = Query(None, description="空间ID(仅admin用户生效)"),
|
||||
):
|
||||
if not current_user.isAdmin and current_user.weight == 0:
|
||||
raise HTTPException("no permission to execute")
|
||||
if current_user.isAdmin:
|
||||
workspace_id = oid
|
||||
workspace_id = oid if oid else current_user.oid
|
||||
else:
|
||||
workspace_id = current_user.oid
|
||||
pagination = PaginationParams(page=pageNum, size=pageSize)
|
||||
|
||||
@@ -3,7 +3,8 @@ import { computed } from 'vue'
|
||||
import { ElMenu } from 'element-plus-secondary'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import MenuItem from './MenuItem.vue'
|
||||
|
||||
import { useUserStore } from '@/stores/user'
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
defineProps({
|
||||
collapse: Boolean,
|
||||
@@ -16,7 +17,6 @@ const activeMenu = computed(() => route.path)
|
||||
const arr = route.path.split('/')
|
||||
return arr[arr.length - 1]
|
||||
}) */
|
||||
|
||||
const showSysmenu = computed(() => {
|
||||
return route.path.includes('/system')
|
||||
})
|
||||
@@ -25,8 +25,7 @@ const routerList = computed(() => {
|
||||
if (showSysmenu.value) {
|
||||
return router.getRoutes().filter((route) => route.path.includes('/system') && !route.redirect)
|
||||
}
|
||||
|
||||
return router.getRoutes().filter((route) => {
|
||||
const list = router.getRoutes().filter((route) => {
|
||||
return (
|
||||
!route.path.includes('canvas') &&
|
||||
!route.path.includes('member') &&
|
||||
@@ -34,11 +33,13 @@ const routerList = computed(() => {
|
||||
!route.path.includes('preview') &&
|
||||
route.path !== '/login' &&
|
||||
!route.path.includes('/system') &&
|
||||
(route.path.includes('set') || !route.redirect) &&
|
||||
((route.path.includes('set') && userStore.isSpaceAdmin) || !route.redirect) &&
|
||||
route.path !== '/:pathMatch(.*)*' &&
|
||||
!route.path.includes('dsTable')
|
||||
)
|
||||
})
|
||||
|
||||
return list
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ defineProps({
|
||||
const name = computed(() => userStore.getName)
|
||||
const account = computed(() => userStore.getAccount)
|
||||
const currentLanguage = computed(() => userStore.getLanguage)
|
||||
const isAdmin = computed(() => userStore.getUid === '1')
|
||||
const isAdmin = computed(() => userStore.isAdmin)
|
||||
const dialogVisible = ref(false)
|
||||
|
||||
const languageList = [
|
||||
|
||||
@@ -16,6 +16,7 @@ interface UserState {
|
||||
language: string
|
||||
exp: number
|
||||
time: number
|
||||
weight: number
|
||||
[key: string]: string | number
|
||||
}
|
||||
|
||||
@@ -30,6 +31,7 @@ export const UserStore = defineStore('user', {
|
||||
language: 'zh-CN',
|
||||
exp: 0,
|
||||
time: 0,
|
||||
weight: 0,
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -57,6 +59,15 @@ export const UserStore = defineStore('user', {
|
||||
getTime(): number {
|
||||
return this.time
|
||||
},
|
||||
isAdmin(): boolean {
|
||||
return this.uid === '1'
|
||||
},
|
||||
getWeight(): number {
|
||||
return this.weight
|
||||
},
|
||||
isSpaceAdmin(): boolean {
|
||||
return this.uid === '1' || !!this.weight
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async login(formData: { username: string; password: string }) {
|
||||
@@ -72,12 +83,12 @@ export const UserStore = defineStore('user', {
|
||||
const res: any = await AuthApi.info()
|
||||
const res_data = res || {}
|
||||
|
||||
const keys = ['uid', 'account', 'name', 'oid', 'language', 'exp', 'time'] as const
|
||||
const keys = ['uid', 'account', 'name', 'oid', 'language', 'exp', 'time', 'weight'] as const
|
||||
|
||||
keys.forEach((key) => {
|
||||
const dkey = key === 'uid' ? 'id' : key
|
||||
const value = res_data[dkey]
|
||||
if (key === 'exp' || key === 'time') {
|
||||
if (key === 'exp' || key === 'time' || key === 'weight') {
|
||||
this[key] = Number(value)
|
||||
} else {
|
||||
this[key] = String(value)
|
||||
@@ -126,8 +137,22 @@ export const UserStore = defineStore('user', {
|
||||
locale.value = language */
|
||||
// locale.setLang(language)
|
||||
},
|
||||
setWeight(weight: number) {
|
||||
wsCache.set('user.weight', weight)
|
||||
this.weight = weight
|
||||
},
|
||||
clear() {
|
||||
const keys: string[] = ['token', 'uid', 'account', 'name', 'oid', 'language', 'exp', 'time']
|
||||
const keys: string[] = [
|
||||
'token',
|
||||
'uid',
|
||||
'account',
|
||||
'name',
|
||||
'oid',
|
||||
'language',
|
||||
'exp',
|
||||
'time',
|
||||
'weight',
|
||||
]
|
||||
keys.forEach((key) => wsCache.delete('user.' + key))
|
||||
this.$reset()
|
||||
},
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, onMounted, reactive } from 'vue'
|
||||
import { uwsOption, workspaceUserList, workspaceUwsDelete, workspaceCreate } from '@/api/workspace'
|
||||
import {
|
||||
uwsOption,
|
||||
workspaceUserList,
|
||||
workspaceUwsDelete,
|
||||
workspaceUwsCreate,
|
||||
} from '@/api/workspace'
|
||||
import icon_add_outlined from '@/assets/svg/icon_add_outlined.svg'
|
||||
import icon_searchOutline_outlined from '@/assets/svg/icon_search-outline_outlined.svg'
|
||||
import EmptyBackground from '@/views/dashboard/common/EmptyBackground.vue'
|
||||
@@ -142,9 +147,8 @@ const closeField = () => {
|
||||
}
|
||||
|
||||
const saveField = () => {
|
||||
workspaceCreate({
|
||||
workspaceUwsCreate({
|
||||
uid_list: [userInfo.value.id],
|
||||
weight: 0,
|
||||
}).then(() => {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
|
||||
Reference in New Issue
Block a user