【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

66 lines
1.4 KiB

export function Now() {
return window.performance
? window.performance.now() / 1000
: Date.now() / 1000
}
export function Fill(array, value) {
if (array.fill) {
array.fill(value)
} else {
for (let i = 0; i < array.length; i++) {
array[i] = value
}
}
}
export function Base64ToArrayBuffer(base64) {
const binary = window.atob(base64)
const length = binary.length
const bytes = new Uint8Array(length)
for (let i = 0; i < length; i++) {
bytes[i] = binary.charCodeAt(i)
}
return bytes.buffer
}
/**
*
* @param {object} param
* @param {string|object|Array} param.data 数据,传入后url参数将被忽略
* @param {string} param.url 文件下载地址
* @param {string} param.name 文件名称
* @param {string} param.mimeType 文件mime类型
* @returns
*/
export function download(blob, name = 'JSMpeg_' + Date.now(), mimeType = '') {
if (!blob) return
const a = document.createElement('a')
a.style.display = 'none'
a.download = name
if (typeof blob === 'string') {
a.href = blob
} else {
blob =
blob instanceof Blob
? blob
: new Blob(blob instanceof Array ? blob : [blob], {
type: mimeType
})
a.href = URL.createObjectURL(blob)
}
setTimeout(() => {
a.click()
}, 0)
setTimeout(() => {
a.remove()
}, 1)
if (blob instanceof Blob) {
setTimeout(() => {
URL.revokeObjectURL(blob)
}, 1000)
}
}