zhangwencui
2 天以前 a2002ba0e8aa2a0e4eee61b5205748d8f6e454fc
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
<script lang="ts" setup>
import { useVbenModal } from '@vben/common-ui';
 
import { message } from 'ant-design-vue';
 
import { useVbenForm } from '#/adapter/form';
import { getAreaByIp } from '#/api/system/area';
import { $t } from '#/locales';
 
import { useFormSchema } from '../data';
 
const [Form, { setFieldValue, validate, getValues }] = useVbenForm({
  commonConfig: {
    componentProps: {
      class: 'w-full',
    },
    formItemClass: 'col-span-2',
    labelWidth: 80,
  },
  layout: 'horizontal',
  schema: useFormSchema(),
  showDefaultActions: false,
});
 
const [Modal, modalApi] = useVbenModal({
  async onConfirm() {
    const { valid } = await validate();
    if (!valid) {
      return;
    }
    modalApi.lock();
    // 提交表单
    const data = await getValues();
    try {
      const result = await getAreaByIp(data.ip);
      // 设置结果
      await setFieldValue('result', result);
      message.success($t('ui.actionMessage.operationSuccess'));
    } finally {
      modalApi.unlock();
    }
  },
});
</script>
 
<template>
  <Modal title="IP 查询">
    <Form class="mx-4" />
  </Modal>
</template>