文章编辑富文本上传图片bug修复

This commit is contained in:
阿怪 2024-02-24 11:13:17 +08:00
parent 71ad46e43c
commit f57e22d74f

View File

@ -3,7 +3,9 @@
* @params file File类型的图片文件
* @return Promise<file> 返回一个promise值为一个压缩后的图片文件
*/
import { getToken } from '@/utils/auth'
import { ref } from 'vue'
// import { getToken } from '@/utils/auth'
const getToken = localStorage.getItem('token')
function imgCutdown(file) {
return new Promise((resolve) => {
const render = new FileReader();
@ -50,11 +52,12 @@ function imgCutdown(file) {
render.readAsDataURL(file);
});
}
const path = ref(import.meta.env.VITE_BASE_API)
// 上传图片的地址我这里使用的是vue的环境变量也可以直接写死
// const uploadUrl = `${process.env.VUE_APP_HOST}image/upload.do`;
// const uploadUrl = `https://192.168.1.23:8000/api/v1/public/uploadFile`
const uploadUrl = `https://apiwx.twzxjy.com/api/v1/public/uploadFile`
// const uploadUrl = `https://apiwx.twzxjy.com/api/v1/public/uploadFile`
const uploadUrl = `${path.value}/fileUploadAndDownload/upload`
// 自定义适配器类
class MyUploadAdapter {
@ -83,7 +86,8 @@ class MyUploadAdapter {
const xhr = (this.xhr = new XMLHttpRequest())
xhr.open('POST', uploadUrl, true)
xhr.setRequestHeader('Authorization', 'Bearer ' + getToken())
// xhr.setRequestHeader('Authorization', 'Bearer ' + getToken())
xhr.setRequestHeader('X-token', getToken)
xhr.responseType = 'json'
}
@ -102,10 +106,11 @@ class MyUploadAdapter {
response && response.error ? response.error.message : genericErrorText
)
}
console.log(response)
console.log('response is ======', response)
resolve({
default: response.data.path,
// default: response.data.path,
default: response.data.file.url,
})
})