1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| <template> <div> <el-dialog :model-value="modelValue" :title="title" @closed="handleClose" :width="width" :top="top" :close-on-click-modal="false" append-to-body> <div> <el-form ref="form1Ref" :model="form1" :rules="form1Rules" label-width="80px"> <el-form-item label="名称" prop="name"> <el-input v-model="form1.name" placeholder="请输入" /> </el-form-item> <el-form-item label="状态" prop="status"> <el-radio-group v-model="form1.status"> <el-radio :label="1">启用</el-radio> <el-radio :label="0">停用</el-radio> </el-radio-group> </el-form-item> </el-form> </div>
<template #footer> <div class="dialog-footer"> <el-button @click="handleClose">关 闭</el-button> <el-button @click="handleConfirm" type="primary">确 认</el-button> </div> </template> </el-dialog> </div> </template>
<script setup> import { reactive, ref, watch } from "vue"; import { ElMessage } from "element-plus"; import RoleAPI from '@/api/role.api';
const { proxy } = getCurrentInstance();
const props = defineProps({ modelValue: { type: Boolean, default: false, }, title: { type: String, default: "XX下拉选择弹框", }, width: { type: String, default: "60vw", }, top: { type: String, default: "5vh", }, id: { type: [String, Number], }, });
const emit = defineEmits(["update:modelValue", "confirm", "close"]);
// const dial_loading = ref(false);
// 是否为更新模式 const isUpdateMode = ref(false);
const init_form1 = { name: '', status: 1 }; const form1Ref = ref(); const form1 = reactive({ id: null, name: '', status: 1 }); const form1Rules = reactive({ name: [ { required: true, message: '名称不能为空', trigger: 'blur' }, // { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' }, ], });
watch(() => props.id, (newId) => { if (newId) { form1.id = newId; isUpdateMode.value = true; } else { form1.id = null; isUpdateMode.value = false; } });
/** 确认并关闭 */ function confirmClose() { emit("confirm"); emit("close"); emit("update:modelValue", false); }
/** 重置弹框里面的数据,比如输入框、下拉框等等 */ function resetDialog() { Object.assign(form1, init_form1); form1Ref.value.resetFields(); }
/** 关闭弹窗 */ function handleClose() { emit("update:modelValue", false); }
/** 确认按钮 */ function handleConfirm() { // 验证表单后再提交 form1Ref.value.validate(valid => { if (valid) { if (this.isUpdateMode) { // 更新时 RoleAPI.roleUpdate(form1).then(() => { proxy.$modal.msgSuccess("修改成功"); confirmClose(); resetDialog(); }); } else { // 新增时 RoleAPI.roleAdd(form1).then(() => { proxy.$modal.msgSuccess("新增成功"); confirmClose(); resetDialog(); }); } } }); } </script>
|