基础设置
This commit is contained in:
46
src/views/Basic/Role/Comp/RoleEmployee.vue
Normal file
46
src/views/Basic/Role/Comp/RoleEmployee.vue
Normal file
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-table v-loading="loading" :data="tableList" border>
|
||||
<el-table-column type="index" width="50" />
|
||||
<el-table-column
|
||||
v-for="col in columns"
|
||||
:prop="col.prop"
|
||||
:key="col.prop"
|
||||
:label="col.label"
|
||||
:width="col.width"
|
||||
/>
|
||||
</el-table>
|
||||
<Pagination
|
||||
v-model:limit="pageSize"
|
||||
v-model:page="currentPage"
|
||||
:total="total"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="RoleEmployee">
|
||||
const loading = ref(false)
|
||||
const tableList = ref([])
|
||||
const total = ref(0)
|
||||
const pageSize = ref(20)
|
||||
const currentPage = ref(1)
|
||||
|
||||
const columns = ref([
|
||||
{ prop: 'userName', label: '姓名' },
|
||||
{ prop: '', label: '手机号' },
|
||||
{ prop: '', label: '部门' },
|
||||
{ prop: '', label: '角色', width: '300px' },
|
||||
{ prop: '', label: '性别' }
|
||||
])
|
||||
|
||||
function getList() {
|
||||
tableList.value = [{ userName: '测试', phone: '18899998888' }]
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
85
src/views/Basic/Role/RoleAssignMenuForm.vue
Normal file
85
src/views/Basic/Role/RoleAssignMenuForm.vue
Normal file
@@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-form ref="formRef" v-loading="formLoading" :model="formData" label-width="0px">
|
||||
<el-form-item>
|
||||
<el-tree
|
||||
ref="treeRef"
|
||||
:data="menuOptions"
|
||||
:props="defaultProps"
|
||||
empty-text="加载中,请稍候"
|
||||
node-key="id"
|
||||
show-checkbox
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">保存权限</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" name="RoleAssignMenuForm" setup>
|
||||
import { defaultProps } from '@/utils/tree'
|
||||
// import * as MenuApi from '@/api/system/menu'
|
||||
// import * as PermissionApi from '@/api/system/permission'
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
menuIds: []
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const menuOptions = ref<any[]>([]) // 菜单树形结构
|
||||
const treeRef = ref() // 菜单树组件 Ref
|
||||
|
||||
/** 提交表单 */
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
// const data = {
|
||||
// roleId: formData.id,
|
||||
// menuIds: [
|
||||
// ...(treeRef.value.getCheckedKeys(false) as unknown as Array<number>), // 获得当前选中节点
|
||||
// ...(treeRef.value.getHalfCheckedKeys() as unknown as Array<number>) // 获得半选中的父节点
|
||||
// ]
|
||||
// }
|
||||
// await PermissionApi.assignRoleMenu(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
dialogVisible.value = false
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
menuOptions.value = [
|
||||
{
|
||||
name: '统计报表',
|
||||
id: '10001',
|
||||
children: [
|
||||
{ name: '首页', id: '20001' },
|
||||
{ name: 'XX统计', id: '20002' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: '线索管理',
|
||||
id: '10002',
|
||||
children: [
|
||||
{ name: '线索库', id: '20002' },
|
||||
{ name: '成交管理', id: '20003' }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped></style>
|
||||
167
src/views/Basic/Role/RoleDataPermissionForm.vue
Normal file
167
src/views/Basic/Role/RoleDataPermissionForm.vue
Normal file
@@ -0,0 +1,167 @@
|
||||
<template>
|
||||
<el-form ref="formRef" v-loading="formLoading" :model="formData" label-width="80px">
|
||||
<el-form-item label="权限范围">
|
||||
<el-select v-model="formData.dataScope">
|
||||
<el-option
|
||||
v-for="item in dataScopeOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="formData.dataScope === SystemDataScopeEnum.DEPT_CUSTOM"
|
||||
label="权限范围"
|
||||
style="display: flex"
|
||||
>
|
||||
<template #header>
|
||||
全选/全不选:
|
||||
<el-switch
|
||||
v-model="treeNodeAll"
|
||||
active-text="是"
|
||||
inactive-text="否"
|
||||
inline-prompt
|
||||
@change="handleCheckedTreeNodeAll()"
|
||||
/>
|
||||
全部展开/折叠:
|
||||
<el-switch
|
||||
v-model="deptExpand"
|
||||
active-text="展开"
|
||||
inactive-text="折叠"
|
||||
inline-prompt
|
||||
@change="handleCheckedTreeExpand"
|
||||
/>
|
||||
父子联动(选中父节点,自动选择子节点):
|
||||
<el-switch v-model="checkStrictly" active-text="是" inactive-text="否" inline-prompt />
|
||||
</template>
|
||||
<el-tree
|
||||
ref="treeRef"
|
||||
:check-strictly="!checkStrictly"
|
||||
:data="deptOptions"
|
||||
:props="defaultProps"
|
||||
default-expand-all
|
||||
empty-text="加载中,请稍后"
|
||||
node-key="id"
|
||||
show-checkbox
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="0">
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">保存权限</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
<script lang="ts" name="RoleDataPermissionForm" setup>
|
||||
// import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import { defaultProps, handleTree } from '@/utils/tree'
|
||||
import { SystemDataScopeEnum } from '@/utils/constants'
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
dataScope: undefined,
|
||||
dataScopeDeptIds: []
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const deptOptions = ref<any[]>([]) // 部门树形结构
|
||||
const deptExpand = ref(false) // 展开/折叠
|
||||
const treeRef = ref() // 菜单树组件 Ref
|
||||
const treeNodeAll = ref(false) // 全选/全不选
|
||||
const checkStrictly = ref(true) // 是否严格模式,即父子不关联
|
||||
|
||||
// const dataScopeOptions = getIntDictOptions(DICT_TYPE.SYSTEM_DATA_SCOPE)
|
||||
const dataScopeOptions = [
|
||||
{ label: '全部数据权限', value: 1 },
|
||||
{ label: '指定部门数据权限', value: 2 },
|
||||
{ label: '部门数据权限', value: 3 },
|
||||
{ label: '部门及以下数据权限', value: 4 },
|
||||
{ label: '仅本人数据权限', value: 5 }
|
||||
]
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
formLoading.value = true
|
||||
try {
|
||||
// await PermissionApi.assignRoleDataScope(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 全选/全不选 */
|
||||
const handleCheckedTreeNodeAll = () => {
|
||||
treeRef.value.setCheckedNodes(treeNodeAll.value ? deptOptions.value : [])
|
||||
}
|
||||
|
||||
/** 展开/折叠全部 */
|
||||
const handleCheckedTreeExpand = () => {
|
||||
const nodes = treeRef.value?.store.nodesMap
|
||||
for (let node in nodes) {
|
||||
if (nodes[node].expanded === deptExpand.value) {
|
||||
continue
|
||||
}
|
||||
nodes[node].expanded = deptExpand.value
|
||||
}
|
||||
}
|
||||
|
||||
deptOptions.value = handleTree([
|
||||
{
|
||||
id: 100,
|
||||
name: '芋道源码',
|
||||
parentId: 0
|
||||
},
|
||||
{
|
||||
id: 101,
|
||||
name: '深圳总公司',
|
||||
parentId: 100
|
||||
},
|
||||
{
|
||||
id: 103,
|
||||
name: '研发部门',
|
||||
parentId: 101
|
||||
},
|
||||
{
|
||||
id: 108,
|
||||
name: '市场部门',
|
||||
parentId: 102
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
name: '长沙分公司',
|
||||
parentId: 100
|
||||
},
|
||||
{
|
||||
id: 104,
|
||||
name: '市场部门',
|
||||
parentId: 101
|
||||
},
|
||||
{
|
||||
id: 109,
|
||||
name: '财务部门',
|
||||
parentId: 102
|
||||
},
|
||||
{
|
||||
id: 105,
|
||||
name: '测试部门',
|
||||
parentId: 101
|
||||
},
|
||||
{
|
||||
id: 106,
|
||||
name: '财务部门',
|
||||
parentId: 101
|
||||
},
|
||||
{
|
||||
id: 107,
|
||||
name: '运维部门',
|
||||
parentId: 101
|
||||
}
|
||||
])
|
||||
</script>
|
||||
100
src/views/Basic/Role/RoleForm.vue
Normal file
100
src/views/Basic/Role/RoleForm.vue
Normal file
@@ -0,0 +1,100 @@
|
||||
<template>
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="400px">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
v-loading="formLoading"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="80px"
|
||||
>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="24" :offset="0">
|
||||
<el-form-item label="角色名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入角色名称" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script lang="ts" name="SystemRoleForm" setup>
|
||||
// import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
// import * as RoleApi from '@/api/system/role'
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
name: ''
|
||||
})
|
||||
const formRules = reactive({
|
||||
name: [{ required: true, message: '岗位标题不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
// formData.value = await RoleApi.getRole(id)
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
name: ''
|
||||
}
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
name: ''
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
// const data = formData.value as unknown as RoleApi.RoleVO
|
||||
if (formType.value === 'create') {
|
||||
// await RoleApi.createRole(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
// await RoleApi.updateRole(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
124
src/views/Basic/Role/index.vue
Normal file
124
src/views/Basic/Role/index.vue
Normal file
@@ -0,0 +1,124 @@
|
||||
<template>
|
||||
<div class="flex">
|
||||
<el-card shadow="always" :body-style="{ padding: '10px' }">
|
||||
<div class="flex justify-between items-center" style="width: 300px">
|
||||
<div class="text-16px font-bold">角色列表</div>
|
||||
<el-button type="primary" style="padding: 0px" text @click="openForm('create')">
|
||||
新增
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="border-top-1px mt-10px pt-10px">
|
||||
<div
|
||||
class="flex justify-between items-center pl-10px pr-10px cursor-pointer pt-5px pb-5px"
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
:class="{ actived: libraryIndex == index }"
|
||||
@click="libraryIndex = index"
|
||||
>
|
||||
<div class="flex-1 text-14px">{{ item.name }}</div>
|
||||
<div class="ml-10px">
|
||||
<el-button
|
||||
type="primary"
|
||||
style="padding: 0px"
|
||||
text
|
||||
@click="openForm('update', item.id)"
|
||||
>
|
||||
修改
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
class="ml-10px"
|
||||
style="padding: 0px"
|
||||
text
|
||||
@click="handleDelete(index)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<Pagination
|
||||
v-model:limit="queryParams.pageSize"
|
||||
v-model:page="queryParams.pageNo"
|
||||
:total="total"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-card class="ml-20px" style="flex: 1" shadow="always" :body-style="{ padding: '10px' }">
|
||||
<el-tabs v-model="roleOperateIndex" type="card">
|
||||
<el-tab-pane label="角色用户" :name="1">
|
||||
<RoleEmployee />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="菜单权限" :name="2">
|
||||
<RoleAssignMenuForm ref="assignMenuFormRef" @success="getList" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="数据权限" :name="3">
|
||||
<RoleDataPermissionForm ref="dataPermissionFormRef" @success="getList" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<RoleForm ref="formRef" @success="getList" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" name="SystemRole" setup>
|
||||
import RoleForm from './RoleForm.vue'
|
||||
import RoleEmployee from './Comp/RoleEmployee.vue'
|
||||
import RoleAssignMenuForm from './RoleAssignMenuForm.vue'
|
||||
import RoleDataPermissionForm from './RoleDataPermissionForm.vue'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const total = ref(0) // 列表的总页数
|
||||
const list = ref([]) // 列表的数据
|
||||
|
||||
const libraryIndex = ref(0)
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
/** 查询角色列表 */
|
||||
const getList = async () => {
|
||||
// const data = await RoleApi.getRolePage(queryParams)
|
||||
list.value = [{ id: 1, name: '管理员' }]
|
||||
total.value = 0
|
||||
}
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 数据权限操作 */
|
||||
const dataPermissionFormRef = ref()
|
||||
|
||||
/** 菜单权限操作 */
|
||||
const assignMenuFormRef = ref()
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
console.log(id)
|
||||
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
// await RoleApi.deleteRole(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const roleOperateIndex = ref(1)
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
Reference in New Issue
Block a user