From 48501e91956f6f5c268ccd63be14eb6d77491ba2 Mon Sep 17 00:00:00 2001
From: zhuhao <979263092@qq.com>
Date: Mon, 15 Jul 2024 18:21:57 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=96=87=E4=BB=B6=E4=B8=8A?=
=?UTF-8?q?=E4=BC=A0=E6=A0=B8=E5=BF=83=E5=BC=80=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/renderer/src/api/file/index.js | 6 +
src/renderer/src/utils/date.js | 78 ++++++++++++
src/renderer/src/views/prepare/index.vue | 154 +++++++++++++++--------
3 files changed, 185 insertions(+), 53 deletions(-)
create mode 100644 src/renderer/src/utils/date.js
diff --git a/src/renderer/src/api/file/index.js b/src/renderer/src/api/file/index.js
index d7e590b..8b03c3b 100644
--- a/src/renderer/src/api/file/index.js
+++ b/src/renderer/src/api/file/index.js
@@ -8,3 +8,9 @@ export const getSmarttalkPage = (params) => {
params
})
}
+export function deleteSmarttalk(id) {
+ return request({
+ url: '/smarttalk/file/' + id,
+ method: 'delete'
+ })
+}
diff --git a/src/renderer/src/utils/date.js b/src/renderer/src/utils/date.js
new file mode 100644
index 0000000..4a1025d
--- /dev/null
+++ b/src/renderer/src/utils/date.js
@@ -0,0 +1,78 @@
+// 判断是不是昨天
+const isYestday = (date) => {
+ var yesterday = new Date(new Date() - 1000 * 60 * 60 * 24)
+ return (
+ yesterday.getYear() === date.getYear() &&
+ yesterday.getMonth() === date.getMonth() &&
+ yesterday.getDate() === date.getDate()
+ )
+}
+
+// 判断是不是今年
+const isYear = (date) => {
+ return date.getYear() === new Date().getYear()
+}
+
+//将时间转为 yy/mm/dd hh:mm:ss
+const formatDateTime = (date) => {
+ if (!date) {
+ return ''
+ }
+ var dateObject = new Date(date)
+ var y = dateObject.getFullYear()
+ var m = dateObject.getMonth() + 1
+ m = m < 10 ? '0' + m : m
+ var d = dateObject.getDate()
+ d = d < 10 ? '0' + d : d
+ var h = dateObject.getHours()
+ h = h < 10 ? '0' + h : h
+ var minute = dateObject.getMinutes()
+ minute = minute < 10 ? '0' + minute : minute
+ var second = dateObject.getSeconds()
+ second = second < 10 ? '0' + second : second
+ return y + '/' + m + '/' + d + ' ' + h + ':' + minute + ':' + second
+}
+
+/**
+ * 将时间戳转换为文本描述。
+ *
+ * 此函数旨在将时间戳转换为更易读的文本格式,以便用户可以更直观地理解时间信息。
+ * 通过传入的时间,函数将生成对应的时间文本,如"刚刚"、"5分钟前"、"昨天"等。
+ * 如果设置了simple参数为true,则会返回更简单的23/06/25,只显示年月日,如果是今年只返回月和日。
+ *
+ * @param {string} timeStamp - 需要转换的时间。
+ * @param {boolean} simple - 是否使用简单的格式,默认为false,如:23/06/25、06/25。
+ * @returns {string} - 转换后的时间文本。
+ */
+export const toTimeText = (timeStamp, simple) => {
+ if (!timeStamp) {
+ return ''
+ }
+ var dateTime = new Date(timeStamp)
+ var currentTime = Date.parse(new Date()) //当前时间
+ var timeDiff = currentTime - dateTime //与当前时间误差
+ var timeText = ''
+ if (timeDiff <= 60000) {
+ //一分钟内
+ timeText = '刚刚'
+ } else if (timeDiff > 60000 && timeDiff < 3600000) {
+ //1小时内
+ timeText = Math.floor(timeDiff / 60000) + '分钟前'
+ } else if (timeDiff >= 3600000 && timeDiff < 86400000 && !isYestday(dateTime)) {
+ //今日
+ timeText = formatDateTime(dateTime).substr(11, 5)
+ } else if (isYestday(dateTime)) {
+ //昨天
+ timeText = '昨天' + formatDateTime(dateTime).substr(11, 5)
+ } else if (isYear(dateTime)) {
+ //今年
+ timeText = formatDateTime(dateTime).substr(5, simple ? 5 : 14)
+ } else {
+ //不属于今年
+ timeText = formatDateTime(dateTime)
+ if (simple) {
+ timeText = timeText.substr(2, 8)
+ }
+ }
+ return timeText
+}
diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue
index 3d9de95..4a60228 100644
--- a/src/renderer/src/views/prepare/index.vue
+++ b/src/renderer/src/views/prepare/index.vue
@@ -8,30 +8,24 @@