董国庆
2025-03-05 1ad0b7bbb05871ce5c8e55bac3b248c3f6ccf326
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 生成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 const exportExcell = (name, params, url) => {
  fetch(BASE_URL + 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);
    });
};