73 lines
1.4 KiB
Vue
73 lines
1.4 KiB
Vue
<script setup lang="ts">
|
|
import type { User } from '@/model/user'
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
|
import type { Role } from '@/model/role'
|
|
import { setUserRoles } from '@/api/user'
|
|
import { MessagePlugin } from 'tdesign-vue-next'
|
|
|
|
const props = defineProps<{
|
|
user: (User | null)
|
|
}>()
|
|
|
|
|
|
const roles = ref<string[]>([])
|
|
|
|
watch(() => props.user, (user) => {
|
|
if (user) {
|
|
roles.value = user.roles.map(role => role.name)
|
|
}
|
|
})
|
|
|
|
const allRoles = ref<Role[]>()
|
|
|
|
const fetchAllRoles = async () => {
|
|
|
|
|
|
}
|
|
|
|
onMounted(fetchAllRoles)
|
|
|
|
const options = computed(() => {
|
|
return allRoles.value?.map(role => {
|
|
return {
|
|
label: role.label,
|
|
value: role.name
|
|
}
|
|
})
|
|
})
|
|
|
|
const emit = defineEmits<{
|
|
success: [void],
|
|
cancel: [void]
|
|
}>()
|
|
|
|
const handleConfirm = async () => {
|
|
await setUserRoles(props.user!.id, roles.value)
|
|
MessagePlugin.success('设置成功')
|
|
emit('success')
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<TDialog>
|
|
<TForm v-if="user">
|
|
<TFormItem label="用户">
|
|
<div>{{ user.name }}</div>
|
|
</TFormItem>
|
|
<TFormItem label="角色">
|
|
<TSelect v-model="roles" :options="options" multiple></TSelect>
|
|
</TFormItem>
|
|
</TForm>
|
|
<template #footer>
|
|
<TSpace>
|
|
<TButton @click="handleConfirm">确定</TButton>
|
|
<TButton theme="default" @click="() => emit('cancel')">取消</TButton>
|
|
</TSpace>
|
|
</template>
|
|
</TDialog>
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|