Commit 84b3fa3d by Sixong.Zhu

enable file upload

parent bfc192a3
Showing with 20 additions and 21 deletions
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
for="chat-upload-file" for="chat-upload-file"
:title="tip4File" :title="tip4File"
@click="allowLoadFile" @click="allowLoadFile"
v-if="enableFileSelection"
> >
<img <img
class="tool-bar-icon" class="tool-bar-icon"
...@@ -36,7 +35,6 @@ ...@@ -36,7 +35,6 @@
id="chat-upload-file" id="chat-upload-file"
type="file" type="file"
:accept="acceptType" :accept="acceptType"
multiple
/> />
</div> </div>
...@@ -121,6 +119,16 @@ ...@@ -121,6 +119,16 @@
); );
} }
const limitedFileExtension = [
"ppt",
"pptx",
"doc",
"docx",
"xls",
"xlsx",
"pdf",
];
@Component({ components: {} }) @Component({ components: {} })
export default class Input extends Vue { export default class Input extends Vue {
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID)
...@@ -139,9 +147,6 @@ ...@@ -139,9 +147,6 @@
private tip4Image = `发送图片(最大${MAX_IMAGE_SIZE_STRING})`; private tip4Image = `发送图片(最大${MAX_IMAGE_SIZE_STRING})`;
private tip4File = `发送文件(最大${MAX_FILE_SIZE_STRING})`; private tip4File = `发送文件(最大${MAX_FILE_SIZE_STRING})`;
private readonly enableFileSelection =
window.location.host.includes("localhost");
private emoji: EmojiItem[] = []; private emoji: EmojiItem[] = [];
@Watch("chatId") @Watch("chatId")
...@@ -202,7 +207,8 @@ ...@@ -202,7 +207,8 @@
} }
private allowLoadFile() { private allowLoadFile() {
this.acceptType = "*"; this.acceptType =
limitedFileExtension.map((i) => `.${i}`).join(",") + ",image/*";
} }
private async handlePasteEvent(event: ClipboardEvent) { private async handlePasteEvent(event: ClipboardEvent) {
...@@ -498,30 +504,23 @@ ...@@ -498,30 +504,23 @@
for (let index = 0; index < files.length; index++) { for (let index = 0; index < files.length; index++) {
const file = files[index]; const file = files[index];
if (file.size <= 0) { if (file.size <= 0) {
this.$emit("error", MESSAGE_FILE_EMPTY); return this.$emit("error", MESSAGE_FILE_EMPTY);
return;
} }
if ( if (file.size >= MAX_FILE_SIZE) {
this.enableFileSelection && return this.$emit("error", MESSAGE_FILE_TOO_LARGE);
file.size >= MAX_FILE_SIZE
) {
this.$emit("error", MESSAGE_FILE_TOO_LARGE);
return;
} }
if (this.isImage(file)) { if (this.isImage(file)) {
if (file.size >= MAX_IMAGE_SIZE) { if (file.size >= MAX_IMAGE_SIZE) {
this.$emit("error", MESSAGE_IMAGE_TOO_LARGE); return this.$emit(
return; "error",
MESSAGE_IMAGE_TOO_LARGE
);
} }
html += this.buildImageHtml(file); html += this.buildImageHtml(file);
} else { } else {
if (this.enableFileSelection) { html += this.buildFileHtml(file);
html += this.buildFileHtml(file);
} else {
return this.$emit("error", ERROR_IMAGE);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment