import moment from 'moment'
/**
* 格式化时间,转换为标准的YYYY-MM-DD HH:mm:ss格式
* @param {object} strTime moment时间对象
* @return {string} 时间字符串
*/
function inputDateFormat (strTime) {
if (strTime === undefined) {
return ''
}
return moment(strTime).format('YYYY-MM-DD HH:mm:ss')
}
/**
* 获取int数值
* @param obj
* @return {number}
*/
function getIntValue (obj) {
let ret = -1
if (obj === undefined) {
return ret
}
const tpy = typeof obj
// 数字类型
switch (tpy) {
case 'number':
ret = Math.round(obj)
break
case 'string':
try {
ret = parseInt(obj)
} catch (e) {
ret = -999
}
break
default:
ret = -999
break
}
return ret
}
function exportExcel (excelBlob, fileName) {
if (browse.isIE() || browse.isIE11()) {
window.navigator.msSaveOrOpenBlob(excelBlob, fileName)
} else {
const url = URL.createObjectURL(excelBlob)// 重要
const link = document.createElement('a')
link.href = url
link.download = fileName
link.click()
link.remove()
}
}
/**
* 获取开始范围随机数
* @param m 开始值
* @param n 截止值
* @return {number}
*/
function getRandomNumber (m, n) {
let num = Math.floor(Math.random() * (m - n) + n)
return num
}
/**
* 从map中获取key对应的值
* @param key
* @param map
* @return {string|*}
*/
function getMapValue (key, map) {
if (!key || !map || map.length === 0) {
return ''
}
if (map.has(key)) {
return map.get(key)
}
return key
}