添加对于用户的组织、角色分配
This commit is contained in:
@@ -20,6 +20,11 @@ export function getCurrentUser() {
|
||||
return request.get<never, UserInfo>('/auth/me')
|
||||
}
|
||||
|
||||
/** 当前用户可见的顶部导航编码 */
|
||||
export function myMenus() {
|
||||
return request.get<never, string[]>('/auth/menus')
|
||||
}
|
||||
|
||||
/** 登出 */
|
||||
export function logout() {
|
||||
return request.post<never, void>('/auth/logout')
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface RoleItem {
|
||||
remark?: string
|
||||
status?: number
|
||||
builtin?: number
|
||||
menuCodes?: string[]
|
||||
}
|
||||
|
||||
export interface RoleSave {
|
||||
@@ -36,6 +37,7 @@ export interface RoleSave {
|
||||
name: string
|
||||
remark?: string
|
||||
status?: number
|
||||
menuCodes?: string[]
|
||||
}
|
||||
|
||||
export interface UserItem {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/** 顶部导航。编码与后端 NavMenus、路由 meta.menu 一致。 */
|
||||
export const NAV_MENUS = [
|
||||
{ code: 'dashboard', title: '首页', path: '/dashboard' },
|
||||
{ code: 'search', title: '资源检索', path: '/search' },
|
||||
{ code: 'hotwords', title: '热词检索', path: '/hotwords' },
|
||||
{ code: 'special', title: '特藏推荐', path: '/special' },
|
||||
{ code: 'deposit', title: '资源呈缴', path: '/deposit' },
|
||||
{ code: 'analysis', title: '数据统计', path: '/analysis' },
|
||||
{ code: 'resource', title: '资源管理', path: '/resource' },
|
||||
{ code: 'collect', title: '数据采集', path: '/collect' },
|
||||
{ code: 'governance', title: '数据治理', path: '/governance' },
|
||||
{ code: 'admin', title: '后台管理', path: '/admin' }
|
||||
] as const
|
||||
|
||||
export type NavCode = (typeof NAV_MENUS)[number]['code']
|
||||
|
||||
export function firstAllowedPath(menus: string[]): string | null {
|
||||
const item = NAV_MENUS.find((menu) => menus.includes(menu.code))
|
||||
return item ? item.path : null
|
||||
}
|
||||
|
||||
export function navTitle(code: string): string {
|
||||
return NAV_MENUS.find((menu) => menu.code === code)?.title || code
|
||||
}
|
||||
@@ -1,37 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { clearAuth, getUser } from '@/utils/auth'
|
||||
import { myMenus } from '@/api/auth'
|
||||
import { NAV_MENUS, firstAllowedPath } from '@/constants/nav'
|
||||
import { clearAuth, getUser, setUser } from '@/utils/auth'
|
||||
import logoUrl from '@/assets/logo-green.png'
|
||||
import noticeUrl from '@/assets/icon-notice.png'
|
||||
import settingUrl from '@/assets/icon-setting.png'
|
||||
import avatarUrl from '@/assets/avatar.png'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const user = computed(() => getUser())
|
||||
const allowed = ref<string[] | null>(getUser()?.menus ?? null)
|
||||
|
||||
const menus = [
|
||||
{ path: '/dashboard', title: '首页' },
|
||||
{ path: '/search', title: '资源检索' },
|
||||
{ path: '/hotwords', title: '热词检索' },
|
||||
{ path: '/special', title: '特藏推荐' },
|
||||
{ path: '/deposit', title: '资源呈缴' },
|
||||
{ path: '/analysis', title: '数据统计' },
|
||||
{ path: '/resource', title: '资源管理' },
|
||||
{ path: '/collect', title: '数据采集' },
|
||||
{ path: '/governance', title: '数据治理' }
|
||||
]
|
||||
const menus = computed(() => {
|
||||
if (allowed.value == null) return NAV_MENUS
|
||||
return NAV_MENUS.filter((menu) => allowed.value!.includes(menu.code))
|
||||
})
|
||||
|
||||
const canSeeCurrent = computed(() => {
|
||||
const code = route.meta.menu as string | undefined
|
||||
if (!code || allowed.value == null) return true
|
||||
return allowed.value.includes(code)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const list = await myMenus()
|
||||
allowed.value = list
|
||||
const current = getUser()
|
||||
if (current) setUser({ ...current, menus: list })
|
||||
const code = route.meta.menu as string | undefined
|
||||
if (code && !list.includes(code)) {
|
||||
const next = firstAllowedPath(list)
|
||||
if (next) router.replace(next)
|
||||
}
|
||||
} catch {
|
||||
// 权限接口暂时不可用时,沿用登录时记下的栏目
|
||||
}
|
||||
})
|
||||
|
||||
function logout() {
|
||||
clearAuth()
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
/** 齿轮按钮:新标签页打开后台管理 */
|
||||
function openAdmin() {
|
||||
window.open(router.resolve('/admin').href, '_blank')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -47,7 +59,7 @@ function openAdmin() {
|
||||
<a
|
||||
v-for="m in menus"
|
||||
:key="m.path"
|
||||
:class="{ active: route.path === m.path }"
|
||||
:class="{ active: route.path === m.path || route.path.startsWith(m.path + '/') }"
|
||||
@click="router.push(m.path)"
|
||||
>
|
||||
{{ m.title }}
|
||||
@@ -55,7 +67,6 @@ function openAdmin() {
|
||||
</nav>
|
||||
<div class="right">
|
||||
<img class="hicon" :src="noticeUrl" alt="notice" />
|
||||
<img class="hicon" :src="settingUrl" alt="setting" title="后台管理" @click="openAdmin" />
|
||||
<img class="avatar" :src="avatarUrl" alt="avatar" />
|
||||
<span class="user">{{ user?.realName || 'admin' }}</span>
|
||||
<a class="quit" @click="logout">退出登录</a>
|
||||
@@ -63,7 +74,8 @@ function openAdmin() {
|
||||
</header>
|
||||
|
||||
<main class="site-main">
|
||||
<router-view />
|
||||
<router-view v-if="canSeeCurrent" />
|
||||
<el-empty v-else description="当前角色没有此栏目的访问权限" />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -177,16 +189,23 @@ function openAdmin() {
|
||||
.nav {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
height: 100%;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
a {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding: 0 11px;
|
||||
padding: 0 8px;
|
||||
color: rgba(255, 255, 255, 0.78);
|
||||
font-size: 14px;
|
||||
letter-spacing: 0.5px;
|
||||
@@ -198,8 +217,8 @@ function openAdmin() {
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 11px;
|
||||
right: 11px;
|
||||
left: 8px;
|
||||
right: 8px;
|
||||
bottom: 0;
|
||||
height: 2px;
|
||||
background: var(--brand-gold);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
||||
import BasicLayout from '@/layouts/BasicLayout.vue'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import { firstAllowedPath } from '@/constants/nav'
|
||||
import { getToken, getUser } from '@/utils/auth'
|
||||
|
||||
/**
|
||||
* 路由表:与招标文件功能模块对应。
|
||||
@@ -16,67 +17,67 @@ const routes: RouteRecordRaw[] = [
|
||||
path: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
component: () => import('@/views/Dashboard.vue'),
|
||||
meta: { title: '首页概览', icon: 'HomeFilled' }
|
||||
meta: { title: '首页概览', icon: 'HomeFilled', menu: 'dashboard' }
|
||||
},
|
||||
{
|
||||
path: 'search',
|
||||
name: 'Search',
|
||||
component: () => import('@/views/search/SearchView.vue'),
|
||||
meta: { title: '检索发现', icon: 'Search' }
|
||||
meta: { title: '检索发现', icon: 'Search', menu: 'search' }
|
||||
},
|
||||
{
|
||||
path: 'hotwords',
|
||||
name: 'HotWords',
|
||||
component: () => import('@/views/search/HotWords.vue'),
|
||||
meta: { title: '热词检索', icon: 'Cloudy' }
|
||||
meta: { title: '热词检索', icon: 'Cloudy', menu: 'hotwords' }
|
||||
},
|
||||
{
|
||||
path: 'advanced',
|
||||
name: 'Advanced',
|
||||
component: () => import('@/views/search/AdvancedView.vue'),
|
||||
meta: { title: '高级检索' }
|
||||
meta: { title: '高级检索', menu: 'search' }
|
||||
},
|
||||
{
|
||||
path: 'resource',
|
||||
name: 'Resource',
|
||||
component: () => import('@/views/resource/ResourceList.vue'),
|
||||
meta: { title: '版本资源库', icon: 'Collection' }
|
||||
meta: { title: '版本资源库', icon: 'Collection', menu: 'resource' }
|
||||
},
|
||||
{
|
||||
path: 'collect',
|
||||
name: 'Collect',
|
||||
component: () => import('@/views/collect/CollectView.vue'),
|
||||
meta: { title: '数据采集', icon: 'Download' }
|
||||
meta: { title: '数据采集', icon: 'Download', menu: 'collect' }
|
||||
},
|
||||
{
|
||||
path: 'governance',
|
||||
name: 'Governance',
|
||||
component: () => import('@/views/governance/GovernanceView.vue'),
|
||||
meta: { title: '数据治理', icon: 'MagicStick' }
|
||||
meta: { title: '数据治理', icon: 'MagicStick', menu: 'governance' }
|
||||
},
|
||||
{
|
||||
path: 'special',
|
||||
name: 'Special',
|
||||
component: () => import('@/views/special/SpecialView.vue'),
|
||||
meta: { title: '特藏推荐', icon: 'Star' }
|
||||
meta: { title: '特藏推荐', icon: 'Star', menu: 'special' }
|
||||
},
|
||||
{
|
||||
path: 'deposit',
|
||||
name: 'Deposit',
|
||||
component: () => import('@/views/deposit/DepositView.vue'),
|
||||
meta: { title: '资源呈缴', icon: 'Upload' }
|
||||
meta: { title: '资源呈缴', icon: 'Upload', menu: 'deposit' }
|
||||
},
|
||||
{
|
||||
path: 'analysis',
|
||||
name: 'Analysis',
|
||||
component: () => import('@/views/analysis/AnalysisView.vue'),
|
||||
meta: { title: '统计分析', icon: 'DataAnalysis' }
|
||||
meta: { title: '统计分析', icon: 'DataAnalysis', menu: 'analysis' }
|
||||
},
|
||||
{
|
||||
path: 'admin',
|
||||
name: 'Admin',
|
||||
component: () => import('@/views/admin/AdminView.vue'),
|
||||
meta: { title: '后台管理' }
|
||||
meta: { title: '后台管理', menu: 'admin' }
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -107,6 +108,12 @@ router.beforeEach((to) => {
|
||||
if (to.path === '/login' && token) {
|
||||
return '/'
|
||||
}
|
||||
const menu = to.meta?.menu as string | undefined
|
||||
const menus = getUser()?.menus
|
||||
if (menu && menus && !menus.includes(menu)) {
|
||||
const next = firstAllowedPath(menus)
|
||||
if (next && next !== to.path) return next
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ a {
|
||||
.el-dialog {
|
||||
border: 1px solid var(--card-gold-border);
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.el-dialog__header,
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface UserInfo {
|
||||
realName: string
|
||||
role: string
|
||||
orgName: string
|
||||
/** 可见的顶部导航编码。未下发时表示尚未刷新,先按全部栏目显示。 */
|
||||
menus?: string[]
|
||||
}
|
||||
|
||||
export function getToken(): string {
|
||||
|
||||
@@ -32,7 +32,8 @@ async function handleLogin() {
|
||||
username: res.username,
|
||||
realName: res.realName,
|
||||
role: res.role,
|
||||
orgName: res.orgName
|
||||
orgName: res.orgName,
|
||||
menus: res.menus
|
||||
})
|
||||
ElMessage.success('登录成功')
|
||||
const redirect = (route.query.redirect as string) || '/'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
createOrg,
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
type UserImportResult,
|
||||
type UserItem
|
||||
} from '@/api/system'
|
||||
import { NAV_MENUS, navTitle } from '@/constants/nav'
|
||||
|
||||
const props = defineProps<{
|
||||
section: 'org' | 'role' | 'user'
|
||||
@@ -42,12 +43,15 @@ const orgForm = reactive<OrgSave & { id?: number }>({
|
||||
const roles = ref<RoleItem[]>([])
|
||||
const roleDialog = ref(false)
|
||||
const roleSaving = ref(false)
|
||||
const roleForm = reactive<{ id?: number; code: string; name: string; remark: string; status: number; builtin?: number }>({
|
||||
const roleForm = reactive<{ id?: number; code: string; name: string; remark: string; status: number; builtin?: number; menuCodes: string[] }>({
|
||||
code: '',
|
||||
name: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
status: 1,
|
||||
menuCodes: NAV_MENUS.map((menu) => menu.code)
|
||||
})
|
||||
const isAdminRole = computed(() => roleForm.code.trim().toUpperCase() === 'ADMIN')
|
||||
const allMenuCodes = () => NAV_MENUS.map((menu) => menu.code)
|
||||
|
||||
const userQuery = reactive<{ current: number; size: number; keyword: string; orgId?: number; roleId?: number }>({
|
||||
current: 1,
|
||||
@@ -170,6 +174,7 @@ function openRoleCreate() {
|
||||
roleForm.remark = ''
|
||||
roleForm.status = 1
|
||||
roleForm.builtin = 0
|
||||
roleForm.menuCodes = allMenuCodes()
|
||||
roleDialog.value = true
|
||||
}
|
||||
|
||||
@@ -180,6 +185,9 @@ function openRoleEdit(row: RoleItem) {
|
||||
roleForm.remark = row.remark || ''
|
||||
roleForm.status = row.status ?? 1
|
||||
roleForm.builtin = row.builtin
|
||||
roleForm.menuCodes = row.code === 'ADMIN'
|
||||
? allMenuCodes()
|
||||
: (row.menuCodes ? [...row.menuCodes] : allMenuCodes())
|
||||
roleDialog.value = true
|
||||
}
|
||||
|
||||
@@ -194,7 +202,8 @@ async function saveRole() {
|
||||
code: roleForm.code.trim(),
|
||||
name: roleForm.name.trim(),
|
||||
remark: roleForm.remark.trim() || undefined,
|
||||
status: roleForm.status
|
||||
status: roleForm.status,
|
||||
menuCodes: isAdminRole.value ? allMenuCodes() : [...roleForm.menuCodes]
|
||||
}
|
||||
if (roleForm.id) {
|
||||
await updateRole(roleForm.id, data)
|
||||
@@ -216,18 +225,30 @@ async function deleteRole(row: RoleItem) {
|
||||
loadRoles()
|
||||
}
|
||||
|
||||
function openUserCreate() {
|
||||
async function openUserCreate() {
|
||||
try {
|
||||
await loadRoles()
|
||||
} catch {
|
||||
// 角色列表失败时仍打开弹窗,下面会提示先去角色管理新增
|
||||
}
|
||||
userForm.id = undefined
|
||||
userForm.username = ''
|
||||
userForm.password = ''
|
||||
userForm.realName = ''
|
||||
userForm.roleId = roles.value.find((role) => role.code === 'USER')?.id
|
||||
userForm.roleId = roles.value.find((role) => role.code === 'USER')?.id ?? roles.value[0]?.id
|
||||
userForm.orgId = undefined
|
||||
userForm.status = 1
|
||||
userDialog.value = true
|
||||
}
|
||||
|
||||
function openUserEdit(row: UserItem) {
|
||||
async function openUserEdit(row: UserItem) {
|
||||
if (!roles.value.length) {
|
||||
try {
|
||||
await loadRoles()
|
||||
} catch {
|
||||
// 沿用已有列表
|
||||
}
|
||||
}
|
||||
userForm.id = row.id
|
||||
userForm.username = row.username
|
||||
userForm.password = ''
|
||||
@@ -381,7 +402,12 @@ onMounted(() => {
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="remark" label="备注" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column label="可见栏目" min-width="220" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ (row.menuCodes || []).map((code: string) => navTitle(code)).join('、') || '无' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openRoleEdit(row)">编辑</el-button>
|
||||
@@ -495,7 +521,7 @@ onMounted(() => {
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="roleDialog" :title="roleForm.id ? '编辑角色' : '新增角色'" width="480px">
|
||||
<el-dialog v-model="roleDialog" :title="roleForm.id ? '编辑角色' : '新增角色'" width="560px">
|
||||
<el-form label-width="88px">
|
||||
<el-form-item label="编码" required>
|
||||
<el-input v-model="roleForm.code" maxlength="32" :disabled="roleForm.builtin === 1" placeholder="如 EDITOR" />
|
||||
@@ -509,6 +535,16 @@ onMounted(() => {
|
||||
<el-radio :value="0">停用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="可见栏目">
|
||||
<el-checkbox-group v-model="roleForm.menuCodes" class="nav-checks" :disabled="isAdminRole">
|
||||
<el-checkbox v-for="menu in NAV_MENUS" :key="menu.code" :value="menu.code">
|
||||
{{ menu.title }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
<div class="form-tip">
|
||||
{{ isAdminRole ? '系统管理员默认可访问全部栏目' : '未勾选的栏目不会出现在该角色用户的顶部导航中,后台管理也在其中' }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="roleForm.remark" type="textarea" maxlength="256" />
|
||||
</el-form-item>
|
||||
@@ -537,9 +573,10 @@ onMounted(() => {
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" required>
|
||||
<el-select v-model="userForm.roleId" style="width: 100%">
|
||||
<el-option v-for="role in roles" :key="role.id" :label="role.name" :value="role.id" />
|
||||
</el-select>
|
||||
<el-radio-group v-if="roles.length" v-model="userForm.roleId" class="role-picks">
|
||||
<el-radio v-for="role in roles" :key="role.id" :value="role.id">{{ role.name }}</el-radio>
|
||||
</el-radio-group>
|
||||
<div v-else class="form-tip">暂无角色,请先在角色管理中新增</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="组织">
|
||||
<el-tree-select
|
||||
@@ -581,4 +618,24 @@ onMounted(() => {
|
||||
margin-top: 12px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.nav-checks {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 16px;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
width: 100%;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.role-picks {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 16px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user