|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { ref, unref,onMounted,nextTick } from 'vue'
|
|
|
|
|
import { updateWarnForm } from './warn.data'
|
|
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
|
|
import { useMessage } from '@/hooks/web/useMessage'
|
|
|
|
|
import { BasicForm, useForm } from '@/components/Form'
|
|
|
|
|
import { BasicModal, useModalInner } from '@/components/Modal'
|
|
|
|
|
import { getWarn, updateWarn } from '@/api/alert/warn'
|
|
|
|
|
import { getSearchFormSchema } from '@/views/run/instant/instant.data'
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'UpdateModal' })
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['success', 'register'])
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
const { createMessage } = useMessage()
|
|
|
|
|
const isUpdate = ref(true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 新增的时候增加查询表单
|
|
|
|
|
const [registerQueryForm, {
|
|
|
|
|
setProps,
|
|
|
|
|
setFieldsValue: setQueryFields,
|
|
|
|
|
resetFields: resetQueryFields,
|
|
|
|
|
validate: validateQueryForm,
|
|
|
|
|
}] = useForm({
|
|
|
|
|
labelWidth: 80,
|
|
|
|
|
baseColProps: { span: 12 },
|
|
|
|
|
schemas: [],
|
|
|
|
|
showSubmitButton:false,
|
|
|
|
|
showActionButtonGroup: false,
|
|
|
|
|
actionColOptions: { span: 3 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
|
|
|
|
labelWidth: 120,
|
|
|
|
|
baseColProps: { span: 24 },
|
|
|
|
|
schemas: updateWarnForm,
|
|
|
|
|
showActionButtonGroup: false,
|
|
|
|
|
actionColOptions: { span: 23 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
|
|
|
|
resetFields()
|
|
|
|
|
setModalProps({ useWrapper: true, minHeight: 180, confirmLoading: false })
|
|
|
|
|
// 如果是修改modal,则赋值给表单
|
|
|
|
|
isUpdate.value = !!data?.isUpdate
|
|
|
|
|
if (unref(isUpdate)) {
|
|
|
|
|
const res = await getWarn(data.record.warnId)
|
|
|
|
|
setFieldsValue({ ...res })
|
|
|
|
|
}
|
|
|
|
|
//如果是新增
|
|
|
|
|
else {
|
|
|
|
|
const queryForm = await getSearchFormSchema(false, false, false, true,true,true) // 不显示算法
|
|
|
|
|
// 等 Vue 渲染完成 form 实例
|
|
|
|
|
await nextTick()
|
|
|
|
|
await setProps({schemas: queryForm})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
|
try {
|
|
|
|
|
const values = await validate()
|
|
|
|
|
setModalProps({ confirmLoading: true })
|
|
|
|
|
if (unref(isUpdate))
|
|
|
|
|
await updateWarn(values)
|
|
|
|
|
|
|
|
|
|
closeModal()
|
|
|
|
|
emit('success')
|
|
|
|
|
createMessage.success(t('common.saveSuccessText'))
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
setModalProps({ confirmLoading: false })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<BasicModal v-bind="$attrs" :title="isUpdate ? t('action.edit') : t('action.create')" @register="registerModal" @ok="handleSubmit">
|
|
|
|
|
<!--查询表单-->
|
|
|
|
|
<BasicForm @register="registerQueryForm" />
|
|
|
|
|
<!--查询出来的结果-->
|
|
|
|
|
|
|
|
|
|
<BasicForm @register="registerForm" />
|
|
|
|
|
</BasicModal>
|
|
|
|
|
</template>
|