|
@@ -1,100 +1,86 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="info-container">
|
|
<div class="info-container">
|
|
|
- <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="auto">
|
|
|
|
|
- <el-form-item v-for="item in formConfig" :key="item.prop" :label="item.label" :prop="item.prop">
|
|
|
|
|
- <template v-if="item.slot">
|
|
|
|
|
- <Upload
|
|
|
|
|
- v-if="item.slot === 'noticeAttachment'"
|
|
|
|
|
- label="上传附件"
|
|
|
|
|
- :fileList="ruleForm.noticeAttachment"
|
|
|
|
|
- @uploadSuccess="handleUploadSuccess"
|
|
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
- <div v-else-if="item.slot === 'isPush'" class="push-container">
|
|
|
|
|
- <el-radio-group v-model="ruleForm.isPush">
|
|
|
|
|
- <el-radio :value="true">是</el-radio>
|
|
|
|
|
- <el-radio :value="false">否</el-radio>
|
|
|
|
|
- </el-radio-group>
|
|
|
|
|
- <PushObject
|
|
|
|
|
- v-if="ruleForm.isPush"
|
|
|
|
|
- :recipientType="ruleForm.recipientType"
|
|
|
|
|
- :userGroupList="ruleForm.userGroupList"
|
|
|
|
|
- :customUserList="ruleForm.customUserList"
|
|
|
|
|
- @recipientTypeChange="handleRecipientTypeChange"
|
|
|
|
|
- @userGroupListChange="handleUserGroupListChange"
|
|
|
|
|
- @customUserListChange="handleCustomUserListChange"
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
- </template>
|
|
|
|
|
-
|
|
|
|
|
- <component v-else :is="item.component" v-model="ruleForm[item.prop]" v-bind="item.componentProps">
|
|
|
|
|
- <el-option
|
|
|
|
|
- v-for="option in item.selectOptions"
|
|
|
|
|
- :key="option.value"
|
|
|
|
|
- :label="option.label"
|
|
|
|
|
- :value="option.value"
|
|
|
|
|
- />
|
|
|
|
|
- </component>
|
|
|
|
|
- </el-form-item>
|
|
|
|
|
- </el-form>
|
|
|
|
|
|
|
+ <BasicForm ref="basicFormRef" :formData="ruleFormData" :formRules="formRules" :formConfig="ruleFormConfig">
|
|
|
|
|
+ <template #noticeAttachment>
|
|
|
|
|
+ <Upload label="上传附件" :fileList="ruleFormData.noticeAttachment" @uploadSuccess="handleUploadSuccess" />
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <template #isPush>
|
|
|
|
|
+ <el-radio-group v-model="ruleFormData.isPush">
|
|
|
|
|
+ <el-radio :value="true">是</el-radio>
|
|
|
|
|
+ <el-radio :value="false">否</el-radio>
|
|
|
|
|
+ </el-radio-group>
|
|
|
|
|
+ <SelectGroup
|
|
|
|
|
+ v-if="ruleFormData.isPush"
|
|
|
|
|
+ ref="selectGroupRef"
|
|
|
|
|
+ :userGroupList="ruleFormData.userGroupList || []"
|
|
|
|
|
+ @userGroupListChange="handleUserGroupListChange"
|
|
|
|
|
+ />
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </BasicForm>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
- import { onMounted, ref } from 'vue';
|
|
|
|
|
- import PushObject from '@/views/disaster/components/PushObject.vue';
|
|
|
|
|
|
|
+ import BasicForm from '@/components/BasicForm.vue';
|
|
|
import Upload from '@/views/disaster/components/Upload.vue';
|
|
import Upload from '@/views/disaster/components/Upload.vue';
|
|
|
- import { useDefenseNoticeFormHook } from '@/views/disaster/disaster-warning/src/useFormHook';
|
|
|
|
|
|
|
+ import { useFormConfigHook } from '@/hooks/useFormConfigHook';
|
|
|
|
|
+ import { DEFENSE_NOTICE_FROM_CONFIG, DEFENSE_NOTICE_FROM_DATA, DEFENSE_NOTICE_FROM_RULES } from '../config';
|
|
|
|
|
+ import { onMounted, ref } from 'vue';
|
|
|
|
|
+ import { DefenseNoticeRuleForm } from '../type';
|
|
|
|
|
+ import SelectGroup from '@/views/disaster/components/SelectGroup.vue';
|
|
|
|
|
+ import type { FileItem } from '@/views/disaster/types';
|
|
|
import { getDefenseNoticeDetail } from '@/api/disaster-warning';
|
|
import { getDefenseNoticeDetail } from '@/api/disaster-warning';
|
|
|
- import type { UserInfo } from '@/types/push-object';
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
|
id: number;
|
|
id: number;
|
|
|
}>();
|
|
}>();
|
|
|
|
|
|
|
|
- const {
|
|
|
|
|
- formConfig,
|
|
|
|
|
- ruleFormRef,
|
|
|
|
|
- ruleForm,
|
|
|
|
|
- rules,
|
|
|
|
|
- validateForm,
|
|
|
|
|
- handleUploadSuccess,
|
|
|
|
|
- beforeRouteLeave,
|
|
|
|
|
- cloneRuleForm,
|
|
|
|
|
- } = useDefenseNoticeFormHook();
|
|
|
|
|
- const handleRecipientTypeChange = (recipientType: number | null) => {
|
|
|
|
|
- ruleForm.recipientType = recipientType;
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const basicFormRef = ref<InstanceType<typeof BasicForm>>();
|
|
|
|
|
+ const selectGroupRef = ref<InstanceType<typeof SelectGroup>>();
|
|
|
|
|
+
|
|
|
|
|
+ const { ruleFormConfig, ruleFormData, formRules, cloneRuleFormData, beforeRouteLeave } =
|
|
|
|
|
+ useFormConfigHook<DefenseNoticeRuleForm>(
|
|
|
|
|
+ DEFENSE_NOTICE_FROM_CONFIG,
|
|
|
|
|
+ DEFENSE_NOTICE_FROM_DATA,
|
|
|
|
|
+ DEFENSE_NOTICE_FROM_RULES,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
const handleUserGroupListChange = (userGroupList: number[]) => {
|
|
const handleUserGroupListChange = (userGroupList: number[]) => {
|
|
|
- ruleForm.userGroupList = userGroupList;
|
|
|
|
|
|
|
+ ruleFormData.userGroupList = userGroupList;
|
|
|
};
|
|
};
|
|
|
- const handleCustomUserListChange = (customUserList: UserInfo[]) => {
|
|
|
|
|
- ruleForm.customUserList = customUserList;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const handleUploadSuccess = (fileList: FileItem[]) => {
|
|
|
|
|
+ ruleFormData.noticeAttachment = fileList;
|
|
|
|
|
+ if (!basicFormRef.value) return;
|
|
|
|
|
+ basicFormRef.value.validateField('noticeAttachment');
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
const getDefenseNoticeDetailData = async () => {
|
|
const getDefenseNoticeDetailData = async () => {
|
|
|
const res = await getDefenseNoticeDetail(props.id);
|
|
const res = await getDefenseNoticeDetail(props.id);
|
|
|
- ruleForm.createUser = res.createUser;
|
|
|
|
|
- ruleForm.disasterType = res.disasterType;
|
|
|
|
|
- ruleForm.disasterLevel = res.disasterLevel;
|
|
|
|
|
- ruleForm.noticeTitle = res.noticeTitle;
|
|
|
|
|
- ruleForm.noticeContent = res.noticeContent;
|
|
|
|
|
- ruleForm.isPush = res.isPush;
|
|
|
|
|
- ruleForm.noticeAttachment = res.noticeAttachment;
|
|
|
|
|
- ruleForm.recipientType = res.recipientType ?? null;
|
|
|
|
|
- ruleForm.userGroupList = res.userGroupList ?? [];
|
|
|
|
|
- ruleForm.customUserList = res.customUserList ?? [];
|
|
|
|
|
- cloneRuleForm();
|
|
|
|
|
|
|
+ for (const key in res) {
|
|
|
|
|
+ ruleFormData[key] = res[key as keyof typeof res];
|
|
|
|
|
+ }
|
|
|
|
|
+ cloneRuleFormData();
|
|
|
};
|
|
};
|
|
|
- const pushObjectRef = ref<InstanceType<typeof PushObject>[]>([]);
|
|
|
|
|
const handleValidate = async () => {
|
|
const handleValidate = async () => {
|
|
|
- if (!pushObjectRef.value) return false;
|
|
|
|
|
- const results = await Promise.all(pushObjectRef.value.map((item) => item.validateForm()));
|
|
|
|
|
- const allValid = results.every((res) => res === true);
|
|
|
|
|
- const res = await validateForm();
|
|
|
|
|
- return allValid && res;
|
|
|
|
|
|
|
+ if (!basicFormRef.value) return;
|
|
|
|
|
+ const parentValidateResult = await basicFormRef.value.validateForm();
|
|
|
|
|
+ let childValidateResult = true;
|
|
|
|
|
+ if (selectGroupRef.value) {
|
|
|
|
|
+ childValidateResult = (await selectGroupRef.value.validateForm()) as boolean;
|
|
|
|
|
+ }
|
|
|
|
|
+ return parentValidateResult && childValidateResult;
|
|
|
|
|
+ };
|
|
|
|
|
+ const getFormData = () => {
|
|
|
|
|
+ if (!ruleFormData.isPush) {
|
|
|
|
|
+ ruleFormData.userGroupList = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ cloneRuleFormData();
|
|
|
|
|
+ return ruleFormData;
|
|
|
};
|
|
};
|
|
|
defineExpose({
|
|
defineExpose({
|
|
|
handleValidate,
|
|
handleValidate,
|
|
|
|
|
+ getFormData,
|
|
|
});
|
|
});
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
getDefenseNoticeDetailData();
|
|
getDefenseNoticeDetailData();
|
|
@@ -104,7 +90,4 @@
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
<style scoped lang="scss">
|
|
|
@use '@/views/disaster/style/info-container.scss' as *;
|
|
@use '@/views/disaster/style/info-container.scss' as *;
|
|
|
- .push-container {
|
|
|
|
|
- width: 100%;
|
|
|
|
|
- }
|
|
|
|
|
</style>
|
|
</style>
|