Commit 3a7d925d by zhousil
parents cd93c141 ae5dedf7
Showing with 29 additions and 27 deletions
......@@ -22,7 +22,6 @@
for="chat-upload-file"
:title="tip4File"
@click="allowLoadFile"
v-if="enableFileSelection"
>
<img
class="tool-bar-icon"
......@@ -36,7 +35,6 @@
id="chat-upload-file"
type="file"
:accept="acceptType"
multiple
/>
</div>
......@@ -121,6 +119,16 @@
);
}
const limitedFileExtension = [
"ppt",
"pptx",
"doc",
"docx",
"xls",
"xlsx",
"pdf",
];
@Component({ components: {} })
export default class Input extends Vue {
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID)
......@@ -139,9 +147,6 @@
private tip4Image = `发送图片(最大${MAX_IMAGE_SIZE_STRING})`;
private tip4File = `发送文件(最大${MAX_FILE_SIZE_STRING})`;
private readonly enableFileSelection =
window.location.host.includes("localhost");
private emoji: EmojiItem[] = [];
@Watch("chatId")
......@@ -202,7 +207,8 @@
}
private allowLoadFile() {
this.acceptType = "*";
this.acceptType =
limitedFileExtension.map((i) => `.${i}`).join(",") + ",image/*";
}
private async handlePasteEvent(event: ClipboardEvent) {
......@@ -222,19 +228,22 @@
const file = items[i].getAsFile();
if (file) {
if (file.size <= 0) {
this.$emit("error", MESSAGE_FILE_EMPTY);
return;
return this.$emit("error", MESSAGE_FILE_EMPTY);
}
if (this.isImage(file)) {
if (file.size >= MAX_IMAGE_SIZE) {
this.$emit("error", MESSAGE_IMAGE_TOO_LARGE);
return;
return this.$emit(
"error",
MESSAGE_IMAGE_TOO_LARGE
);
}
html += this.buildImageHtml(file);
} else {
if (file.size >= MAX_FILE_SIZE) {
this.$emit("error", MESSAGE_FILE_TOO_LARGE);
return;
return this.$emit(
"error",
MESSAGE_FILE_TOO_LARGE
);
}
html += this.buildFileHtml(file);
}
......@@ -498,30 +507,23 @@
for (let index = 0; index < files.length; index++) {
const file = files[index];
if (file.size <= 0) {
this.$emit("error", MESSAGE_FILE_EMPTY);
return;
return this.$emit("error", MESSAGE_FILE_EMPTY);
}
if (
this.enableFileSelection &&
file.size >= MAX_FILE_SIZE
) {
this.$emit("error", MESSAGE_FILE_TOO_LARGE);
return;
if (file.size >= MAX_FILE_SIZE) {
return this.$emit("error", MESSAGE_FILE_TOO_LARGE);
}
if (this.isImage(file)) {
if (file.size >= MAX_IMAGE_SIZE) {
this.$emit("error", MESSAGE_IMAGE_TOO_LARGE);
return;
return this.$emit(
"error",
MESSAGE_IMAGE_TOO_LARGE
);
}
html += this.buildImageHtml(file);
} else {
if (this.enableFileSelection) {
html += this.buildFileHtml(file);
} else {
return this.$emit("error", ERROR_IMAGE);
}
html += this.buildFileHtml(file);
}
}
......
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