108 lines
2.6 KiB
Vue
108 lines
2.6 KiB
Vue
<!--
|
||
ExampleFormDialog — 示例表单弹窗(模板)
|
||
|
||
功能按钮对应的表单组件放在 pages/ 目录下。
|
||
|
||
使用方式:
|
||
1. 在 template-config.ts 的 COMPONENT_REGISTRY 中注册
|
||
2. 在 template-config.ts 的 TOOLBAR_BUTTONS 中添加功能按钮,设置 formKey
|
||
3. index.vue 中通过工具栏按钮触发打开
|
||
-->
|
||
<template>
|
||
<el-dialog
|
||
:model-value="visible"
|
||
title="示例操作"
|
||
width="500px"
|
||
align-center
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@closed="handleClosed"
|
||
>
|
||
<div class="form-body">
|
||
<el-form ref="formRef" :model="form" label-width="100px" size="small">
|
||
<el-form-item label="名称" prop="name">
|
||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||
</el-form-item>
|
||
<el-form-item label="描述" prop="description">
|
||
<el-input
|
||
v-model="form.description"
|
||
type="textarea"
|
||
:rows="3"
|
||
placeholder="请输入描述"
|
||
/>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||
确认
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { reactive, ref, watch } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
|
||
defineOptions({ name: 'ExampleFormDialog' })
|
||
|
||
const props = defineProps<{
|
||
visible: boolean
|
||
/** 从行数据注入的初始值(由 OperationCellRenderer 的 paramMap 传递) */
|
||
id?: string | number
|
||
code?: string
|
||
name?: string
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'update:visible', v: boolean): void
|
||
(e: 'success'): void
|
||
}>()
|
||
|
||
const formRef = ref<any>(null)
|
||
const submitting = ref(false)
|
||
|
||
const form = reactive({
|
||
name: '',
|
||
description: ''
|
||
})
|
||
|
||
// 重置表单
|
||
watch(() => props.visible, (v) => {
|
||
if (v) {
|
||
form.name = props.name ?? ''
|
||
form.description = ''
|
||
}
|
||
})
|
||
|
||
function handleClosed() {
|
||
emit('update:visible', false)
|
||
}
|
||
|
||
async function handleSubmit() {
|
||
submitting.value = true
|
||
try {
|
||
// ★ 替换为真实 API 调用
|
||
// const res = await yourApi.submit({ id: props.id, ...form })
|
||
await new Promise((r) => setTimeout(r, 500))
|
||
|
||
ElMessage.success('操作成功')
|
||
emit('update:visible', false)
|
||
emit('success')
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '操作失败')
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.form-body {
|
||
padding: 12px 0;
|
||
}
|
||
</style>
|