hide pagetype and workspace menus for non-System User in menu management

This commit is contained in:
jingrow 2025-11-18 23:46:10 +08:00
parent 394f867eb1
commit d2cd80be73

View File

@ -126,11 +126,13 @@
import { ref, h, computed } from 'vue'
import { NButton, NSpace, NDataTable, NModal, NForm, NFormItem, NInput, NSelect, NInputNumber, NSwitch, NText, useDialog, type FormInst, type FormRules } from 'naive-ui'
import { useMenuStore, type AppMenuItem } from '../../shared/stores/menu'
import { useAuthStore } from '../../shared/stores/auth'
import { pageTypeToSlug } from '../../shared/utils/slug'
import IconPicker from '../../core/components/IconPicker.vue'
import { t } from '../../shared/i18n'
const menuStore = useMenuStore()
const authStore = useAuthStore()
// items
function buildTree(items: AppMenuItem[]) {
const byId: Record<string, AppMenuItem & { children?: AppMenuItem[] }> = {}
@ -156,7 +158,21 @@ function buildTree(items: AppMenuItem[]) {
return roots
}
const displayItems = computed(() => (draggedItem.value ? previewItems.value : menuStore.items))
//
const filteredItems = computed(() => {
const userType = authStore.user?.user_type
const isSystemUser = userType === 'System User'
return menuStore.items.filter(m => {
// System User pagetype workspace
if (!isSystemUser && (m.type === 'pagetype' || m.type === 'workspace')) {
return false
}
return true
})
})
const displayItems = computed(() => (draggedItem.value ? previewItems.value : filteredItems.value))
const tableData = computed(() => buildTree(displayItems.value))
const dialog = useDialog()
@ -209,18 +225,31 @@ const rules: FormRules = {
type: [{ required: true, message: t('Please select menu type') }],
}
const typeOptions = [
{ label: t('PageType'), value: 'pagetype' },
{ label: t('Route'), value: 'route' },
{ label: t('URL'), value: 'url' },
{ label: t('Workspace'), value: 'workspace' },
{ label: t('Group'), value: 'group' }
]
const typeOptions = computed(() => {
const userType = authStore.user?.user_type
const isSystemUser = userType === 'System User'
const allOptions = [
{ label: t('PageType'), value: 'pagetype' },
{ label: t('Route'), value: 'route' },
{ label: t('URL'), value: 'url' },
{ label: t('Workspace'), value: 'workspace' },
{ label: t('Group'), value: 'group' }
]
// System User pagetype workspace
if (!isSystemUser) {
return allOptions.filter(opt => opt.value !== 'pagetype' && opt.value !== 'workspace')
}
return allOptions
})
const parentMenuOptions = computed(() => {
const opts = menuStore.items.map(m => ({ label: m.label, value: m.id }))
// 使
const opts = filteredItems.value.map(m => ({ label: m.label, value: m.id }))
return [{ label: t('None'), value: null as any }].concat(opts)
})
@ -235,12 +264,15 @@ const previewUrl = computed(() => {
function openCreate() {
editing.value = null
const userType = authStore.user?.user_type
const isSystemUser = userType === 'System User'
form.value = {
id: '',
key: '',
label: '',
icon: '',
type: 'pagetype', //
type: isSystemUser ? 'pagetype' : 'route', //
pagetype: '',
routeName: '',
url: '',
@ -278,6 +310,18 @@ function onPageTypeChange() {
function save() {
const data = { ...form.value }
// System User pagetype workspace
const userType = authStore.user?.user_type
const isSystemUser = userType === 'System User'
if (!isSystemUser && (data.type === 'pagetype' || data.type === 'workspace')) {
dialog.error({
title: t('Permission Denied'),
content: t('Non-System User cannot create or edit pagetype and workspace menu items'),
positiveText: t('OK')
})
return
}
// key
if (data.type === 'pagetype' && data.pagetype) {
data.key = pageTypeToSlug(data.pagetype)