Browse Source

修复mounted获取月份

lighter 3 years ago
parent
commit
56c3b9b5bf
2 changed files with 15 additions and 2 deletions
  1. 2 2
      src/components/inpatient/CaseFrontSheetQuality.vue
  2. 13 0
      src/utils/date.js

+ 2 - 2
src/components/inpatient/CaseFrontSheetQuality.vue

@@ -46,7 +46,7 @@
 
 <script>
 import { ref, onMounted } from 'vue'
-import { getOneMonthOffset, formatMonth, formatYear } from '@/utils/date'
+import { getRawMonthOffset, formatMonth, formatYear } from '@/utils/date'
 import { analyzeQualityControl } from '@/api/case-front-sheet/index'
 import { Export } from '@/utils/ExportExcel'
 import { ElMessage } from 'element-plus'
@@ -103,7 +103,7 @@ export default {
     }
 
     onMounted(() => {
-      const offset = getOneMonthOffset()
+      const offset = getRawMonthOffset()
       monthrange.value[0] = offset.start
       monthrange.value[1] = offset.end
       year.value = new Date()

+ 13 - 0
src/utils/date.js

@@ -94,6 +94,19 @@ export function getOneMonthOffset() {
   return { start, end }
 }
 
+export function getRawMonthOffset() {
+  const myDate = new Date()
+  let year = myDate.getFullYear()
+  let month = myDate.getMonth()
+  let end = year + '-' + ('0' + (month + 1)).slice(-2)
+  if (month === 0) {
+    year -= 1
+    month = 12
+  }
+  let start = year + '-' + ('0' + month).slice(-2)
+  return { start, end }
+}
+
 export function getDateRangeFormatDate(data) {
   let startTime = ''
   let endTime = ''