pref(common): 优化时分秒格式化函数的输出

master
钟良源 2 weeks ago
parent 1621cb920b
commit 5139400957

@ -20,13 +20,14 @@ export const getObjType = (obj) => {
'[object RegExp]': 'regExp', '[object RegExp]': 'regExp',
'[object Undefined]': 'undefined', '[object Undefined]': 'undefined',
'[object Null]': 'null', '[object Null]': 'null',
'[object Object]': 'object', '[object Object]': 'object'
}; };
if (obj instanceof Element) { if (obj instanceof Element) {
return 'element'; return 'element';
} }
return map[toString.call(obj)]; return map[toString.call(obj)];
}; };
// 新窗口打开处理函数 // 新窗口打开处理函数
export function openWindow(url: string, opts?: OpenWindowOptions) { export function openWindow(url: string, opts?: OpenWindowOptions) {
const { target = '_blank', ...others } = opts || {}; const { target = '_blank', ...others } = opts || {};
@ -210,12 +211,12 @@ export function formatSeconds(value: string) {
if (secondTime > 0) { if (secondTime > 0) {
result = `${parseInt(`${secondTime}`, 10)}`; result = `${parseInt(`${secondTime}`, 10)}`;
} }
if (minuteTime > 0) { // if (minuteTime > 0) {
result = `${parseInt(`${minuteTime}`, 10)}${result}`; // result = `${parseInt(`${minuteTime}`, 10)}分${result}`;
} // }
if (hourTime > 0) { // if (hourTime > 0) {
result = `${parseInt(`${hourTime}`, 10)}小时${result}`; // result = `${parseInt(`${hourTime}`, 10)}小时${result}`;
} // }
return result; return result;
} }
@ -258,9 +259,11 @@ export const deepClone = (data) => {
let obj; let obj;
if (type === 'array') { if (type === 'array') {
obj = []; obj = [];
} else if (type === 'object') { }
else if (type === 'object') {
obj = {}; obj = {};
} else { }
else {
//不再具有下一层次 //不再具有下一层次
return data; return data;
} }
@ -268,7 +271,8 @@ export const deepClone = (data) => {
for (let i = 0, len = data.length; i < len; i++) { for (let i = 0, len = data.length; i < len; i++) {
obj.push(deepClone(data[i])); obj.push(deepClone(data[i]));
} }
} else if (type === 'object') { }
else if (type === 'object') {
for (const key in data) { for (const key in data) {
obj[key] = deepClone(data[key]); obj[key] = deepClone(data[key]);
} }

Loading…
Cancel
Save