diff --git a/src/components/richText/customUploadAdapter.js b/src/components/richText/customUploadAdapter.js index 4dcc110..eda880c 100644 --- a/src/components/richText/customUploadAdapter.js +++ b/src/components/richText/customUploadAdapter.js @@ -3,7 +3,9 @@ * @params file File类型的图片文件 * @return Promise 返回一个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, }) })