# 弹窗
URL: /%E6%96%87%E6%A1%A3/04.%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/01.%20%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/01.%20%E5%9F%BA%E7%A1%80%E8%A7%84%E8%8C%83/18.%20%E5%89%8D%E7%AB%AF%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/%E5%BC%B9%E7%AA%97


## vue

```vue
<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
      <a-row>
        <a-col :span="24">
          <a-form-item label="字段名称" v-bind="validateInfos.auditStatus">
            <JDictSelectTag
              v-model:value="formData.auditStatus"
              placeholder="是否通过"
              :options="[
                {
                  label: '通过',
                  value: 2,
                },
                {
                  label: '不通过',
                  value: 3,
                },
              ]"
            ></JDictSelectTag>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="备注" v-bind="validateInfos.auditInfo">
            <a-input  v-model:value="formData.auditInfo" placeholder="请输入字段名称" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script lang="ts" setup>
  import { ref, nextTick, defineExpose, reactive } from 'vue';
  import { JDictSelectTag } from '/@/components/Form';
  import { Form, message } from 'ant-design-vue';
  import { getValueType } from '@/utils';

  const title = ref<string>('弹窗');
  const width = ref<number>(800);
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const formRef = ref();
  const useForm = Form.useForm;
  const emit = defineEmits(['success', 'ok']);
  const formData = reactive<Record<string, any>>({
    auditStatus: '',
    auditInfo: '',
  });
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  //表单验证
  const validatorRules = {};
  const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });

  function open(record) {
    visible.value = true;
    nextTick(() => {
      resetFields();
      //赋值
      Object.assign(formData, record);
    });
  }

  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    submitForm();
  }

  async function submitForm() {
    await validate();
    let model = formData;

    //循环数据
    for (let data in model) {
      //如果该数据是数组并且是字符串类型
      if (model[data] instanceof Array) {
        let valueType = getValueType(formRef.value.getProps, data);
        //如果是字符串类型的需要变成以逗号分割的字符串
        if (valueType === 'string') {
          model[data] = model[data].join(',');
        }
      }
    }
    // api

    submitCallback();
  }

  function submitCallback() {
    handleCancel();
    emit('success');
  }

  /**
   * 取消按钮回调事件
   */
  function handleCancel() {
    visible.value = false;
  }

  defineExpose({
    open,
    disableSubmit,
  });
</script>

<style>
  /**隐藏样式-modal确定按钮 */
  .jee-hidden {
    display: none !important;
  }
  .antd-modal-form {
    min-height: 200px !important;
    overflow-y: auto;
    padding: 24px 24px 24px 24px;
  }
</style>
```

## TS

```ts
<script lang="tsx">
  import { defineComponent, ref } from 'vue';

  export default defineComponent({
    emits: ['success'],
    setup(_, { emit, expose }) {
      const title = ref<string>('事件埋点');
      const visible = ref<boolean>(false);
      const width = ref<number>(1380);

      function handleOpen() {
        visible.value = true;
      }

      function handleOk() {
        emit('success');
      }

      function handleCancel() {
        visible.value = false;
      }

      expose({
        handleOpen,
      });

      const coentWrap = () => {
        return <div>1555</div>;
      };

      return () => {
        return (
          <a-modal title={title.value} width={width.value} visible={visible.value} onOk={handleOk} onCancel={handleCancel} cancelText="关闭">
            <a-form ref="formRef" class="antd-modal-form">
              {visible.value && <coentWrap />}
            </a-form>
          </a-modal>
        );
      };
    },
  });
</script>

<style scoped lang="less">
  .antd-modal-form {
    min-height: 500px !important;
    overflow-y: auto;
    padding: 12px;
  }
</style>

```
