| | |
| | | label: 'label', |
| | | children: 'children' |
| | | } |
| | | const scopeState = reactive( |
| | | Object.fromEntries( |
| | | scopeConfigs.map((config) => [ |
| | | config.scopeType, |
| | | { |
| | | loading: false, |
| | | loaded: false, |
| | | treeData: [], |
| | | checkedKeys: [], |
| | | halfCheckedKeys: [], |
| | | condition: '' |
| | | } |
| | | ]) |
| | | ) |
| | | ) |
| | | const scopeState = reactive(Object.fromEntries(scopeConfigs.map((config) => [config.scopeType, createScopeTabState()]))) |
| | | |
| | | const visible = computed({ |
| | | get: () => props.visible, |
| | |
| | | |
| | | const roleLabel = computed(() => props.roleData?.name || props.roleData?.code || '未选择角色') |
| | | |
| | | function createScopeTabState() { |
| | | return { |
| | | loading: false, |
| | | loaded: false, |
| | | treeData: [], |
| | | checkedKeys: [], |
| | | halfCheckedKeys: [], |
| | | condition: '' |
| | | } |
| | | } |
| | | |
| | | function resetScopeTabState(state) { |
| | | Object.assign(state, createScopeTabState()) |
| | | } |
| | | |
| | | function hasNodeKey(value) { |
| | | return value !== void 0 && value !== null && value !== '' |
| | | } |
| | | |
| | | const loadScopeData = async (scopeType, { reloadSelection = true } = {}) => { |
| | | const config = getRoleScopeConfig(scopeType) |
| | | const state = scopeState[scopeType] |
| | | state.loading = true |
| | | try { |
| | | const requests = [fetchGetRoleScopeTree(config.scopeType, { condition: state.condition || '' })] |
| | | if (reloadSelection) { |
| | | requests.unshift(fetchGetRoleScopeList(config.scopeType, props.roleData.id)) |
| | | } |
| | | const selectionRequest = reloadSelection |
| | | ? fetchGetRoleScopeList(config.scopeType, props.roleData.id) |
| | | : Promise.resolve(state.checkedKeys) |
| | | const treeRequest = fetchGetRoleScopeTree(config.scopeType, { condition: state.condition || '' }) |
| | | |
| | | const guardedResult = await guardRequestWithMessage( |
| | | reloadSelection ? Promise.all(requests) : Promise.resolve([state.checkedKeys, await requests[0]]), |
| | | Promise.all([selectionRequest, treeRequest]), |
| | | null, |
| | | { |
| | | timeoutMessage: `${config.title}加载超时,已停止等待` |
| | |
| | | const handleClosed = () => { |
| | | activeScopeType.value = props.scopeType || 'menu' |
| | | Object.keys(scopeState).forEach((key) => { |
| | | scopeState[key].loading = false |
| | | scopeState[key].loaded = false |
| | | scopeState[key].treeData = [] |
| | | scopeState[key].checkedKeys = [] |
| | | scopeState[key].halfCheckedKeys = [] |
| | | scopeState[key].condition = '' |
| | | resetScopeTabState(scopeState[key]) |
| | | }) |
| | | } |
| | | |
| | |
| | | const keys = [] |
| | | const traverse = (nodeList) => { |
| | | nodeList.forEach((node) => { |
| | | if (node.id !== void 0 && node.id !== null && node.id !== '') { |
| | | if (hasNodeKey(node.id)) { |
| | | keys.push(String(node.id)) |
| | | } |
| | | if (node.children?.length) { |