123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <el-dialog v-model="state.showDialog" destroy-on-close :title="innerTitle" append-to-body draggable width="780px">
- <div>
- <el-tree
- ref="permissionTreeRef"
- :data="state.permissionTreeData"
- node-key="id"
- show-checkbox
- highlight-current
- default-expand-all
- check-on-click-node
- :expand-on-click-node="false"
- :props="{ class: customNodeClass }"
- :default-checked-keys="state.checkedKeys"
- />
- </div>
- <template #footer>
- <span class="dialog-footer">
- <el-button @click="onCancel" size="default">取 消</el-button>
- <el-button type="primary" @click="onSure" size="default" :loading="state.sureLoading">确 定</el-button>
- </span>
- </template>
- </el-dialog>
- </template>
- <script lang="ts" setup name="admin/tenant/components/set-tenant-menu">
- import { ref, reactive, getCurrentInstance, computed } from 'vue'
- import { TenantListOutput, PermissionSaveTenantPermissionsInput } from '/@/api/admin/data-contracts'
- import { PermissionApi } from '/@/api/admin/Permission'
- import { ElTree } from 'element-plus'
- import { listToTree } from '/@/utils/tree'
- import { cloneDeep } from 'lodash-es'
- const props = defineProps({
- title: {
- type: String,
- default: '',
- },
- })
- const innerTitle = computed(() => {
- return props.title ? props.title : state.name ? `设置【${state.name}】菜单权限` : '设置菜单权限'
- })
- const state = reactive({
- showDialog: false,
- loading: false,
- sureLoading: false,
- permissionTreeData: [],
- id: 0 as number | undefined,
- name: '' as string | undefined | null,
- checkedKeys: [],
- })
- const { proxy } = getCurrentInstance() as any
- const permissionTreeRef = ref<InstanceType<typeof ElTree>>()
- const getTenantPermissionList = async () => {
- const res = await new PermissionApi().getTenantPermissionList({ tenantId: state.id })
- state.checkedKeys = res?.success ? (res.data as never[]) : []
- }
- // 打开对话框
- const open = async (tenat: TenantListOutput) => {
- state.id = tenat.id
- state.name = tenat.name
- proxy.$modal.loading()
- await onQuery()
- await getTenantPermissionList()
- proxy.$modal.closeLoading()
- state.showDialog = true
- }
- // 关闭对话框
- const close = () => {
- state.showDialog = false
- }
- const onQuery = async () => {
- state.loading = true
- const res = await new PermissionApi().getPermissionList().catch(() => {
- state.loading = false
- })
- if (res && res.data && res.data.length > 0) {
- state.permissionTreeData = listToTree(cloneDeep(res.data))
- } else {
- state.permissionTreeData = []
- }
- state.loading = false
- }
- const customNodeClass = (data: any) => {
- return data.row ? 'is-penultimate' : ''
- }
- // 取消
- const onCancel = () => {
- state.showDialog = false
- }
- // 确定
- const onSure = async () => {
- state.sureLoading = true
- const permissionIds = permissionTreeRef.value?.getCheckedKeys(true)
- const input = { tenantId: state.id, permissionIds: permissionIds } as PermissionSaveTenantPermissionsInput
- const res = await new PermissionApi().saveTenantPermissions(input, { showSuccessMessage: true }).catch(() => {
- state.sureLoading = false
- })
- state.sureLoading = false
- if (res?.success) {
- state.showDialog = false
- }
- }
- defineExpose({
- open,
- close,
- })
- </script>
- <style scoped lang="scss">
- :deep(.el-dialog__body) {
- padding: 5px 10px;
- }
- :deep(.is-penultimate) {
- .el-tree-node__children {
- padding-left: 65px;
- white-space: pre-wrap;
- line-height: 100%;
- .el-tree-node {
- display: inline-block;
- }
- .el-tree-node__content {
- padding-left: 12px !important;
- padding-right: 12px;
- .el-tree-node__expand-icon.is-leaf {
- display: none;
- }
- }
- }
- }
- </style>
|