diff --git a/src/utils/format.js b/src/utils/format.js new file mode 100644 index 0000000..24bb006 --- /dev/null +++ b/src/utils/format.js @@ -0,0 +1,23 @@ +/** + * 将 Date 格式化为 YYYY-MM-DD HH:mm:ss + * @param {Date} [date=new Date()] - 待格式化的日期对象 + * @returns {string} 格式化后的时间串,例如 2026-10-30 13:28:54 + */ +export function formatDateTime(date = new Date()) { + const pad = (value) => String(value).padStart(2, '0') + const year = date.getFullYear() + const month = pad(date.getMonth() + 1) + const day = pad(date.getDate()) + const hours = pad(date.getHours()) + const minutes = pad(date.getMinutes()) + const seconds = pad(date.getSeconds()) + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}` +} + +/** + * 获取当前时间串 + * @returns {string} 当前时间,格式 YYYY-MM-DD HH:mm:ss + */ +export function getNowDateTime() { + return formatDateTime(new Date()) +} diff --git a/src/views/abnormal/index.vue b/src/views/abnormal/index.vue index 0dd3f01..ea74794 100644 --- a/src/views/abnormal/index.vue +++ b/src/views/abnormal/index.vue @@ -6,6 +6,7 @@ import { ref, onMounted } from 'vue' import { showToast, showLoadingToast, closeToast } from 'vant' import { pushInfoApi, confirmInfoApi } from '@/api/abnormal' +import { getNowDateTime } from '@/utils/format' // 数据加载中状态 const loading = ref(false); @@ -62,7 +63,7 @@ const onFeedback = async (type) => { messageInfo.value.feedback = true, messageInfo.value.feedbackType = type, messageInfo.value.feedbackBy = '张三', - messageInfo.value.feedbackTime = '2026-10-30 13:28:54', + messageInfo.value.feedbackTime = getNowDateTime()?.slice(0, 16), closeToast() showToast(`${type === 1 ? '真实异常' : '信息误报'}已确认,已通知相关人员`) }, 1000)