Kaynağa Gözat

fix: 修改web端工作量分配出现的计数错误问题

qiny 1 yıl önce
ebeveyn
işleme
e8289f8ed6

+ 32 - 24
client/src/utils/PubsubService.ts

@@ -3,51 +3,59 @@
  * 一个简单的发布者、订阅者模式,提供了发布、订阅、删除的方法
  * from chinyan
  */
-class PubsubService {
-  private topics: Record<string, ((params?: any) => void)[]> = {}
+const PubsubService = (function () {
+  const topics: Record<string, ((params?: any) => void)[]> = {}
 
   // 发布事件
-  publish(topic: string, data: any) {
-    if (!this.topics[topic]) return
-    this.topics[topic].forEach((fn) => fn(data))
+  function publish(topic: string, data: any) {
+    if (!topics[topic]) return
+    topics[topic].forEach((fn) => fn(data))
   }
 
   // 订阅事件
-  subscribe(topic: string, callback: (params?: any) => void) {
-    if (!this.topics[topic]) {
-      this.topics[topic] = []
+  function subscribe(topic: string, callback: (params?: any) => void) {
+    if (!topics[topic]) {
+      topics[topic] = []
     }
 
-    if (!this.topics[topic].includes(callback)) {
-      this.topics[topic].push(callback)
+    if (topics[topic].includes(callback)) {
+      return // 已经订阅过,不重复添加
     }
 
+    topics[topic].push(callback)
     // 返回取消订阅的方法
-    return () => {
-      const index = this.topics[topic].indexOf(callback)
+    return function unsubscribe() {
+      const index = topics[topic].indexOf(callback)
       if (index !== -1) {
-        this.topics[topic].splice(index, 1)
+        topics[topic].splice(index, 1)
       }
     }
   }
 
   // 清空所有订阅者
-  clearAllSub() {
-    this.topics = {}
+  function clearAllSub() {
+    for (const key in topics) {
+      topics[key] = []
+    }
   }
 
   // 清空某个主题的订阅者
-  clearSubsByTopic(topic: string) {
-    if (this.topics[topic]) {
-      this.topics[topic] = []
-    }
+  function clearSubsByTopic(topic: string) {
+    topics[topic] = []
   }
 
   // 判断是否有某个主题的订阅者
-  hasSubsByTopic(topic: string) {
-    return this.topics[topic] && this.topics[topic].length > 0
+  function hasSubsByTopic(topic: string) {
+    return topics[topic] && topics[topic].length > 0
+  }
+
+  return {
+    publish,
+    subscribe,
+    clearSubsByTopic,
+    clearAllSub,
+    hasSubsByTopic
   }
-}
+})()
 
-// 实例化并导出单例
-export default new PubsubService()
+export default PubsubService

+ 40 - 13
client/src/views/OaSystem/personnelManagement/components/AmountOfWork.vue

@@ -104,6 +104,17 @@ const popperRef = ref<any>(null)
 const dataList = ref<any[]>([])
 
 const setInitData = () => {
+  // 如果不是切换天数,则不重置
+  if (defaultTotalTime.value > 0) return
+  if (initialData?.value?.length == 0) {
+    dataList.value = dataList.value.map((item) => {
+      return {
+        ...item,
+        count: 0
+      }
+    })
+    return
+  }
   if (initialData.value && initialData.value.length > 0) {
     const initialObj = {}
     initialData.value.forEach((item) => {
@@ -130,11 +141,19 @@ const setInitData = () => {
 }
 
 watch(
-  () => [nowDate.value, initialData.value],
+  () => initialData.value,
   () => {
     setInitData()
   }
 )
+watch(
+  () => nowDate.value,
+  () => {
+    // 切换日期,重置数据
+    defaultTotalTime.value = 0
+    setInitData()
+  }
+)
 
 onMounted(async () => {
   await getAllProject()
@@ -187,21 +206,20 @@ const panelSubmit = (index: number) => {
   dataList.value[index].visible = false
   getTotalTime()
   tempCount.value = 0
-  // 提交后进行一下数据排序
-  dataList.value.sort((x, y) => y['count'] - x['count'])
-
-  // 提交工时后将已填数据传出去
-  const countList = dataList.value
-    .filter((item) => item.count > 0)
-    .map((item) => ({
-      workTime: item.count,
-      projectId: item.id
-    }))
-  onChange(countList)
-
   // 提交工时后清空搜索框
   if (tempSearchList.value.length > 0) {
     searchInputRef.value?.clear()
+  } else {
+    // 提交后进行一下数据排序
+    dataList.value.sort((x, y) => y['count'] - x['count'])
+    // 提交工时后将已填数据传出去
+    const countList = dataList.value
+      .filter((item) => item.count > 0)
+      .map((item) => ({
+        workTime: item.count,
+        projectId: item.id
+      }))
+    onChange(countList)
   }
 }
 
@@ -255,6 +273,15 @@ const clearSearch = () => {
   tempSearchList.value.sort((x, y) => y['count'] - x['count'])
   // 还原全部数据
   dataList.value = tempSearchList.value
+  // 提交工时后将已填数据传出去
+  const countList = dataList.value
+    .filter((item) => item.count > 0)
+    .map((item) => ({
+      workTime: item.count,
+      projectId: item.id
+    }))
+  onChange(countList)
+
   tempSearchList.value = []
   getTotalTime()
 }

+ 13 - 9
client/src/views/OaSystem/personnelManagement/dailyCenter/editorDetail.vue

@@ -133,14 +133,19 @@ const userInfo = getUserInfo()
 // 提交(暂存)
 const message = useMessage()
 const sendReportHandle = async (isTemp) => {
-  // if (formData.value.receiveUserIds.length === 0) {
-  //   message.warning('请选择接收人')
-  //   return
-  // }
-  // if (formData.value.weeklyWorkloadList.length === 0) {
-  //   message.warning('请对工作量进行分配')
-  //   return
-  // }
+  if (formData.value.receiveUserIds.length === 0) {
+    message.warning('请选择接收人')
+    return
+  }
+  if (formData.value.reportContent?.length === 0) {
+    message.warning('请填报工作内容')
+    return
+  }
+  if (formData.value.weeklyWorkloadList.length === 0) {
+    message.warning('请对工作量进行分配')
+    return
+  }
+
   const params: any = {
     userId: userInfo.id ?? '',
     deptId: userInfo.deptId ?? '',
@@ -168,7 +173,6 @@ const sendReportHandle = async (isTemp) => {
     url: '/adm/report/add-report-info',
     data: params
   })
-  // console.log('提交(暂存)~~~~~~~result~~~~~~', result)
   if (result?.msg && !isTemp) {
     message.success('日志发送成功')
     // 发布提交(暂存)事件

+ 5 - 2
client/src/views/OaSystem/personnelManagement/weeklyCenter/editorDetail.vue

@@ -152,7 +152,10 @@ const sendReportHandle = async (isTemp) => {
     message.warning('请选择接收人')
     return
   }
-
+  if (formData.value.reportContent?.length === 0) {
+    message.warning('请填报工作内容')
+    return
+  }
   if (formData.value.weeklyWorkloadList.length === 0) {
     message.warning('请对工作量进行分配')
     return
@@ -174,6 +177,7 @@ const sendReportHandle = async (isTemp) => {
     // reportDay: writeData.value.dayOfWeek // 天
   }
   // console.log('提交(暂存)~~~~~~~~~~~~~~~~~~~', params, weekDate.value)
+  // return
   // 如果是更新的话要传一下报告id
   if (isUpDate.value) {
     const reportId = writeData.value?.isLog?.id ?? ''
@@ -183,7 +187,6 @@ const sendReportHandle = async (isTemp) => {
     url: '/adm/report/add-report-info',
     data: params
   })
-  // console.log('提交(暂存)~~~~~~~result~~~~~~', result)
   if (result?.msg && !isTemp) {
     message.success('周报发送成功')
     // 发布提交(暂存)事件

+ 2 - 1
client_h5/src/pages/myLogs/components/LogDetail.vue

@@ -149,7 +149,8 @@ const initData = async () => {
       "YYYY/MM/DD"
     )} ~ ${moment(result.reportEndDate).format("YYYY/MM/DD")}`;
   } else {
-    today.value = result.reportStartDate ?? today.value;
+    today.value =
+      moment(result.reportEndDate).format("YYYY-MM-DD") ?? today.value;
   }
 };