Просмотр исходного кода

fix: 修复子项目修改异常

hotchicken1996 1 год назад
Родитель
Сommit
93a7b71fab

+ 0 - 1
client/src/components/TreeSelectV2/index.vue

@@ -76,7 +76,6 @@ const nodeClickHandle = (data) => {
 }
 watchEffect(() => {
   const item = treeRef.value?.getNode($props.modelValue)
-  console.log(item)
   if (item) {
     xzqdmName.value = item['label']
   }

+ 8 - 1
client/src/service/project.ts

@@ -20,7 +20,6 @@ export const getProjectById = async (projectId: ProjectId): Promise<ProjectRecor
  * @param projectId
  */
 export const getProjectWithChildrenById = async (projectId: ProjectId): Promise<ProjectRecord> => {
-  console.log('get project: ', projectId)
   return await request.get(
     {
       url: '/project-with-children',
@@ -30,6 +29,14 @@ export const getProjectWithChildrenById = async (projectId: ProjectId): Promise<
   )
 }
 
+/**
+ * 修改项目信息
+ * @param data
+ */
+export const saveProject = async (data: ProjectRecord) => {
+  return await request.put({ url: '/project', data }, '/business')
+}
+
 /**
  * 添加子项目
  * @param data

+ 22 - 17
client/src/views/OaSystem/projectCenter/projectDetail/components/xmxx/index.vue

@@ -195,14 +195,13 @@
 </template>
 <script setup lang="ts">
 import { ElMessage } from 'element-plus'
-import request from '@/config/axios'
 import { industryList } from '@/utils/business'
 import UserOrgTree from '@/views/OaSystem/components/UserOrgTree/index.vue'
 import DistrictTree from '@/views/OaSystem/components/DistrictTree/index.vue'
 import ProjectTypeTree from '@/views/OaSystem/components/ProjectTypeTree/index.vue'
 import AddSubProject from '@/views/OaSystem/projectCenter/projectDetail/components/xmxx/AddSubProject.vue'
-import { useQuery } from '@tanstack/vue-query'
-import { getProjectWithChildrenById } from '@/service/project'
+import { useMutation, useQuery } from '@tanstack/vue-query'
+import { getProjectWithChildrenById, saveProject } from '@/service/project'
 import ProjectMember from '@/views/OaSystem/projectCenter/projectDetail/components/xmxx/ProjectMember.vue'
 import ProjectMileStone from '@/views/OaSystem/projectCenter/projectDetail/components/xmxx/ProjectMileStone.vue'
 
@@ -211,7 +210,7 @@ const props = defineProps<{ editor: boolean }>()
 const { editor } = toRefs(props)
 const { query } = useRoute()
 const { id: _mainProjectId = '', subId = '' } = query
-const currentProjectId = ref<string>(_mainProjectId)
+const currentProjectId = ref<string>()
 const isMaster = computed(() => _mainProjectId === currentProjectId.value)
 /***
  * 查询项目和子项目详情数据
@@ -227,19 +226,26 @@ const { data: originData, refetch } = useQuery(
   async () => await getProjectWithChildrenById(_mainProjectId as string),
   {
     onSuccess: (tData) => {
-      switchProjectInfo(subId !== '' ? subId : _mainProjectId, tData)
+      const targetId =
+        (currentProjectId.value ?? '') === ''
+          ? subId !== ''
+            ? subId
+            : _mainProjectId
+          : currentProjectId.value
+      switchProjectInfo(targetId, tData)
     },
     enabled: (_mainProjectId ?? '') !== ''
   }
 )
 
 // 选择当前查看项目
-const switchProjectInfo = (switchId: string, data = originData.value) => {
+const switchProjectInfo = (switchId: string, data = originData) => {
+  const { children, ...other } = unref(data)
   currentProjectId.value = switchId
   if (switchId === _mainProjectId) {
-    projectDetail.value = data
+    projectDetail.value = { ...other }
   } else {
-    projectDetail.value = data?.children?.find(({ id }) => id === switchId)
+    projectDetail.value = { ...(children?.find(({ id }) => id === switchId) ?? {}) }
   }
 }
 
@@ -264,17 +270,16 @@ const onHandleSuccess = () => {
  * 项目编辑保存成操作
  * **/
 const saveProjectHandle = (): void => {
-  const urlApi = `/project`
-  request.put({ url: urlApi, data: projectDetail.value }, '/business').then((resultData) => {
-    if (resultData) {
-      ElMessage({
-        message: '保存项目成功',
-        type: 'success'
-      })
-    }
-  })
+  save(projectDetail.value)
 }
 
+const { mutate: save } = useMutation(saveProject, {
+  onSuccess: () => {
+    refetch()
+    ElMessage({ message: '保存项目成功', type: 'success' })
+  }
+})
+
 defineExpose({
   saveProjectHandle,
   handleAddSubProject