125 lines
3.1 KiB
Vue
125 lines
3.1 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue';
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { cloneDeep } from '@vben/utils';
|
|
|
|
import { useVbenForm } from '#/adapter/form';
|
|
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
|
|
|
import { modalSchema } from './data';
|
|
import { alarmEventComplete } from '#/api/sis/alarmEvents';
|
|
|
|
const emit = defineEmits<{ reload: [] }>();
|
|
|
|
const isUpdate = ref(false);
|
|
const [BasicForm, formApi] = useVbenForm({
|
|
commonConfig: {
|
|
formItemClass: 'col-span-1',
|
|
labelWidth: 110,
|
|
componentProps: {
|
|
class: 'w-full',
|
|
},
|
|
},
|
|
schema: modalSchema(),
|
|
showDefaultActions: false,
|
|
wrapperClass: 'grid-cols-2',
|
|
});
|
|
|
|
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
|
{
|
|
initializedGetter: defaultFormValueGetter(formApi),
|
|
currentGetter: defaultFormValueGetter(formApi),
|
|
},
|
|
);
|
|
let currentSelectData: any = null;
|
|
const [BasicModal, modalApi] = useVbenModal({
|
|
class: 'w-[70%]',
|
|
fullscreenButton: false,
|
|
onBeforeClose,
|
|
onClosed: handleClosed,
|
|
onConfirm: handleConfirm,
|
|
onOpenChange: async (isOpen) => {
|
|
if (!isOpen) {
|
|
return null;
|
|
}
|
|
modalApi.modalLoading(true);
|
|
const { id } = modalApi.getData() as { id?: number | string };
|
|
isUpdate.value = !!id;
|
|
|
|
if (isUpdate.value && id) {
|
|
// 从传递的数据中查找对应的记录
|
|
const { data } = modalApi.getData() as {
|
|
id: number | string;
|
|
data: any;
|
|
};
|
|
if (data) {
|
|
// 处理预警上报类型
|
|
data.alarmType = `${data.bigTypeName} - ${data.smallTypeName}`;
|
|
await formApi.setValues(data);
|
|
}
|
|
}
|
|
await markInitialized();
|
|
modalApi.modalLoading(false);
|
|
},
|
|
});
|
|
|
|
async function handleConfirm() {
|
|
try {
|
|
modalApi.lock(true);
|
|
const { valid } = await formApi.validate();
|
|
if (!valid) {
|
|
return;
|
|
}
|
|
// 表单数据
|
|
const formData = cloneDeep(await formApi.getValues());
|
|
// 处理数据
|
|
console.log(formData);
|
|
const { files = [] } = formData;
|
|
const ossids: string[] = [];
|
|
files.forEach((file: any) => {
|
|
const ossId = file.response.ossId;
|
|
ossids.push(ossId);
|
|
});
|
|
|
|
const params = {
|
|
alarmId: formData.id,
|
|
remark: formData.remark,
|
|
attachments: ossids,
|
|
};
|
|
await alarmEventComplete(params);
|
|
resetInitialized();
|
|
emit('reload');
|
|
modalApi.close();
|
|
} catch (error) {
|
|
console.error(error);
|
|
} finally {
|
|
modalApi.lock(false);
|
|
}
|
|
}
|
|
|
|
async function handleClosed() {
|
|
await formApi.resetForm();
|
|
resetInitialized();
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<BasicModal title="处理">
|
|
<BasicForm></BasicForm>
|
|
</BasicModal>
|
|
</template>
|
|
<style scoped>
|
|
/* 使用 :deep() 穿透 scoped 样式,影响子组件 */
|
|
:deep(.ant-input[disabled]),
|
|
:deep(.ant-input-number-disabled .ant-input-number-input),
|
|
:deep(.ant-select-disabled .ant-select-selection-item),
|
|
:deep(.ant-picker-disabled .ant-picker-input > input) {
|
|
/* 设置一个更深的颜色 */
|
|
color: rgb(0 0 0 / 65%) !important;
|
|
|
|
/* 有些浏览器需要这个来覆盖默认颜色 */
|
|
-webkit-text-fill-color: rgb(0 0 0 / 65%) !important;
|
|
}
|
|
</style>
|