From 01b2c3385df6d4945b428817c54072abe5566009 Mon Sep 17 00:00:00 2001 From: sunzhuangzhuang <961120009@qq.com> Date: Sun, 24 Aug 2025 10:41:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 1 + package.json | 1 + src/main.js | 4 ++++ src/views/AgentDashboard.vue | 13 +++++++------ src/views/Matching.vue | 21 +++++++-------------- src/views/MyPointsHistory.vue | 9 ++------- src/views/PointsHistory.vue | 9 ++------- 7 files changed, 24 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index 78ad576..b4d3a8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@element-plus/icons-vue": "^2.3.1", "axios": "^1.6.2", + "dayjs": "^1.11.13", "echarts": "^5.6.0", "element-plus": "^2.4.4", "nprogress": "^0.2.0", diff --git a/package.json b/package.json index 4e773bf..978c8e8 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@element-plus/icons-vue": "^2.3.1", "axios": "^1.6.2", + "dayjs": "^1.11.13", "echarts": "^5.6.0", "element-plus": "^2.4.4", "nprogress": "^0.2.0", diff --git a/src/main.js b/src/main.js index 5a20fbe..3d82254 100644 --- a/src/main.js +++ b/src/main.js @@ -6,6 +6,7 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue' import zhCn from 'element-plus/dist/locale/zh-cn.mjs' import NProgress from 'nprogress' import 'nprogress/nprogress.css' +import dayjs from 'dayjs' import App from './App.vue' import router from './router' @@ -29,6 +30,9 @@ app.use(ElementPlus, { locale: zhCn, }) +// 全局注册dayjs +app.config.globalProperties.$dayjs = dayjs + // 应用初始化后检查用户状态 app.mount('#app') diff --git a/src/views/AgentDashboard.vue b/src/views/AgentDashboard.vue index 37c8044..dbc02e9 100644 --- a/src/views/AgentDashboard.vue +++ b/src/views/AgentDashboard.vue @@ -467,6 +467,7 @@ import { Warning, Check } from '@element-plus/icons-vue' +import dayjs from 'dayjs' import { use } from 'echarts/core' import { CanvasRenderer } from 'echarts/renderers' import { LineChart, PieChart } from 'echarts/charts' @@ -827,17 +828,17 @@ const getTransferTypeText = (type) => { const formatDateTime = (date) => { if (!date) return '' - // 尝试转换为日期对象 - const dateObj = new Date(date) + // 使用dayjs进行格式化 + const dayjsDate = dayjs(date) // 检查是否为有效日期 - if (isNaN(dateObj.getTime())) { + if (!dayjsDate.isValid()) { // 如果不是有效日期,返回原文本 return date } // 如果是有效日期,进行格式化 - return dateObj.toLocaleString('zh-CN') + return dayjsDate.format('YYYY-MM-DD HH:mm:ss') } /** @@ -982,8 +983,8 @@ const updateChartOptions = () => { xAxis: { type: 'category', data: chartData.value.commissionTrend.map(item => { - const date = new Date(item.date) - return `${date.getMonth() + 1}/${date.getDate()}` + const date = dayjs(item.date) + return date.format('M/D') }), axisLabel: { fontSize: 10 diff --git a/src/views/Matching.vue b/src/views/Matching.vue index 18b0f0b..a9db3e9 100644 --- a/src/views/Matching.vue +++ b/src/views/Matching.vue @@ -644,7 +644,7 @@ export default { }, formatDate(dateString) { - return new Date(dateString).toLocaleString('zh-CN') + return this.$dayjs(dateString).format('YYYY-MM-DD HH:mm:ss') }, /** @@ -654,24 +654,17 @@ export default { */ formatDeadline(dateString) { if (!dateString) return '' - const date = new Date(dateString) - const now = new Date() - const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()) - const targetDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()) + const date = this.$dayjs(dateString) + const now = this.$dayjs() - const timeStr = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }) + const timeStr = date.format('HH:mm') - if (targetDate.getTime() === today.getTime()) { + if (date.isSame(now, 'day')) { return `今天${timeStr}` - } else if (targetDate.getTime() === today.getTime() + 24 * 60 * 60 * 1000) { + } else if (date.isSame(now.add(1, 'day'), 'day')) { return `明天${timeStr}` } else { - return date.toLocaleString('zh-CN', { - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - }) + return date.format('MM-DD HH:mm') } }, diff --git a/src/views/MyPointsHistory.vue b/src/views/MyPointsHistory.vue index ff3203e..1ae714d 100644 --- a/src/views/MyPointsHistory.vue +++ b/src/views/MyPointsHistory.vue @@ -170,6 +170,7 @@ import { ref, computed, onMounted } from 'vue' import { useRouter } from 'vue-router' import { useUserStore } from '@/stores/user' import { ElMessage } from 'element-plus' +import dayjs from 'dayjs' import { ArrowLeft, ShoppingBag, @@ -272,13 +273,7 @@ const getPointsText = (type, points) => { } const formatDateTime = (date) => { - return new Date(date).toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - }) + return dayjs(date).format('YYYY-MM-DD HH:mm:ss') } const viewOrder = (orderId) => { diff --git a/src/views/PointsHistory.vue b/src/views/PointsHistory.vue index 5d0cd04..3ebbf16 100644 --- a/src/views/PointsHistory.vue +++ b/src/views/PointsHistory.vue @@ -180,6 +180,7 @@ import { ref, reactive, computed, onMounted } from 'vue' import { useRouter } from 'vue-router' import { useUserStore } from '@/stores/user' import { ElMessage } from 'element-plus' +import dayjs from 'dayjs' import { ArrowLeft, ShoppingBag, @@ -303,13 +304,7 @@ const getPointsText = (type, points) => { } const formatDateTime = (date) => { - return new Date(date).toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit' - }) + return dayjs(date).format('YYYY-MM-DD HH:mm:ss') } const viewOrder = (orderId) => {