Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
perf: reduce handle upload method
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazyokd committed Apr 15, 2023
1 parent 11d7f9c commit 3cef0d6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/MessageArea/MessageBottomInputArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
</el-button>
</el-popover>
<el-upload
action="/chatting/upload"
:before-upload="beforeAvatarUpload"
:action="file_upload_url"
:before-upload="beforeImageUpload"
:on-success="uploadImageSuccess"
:on-error="uploadImageError"
:on-error="uploadError"
:show-file-list="false"
accept=".jpg,.jpeg,.png,.JPG,JPEG,.PNG,.gif,.GIF"
>
Expand All @@ -31,10 +31,9 @@
></el-button>
</el-upload>
<el-upload
action="/chatting/upload"
:before-upload="beforeFileUpload"
:action="file_upload_url"
:on-success="uploadFileSuccess"
:on-error="uploadFileError"
:on-error="uploadError"
:show-file-list="false"
:multiple="false"
>
Expand Down Expand Up @@ -71,6 +70,7 @@
const emojiData = require("@/assets/emoji.json");
import { mapGetters, mapState } from "vuex";
import { messageType2wsType } from "@/utils/common";
import { API_BASE_URL, FILE_UPLOAD_API_URL } from "@/config/api";
export default {
name: "MessageBottomInputArea",
data() {
Expand All @@ -79,6 +79,7 @@ export default {
emojiList: [],
emojiCounter: 40,
user: JSON.parse(window.sessionStorage.getItem("user")),
file_upload_url: API_BASE_URL + FILE_UPLOAD_API_URL,
};
},
computed: {
Expand Down Expand Up @@ -138,7 +139,7 @@ export default {
this.$bus.$emit("scrollToBottom");
});
},
beforeAvatarUpload(file) {
beforeImageUpload(file) {
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
this.$message.error("上传图片大小不能超过 2MB!");
Expand All @@ -150,18 +151,14 @@ export default {
this.content = res.data.fileUrl;
this.sendMessage(1);
},
uploadImageError() {
this.$message.error("上传图片失败!");
},
beforeFileUpload() {},
uploadFileSuccess(res, file) {
this.$message.success("上传文件成功!");
console.log("success", res, file);
this.content = file.name;
this.sendMessage(2, res.data.fileUrl, res.data.fileSize);
},
uploadFileError() {
this.$message.error("上传文件失败!");
uploadError() {
this.$message.error("上传失败!");
},
},
mounted() {
Expand Down

0 comments on commit 3cef0d6

Please sign in to comment.