脱敏信息
js
/**
* 脱敏信息
* @param {*} str
* @param {*} start 开始保留几位
* @param {*} end 结束保留几位
* @param {*} 示例:hideStr(13871441556)(3,4)
* @returns 138****1556
* @param {*} 示例:hideStr(李林)(1,0)
* @returns 李*
*/
export const hideStr = (str) => (start, end) => {
try {
const startStr = str.substring(0, start)
const endStr = str.substring(str.length - end, str.length)
const label = [...new Array(str.length - (start + end)).keys()].map(() => '*').join('')
return `${startStr}${label}${endStr}`
} catch (error) {
return ''
}
}
文件下载
使用 iframe 下载文件
使用此方法可以在for循环中连续下载文件
js
export const downloadFile = (url) => {
const iframe = document.createElement("iframe");
iframe.style.display = "none"; // 防止影响页面
iframe.style.height = 0; // 防止影响页面
iframe.src = url;
document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
setTimeout(() => { iframe.remove(); }, 1 * 60 * 1000);// 1分钟之后删除
}