import apiConfig from '@/utils/baseurl'
|
import {
|
Message
|
} from 'element-ui'
|
|
// 生成4位随机验证码
|
export function generateVerificationCode() {
|
const characters = '123456789abcdefghijkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXY';
|
let code = '';
|
for (let i = 0; i < 4; i++) {
|
code += characters.charAt(Math.floor(Math.random() * characters.length));
|
}
|
return code;
|
}
|
// 生成随机字符串
|
export function generateRandomString(length) {
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
const str = [];
|
for (let i = 0; i < length; i++) {
|
const randomIndex = Math.floor(Math.random() * chars.length);
|
str.push(chars[randomIndex]);
|
}
|
return str.join('');
|
};
|
|
// 导出
|
export const exportExcell = (name, params, url) => {
|
fetch(apiConfig.baseURL + url, {
|
method: 'get',
|
params: JSON.stringify({
|
...params,
|
}),
|
headers: {
|
Authorization: localStorage.getItem('token'),
|
'ConTent-Type': 'application/json;charset=UTF-8',
|
timestamp: new Date().getTime(),
|
client: localStorage.getItem('client')
|
},
|
responseType: 'blob',
|
})
|
.then((res) => res.blob())
|
.then((res) => {
|
const link = document.createElement('a');
|
link.style.display = 'none';
|
link.href = URL.createObjectURL(res);
|
link.download = name;
|
document.body.appendChild(link);
|
link.click();
|
// 释放的 URL 对象以及移除 a 标签
|
URL.revokeObjectURL(link.href);
|
document.body.removeChild(link);
|
Message({
|
message: '导出成功',
|
type: 'success',
|
duration: 2000
|
})
|
});
|
};
|