-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgHandler.js
37 lines (37 loc) · 1.46 KB
/
imgHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {QuillWatch} from 'QuillWatch'
/**
* @description 点击图片上传
*/
export function imgHandler() {
let fileInput = document.querySelector('.quill-image-input');
if (fileInput === null) {
fileInput = document.createElement('input');
fileInput.setAttribute('type', 'file');
fileInput.classList.add('quill-image-input');
fileInput.style.display = 'none'
// 监听选择文件
fileInput.addEventListener('change', function () {
let self = QuillWatch.active
self.file = fileInput.files[0]
fileInput.value = ''
// 如果图片限制大小
if (self.config.size && self.file.size >= self.config.size * 1024 * 1024 && self.config.loading) {
self.quillLoading.classList.remove('extend-upload-success')
self.quillLoading.classList.add('extend-upload-warning-color')
self.quillLoading.innerHTML = '图片大小超过限制'
setTimeout(function () {
self.quillLoading.classList.remove('extend-upload-warning-color')
self.quillLoading.classList.add('extend-upload-success')
}, 1500)
return
}
if (self.config.action) {
self.uploadImg(self.config.change)
} else {
self.toBase64()
}
})
document.body.appendChild(fileInput);
}
fileInput.click();
}