From 84ad493bb7febd5d90ff5fe03f43f6873278d23e Mon Sep 17 00:00:00 2001 From: "xie.bx" Date: Fri, 17 Nov 2023 23:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtoken=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 8 +-- im-ui/src/api/httpRequest.js | 4 +- im-ui/src/components/chat/ChatBox.vue | 25 +++----- im-ui/src/components/common/FileUpload.vue | 60 +++++++++++-------- im-ui/src/components/setting/Setting.vue | 2 +- im-ui/src/view/Group.vue | 2 +- 6 files changed, 52 insertions(+), 49 deletions(-) diff --git a/im-platform/src/main/resources/application.yml b/im-platform/src/main/resources/application.yml index 49acc51..59192d6 100644 --- a/im-platform/src/main/resources/application.yml +++ b/im-platform/src/main/resources/application.yml @@ -32,11 +32,11 @@ mybatis-plus: # *.xml的具体路径 - classpath*:mapper/*.xml minio: - endpoint: http://42.194.187.243:9001 #内网地址 - public: http://42.194.187.243:9001 #外网访问地址 + endpoint: http://127.0.0.1:9001 #内网地址 + public: http://127.0.0.1:9001 #外网访问地址 accessKey: admin - secretKey: admin123456 - bucketName: box-im2 + secretKey: 12345678 + bucketName: box-im imagePath: image filePath: file diff --git a/im-ui/src/api/httpRequest.js b/im-ui/src/api/httpRequest.js index aacc0a5..d3d0dd5 100644 --- a/im-ui/src/api/httpRequest.js +++ b/im-ui/src/api/httpRequest.js @@ -54,7 +54,9 @@ http.interceptors.response.use(async response => { sessionStorage.setItem("accessToken", data.accessToken); sessionStorage.setItem("refreshToken", data.refreshToken); // 这里需要把headers清掉,否则请求时会报错,原因暂不详... - response.config.headers=undefined; + if(typeof response.config.data != 'object'){ + response.config.headers=undefined; + } // 重新发送刚才的请求 return http(response.config) } else { diff --git a/im-ui/src/components/chat/ChatBox.vue b/im-ui/src/components/chat/ChatBox.vue index 82744db..20f4cce 100644 --- a/im-ui/src/components/chat/ChatBox.vue +++ b/im-ui/src/components/chat/ChatBox.vue @@ -27,14 +27,14 @@ @click.stop="showEmotionBox()">
-
- @@ -264,7 +264,7 @@ this.sendImageFile = null; }, onImageSuccess(data, file) { - let msgInfo = JSON.parse(JSON.stringify(file.msgInfo || file.raw.msgInfo)); + let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); msgInfo.content = JSON.stringify(data); this.$http({ url: this.messageAction, @@ -277,7 +277,7 @@ }) }, onImageFail(e, file) { - let msgInfo = JSON.parse(JSON.stringify(file.msgInfo || file.raw.msgInfo)); + let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); msgInfo.loadStatus = 'fail'; this.$store.commit("insertMessage", msgInfo); }, @@ -313,7 +313,7 @@ size: file.size, url: url } - let msgInfo = JSON.parse(JSON.stringify(file.raw.msgInfo)); + let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); msgInfo.content = JSON.stringify(data); this.$http({ url: this.messageAction, @@ -326,7 +326,7 @@ }) }, onFileFail(e, file) { - let msgInfo = JSON.parse(JSON.stringify(file.raw.msgInfo)); + let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); msgInfo.loadStatus = 'fail'; this.$store.commit("insertMessage", msgInfo); }, @@ -462,7 +462,7 @@ let file = this.sendImageFile; this.onImageBefore(this.sendImageFile); let formData = new FormData() - formData.append('file', file.raw || file) + formData.append('file', file) this.$http.post("/image/upload", formData, { headers: { 'Content-Type': 'multipart/form-data' @@ -546,6 +546,7 @@ if(this.chat.unreadCount==0){ return; } + this.$store.commit("resetUnreadCount", this.chat) if (this.chat.type == "GROUP") { var url = `/message/group/readed?groupId=${this.chat.targetId}` } else { @@ -554,9 +555,7 @@ this.$http({ url: url, method: 'put' - }).then(() => { - this.$store.commit("resetUnreadCount", this.chat) - }) + }).then(() => {}) }, loadGroup(groupId) { this.$http({ @@ -631,12 +630,6 @@ } return title; }, - imageAction() { - return `${process.env.VUE_APP_BASE_API}/image/upload`; - }, - fileAction() { - return `${process.env.VUE_APP_BASE_API}/file/upload`; - }, messageAction() { return `/message/${this.chat.type.toLowerCase()}/send`; }, diff --git a/im-ui/src/components/common/FileUpload.vue b/im-ui/src/components/common/FileUpload.vue index 480038c..e66c0c9 100644 --- a/im-ui/src/components/common/FileUpload.vue +++ b/im-ui/src/components/common/FileUpload.vue @@ -1,6 +1,6 @@ @@ -11,13 +11,15 @@ data() { return { loading: null, - uploadHeaders: {"accessToken":sessionStorage.getItem('accessToken')} + uploadHeaders: { + "accessToken": sessionStorage.getItem('accessToken') + } } }, props: { action: { type: String, - required: true + required: false }, fileTypes: { type: Array, @@ -37,17 +39,33 @@ } }, methods: { - onSuccess(res, file) { - this.loading && this.loading.close(); - if (res.code == 200) { - this.$emit("success", res.data, file); - } else { - this.$message.error(res.message); - this.$emit("fail", res, file); + onFileUpload(file) { + // 展示加载条 + if (this.showLoading) { + this.loading = this.$loading({ + lock: true, + text: '正在上传...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' + }); } - }, - onError(err, file) { - this.$emit("fail", err, file); + + let formData = new FormData() + formData.append('file', file.file) + this.$http({ + url: this.action, + data: formData, + method: 'post', + headers: { + 'Content-Type': 'multipart/form-data' + } + }).then((data) => { + this.$emit("success", data, file.file); + }).catch((e) => { + this.$emit("fail", e, file.file); + }).finally(() => { + this.loading && this.loading.close(); + }) }, beforeUpload(file) { // 校验文件类型 @@ -64,20 +82,10 @@ this.$message.error(`文件大小不能超过 ${this.fileSizeStr}!`); return false; } - // 展示加载条 - if (this.showLoading) { - this.loading = this.$loading({ - lock: true, - text: '正在上传...', - spinner: 'el-icon-loading', - background: 'rgba(0, 0, 0, 0.7)' - }); - } + this.$emit("before", file); return true; } - - }, computed: { fileSizeStr() { @@ -94,4 +102,4 @@ + \ No newline at end of file diff --git a/im-ui/src/components/setting/Setting.vue b/im-ui/src/components/setting/Setting.vue index 366d7c6..e1c46dd 100644 --- a/im-ui/src/components/setting/Setting.vue +++ b/im-ui/src/components/setting/Setting.vue @@ -93,7 +93,7 @@ }, computed:{ imageAction(){ - return `${process.env.VUE_APP_BASE_API}/image/upload`; + return `/image/upload`; } }, watch: { diff --git a/im-ui/src/view/Group.vue b/im-ui/src/view/Group.vue index 83d78c0..c86513e 100644 --- a/im-ui/src/view/Group.vue +++ b/im-ui/src/view/Group.vue @@ -267,7 +267,7 @@ return this.activeGroup.ownerId == this.$store.state.userStore.userInfo.id; }, imageAction() { - return `${process.env.VUE_APP_BASE_API}/image/upload`; + return `/image/upload`; } }, mounted() {