diff --git a/utils/index.js b/utils/index.js index d368ab0..28feac5 100644 --- a/utils/index.js +++ b/utils/index.js @@ -75,6 +75,23 @@ export function formatTime(value) { return `(${period})${hour}:${minute}` } + +/** + * 格式化秒数为 mm:ss 的格式 + * @param {number} seconds 总秒数 + * @returns {string} 格式化后的时间字符串 + */ +export function formatSeconds(seconds) { + if (seconds < 0) return '00:00' // 如果秒数为负,则返回 00:00 + + let minutes = Math.floor(seconds / 60) + let remainingSeconds = seconds % 60 + + minutes = minutes.toString().padStart(2, '0') + remainingSeconds = remainingSeconds.toString().padStart(2, '0') + + return `${minutes}:${remainingSeconds}` +} /** * 过滤价格数值 超过小数点两位得 保留两位 * @param {string} value @@ -257,7 +274,7 @@ function initMqtt() { const topic = `refreshOrderList/${store.state.userInfo.topic_prefix}` mqtt.doSubscribe(topic, (res) => { if (res.topic.indexOf(topic) > -1) { - store.dispatch('fetchOrderList').then(()=>{ + store.dispatch('fetchOrderList').then(() => { console.log('有订单更新') }) //更新订单 }