提交 4b3d0e9b 作者: 郁骅焌

角色功能完善

上级 d277ea95
......@@ -165,6 +165,7 @@ declare module 'vue' {
RoleManagementAuth: typeof import('./../../../src/views/system/roleManagement/vabAutoComponents/RoleManagementAuth.vue')['default']
RoleManagementEdit: typeof import('./../../../src/views/setting/roleManagement/vabAutoComponents/RoleManagementEdit.vue')['default']
RoleManagementEdit2: typeof import('./../../../src/views/system/roleManagement/vabAutoComponents/RoleManagementEdit2.vue')['default']
RoleSelectUser: typeof import('./../../../src/views/system/roleManagement/vabAutoComponents/RoleSelectUser.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
SegmentedBasic: typeof import('./../../../src/views/vab/segmented/vabAutoComponents/SegmentedBasic.vue')['default']
......
......@@ -237,6 +237,7 @@ const addTabs = async (tag: VabRoute | RouteLocationNormalizedLoaded) => {
* @returns {Promise<void>}
*/
const handleTabRemove: any = async (rawPath: string) => {
console.log(rawPath)
await delVisitedRoute(rawPath)
if (isActive(rawPath)) await toLastTab()
}
......
......@@ -72,3 +72,48 @@ export function dataScope(data: any) {
data,
})
}
// 查询角色已授权用户列表
export function allocatedUserList(params: any) {
return request({
url: '/system/role/authUser/allocatedList',
method: 'get',
params,
})
}
// 取消用户授权角色
export function authUserCancel(data: any) {
return request({
url: '/system/role/authUser/cancel',
method: 'put',
data,
})
}
// 批量取消用户授权角色
export function authUserCancelAll(data: any) {
return request({
url: '/system/role/authUser/cancelAll',
method: 'put',
params: data,
})
}
// 授权用户选择
export function authUserSelectAll(params: any) {
return request({
url: '/system/role/authUser/selectAll',
method: 'put',
params,
})
}
// 查询角色未授权用户列表
export function unallocatedUserList(params: any) {
return request({
url: '/system/role/authUser/unallocatedList',
method: 'get',
params,
})
}
......@@ -235,6 +235,33 @@ export const asyncRoutes: VabRouteRecord[] = [
},
]
/** 自定义路由 */
export const customRoutes: VabRouteRecord[] = [
{
path: '/system',
name: 'System',
component: Layout,
meta: {
hidden: true,
title: '系统管理',
},
children: [
{
path: 'roleManagement/authUser/:roleId',
component: '/@/views/system/roleManagement/authUser.vue',
name: 'AuthUser',
meta: {
hidden: true,
title: '分配用户',
noKeepAlive: true,
dynamicNewTab: true,
activeMenu: '/system/roleManagement',
},
},
],
},
]
const router = createRouter({
history: isHashRouterMode ? createWebHashHistory(base) : createWebHistory(base),
routes: constantRoutes as RouteRecordRaw[],
......
......@@ -3,7 +3,7 @@
*/
import { getList } from '/@/api/router'
import { authentication, rolesControl } from '/@/config'
import { asyncRoutes, constantRoutes, resetRouter } from '/@/router'
import { asyncRoutes, constantRoutes, customRoutes, resetRouter } from '/@/router'
import { convertRouter, filterRoutes } from '/@/utils/routes'
import { isArray } from '/@/utils/validate'
import { gp } from '/@vab/plugins/vab'
......@@ -102,6 +102,17 @@ export const useRoutesStore = defineStore('routes', {
],
})
}
/** 添加自定义路由 */
if (customRoutes.length > 0) {
customRoutes.forEach((item) => {
const index = list.findIndex((route: any) => route.name === item.name)
if (index !== -1) {
item.children?.forEach((child: any) => {
list[index].children.push(child)
})
}
})
}
routes = convertRouter(list)
}
// 根据权限和rolesControl过滤路由
......
......@@ -49,14 +49,14 @@
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<el-table-column label="部门名称" prop="deptName" width="260" />
<el-table-column label="排序" prop="orderNum" width="200" />
<el-table-column label="状态" prop="status" width="100">
<el-table-column align="center" label="排序" prop="orderNum" />
<el-table-column align="center" label="状态" prop="status">
<template #default="scope">
<dict-tag :options="sys_normal_disable" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column align="center" label="创建时间" prop="createTime" width="200" />
<el-table-column align="center" fixed="right" label="操作" min-width="180">
<el-table-column align="center" label="创建时间" prop="createTime" />
<el-table-column align="center" fixed="right" label="操作" width="240">
<template #default="scope">
<el-button icon="Edit" link type="primary" @click="handleUpdate(scope.row)">修改</el-button>
<el-button icon="Plus" link type="primary" @click="handleAdd(scope.row)">新增</el-button>
......
......@@ -70,7 +70,7 @@
</template>
</el-table-column>
<el-table-column align="center" label="创建时间" prop="createTime" width="160" />
<el-table-column align="center" fixed="right" label="操作" min-width="240">
<el-table-column align="center" fixed="right" label="操作" width="240">
<template #default="scope">
<el-button icon="Edit" link type="primary" @click="handleUpdate(scope.row)">修改</el-button>
<el-button icon="Plus" link type="primary" @click="handleAdd(scope.row)">新增</el-button>
......
<template>
<div class="authUser-container auto-height-container" :class="{ 'fullscreen-container': isFullscreen }">
<vab-query-form>
<vab-query-form-top-panel>
<el-form ref="queryRef" inline label-width="70px" :model="queryForm" @submit.prevent>
<el-form-item label="用户名称" prop="userName">
<el-input v-model="queryForm.userName" clearable placeholder="请输入用户名称" style="width: 240px" @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item v-show="!fold" label="手机号码" prop="phonenumber">
<el-input
v-model="queryForm.phonenumber"
clearable
placeholder="请输入手机号码"
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button icon="Search" :loading="listLoading" native-type="submit" type="primary" @click="handleQuery">查询</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
<el-button class="hidden-xs-only" text type="primary" @click="handleFold">
<span v-if="fold">展开</span>
<span v-else>合并</span>
<vab-icon class="vab-dropdown" :class="{ 'vab-dropdown-active': fold }" icon="arrow-up-s-line" />
</el-button>
</el-form-item>
</el-form>
</vab-query-form-top-panel>
<vab-query-form-left-panel>
<el-button icon="Plus" type="primary" @click="openSelectUser">添加用户</el-button>
<el-button icon="CircleClose" type="danger" @click="cancelAuthUserAll">批量取消授权</el-button>
<el-button icon="Close" plain type="warning" @click="handleClose">关闭</el-button>
</vab-query-form-left-panel>
<vab-query-form-right-panel>
<div class="custom-table-right-tools">
<el-button @click="handleQuery">
<vab-icon icon="refresh-line" />
</el-button>
<el-button @click="clickFullScreen">
<vab-icon :icon="isFullscreen ? 'fullscreen-exit-fill' : 'fullscreen-fill'" />
</el-button>
<el-popover popper-class="custom-table-checkbox">
<template #reference>
<el-button>
<vab-icon icon="settings-line" />
</el-button>
</template>
<vab-draggable v-model="columns" :animation="600" target=".el-checkbox-group">
<el-checkbox-group v-model="checkList">
<el-checkbox
v-for="item in columns"
:key="item.label"
:disabled="item.disableCheck"
:label="item.label"
:value="item.label"
>
{{ item.label }}
</el-checkbox>
</el-checkbox-group>
</vab-draggable>
</el-popover>
</div>
</vab-query-form-right-panel>
</vab-query-form>
<el-table ref="tableRef" v-loading="listLoading" border :data="list" @selection-change="setSelectRows">
<el-table-column align="center" type="selection" width="50" />
<el-table-column
v-for="(item, index) in finallyColumns"
:key="index"
align="center"
:fixed="item.fixed"
:label="item.label"
:min-width="item.minWidth || 160"
:prop="item.prop"
show-overflow-tooltip
:sortable="item.sortable"
>
<template #default="scope">
<span v-if="item.label === '状态'">
<dict-tag :options="sys_normal_disable" :value="scope.row.status" />
</span>
<span v-else>{{ scope.row[item.prop] }}</span>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" min-width="160">
<template #default="scope">
<el-button icon="CircleClose" link type="primary" @click="cancelAuthUser(scope.row)">取消授权</el-button>
</template>
</el-table-column>
<template #empty>
<el-empty class="vab-data-empty" description="暂无数据" />
</template>
</el-table>
<vab-pagination
:current-page="queryForm.pageNum"
:page-size="queryForm.pageSize"
:total="total"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
/>
<role-select-user ref="editRef" :role-id="queryForm.roleId" @fetch-data="fetchData" />
</div>
</template>
<script lang="ts" setup>
import type { TableInstance } from 'element-plus'
import { allocatedUserList, authUserCancel, authUserCancelAll } from '/@/api/roleManagement'
import { useTabsStore } from '/@/store/modules/tabs'
defineOptions({
name: 'AuthUser',
})
const route = useRoute()
const router = useRouter()
const tabStore = useTabsStore()
const { delVisitedRoute } = tabStore
const { proxy } = getCurrentInstance() as any
const { sys_normal_disable } = proxy.useDict('sys_normal_disable')
const { exit, enter, isFullscreen: _isFullscreen } = useFullscreen()
const isFullscreen = ref<boolean>(false)
const fold = ref<boolean>(true)
const tableRef = ref<TableInstance>()
const editRef = ref<any>(null)
const list = ref<any>([])
const listLoading = ref<boolean>(true)
const total = ref<number>(0)
const selectRows = ref<any>([])
const checkList = ref<any>([])
const queryForm = reactive<any>({
pageNum: 1,
pageSize: 10,
roleId: route.params.roleId,
userName: undefined,
phonenumber: undefined,
})
const columns = ref<any>([
{ label: '用户名称', prop: 'userName', minWidth: 160, checked: true },
{ label: '用户昵称', prop: 'nickName', minWidth: 160, checked: true },
{ label: '邮箱', prop: 'email', minWidth: 160, checked: true },
{ label: '手机', prop: 'phonenumber', minWidth: 120, checked: true },
{ label: '状态', prop: 'status', minWidth: 120, checked: true },
{ label: '创建时间', prop: 'createTime', minWidth: 160, checked: true },
])
const finallyColumns = computed(() => columns.value.filter((item: any) => checkList.value.includes(item.label)))
watch(
_isFullscreen,
() => {
if (_isFullscreen.value) isFullscreen.value = true
else isFullscreen.value = false
},
{ immediate: true }
)
onActivated(() => {
tableRef.value?.doLayout()
})
onBeforeMount(() => {
columns.value.forEach((item: any) => {
if (item.checked) checkList.value.push(item.label)
})
fetchData()
})
/** 点击全屏 */
const clickFullScreen = () => {
isFullscreen.value = !isFullscreen.value
isFullscreen.value ? enter() : exit()
}
/** 搜索条件折叠 */
const handleFold = () => {
fold.value = !fold.value
}
/** 查询授权用户列表 */
const fetchData = async () => {
listLoading.value = true
const pp = Object.assign({}, queryForm)
const { rows, total: _total } = (await allocatedUserList(pp)) as any
list.value = rows
total.value = _total
listLoading.value = false
}
/** 搜索按钮操作 */
function handleQuery() {
queryForm.pageNum = 1
fetchData()
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm('queryRef')
handleQuery()
}
const handleSizeChange = (value: number) => {
queryForm.pageNum = 1
queryForm.pageSize = value
fetchData()
}
const handleCurrentChange = (value: number) => {
queryForm.pageNum = value
fetchData()
}
const setSelectRows = (value: string) => {
selectRows.value = value
}
/** 添加用户按钮操作 */
const openSelectUser = () => {
editRef.value.show()
}
/** 取消授权按钮操作 */
function cancelAuthUser(row: any) {
$baseConfirm(`确认要取消该用户“${row.userName}”角色吗`, null, async () => {
authUserCancel({ userId: row.userId, roleId: queryForm.roleId }).then(() => {
$baseMessage('取消授权成功', 'success', 'hey')
fetchData()
})
})
}
/** 批量取消按钮操作 */
const cancelAuthUserAll = () => {
if (selectRows.value.length > 0) {
const ids = selectRows.value.map((item: { userId: any }) => item.userId)
const roleId = queryForm.roleId
const uIds = ids.join(',')
$baseConfirm('您确定要取消选中用户授权数据项吗?', null, async () => {
authUserCancelAll({ roleId, userIds: uIds }).then(() => {
$baseMessage('取消授权成功', 'success', 'hey')
fetchData()
})
})
} else {
$baseMessage('您未选中任何行', 'warning', 'hey')
}
}
/** 关闭按钮操作 */
async function handleClose() {
await delVisitedRoute(route.path)
router.push({ name: 'RoleManagement' })
}
</script>
......@@ -73,7 +73,7 @@
</vab-query-form>
<el-table ref="tableRef" v-loading="listLoading" border :data="list" @selection-change="setSelectRows">
<el-table-column type="selection" width="50" />
<el-table-column align="center" type="selection" width="50" />
<el-table-column
v-for="(item, index) in finallyColumns"
:key="index"
......@@ -126,6 +126,7 @@ defineOptions({
name: 'RoleManagement',
})
const router = useRouter()
const { proxy } = getCurrentInstance() as any
const { sys_normal_disable } = proxy.useDict('sys_normal_disable')
......@@ -296,7 +297,6 @@ function handleDataScope(row: any) {
/** 分配用户 */
function handleAuthUser(row: any) {
console.log(row)
// router.push("/system/role-auth/user/" + row.roleId);
router.push(`/system/roleManagement/authUser/${row.roleId}`)
}
</script>
<template>
<vab-dialog v-model="visible" append-to-body title="选择用户" width="840px" @close="close">
<el-form ref="formRef" :inline="true" :model="queryParams">
<el-form-item label="用户名称" prop="userName">
<el-input v-model="queryParams.userName" clearable placeholder="请输入用户名称" style="width: 180px" @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="手机号码" prop="phonenumber">
<el-input
v-model="queryParams.phonenumber"
clearable
placeholder="请输入手机号码"
style="width: 180px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button icon="Search" type="primary" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row>
<el-table ref="refTable" :data="userList" height="260px" @row-click="clickRow" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
<el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
<el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
<el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
<el-table-column align="center" label="状态" prop="status">
<template #default="scope">
<dict-tag :options="sys_normal_disable" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column align="center" label="创建时间" prop="createTime" width="180" />
</el-table>
<pagination
v-show="total > 0"
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNum"
:total="total"
@pagination="getList"
/>
</el-row>
<template #footer>
<el-button type="primary" @click="handleSelectUser">确 定</el-button>
<el-button @click="visible = false">取 消</el-button>
</template>
</vab-dialog>
</template>
<script lang="ts" setup>
import { authUserSelectAll, unallocatedUserList } from '/@/api/roleManagement'
defineOptions({
name: 'RoleSelectUser',
})
const { proxy } = getCurrentInstance() as any
const { sys_normal_disable } = proxy.useDict('sys_normal_disable')
const emit = defineEmits(['fetch-data'])
const props = defineProps({
roleId: {
type: [Number, String],
},
})
const userList = ref([])
const visible = ref(false)
const total = ref(0)
const userIds = ref([])
const queryParams = reactive<any>({
pageNum: 1,
pageSize: 10,
roleId: undefined,
userName: undefined,
phonenumber: undefined,
})
function close() {
visible.value = false
}
// 显示弹框
function show() {
queryParams.roleId = props.roleId
getList()
visible.value = true
}
/**选择行 */
function clickRow(row: any) {
proxy.$refs['refTable'].toggleRowSelection(row)
}
// 多选框选中数据
function handleSelectionChange(selection: any) {
userIds.value = selection.map((item: any) => item.userId)
}
// 查询表数据
function getList() {
unallocatedUserList(queryParams).then((res: any) => {
userList.value = res.rows
total.value = res.total
})
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.pageNum = 1
getList()
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm('queryRef')
handleQuery()
}
/** 选择授权用户操作 */
function handleSelectUser() {
const roleId = queryParams.roleId
const uIds = userIds.value.join(',')
if (uIds == '') {
$baseMessage('请选择要分配的用户', 'error')
return
}
authUserSelectAll({ roleId, userIds: uIds }).then((res: any) => {
$baseMessage(res.msg, 'success')
visible.value = false
emit('fetch-data')
})
}
defineExpose({
show,
})
</script>
......@@ -141,7 +141,7 @@
<span v-else>{{ scope.row[item.prop] }}</span>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" min-width="240">
<el-table-column align="center" fixed="right" label="操作" width="240">
<template #default="scope">
<div v-if="scope.row.userId !== 1" class="table-operation-button">
<el-button icon="Edit" link type="primary" @click="handleUpdate(scope.row)">修改</el-button>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论