# InitDialog

`InitDialog` 用于统一处理新增/编辑弹窗场景，减少页面里重复的标题切换、数据回填、关闭重置和表单校验逻辑。

## 初始化参数

```ts
new InitDialog({
  addText: '新增',
  editText: '编辑',
  modelData,
  dialogConfig,
  AddFrom: AddForm,
  addOrEditTable
})
```

## 能力说明

### showDialog(row)

- 当 `row.id` 存在时，进入编辑态
- 当 `row.id` 不存在时，进入新增态
- 自动设置 `dialogConfig.title`
- 自动控制 `dialogConfig.isShowDialog = true`

### closeDialog()

- 使用 `new AddFrom()` 重置表单数据
- 关闭弹窗

### confirmDialog()

- 调用 `formRef.value.validate`
- 校验通过后执行 `addOrEditTable`

## 示例

```ts
import { reactive } from 'vue'
import { InitDialog } from 'element-plus-form-test'

class AddForm {
  id?: string
  name = ''
}

const modelData = reactive(new AddForm())
const dialogConfig = reactive({
  title: '',
  isShowDialog: false
})

const { showDialog, closeDialog, confirmDialog, formRef } = new InitDialog({
  addText: '新增',
  editText: '编辑',
  modelData,
  dialogConfig,
  AddFrom: AddForm,
  addOrEditTable: () => {}
})
```

## 已补充测试点

当前已提供首个单测样板，覆盖：

- 新增态 `showDialog`
- 编辑态 `showDialog`
- `closeDialog`
- `confirmDialog` 校验通过/失败
