- 401 自动登出:http 会话过期回调 + main.ts 注册(清 menu/tabs + 跳登录) - 参数配置/字典/组织/资源/角色/操作日志/登录日志对接真实接口 - 角色管理新增权限分配树(el-tree 勾选资源,/roles/:code/resources) - 操作日志/登录日志只读页(ty-search-form + ty-table + useRequest) - listOrgs 迁到 api/org.ts Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
54 lines
1.6 KiB
Vue
54 lines
1.6 KiB
Vue
<template>
|
|
<el-tree
|
|
v-if="ready"
|
|
ref="treeRef"
|
|
class="assign-tree"
|
|
:data="tree"
|
|
node-key="code"
|
|
show-checkbox
|
|
:props="{ label: 'name', children: 'children' }"
|
|
:default-checked-keys="assigned ?? []"
|
|
default-expand-all
|
|
/>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, ref } from 'vue'
|
|
import { useRequest } from '@/composables/useRequest'
|
|
import { listResources } from '@/api/resource'
|
|
import { listAssignedResources } from '@/api/role'
|
|
import { buildTree, type TreeNode } from '@/utils/tree'
|
|
import type { Resource } from '@/api/resource'
|
|
|
|
defineOptions({ name: 'AssignResourcesForm' })
|
|
|
|
const props = defineProps<{ roleCode: string }>()
|
|
|
|
interface TreeApi {
|
|
getCheckedKeys: () => (string | number)[]
|
|
getHalfCheckedKeys: () => (string | number)[]
|
|
}
|
|
const treeRef = ref<TreeApi>()
|
|
|
|
const { data: resourceList } = useRequest((signal: AbortSignal) => listResources(signal))
|
|
const { data: assigned } = useRequest((signal: AbortSignal) => listAssignedResources(props.roleCode, signal))
|
|
|
|
const tree = computed(() => buildTree(resourceList.value ?? []) as TreeNode<Resource>[])
|
|
const ready = computed(() => resourceList.value !== undefined && assigned.value !== undefined)
|
|
|
|
function submit(): { resourceCodes: string[] } {
|
|
const checked = treeRef.value?.getCheckedKeys() ?? []
|
|
const half = treeRef.value?.getHalfCheckedKeys() ?? []
|
|
return { resourceCodes: [...new Set([...checked, ...half].map(String))] }
|
|
}
|
|
|
|
defineExpose({ submit })
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.assign-tree {
|
|
max-height: 420px;
|
|
overflow-y: auto;
|
|
}
|
|
</style>
|