new feature
This commit is contained in:
@@ -136,7 +136,7 @@ onMounted(() => {
|
||||
// 监听 form data
|
||||
watch(
|
||||
formData,
|
||||
(value, oldValue) => {
|
||||
() => {
|
||||
const type: number = formData.value.type
|
||||
|
||||
if (type === 1) {
|
||||
|
@@ -12,7 +12,13 @@
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }">
|
||||
<el-table-column prop="permission_name" label="菜单名称" />
|
||||
<el-table-column prop="route" label="菜单路由" />
|
||||
<el-table-column prop="permission_mark" label="权限标识" />
|
||||
<el-table-column prop="permission_mark" label="权限标识" width="300">
|
||||
<template #default="scope">
|
||||
<div v-if="scope.row.actions.length" class="flex gap gap-1">
|
||||
<el-tag v-for="action in scope.row.actions" class="cursor-pointer" @click="open(action.id)" closable @close="destroy(api, action.id)">{{ action.permission_name }}</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="hidden" label="状态">
|
||||
<template #default="scope">
|
||||
<Status v-model="scope.row.hidden" :id="scope.row.id" :api="api" />
|
||||
|
@@ -1,7 +1,16 @@
|
||||
<template>
|
||||
<el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-6">
|
||||
<el-form-item label="上级角色" prop="parent_id">
|
||||
<el-cascader :options="roles" name="parent_id" v-model="formData.parent_id" clearable :props="{ value: 'id', label: 'role_name', checkStrictly: true }" class="w-full" />
|
||||
<el-cascader
|
||||
:options="roles"
|
||||
name="parent_id"
|
||||
v-model="formData.parent_id"
|
||||
clearable
|
||||
check-strictly
|
||||
class="w-full"
|
||||
@change="getPermissions"
|
||||
:props="{ value: 'id', label: 'role_name', checkStrictly: true }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="角色名称"
|
||||
@@ -31,22 +40,23 @@
|
||||
<el-form-item label="角色描述" prop="description">
|
||||
<el-input v-model="formData.description" name="description" clearable type="textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="数据权限" prop="data_range">
|
||||
<Select v-model="formData.data_range" name="data_range" clearable api="dataRange" class="w-full" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选择权限" prop="permissions">
|
||||
<el-tree
|
||||
ref="permissionTree"
|
||||
v-model="formData.permissions"
|
||||
:default-expanded-keys="formData.permissions"
|
||||
:data="permissions"
|
||||
value-key="id"
|
||||
check-strictly
|
||||
node-key="id"
|
||||
class="w-full"
|
||||
:props="{ label: 'permission_name', value: 'id' }"
|
||||
show-checkbox
|
||||
default-expand-all
|
||||
@check="selectPermissions"
|
||||
:empty-text="permissionLoadingText"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据权限" prop="data_range">
|
||||
<Select v-model="formData.data_range" name="data_range" clearable api="dataRange" class="w-full" />
|
||||
</el-form-item>
|
||||
<div class="flex justify-end">
|
||||
<el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
|
||||
</div>
|
||||
@@ -56,28 +66,17 @@
|
||||
<script lang="ts" setup>
|
||||
import { useCreate } from '/admin/composables/curd/useCreate'
|
||||
import { useShow } from '/admin/composables/curd/useShow'
|
||||
import { onMounted, ref, unref, watch } from 'vue'
|
||||
import { nextTick, onMounted, ref, unref } from 'vue'
|
||||
import http from '/admin/support/http'
|
||||
|
||||
const props = defineProps({
|
||||
primary: String | Number,
|
||||
api: String,
|
||||
hasPermissions: Array<Object>,
|
||||
})
|
||||
|
||||
const { formData, form, loading, submitForm, close, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
|
||||
|
||||
beforeCreate.value = () => {
|
||||
formData.value.parent_id = getParent(formData.value.parent_id)
|
||||
}
|
||||
|
||||
beforeUpdate.value = () => {
|
||||
formData.value.parent_id = getParent(formData.value.parent_id)
|
||||
}
|
||||
|
||||
const getParent = (parentId: any) => {
|
||||
return typeof parentId === 'undefined' ? 0 : parentId[parentId.length - 1]
|
||||
}
|
||||
|
||||
if (props.primary) {
|
||||
const { afterShow } = useShow(props.api, props.primary, formData)
|
||||
|
||||
@@ -96,21 +95,66 @@ if (props.primary) {
|
||||
const emit = defineEmits(['close'])
|
||||
const roles = ref()
|
||||
const permissions = ref()
|
||||
onMounted(() => {
|
||||
http.get(props.api).then(r => {
|
||||
// 权限树对象
|
||||
const permissionTree = ref()
|
||||
const permissionLoadingText = ref<string>('加载中...')
|
||||
const getPermissions = async (value: number = 0) => {
|
||||
if (value) {
|
||||
http.get('permissions/roles/' + getParent(value)).then(r => {
|
||||
permissions.value = r.data.data.permissions
|
||||
setCheckedPermissions()
|
||||
})
|
||||
} else {
|
||||
http.get('permissions/permissions').then(r => {
|
||||
permissions.value = r.data.data
|
||||
setCheckedPermissions()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const setCheckedPermissions = () => {
|
||||
nextTick(() => {
|
||||
props.hasPermissions.forEach(p => {
|
||||
permissionTree.value.setChecked(p.id, true, false)
|
||||
})
|
||||
})
|
||||
|
||||
if (!permissions.value.length) {
|
||||
permissionLoadingText.value = '暂无数据'
|
||||
}
|
||||
}
|
||||
const getRoles = () => {
|
||||
http.get(props.api, { id: props.primary ? props.primary : '' }).then(r => {
|
||||
roles.value = r.data.data
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getRoles()
|
||||
getPermissions()
|
||||
close(() => emit('close'))
|
||||
|
||||
http.get('permissions/permissions').then(r => {
|
||||
permissions.value = r.data.data
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
:deep(.el-tree .el-tree-node__children:last-child) {
|
||||
@apply flex flex-row;
|
||||
const selectPermissions = (checkedNodes, checkedKeys) => {
|
||||
formData.value.permissions = checkedKeys.checkedKeys.concat(checkedKeys.halfCheckedKeys).sort()
|
||||
}
|
||||
|
||||
// 创建前的钩子
|
||||
beforeCreate.value = () => {
|
||||
formData.value.parent_id = getParent(formData.value.parent_id)
|
||||
}
|
||||
|
||||
// 更新前的钩子
|
||||
beforeUpdate.value = () => {
|
||||
formData.value.parent_id = getParent(formData.value.parent_id)
|
||||
}
|
||||
|
||||
const getParent = (parentId: any) => {
|
||||
return typeof parentId === 'undefined' ? 0 : parentId[parentId.length - 1]
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
:deep(.el-tree .el-tree__empty-block .el-tree__empty-text) {
|
||||
@apply left-10 top-4;
|
||||
}
|
||||
</style>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
</Search>
|
||||
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
|
||||
<div class="pt-5 pl-2">
|
||||
<Add @click="open(null)" />
|
||||
<Add @click="openRoleForm(null, [])" />
|
||||
</div>
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }">
|
||||
<el-table-column prop="role_name" label="角色名称" />
|
||||
@@ -18,20 +18,20 @@
|
||||
<el-table-column prop="created_at" label="创建时间" />
|
||||
<el-table-column label="操作" width="200">
|
||||
<template #default="scope">
|
||||
<Update @click="open(scope.row.id)" />
|
||||
<Update @click="openRoleForm(scope.row.id, scope.row.permissions)" />
|
||||
<Destroy @click="destroy(api, scope.row.id)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<Dialog v-model="visible" :title="title" destroy-on-close>
|
||||
<Create @close="close(reset)" :primary="id" :api="api" />
|
||||
<Create @close="close(reset)" :primary="id" :api="api" :has-permissions="rolePermissions" />
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import Create from './form/create.vue'
|
||||
import { useGetList } from '/admin/composables/curd/useGetList'
|
||||
import { useDestroy } from '/admin/composables/curd/useDestroy'
|
||||
@@ -45,6 +45,11 @@ const { open, close, title, visible, id } = useOpen()
|
||||
|
||||
const tableData = computed(() => data.value?.data)
|
||||
|
||||
const rolePermissions = ref<Array<number>>([])
|
||||
const openRoleForm = (id, permissions) => {
|
||||
rolePermissions.value = permissions
|
||||
open(id)
|
||||
}
|
||||
onMounted(() => {
|
||||
search()
|
||||
|
||||
|
Reference in New Issue
Block a user