zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
import request from '@/router/axios'
 
/**
 * 获取验证码
 * @param query 查询条件
 * @param code 验证码对象
 * @returns {Promise<T>}
 */
export function getCode(query, code) {
  return request({
    url: '/code',
    method: 'get',
    params: query,
    responseType: 'arraybuffer'
  }).then(response => {
    //将从后台获取的图片流进行转换
    return 'data:image/png;base64,' + btoa(
      new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
    )
  }).then(function(data) {
    //接收转换后的Base64图片
    code.src = data
  }).catch(function(err) {
    console.log(err)
  })
}