<template>
|
<ywDialog
|
v-model="dialogIsShow"
|
:headerIcon="dialogHeaderIcon"
|
:title="dialogTitle"
|
width="470"
|
@dlgClosed="closeDialog"
|
@submit="submitFormValue"
|
>
|
<el-form :model="dialogFormValue" ref="dialogFormRef" :rules="dialogFormRules" label-width="76">
|
<el-form-item label="角色" prop="user_roles">
|
<el-select class="w100" placeholder="请选择角色" filterable multiple v-model="dialogFormValue.user_roles">
|
<el-option v-for="(item, index) in roleList" :key="index + ''" :value="item.id" :label="item?.title"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
</ywDialog>
|
</template>
|
|
<script setup lang="ts">
|
import ywDialog from '/@/components/dialog/yw-dialog.vue';
|
|
import type { FormInstance, FormRules } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
|
import { computed, ref, watch } from 'vue';
|
// import { useTableSort } from '/@/hooks/useTableSort';
|
// import { useValidateUniqueness } from '/@/hooks/useValidateUniqueness';
|
import { deepClone } from '/@/utils/other';
|
|
import { userSexMap } from '../types';
|
import * as userApi from '/@/api/auth/user';
|
|
const props = defineProps(['item', 'roleList']);
|
const emit = defineEmits(['update', 'insert']);
|
//#region ====================== 增加、修改记录操作, dialog init======================
|
const isEditDialog = ref(false);
|
const dialogTitle = computed(() => {
|
return `修改用户【${props.item?.user_name}】角色`;
|
});
|
const dialogHeaderIcon = computed(() => {
|
return isEditDialog.value ? 'ele-Edit' : 'ele-Plus';
|
});
|
const dialogFormValue = ref(null);
|
const dialogIsShow = defineModel({
|
type: Boolean,
|
});
|
const dialogFormRef = ref<FormInstance>(null);
|
|
const dialogFormRules = ref<FormRules>({});
|
const openOperateDialog = (row) => {
|
dialogFormValue.value = {
|
user_roles: row.user_roles ?? [],
|
};
|
};
|
const closeDialog = () => {
|
dialogIsShow.value = false;
|
dialogFormRef.value.clearValidate();
|
};
|
|
const submitFormValue = async () => {
|
const valid = await dialogFormRef.value.validate().catch(() => {});
|
if (!valid) return;
|
|
const sendForm = { user_id: props.item.user_id, user_roles: dialogFormValue.value.user_roles.join(',') };
|
|
const res = await userApi.updateUserRolesByPost(sendForm);
|
emit('update', { user_id: props.item.user_id, user_roles: dialogFormValue.value.user_roles });
|
|
closeDialog();
|
ElMessage.success('修改角色成功');
|
};
|
|
//#endregion
|
|
watch(
|
() => dialogIsShow.value,
|
(val) => {
|
if (!val) return;
|
openOperateDialog(props.item);
|
}
|
);
|
</script>
|
<style scoped lang="scss"></style>
|