Sfoglia il codice sorgente

完成防御通知的联调

chauncey 11 mesi fa
parent
commit
98521e6246

+ 22 - 0
src/api/disaster-warning/index.ts

@@ -57,6 +57,17 @@ export const createDefenseNoticeItem = (data: Omit<DefenseNoticeRuleForm, 'creat
   });
 };
 
+/**
+ * 编辑防御通知项
+ */
+export const editDefenseNoticeItem = (data: Omit<DefenseNoticeRuleForm, 'createUser'>) => {
+  return http.request({
+    url: '/defenseNotice/updateDefenseNoticeInfo',
+    method: 'post',
+    data,
+  });
+};
+
 /**
  * 查看防御通知详情
  */
@@ -70,6 +81,17 @@ export const getDefenseNoticeDetail = (defenseNoticeInfoId: number) => {
   });
 };
 
+/**
+ *  发布、撤消防御通知
+ */
+export const publishDefenseNoticeItem = (editParam: { id: number; isPush: number }) => {
+  return http.request({
+    url: '/defenseNotice/updateDefenseNoticeInfo',
+    method: 'post',
+    data: editParam,
+  });
+};
+
 /**
  * 删除防御通知项
  */

+ 19 - 13
src/api/push-object/index.ts

@@ -1,19 +1,25 @@
 import { http } from '@/utils/http/axios';
-import type { PushObjectGroupInfoResponse, PushObjectUserInfoResponse } from '@/types/push-object';
+import type { PushObjectUserInfoResponse, UserGroupOption, PushObjectGroupInfoResponse } from '@/types/push-object';
+
 /**
- * 查询推送人员
+ * 全量查询用户
  */
