-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<template> | ||
<a-modal | ||
v-model:visible="visible" | ||
title="分配角色" | ||
:mask-closable="false" | ||
:esc-to-close="false" | ||
:width="width >= 500 ? 500 : '100%'" | ||
draggable | ||
@before-ok="save" | ||
@close="reset" | ||
> | ||
<GiForm ref="formRef" v-model="form" :options="options" :columns="columns" /> | ||
</a-modal> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Message } from '@arco-design/web-vue' | ||
import { useWindowSize } from '@vueuse/core' | ||
import { getUser, updateUserRole } from '@/apis/system' | ||
import { type Columns, GiForm, type Options } from '@/components/GiForm' | ||
import { useForm } from '@/hooks' | ||
import { useRole } from '@/hooks/app' | ||
const emit = defineEmits<{ | ||
(e: 'save-success'): void | ||
}>() | ||
const { width } = useWindowSize() | ||
const dataId = ref('') | ||
const visible = ref(false) | ||
const formRef = ref<InstanceType<typeof GiForm>>() | ||
const { roleList, getRoleList } = useRole() | ||
const options: Options = { | ||
form: { size: 'large' }, | ||
btns: { hide: true }, | ||
} | ||
const columns: Columns = reactive([ | ||
{ | ||
label: '角色', | ||
field: 'roleIds', | ||
type: 'select', | ||
options: roleList, | ||
props: { | ||
multiple: true, | ||
allowClear: true, | ||
allowSearch: { retainInputValue: true }, | ||
placeholder: '请选择角色', | ||
}, | ||
rules: [{ required: true, message: '请选择角色' }], | ||
}, | ||
]) | ||
const { form, resetForm } = useForm({}) | ||
// 重置 | ||
const reset = () => { | ||
formRef.value?.formRef?.resetFields() | ||
resetForm() | ||
} | ||
// 保存 | ||
const save = async () => { | ||
try { | ||
const isInvalid = await formRef.value?.formRef?.validate() | ||
if (isInvalid) return false | ||
await updateUserRole({ roleIds: form.roleIds }, dataId.value) | ||
Message.success('分配成功') | ||
emit('save-success') | ||
return true | ||
} catch (error) { | ||
return false | ||
} | ||
} | ||
// 初始化 | ||
const onOpen = async (id: string) => { | ||
reset() | ||
dataId.value = id | ||
if (!roleList.value.length) { | ||
await getRoleList() | ||
} | ||
const res = await getUser(id) | ||
Object.assign(form, res.data) | ||
visible.value = true | ||
} | ||
defineExpose({ onOpen }) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters