瀏覽代碼

fix: dateFromNow时间格式化函数逻辑修复&eslint警告修复

cuiyalong 4 年之前
父節點
當前提交
ea6f16b77d
共有 2 個文件被更改,包括 3 次插入3 次删除
  1. 1 1
      src/components/report-data/SelectMonth.vue
  2. 2 2
      src/utils/globalFunctions.js

+ 1 - 1
src/components/report-data/SelectMonth.vue

@@ -101,7 +101,7 @@ export default {
       // })
       // })
       // 处理年份、添加12月
       // 处理年份、添加12月
       const nowyear = dateFormatter(new Date(), 'yyyy')
       const nowyear = dateFormatter(new Date(), 'yyyy')
-      let year = date.slice(0, 4)
+      const year = date.slice(0, 4)
       // 如果第一个月报时间是现在的时间,不显示更多按钮
       // 如果第一个月报时间是现在的时间,不显示更多按钮
       if (nowyear === year) {
       if (nowyear === year) {
         this.isMany = false
         this.isMany = false

+ 2 - 2
src/utils/globalFunctions.js

@@ -232,7 +232,7 @@ export function dateFromNow (originTime, useOld = false) {
   // 10天前
   // 10天前
   const tenDaysAgo = diffTimeStampAbsS > days11
   const tenDaysAgo = diffTimeStampAbsS > days11
   // 是否是当天
   // 是否是当天
-  const isCurrentDay = new Date(originTimeStamp).pattern('yyyy.MM.dd') === new Date().pattern('yyyy.MM.dd')
+  const isCurrentDay = dateFormatter(originTimeStamp, 'yyyy.MM.dd') === dateFormatter(nowTimeStamp, 'yyyy.MM.dd')
 
 
   let condition = !isCurrentDay
   let condition = !isCurrentDay
   if (useOld) {
   if (useOld) {
@@ -247,7 +247,7 @@ export function dateFromNow (originTime, useOld = false) {
     const sameYear = originDate.getFullYear() === nowDate.getFullYear()
     const sameYear = originDate.getFullYear() === nowDate.getFullYear()
     // 如果是当年,则不显示年
     // 如果是当年,则不显示年
     const patternString = sameYear ? 'MM-dd' : 'yyyy-MM-dd'
     const patternString = sameYear ? 'MM-dd' : 'yyyy-MM-dd'
-    timeString = originDate.pattern(patternString)
+    timeString = dateFormatter(originDate, patternString)
   } else {
   } else {
     for (let i = 0; i < 7; i++) {
     for (let i = 0; i < 7; i++) {
       const inm = Math.floor(diffTimeStampAbsS / dataMap.number[i])
       const inm = Math.floor(diffTimeStampAbsS / dataMap.number[i])