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.
 
 
 

27 lines
655 B

  1. import request from '@/router/axios'
  2. /**
  3. * 获取验证码
  4. * @param query 查询条件
  5. * @param code 验证码对象
  6. * @returns {Promise<T>}
  7. */
  8. export function getCode(query, code) {
  9. return request({
  10. url: '/code',
  11. method: 'get',
  12. params: query,
  13. responseType: 'arraybuffer'
  14. }).then(response => {
  15. //将从后台获取的图片流进行转换
  16. return 'data:image/png;base64,' + btoa(
  17. new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
  18. )
  19. }).then(function(data) {
  20. //接收转换后的Base64图片
  21. code.src = data
  22. }).catch(function(err) {
  23. console.log(err)
  24. })
  25. }