import { UnitType } from '../../number/IOTTimeSlider/interface' import { getSeconds } from "../../number/IOTTimeSlider/utils"; import { unitProps } from "../IOTMiniCardText/interface" export const getSymbolDisplayTime = (unit: string,timeConver?: unitProps) => { let type = ''; if(!timeConver) return; const { hour, minute, second } = timeConver; if (hour) { type = 'h'; } if (minute) { type += 'min'; } if (second) { type += 's'; } if (type === '') { type = unit } return type } export const isSymbolFormatTime = (initTime: number, unit: string, timeConver?: unitProps) => { if (initTime === undefined) return ''; const initSecond = getSeconds(initTime, unit); const displayTimeType = getSymbolDisplayTime(unit,timeConver); let res = ''; let hour: number = 0; let mins: number = 0; let secs: number = 0; switch (displayTimeType) { case 'h': res = `${Math.round(initSecond / 3600 * 100) / 100}h`; break; case 'min': res = `${Math.round(initSecond / 60 * 100) / 100}min`; break; case 's': res = `${initSecond}s`; break; case 'mins': mins = Math.floor(initSecond / 60); secs = initSecond % 60; res = `${formatNumber(mins)}:${formatNumber(secs)}`; break; case 'hmins': hour = Math.floor(initSecond / 3600); mins = Math.floor(initSecond % 3600 / 60); secs = initSecond % 3600 % 60; res = `${formatNumber(hour)}:${formatNumber(mins)}:${formatNumber(secs)}`; break; case 'hmin': hour = Math.floor(initSecond / 3600); mins = Math.round(initSecond % 3600 / 60 * 100) / 100; res = `${formatNumber(hour)}:${formatNumber(mins)}`; break; default: break; } return res; } //数据转化 function formatNumber(n: any) { n = n.toString(); return n[1] ? n : "0" + n; }