-export const queryUserGroupDetailByIds = (userGroupList: number[]) => {
-  return http.request<PushObjectGroupInfoResponse[]>(
-    {
-      url: '/userGroup/queryUserGroupDetailByIds',
-      method: 'get',
-      params: userGroupList,
-    },
-    {
-      ignoreTargetTenantId: true,
-    },
-  );
+export const getAllUserGroup = () => {
+  return http.request<{ groupVOList: UserGroupOption[] }>({
+    url: '/userGroup/ToPushObjectQueryUserGroupList',
+    method: 'post',
+  });
+};
+
+/**
+ * 查询用户组人员情况
+ */
+export const getUserGroupDetailByIds = (userGroupList: number[]) => {
+  return http.request<PushObjectGroupInfoResponse[]>({
+    url: '/userGroup/queryUserGroupDetailByIds',
+    method: 'post',
+    data: { userGroupList },
+  });
 };
 
 /**

+ 4 - 0
src/types/push-object/index.ts

@@ -1,3 +1,7 @@
+export interface UserGroupOption {
+  name: string;
+  id: number;
+}
 export interface PushObjectGroupInfoResponse {
   userGroupId: number;
   name: string;

+ 9 - 15
src/views/disaster/components/SelectGroup.vue

@@ -33,11 +33,10 @@
 </template>
 
 <script lang="ts" setup>
-  import { ref, reactive, watch } from 'vue';
+  import { ref, reactive, watch, onMounted } from 'vue';
   import type { FormInstance } from 'element-plus';
-  import type { GroupOptionType } from '@/views/disaster/types';
-  import type { UserGroupInfo } from '@/types/push-object';
-  import { queryUserGroupDetailByIds } from '@/api/push-object';
+  import type { UserGroupInfo, UserGroupOption } from '@/types/push-object';
+  import { getUserGroupDetailByIds, getAllUserGroup } from '@/api/push-object';
   import Group from './Group.vue';
   const props = defineProps<{
     userGroupList: number[];
@@ -45,16 +44,7 @@
   interface RuleForm {
     userGroupList: number[];
   }
-  const groupOptions = ref<GroupOptionType[]>([
-    {
-      id: 1,
-      name: '测试1',
-    },
-    {
-      id: 2,
-      name: '测试2',
-    },
-  ]);
+  const groupOptions = ref<UserGroupOption[]>([]);
   const ruleFormRef = ref<FormInstance>();
   const ruleForm = reactive<RuleForm>({
     userGroupList: [],
@@ -66,7 +56,7 @@
   };
   const userGroupInfo = ref<UserGroupInfo[]>([]);
   const getUserGroupInfo = async () => {
-    const res = await queryUserGroupDetailByIds(ruleForm.userGroupList);
+    const res = await getUserGroupDetailByIds(ruleForm.userGroupList);
     userGroupInfo.value = res.map((item) => ({
       ...item,
       isExpand: false,
@@ -86,6 +76,10 @@
   defineExpose({
     validateForm,
   });
+  onMounted(async () => {
+    const res = await getAllUserGroup();
+    groupOptions.value = res.groupVOList;
+  });
   watch(
     () => props.userGroupList,
     (newUserGroupList) => {

+ 11 - 0
src/views/disaster/disaster-warning/PageDefenseNotice.vue

@@ -58,6 +58,7 @@
                 title: '确定要发布?',
               }"
               v-if="scope.row.effectState === ACTIVE_STATUS.NOT_EFFECTIVE"
+              @confirm="handlePublishDefenseNotice(scope.row.id, scope.row.isPush)"
             />
             <ActionButton
               text="撤回"
@@ -65,6 +66,7 @@
                 title: '确定要撤回?',
               }"
               v-else-if="scope.row.effectState === ACTIVE_STATUS.ACTIVE"
+              @confirm="handlePublishDefenseNotice(scope.row.id, scope.row.isPush)"
             />
             <ActionButton
               text="删除"
@@ -96,6 +98,8 @@
   import { formatDisasterLevel, formatDisasterType } from '@/views/disaster/utils/formatTable';
   import { useRouter } from 'vue-router';
   import { ElMessage } from 'element-plus';
+  import { publishDefenseNoticeItem } from '@/api/disaster-warning';
+
   const tableData = ref<DefenseNoticeListResponse[]>([]);
   const router = useRouter();
   const defaultPath = '/disaster-prevention/disaster-warning/defense-notice-item';
@@ -119,6 +123,13 @@
       query: { id },
     });
   };
+  const handlePublishDefenseNotice = async (id: number, isPush: number) => {
+    const message = isPush === PUSH_STATUS.PUSHED ? '确定要发布吗?' : '确定要撤回吗?';
+    const pushStatus = isPush === PUSH_STATUS.PUSHED ? PUSH_STATUS.NOT_PUSH : PUSH_STATUS.PUSHED;
+    await publishDefenseNoticeItem({ id, isPush: pushStatus });
+    await getTableData();
+    ElMessage.success('发布成功');
+  };
   const handleDeleteDefenseNotice = async (id: number) => {
     await deleteDefenseNoticeItem(id);
     await getTableData();

+ 32 - 7
src/views/disaster/disaster-warning/PageDefenseNoticeItem.vue

@@ -25,7 +25,7 @@
   import { uploadFile } from '@/api/minio';
   import { BIZ_TYPE } from '@/views/disaster/constant';
   import type { FileItem } from '@/views/disaster/types';
-  import { createDefenseNoticeItem } from '@/api/disaster-warning/index';
+  import { createDefenseNoticeItem, editDefenseNoticeItem } from '@/api/disaster-warning/index';
 
   const router = useRouter();
   const route = useRoute();
@@ -78,21 +78,46 @@
       content: formData.content,
       attachmentListRes,
       isPush: formData.isPush,
+      userGroupList: formData.isPush ? formData.userGroupList : [],
     };
     await createDefenseNoticeItem(createParam);
   };
+  const editDefenseNoticeItemFunc = async (formData: DefenseNoticeRuleForm) => {
+    const attachmentListRes: FileItem[] = await Promise.all(
+      formData.attachmentListRes.map((item) => formatAttachmentList(item)),
+    );
+    const editParam = {
+      id: Number(id),
+      disasterType: formData.disasterType,
+      disasterLevel: formData.disasterLevel,
+      title: formData.title,
+      content: formData.content,
+      attachmentListRes,
+      isPush: formData.isPush,
+      userGroupList: formData.isPush ? formData.userGroupList : [],
+    };
+    await editDefenseNoticeItem(editParam);
+  };
   const submit = async () => {
     if (!dynamicComponentRef.value) return;
     const res = await dynamicComponentRef.value.handleValidate();
     if (res) {
       formLoading.value = true;
       const formData = dynamicComponentRef.value.getFormData();
-      await createDefenseNoticeItemFunc(formData);
-      ElMessage.success('提交成功');
-      formLoading.value = false;
-      router.back();
-    } else {
-      console.log('不提交');
+      let message;
+      try {
+        if (operate === 'create') {
+          await createDefenseNoticeItemFunc(formData);
+          message = '创建成功';
+        } else if (operate === 'edit') {
+          await editDefenseNoticeItemFunc(formData);
+          message = '编辑成功';
+        }
+        ElMessage.success(message);
+        router.back();
+      } finally {
+        formLoading.value = false;
+      }
     }
   };
 </script>

+ 1 - 0
src/views/disaster/disaster-warning/src/components/EditDefenseNoticeItem.vue

@@ -61,6 +61,7 @@
     for (const key in res) {
       ruleFormData[key] = res[key as keyof typeof res];
       ruleFormData.createUser = res.realname;
+      ruleFormData.userGroupList = JSON.parse(res.userGroupList as unknown as string);
     }
     cloneRuleFormData();
   };

+ 1 - 0
src/views/disaster/disaster-warning/src/components/ViewDefenseNoticeItem.vue

@@ -121,6 +121,7 @@
     width: 100%;
     height: 1px;
     background-color: #979797;
+    opacity: 0.26;
     margin-top: 18cpx;
     margin-bottom: 18cpx;
   }

+ 1 - 1
src/views/disaster/disaster-warning/src/config/search.ts

@@ -47,7 +47,7 @@ export const DEFENSE_NOTICE_SEARCH_CONFIG: SearchConfig[] = [
   BASIC_SEARCH_CONFIG.DISASTER_LEVEL,
   {
     label: '生效状态',
-    prop: 'activeStatus',
+    prop: 'effectState',
     component: 'ElSelect',
     selectOptions: ACTIVE_STATUS_OPTIONS,
     componentProps: {

+ 6 - 0
src/views/disaster/style/disaster.scss

@@ -54,6 +54,7 @@
 
 .active-status--div {
   @include flex-center;
+  justify-content: space-between;
   width: 100%;
   gap: 8cpx;
   .dot {
@@ -61,4 +62,9 @@
     height: 6cpx;
     border-radius: 50%;
   }
+  span {
+    flex: 1;
+    height: 100%;
+    text-align: center;
+  }
 }

+ 0 - 5
src/views/disaster/types/index.ts

@@ -1,8 +1,3 @@
-export interface GroupOptionType {
-  id: number;
-  name: string;
-}
-
 export interface TreeNodeData {
   id: number;
   name: string;