UnisKB/ui/src/views/system/user-manage/component/RoleAssignDialog.vue

70 lines
2.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<el-dialog v-model="visible" title="分配角色" width="600px" :close-on-click-modal="false">
<div v-loading="loading">
<p class="mb-16">
{{ currentUser.nick_name || currentUser.username }}({{ currentUser.username }})
</p>
<el-form label-position="top">
<el-form-item label="角色"
><el-select v-model="roleIds" multiple filterable style="width: 100%"
><el-option
v-for="r in roles"
:key="r.id"
:label="r.name + (r.enabled ? '' : '(停用)')"
:disabled="
r.is_default ||
(r.is_admin_role && currentUser.id === 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab')
"
:value="r.id" /></el-select
></el-form-item>
</el-form>
<el-button link type="primary" class="mt-16" @click="viewPermissions">查看权限来源</el-button>
</div>
<template #footer
><el-button @click="visible = false">取消</el-button
><el-button type="primary" :loading="loading" @click="save">保存</el-button></template
>
</el-dialog>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import accessApi from '@/api/system/platform-access'
import { MsgSuccess } from '@/utils/message'
const emit = defineEmits(['refresh'])
const router = useRouter()
const visible = ref(false),
loading = ref(false),
currentUser = ref<any>({})
const roleIds = ref<string[]>([]),
roles = ref<any[]>([])
async function open(row: any) {
currentUser.value = row
visible.value = true
loading.value = true
try {
const [config, detail]: any[] = await Promise.all([accessApi.config(), accessApi.user(row.id)])
roles.value = config.data.roles
roleIds.value = detail.data.role_ids
} finally {
loading.value = false
}
}
async function save() {
loading.value = true
try {
await accessApi.setUserRoles(currentUser.value.id, roleIds.value)
MsgSuccess('角色已更新')
visible.value = false
emit('refresh')
} finally {
loading.value = false
}
}
function viewPermissions() {
visible.value = false
router.push({ path: '/system/role', query: { user: currentUser.value.id } })
}
defineExpose({ open })
</script>