Browse Source

回滚date.js

lighter 2 years ago
parent
commit
f457f06aef

+ 1 - 1
src/components/fullScreen/thirdPage/TopRightCmp.vue

@@ -10,7 +10,7 @@
 
 <script setup name='TopRightCmp' lang="ts">
 import { reactive, ref, onUpdated, Ref, nextTick } from 'vue'
-import { getDayAgo } from '../../../utils/date.ts'
+import { getDayAgo } from '../../../utils/date.js'
 
 const props = defineProps({
     topRightData: {

+ 12 - 18
src/utils/date.ts → src/utils/date.js

@@ -1,14 +1,12 @@
-//@ts-ignore
+import {stringIsBlank} from '@/utils/blank-utils'
 import moment from 'moment'
-//@ts-ignore
 import {getServerDateApi} from "@/api/public-api";
 import XEUtils from 'xe-utils'
 
-export enum DATEFORMAT {
-    DATE = 'YYYY-MM-DD',
-    DATE_TIME = 'YYYY-MM-DD HH:mm:ss',
-    TIME = 'HH:mm:ss',
-    DATE_HOUR_CHINE = 'YYYY年MM月DD日HH点'
+export const DATEFORMAT = {
+    DATE: 'YYYY-MM-DD',
+    DATE_TIME: 'YYYY-MM-DD HH:mm:ss',
+    TIME: 'HH:mm:ss',
 }
 
 export function getDate() {
@@ -123,11 +121,11 @@ export function getDateRangeFormatDate(data) {
     //用户手动输入了日期 并且没有按下大键盘上面的回车
     if (data === null || data.length === 0) return {startTime, endTime}
     if (typeof data[0].$d !== 'undefined') {
-        startTime = getFormatDatetime(data[0].$d, DATEFORMAT.DATE) + ' 00:00:00'
-        endTime = getFormatDatetime(data[1].$d, DATEFORMAT.DATE) + ' 23:59:59'
+        startTime = getFormatDatetime(data[0].$d, 'YYYY-MM-DD') + ' 00:00:00'
+        endTime = getFormatDatetime(data[1].$d, 'YYYY-MM-DD') + ' 23:59:59'
     } else {
-        startTime = getFormatDatetime(data[0], DATEFORMAT.DATE) + ' 00:00:00'
-        endTime = getFormatDatetime(data[1], DATEFORMAT.DATE) + ' 23:59:59'
+        startTime = getFormatDatetime(data[0], 'YYYY-MM-DD') + ' 00:00:00'
+        endTime = getFormatDatetime(data[1], 'YYYY-MM-DD') + ' 23:59:59'
     }
     return {startTime, endTime}
 }
@@ -170,8 +168,8 @@ export function formatMonth(date) {
  * @param pattern 格式
  * @returns {string} 返回格式好的日期
  */
-export function getFormatDatetime(date: any, pattern: DATEFORMAT | string = DATEFORMAT.DATE_TIME): string {
-    if (XEUtils.isEmpty(date)) {
+export function getFormatDatetime(date, pattern = 'YYYY-MM-DD HH:mm:ss') {
+    if (stringIsBlank(date)) {
         return ''
     }
     return moment(date).format(pattern)
@@ -251,7 +249,7 @@ function doHandleMonth(month) {
     return m;
 }
 
-export const currentAndAFewDaysAgo = async (day = 7, format: string = 'YYYY-MM-DD') => {
+export const currentAndAFewDaysAgo = async (day = 7, format = 'YYYY-MM-DD') => {
     let date = await getServerDateApi();
     let now = moment(new Date(date)).format(format)
     let start = moment(new Date(date)).subtract(day, 'day')
@@ -284,10 +282,6 @@ export const getDateRange = (val) => {
     if (XEUtils.isEmpty(val)) {
         return {start: '', end: ''}
     }
-    if (!XEUtils.isArray(val)) {
-        return {start: '', end: ''}
-    }
-
     if (val.length === 2) {
         let start = moment(val[0]).format(DATEFORMAT.DATE)
         let end = moment(val[1]).format(DATEFORMAT.DATE)

+ 1 - 1
src/views/operate-monitoring/DataBigScreen.vue

@@ -18,7 +18,7 @@ import { ref, reactive } from 'vue'
 import FullScreenFirstPage from '../../components/fullScreen/fullPage/FullScreenFirstPage.vue'
 import FullScreenSecondPage from '../../components/fullScreen/fullPage/FullScreenSecondPage.vue'
 import FullScreenThirdPage from '../../components/fullScreen/fullPage/FullScreenThirdPage.vue'
-import { getDate } from '../../utils/date.ts'
+import { getDate } from '../../utils/date.js'
 
 let dateS = getDate()
 const params = reactive({