提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" title="IP 查询"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="80px" |
|
9 |
> |
|
10 |
<el-form-item label="IP" prop="ip"> |
|
11 |
<el-input v-model="formData.ip" placeholder="请输入 IP 地址" /> |
|
12 |
</el-form-item> |
|
13 |
<el-form-item label="地址" prop="result"> |
|
14 |
<el-input v-model="formData.result" placeholder="展示查询 IP 结果" readonly /> |
|
15 |
</el-form-item> |
|
16 |
</el-form> |
|
17 |
<template #footer> |
|
18 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
19 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
20 |
</template> |
|
21 |
</Dialog> |
|
22 |
</template> |
|
23 |
<script lang="ts" setup> |
|
24 |
import * as AreaApi from '@/api/system/area' |
|
25 |
|
|
26 |
defineOptions({ name: 'SystemAreaForm' }) |
|
27 |
|
|
28 |
const message = useMessage() // 消息弹窗 |
|
29 |
|
|
30 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
31 |
const formLoading = ref(false) // 表单的加载中:提交的按钮禁用 |
|
32 |
const formData = ref({ |
|
33 |
ip: '', |
|
34 |
result: undefined |
|
35 |
}) |
|
36 |
const formRules = reactive({ |
|
37 |
ip: [{ required: true, message: 'IP 地址不能为空', trigger: 'blur' }] |
|
38 |
}) |
|
39 |
const formRef = ref() // 表单 Ref |
|
40 |
|
|
41 |
/** 打开弹窗 */ |
|
42 |
const open = async () => { |
|
43 |
dialogVisible.value = true |
|
44 |
resetForm() |
|
45 |
} |
|
46 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
47 |
|
|
48 |
/** 提交表单 */ |
|
49 |
const submitForm = async () => { |
|
50 |
// 校验表单 |
|
51 |
if (!formRef) return |
|
52 |
const valid = await formRef.value.validate() |
|
53 |
if (!valid) return |
|
54 |
// 提交请求 |
|
55 |
formLoading.value = true |
|
56 |
try { |
|
57 |
formData.value.result = await AreaApi.getAreaByIp(formData.value.ip!.trim()) |
|
58 |
message.success('查询成功') |
|
59 |
} finally { |
|
60 |
formLoading.value = false |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
/** 重置表单 */ |
|
65 |
const resetForm = () => { |
|
66 |
formData.value = { |
|
67 |
ip: '', |
|
68 |
result: undefined |
|
69 |
} |
|
70 |
formRef.value?.resetFields() |
|
71 |
} |
|
72 |
</script> |