Dailog.vue
2.58 KB
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
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-09-04 21:13:18
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-09-25 16:06:16
* @FilePath: \Apper-Admin-master\src\views\log\dictionary\components\Dailog.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<el-dialog v-model="dialogVisible" width="30%" :title="`${dialogProps.title}字段`">
<el-form
ref="ruleFormRef"
label-width="120px"
label-suffix=" :"
:rules="rules"
:disabled="dialogProps.isView"
:model="dialogProps.row"
:hide-required-asterisk="dialogProps.isView"
>
<el-form-item label="字段名" prop="name">
<el-input v-model="dialogProps.row!.name" placeholder="请填写字段名" clearable></el-input>
</el-form-item>
<el-form-item label="字段值" prop="type">
<el-input v-model="dialogProps.row!.type" placeholder="请填写字段值" clearable></el-input>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button v-show="!dialogProps.isView" type="primary" @click="handleSubmit">确定</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="DictionaryDailog">
import { ref, reactive } from "vue";
import { ElMessage, FormInstance } from "element-plus";
import { Fields } from "@/api/interface";
const rules = reactive({
name: [{ required: true, message: "请填写字段名" }],
type: [{ required: true, message: "请填写字段名类型" }]
});
interface DialogProps {
title: string;
isView: boolean;
row: Partial<Fields.ResFieldsList>;
api?: (params: any) => Promise<any>;
getTableList?: () => void;
}
const dialogVisible = ref(false);
const dialogProps = ref<DialogProps>({
isView: false,
title: "",
row: {}
});
// 接收父组件传过来的参数
const acceptParams = (params: DialogProps) => {
dialogProps.value = params;
dialogVisible.value = true;
};
// 提交数据(新增/编辑)
const ruleFormRef = ref<FormInstance>();
const handleSubmit = () => {
ruleFormRef.value!.validate(async valid => {
if (!valid) return;
try {
await dialogProps.value.api!(dialogProps.value.row);
ElMessage.success({ message: `${dialogProps.value.title}成功!` });
dialogProps.value.getTableList!();
dialogVisible.value = false;
} catch (error) {
console.log(error);
}
});
};
defineExpose({
acceptParams
});
</script>