wwf
昨天 4e6f18dfa08e2f2f4f02aaa1b8e8e51852b7a9a1
src/utils/tool.js
@@ -1,5 +1,7 @@
import { useOptionItemsStore } from '@/stores/optionItems.js';
import $qxueyou from '@/config/qxueyou.js'
import { tokenUtils } from '@/utils/axios.js'
import $axios from '@/utils/axios.js'
/**
 * 获取 assets/images 目录下的图片URL
 * @param {string} imageName - 图片文件名(包含扩展名)
@@ -159,20 +161,25 @@
let uploadRequest = function(blob, fileName, fileType){
  return new Promise((resolve) => {
    const file = new File([blob], fileName, {
      type: blob.type || 'application/octet-stream',
      lastModified: Date.now()
    });
    let fd = new FormData()
    let xhr = new XMLHttpRequest()
    fd.append('image', blob, `${fileName}.${fileType}`)
    fd.append('file', file)
    xhr.open('POST', $qxueyou.upload, true)
    xhr.setRequestHeader('Authorization', localStorage.getItem($qxueyou.ACCESS_TOKEN_KEY));
    xhr.onreadystatechange = () => {
      if (xhr.readyState === 4 && xhr.status === 200 && xhr.responseText) {
        let file = JSON.parse(xhr.responseText)[0] // 返回结果
        resolve(file.path)
        let file = JSON.parse(xhr.responseText) // 返回结果
        resolve(file.data)
      }
    }
    xhr.onerror = (evt) => { // 上传失败回调
      store.commit("snack/error", "上传失败!")
      console.log(JSON.stringify(evt.target))
      resolve()
      resolve(false)
    }
    xhr.send(fd);
  })