From 658150c1c8e7f7d49cbb378a450914ba5c12bc98 Mon Sep 17 00:00:00 2001 From: kinlon92 Date: Tue, 28 Mar 2023 18:23:58 +0800 Subject: [PATCH] =?UTF-8?q?Vue3=E9=87=8D=E6=9E=84=EF=BC=9A=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E7=BB=9F=E8=AE=A1=E4=BC=98=E5=8C=96=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dateUtils.ts | 79 ---------------------------- src/utils/formatTime.ts | 51 ++++++++++++++++++ src/views/mp/statistics/index.vue | 87 +++++++++++-------------------- 3 files changed, 82 insertions(+), 135 deletions(-) delete mode 100644 src/utils/dateUtils.ts diff --git a/src/utils/dateUtils.ts b/src/utils/dateUtils.ts deleted file mode 100644 index 617a88af..00000000 --- a/src/utils/dateUtils.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 将毫秒,转换成时间字符串。例如说,xx 分钟 - * - * @param ms 毫秒 - * @returns {string} 字符串 - */ -export function getDate(ms) { - const day = Math.floor(ms / (24 * 60 * 60 * 1000)) - const hour = Math.floor(ms / (60 * 60 * 1000) - day * 24) - const minute = Math.floor(ms / (60 * 1000) - day * 24 * 60 - hour * 60) - const second = Math.floor(ms / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60) - if (day > 0) { - return day + '天' + hour + '小时' + minute + '分钟' - } - if (hour > 0) { - return hour + '小时' + minute + '分钟' - } - if (minute > 0) { - return minute + '分钟' - } - if (second > 0) { - return second + '秒' - } else { - return 0 + '秒' - } -} - -export function beginOfDay(date) { - return new Date(date.getFullYear(), date.getMonth(), date.getDate()) -} - -export function endOfDay(date) { - return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999) -} - -export function betweenDay(date1, date2) { - date1 = convertDate(date1) - date2 = convertDate(date2) - // 计算差值 - return Math.floor((date2.getTime() - date1.getTime()) / (24 * 3600 * 1000)) -} - -export function formatDate(date, fmt) { - date = convertDate(date) - const o = { - 'M+': date.getMonth() + 1, //月份 - 'd+': date.getDate(), //日 - 'H+': date.getHours(), //小时 - 'm+': date.getMinutes(), //分 - 's+': date.getSeconds(), //秒 - 'q+': Math.floor((date.getMonth() + 3) / 3), //季度 - S: date.getMilliseconds() //毫秒 - } - if (/(y+)/.test(fmt)) { - // 年份 - fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) - } - for (const k in o) { - if (new RegExp('(' + k + ')').test(fmt)) { - fmt = fmt.replace( - RegExp.$1, - RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length) - ) - } - } - return fmt -} - -export function addTime(date, time) { - date = convertDate(date) - return new Date(date.getTime() + time) -} - -export function convertDate(date) { - if (typeof date === 'string') { - return new Date(date) - } - return date -} diff --git a/src/utils/formatTime.ts b/src/utils/formatTime.ts index 008bc929..d4dea9b5 100644 --- a/src/utils/formatTime.ts +++ b/src/utils/formatTime.ts @@ -196,3 +196,54 @@ export const dateFormatter = (row, column, cellValue) => { } return formatDate(cellValue) } + +/** + * 设置起始日期,时间为00:00:00 + * @param param 传入日期 + * @returns 带时间00:00:00的日期 + */ +export function beginOfDay(param: Date) { + return new Date(param.getFullYear(), param.getMonth(), param.getDate(), 0, 0, 0, 0) +} + +/** + * 设置结束日期,时间为23:59:59 + * @param param 传入日期 + * @returns 带时间23:59:59的日期 + */ +export function endOfDay(param: Date) { + return new Date(param.getFullYear(), param.getMonth(), param.getDate(), 23, 59, 59, 999) +} + +/** + * 计算两个日期间隔天数 + * @param param1 日期1 + * @param param2 日期2 + */ +export function betweenDay(param1: Date, param2: Date) { + param1 = convertDate(param1) + param2 = convertDate(param2) + // 计算差值 + return Math.floor((param2.getTime() - param1.getTime()) / (24 * 3600 * 1000)) +} + +/** + * 日期计算 + * @param param1 日期 + * @param param2 添加的时间 + */ +export function addTime(param1: Date, param2: number) { + param1 = convertDate(param1) + return new Date(param1.getTime() + param2) +} + +/** + * 日期转换 + * @param param 日期 + */ +export function convertDate(param: Date | string) { + if (typeof param === 'string') { + return new Date(param) + } + return param +} diff --git a/src/views/mp/statistics/index.vue b/src/views/mp/statistics/index.vue index d1dcb53c..c625f9dc 100644 --- a/src/views/mp/statistics/index.vue +++ b/src/views/mp/statistics/index.vue @@ -6,9 +6,9 @@ @@ -37,9 +37,7 @@ 用户增减数据 -
-
-
+ @@ -49,9 +47,7 @@ 累计用户数据 -
-
-
+
@@ -61,9 +57,7 @@ 消息概况数据 -
-
-
+
@@ -73,9 +67,7 @@ 接口分析数据 -
-
-
+
@@ -83,38 +75,28 @@