|
|
@@ -750,16 +750,21 @@ Vue.component('spaceEditor', {
|
|
|
|
|
|
var missingImageIndex = 0;
|
|
|
for (var imageIndex = 0; imageIndex < outputImages.length; imageIndex++) {
|
|
|
- if (outputImages[imageIndex].getAttribute("src")) {
|
|
|
- continue;
|
|
|
+ var outputImage = outputImages[imageIndex];
|
|
|
+ var src = getImageSrc(outputImage);
|
|
|
+ if (!src) {
|
|
|
+ src = editorImages[imageIndex]
|
|
|
+ || modelImages[imageIndex]
|
|
|
+ || (this.uploadedImageUrls ? this.uploadedImageUrls[missingImageIndex] : "")
|
|
|
+ || (this.uploadedImageUrls ? this.uploadedImageUrls[imageIndex] : "")
|
|
|
+ || "";
|
|
|
+ src = this.normalizeEditorMediaUrl(src);
|
|
|
}
|
|
|
- var src = editorImages[imageIndex]
|
|
|
- || modelImages[imageIndex]
|
|
|
- || (this.uploadedImageUrls ? this.uploadedImageUrls[missingImageIndex] : "")
|
|
|
- || (this.uploadedImageUrls ? this.uploadedImageUrls[imageIndex] : "")
|
|
|
- || "";
|
|
|
if (src) {
|
|
|
- outputImages[imageIndex].setAttribute("src", src);
|
|
|
+ outputImage.setAttribute("src", src);
|
|
|
+ outputImage.removeAttribute("data-original");
|
|
|
+ outputImage.removeAttribute("data-src");
|
|
|
+ outputImage.removeAttribute("data-lazy-src");
|
|
|
}
|
|
|
missingImageIndex++;
|
|
|
}
|
|
|
@@ -1985,6 +1990,69 @@ Vue.component('spaceEditor', {
|
|
|
});
|
|
|
this.refreshLineHeightControl(editor);
|
|
|
},
|
|
|
+ mountAttachmentToolbarButton: function (editor) {
|
|
|
+ if (!editor || !editor.ui || !editor.ui.view || !editor.ui.view.element) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var toolbarItems = editor.ui.view.element.querySelector('.ck-toolbar__items');
|
|
|
+ if (!toolbarItems || toolbarItems.querySelector('[data-space-attachment="true"]')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var phraseButton = null;
|
|
|
+ var buttons = toolbarItems.querySelectorAll('.ck-button');
|
|
|
+ for (var i = 0; i < buttons.length; i++) {
|
|
|
+ var label = (buttons[i].getAttribute('aria-label') || buttons[i].getAttribute('title') || buttons[i].textContent || '').replace(/\s/g, '');
|
|
|
+ if (label.indexOf('常用语') !== -1) {
|
|
|
+ phraseButton = buttons[i];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!phraseButton) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var button = phraseButton.cloneNode(true);
|
|
|
+ button.removeAttribute('aria-haspopup');
|
|
|
+ button.removeAttribute('aria-controls');
|
|
|
+ button.removeAttribute('aria-expanded');
|
|
|
+ button.removeAttribute('aria-disabled');
|
|
|
+ button.removeAttribute('aria-labelledby');
|
|
|
+ button.removeAttribute('data-cke-tooltip-text');
|
|
|
+ button.classList.remove('ck-dropdown__button', 'ck-disabled', 'ck-on');
|
|
|
+ button.classList.add('ck-off');
|
|
|
+ button.setAttribute('aria-label', '附件');
|
|
|
+ button.setAttribute('title', '附件');
|
|
|
+ button.setAttribute('data-space-attachment', 'true');
|
|
|
+ button.tabIndex = 0;
|
|
|
+
|
|
|
+ var buttonLabel = button.querySelector('.ck-button__label');
|
|
|
+ if (buttonLabel) {
|
|
|
+ buttonLabel.textContent = '附件';
|
|
|
+ }
|
|
|
+ var arrow = button.querySelector('.ck-dropdown__arrow');
|
|
|
+ if (arrow) {
|
|
|
+ arrow.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ var _this = this;
|
|
|
+ button.addEventListener('click', function (event) {
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ _this.openAttachmentPicker();
|
|
|
+ });
|
|
|
+
|
|
|
+ var anchor = phraseButton;
|
|
|
+ while (anchor && anchor.parentNode && anchor.parentNode !== toolbarItems) {
|
|
|
+ anchor = anchor.parentNode;
|
|
|
+ }
|
|
|
+ if (anchor && anchor.parentNode === toolbarItems) {
|
|
|
+ toolbarItems.insertBefore(button, anchor.nextSibling);
|
|
|
+ } else {
|
|
|
+ toolbarItems.appendChild(button);
|
|
|
+ }
|
|
|
+ },
|
|
|
alignFullScreenToolbarButton: function () {
|
|
|
if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
|
|
|
return;
|
|
|
@@ -2632,6 +2700,21 @@ Vue.component('spaceEditor', {
|
|
|
}
|
|
|
inlineNode.parentNode.removeChild(inlineNode);
|
|
|
}
|
|
|
+ var importedImages = wrapper.querySelectorAll('img');
|
|
|
+ for (var importedImageIndex = 0; importedImageIndex < importedImages.length; importedImageIndex++) {
|
|
|
+ var importedImage = importedImages[importedImageIndex];
|
|
|
+ var importedSrc = this.normalizeEditorMediaUrl(importedImage.getAttribute('data-original')
|
|
|
+ || importedImage.getAttribute('data-src')
|
|
|
+ || importedImage.getAttribute('data-lazy-src')
|
|
|
+ || importedImage.getAttribute('src')
|
|
|
+ || '');
|
|
|
+ if (importedSrc) {
|
|
|
+ importedImage.setAttribute('src', importedSrc);
|
|
|
+ importedImage.removeAttribute('data-original');
|
|
|
+ importedImage.removeAttribute('data-src');
|
|
|
+ importedImage.removeAttribute('data-lazy-src');
|
|
|
+ }
|
|
|
+ }
|
|
|
var normalizedHtml = wrapper.innerHTML;
|
|
|
document.body.removeChild(wrapper);
|
|
|
return normalizedHtml;
|
|
|
@@ -2793,6 +2876,11 @@ Vue.component('spaceEditor', {
|
|
|
this.$refs.pdfInput.click();
|
|
|
}
|
|
|
},
|
|
|
+ openAttachmentPicker: function () {
|
|
|
+ if (this.$refs.attachmentInput) {
|
|
|
+ this.$refs.attachmentInput.click();
|
|
|
+ }
|
|
|
+ },
|
|
|
handleVideoSelect: function (event) {
|
|
|
var files = Array.prototype.slice.call(event.target.files || []);
|
|
|
event.target.value = "";
|
|
|
@@ -2807,6 +2895,56 @@ Vue.component('spaceEditor', {
|
|
|
this.uploadPdfFile(files[0]);
|
|
|
}
|
|
|
},
|
|
|
+ handleAttachmentSelect: function (event) {
|
|
|
+ var files = Array.prototype.slice.call(event.target.files || []);
|
|
|
+ event.target.value = "";
|
|
|
+ if (files.length > 0) {
|
|
|
+ this.uploadAttachmentFile(files[0]);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ uploadAttachmentFile: function (file) {
|
|
|
+ if (!file) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var _this = this;
|
|
|
+ _this.uploading = true;
|
|
|
+ _this.uploadStatus = '正在上传附件';
|
|
|
+ _this.uploadPlainFileByAdapter(file, {
|
|
|
+ imageQuality: 'origin',
|
|
|
+ fileMaxSize: 100 * 1024 * 1024
|
|
|
+ }, function (loaded, total) {
|
|
|
+ if (total > 0) {
|
|
|
+ _this.uploadStatus = '正在上传附件 ' + Math.round(loaded * 100 / total) + '%';
|
|
|
+ }
|
|
|
+ }).then(function (res) {
|
|
|
+ var attachmentUrl = _this.normalizeLocalUploadUrl(res && res.default ? res.default : res);
|
|
|
+ if (!attachmentUrl) {
|
|
|
+ throw new Error('附件上传失败');
|
|
|
+ }
|
|
|
+ _this.insertAttachmentLink(attachmentUrl, file.name);
|
|
|
+ _this.$emit('input', _this.getEditorSaveHtml());
|
|
|
+ space.message.success('附件已插入正文');
|
|
|
+ }).catch(function (msg) {
|
|
|
+ space.message.error(msg || '附件上传失败');
|
|
|
+ }).finally(function () {
|
|
|
+ _this.uploading = false;
|
|
|
+ _this.uploadStatus = '';
|
|
|
+ });
|
|
|
+ },
|
|
|
+ buildAttachmentLink: function (url, fileName) {
|
|
|
+ var safeUrl = this.escapeHtmlAttr(url);
|
|
|
+ var safeName = this.escapeHtmlAttr(fileName || '附件');
|
|
|
+ return '<p data-space-attachment="true"><a href="' + safeUrl + '" download="' + safeName
|
|
|
+ + '" target="_blank" rel="noopener" title="下载附件:' + safeName
|
|
|
+ + '" style="color:#1769ff;text-decoration:underline;">' + safeName + '</a></p><p></p>';
|
|
|
+ },
|
|
|
+ insertAttachmentLink: function (url, fileName) {
|
|
|
+ if (!url) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.insertHtml(this.buildAttachmentLink(url, fileName));
|
|
|
+ },
|
|
|
isPdfFile: function (file) {
|
|
|
return !!file && ((file.type && file.type.toLowerCase() == "application/pdf") || /\.pdf$/i.test(file.name || ""));
|
|
|
},
|
|
|
@@ -3596,6 +3734,7 @@ Vue.component('spaceEditor', {
|
|
|
_this.alignFullScreenToolbarButton();
|
|
|
_this.mountFirstLineIndentToolbarButton(editor);
|
|
|
_this.mountLineHeightToolbar(editor);
|
|
|
+ _this.mountAttachmentToolbarButton(editor);
|
|
|
_this.configureWordUploadPlugin(editor);
|
|
|
if (_this.type !== 'flow') {
|
|
|
_this.mountVideoUploadToolbarButton();
|
|
|
@@ -3716,6 +3855,7 @@ Vue.component('spaceEditor', {
|
|
|
</div>
|
|
|
<input ref="videoInput" type="file" accept="video/*" style="display:none;" @change="handleVideoSelect">
|
|
|
<input ref="pdfInput" type="file" accept="application/pdf,.pdf" style="display:none;" @change="handlePdfSelect">
|
|
|
+ <input ref="attachmentInput" type="file" style="display:none;" @change="handleAttachmentSelect">
|
|
|
<div :id="id">
|
|
|
<script type="text/plain"></script>
|
|
|
</div>
|