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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| const uploadConfig = { fastDfsUrl:'http://123.207.27.208', action: 'http://localhost:8080/fastDfs', methods: 'POST', token: '', name: 'file', size: 500, accept: 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon' };
const toolOptions = [ ['bold', 'italic', 'underline', 'strike'], ['blockquote', 'code-block'], [{'header': 1}, {'header': 2}], [{'list': 'ordered'}, {'list': 'bullet'}], [{'script': 'sub'}, {'script': 'super'}], [{'indent': '-1'}, {'indent': '+1'}], [{'direction': 'rtl'}], [{'size': ['small', false, 'large', 'huge']}], [{'header': [1, 2, 3, 4, 5, 6, false]}], [{'color': []}, {'background': []}], [{'font': []}], [{'align': []}], ['clean'], ['link', 'image', 'video'] ]; const handlers = { image: function image() { var self = this; var fileInput = this.container.querySelector('input.ql-image[type=file]'); if (fileInput === null) { fileInput = document.createElement('input'); fileInput.setAttribute('type', 'file'); if (uploadConfig.name) { fileInput.setAttribute('name', uploadConfig.name); } fileInput.setAttribute('accept', uploadConfig.accept); fileInput.classList.add('ql-image'); fileInput.addEventListener('change', function () { var formData = new FormData(); formData.append(uploadConfig.name, fileInput.files[0]); formData.append('object','product'); if (uploadConfig.token) { formData.append('token', uploadConfig.token) } var xhr = new XMLHttpRequest(); xhr.open(uploadConfig.methods, uploadConfig.action, true); xhr.onload = function (e) { if (xhr.status === 200) { var res = JSON.parse(xhr.responseText); let length = self.quill.getSelection(true).index; self.quill.insertEmbed(length, 'image', uploadConfig.fastDfsUrl+res.data); self.quill.setSelection(length + 1) } fileInput.value = '' }; xhr.upload.onloadstart = function (e) { fileInput.value = '' }; xhr.upload.onerror = function (e) { }; xhr.upload.onloadend = function (e) { }; xhr.send(formData) }); this.container.appendChild(fileInput); } fileInput.click(); } };
export default { placeholder: '', theme: 'snow', modules: { toolbar: { container: toolOptions, handlers: handlers } } };
|