This commit is contained in:
2025-08-24 10:41:24 +08:00
parent d2e3c70616
commit 01b2c3385d
7 changed files with 24 additions and 34 deletions

1
package-lock.json generated
View File

@@ -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",

View File

@@ -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",

View File

@@ -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')

View File

@@ -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

View File

@@ -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')
}
},

View File

@@ -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) => {

View File

@@ -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) => {