From f57e22d74fe72563178eaec9232b1a258d1ab8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=80=AA?= <690927457@qq.com> Date: Sat, 24 Feb 2024 11:13:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E7=BC=96=E8=BE=91=E5=AF=8C?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/richText/customUploadAdapter.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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, }) })