From 9aae2af6f3937a7d99ec619b51f457002cef969f Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 03 十一月 2025 14:29:37 +0800
Subject: [PATCH] 档案管理-添加导出功能
---
src/components/Editor/index.vue | 83 +++++++++++++++++++++++++++++++----------
1 files changed, 62 insertions(+), 21 deletions(-)
diff --git a/src/components/Editor/index.vue b/src/components/Editor/index.vue
index 1bd01ed..c283e42 100644
--- a/src/components/Editor/index.vue
+++ b/src/components/Editor/index.vue
@@ -27,6 +27,7 @@
</template>
<script setup>
+import axios from "axios";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import { getToken } from "@/utils/auth";
@@ -36,7 +37,7 @@
const quillEditorRef = ref();
const uploadUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃
const headers = ref({
- Authorization: "Bearer " + getToken()
+ Authorization: "Bearer " + getToken(),
});
const props = defineProps({
@@ -68,7 +69,7 @@
type: {
type: String,
default: "url",
- }
+ },
});
const options = ref({
@@ -78,20 +79,20 @@
modules: {
// 宸ュ叿鏍忛厤缃�
toolbar: [
- ["bold", "italic", "underline", "strike"], // 鍔犵矖 鏂滀綋 涓嬪垝绾� 鍒犻櫎绾�
- ["blockquote", "code-block"], // 寮曠敤 浠g爜鍧�
- [{ list: "ordered" }, { list: "bullet" }], // 鏈夊簭銆佹棤搴忓垪琛�
- [{ indent: "-1" }, { indent: "+1" }], // 缂╄繘
- [{ size: ["small", false, "large", "huge"] }], // 瀛椾綋澶у皬
- [{ header: [1, 2, 3, 4, 5, 6, false] }], // 鏍囬
- [{ color: [] }, { background: [] }], // 瀛椾綋棰滆壊銆佸瓧浣撹儗鏅鑹�
- [{ align: [] }], // 瀵归綈鏂瑰紡
- ["clean"], // 娓呴櫎鏂囨湰鏍煎紡
- ["link", "image", "video"] // 閾炬帴銆佸浘鐗囥�佽棰�
+ ["bold", "italic", "underline", "strike"], // 鍔犵矖 鏂滀綋 涓嬪垝绾� 鍒犻櫎绾�
+ ["blockquote", "code-block"], // 寮曠敤 浠g爜鍧�
+ [{ list: "ordered" }, { list: "bullet" }], // 鏈夊簭銆佹棤搴忓垪琛�
+ [{ indent: "-1" }, { indent: "+1" }], // 缂╄繘
+ [{ size: ["small", false, "large", "huge"] }], // 瀛椾綋澶у皬
+ [{ header: [1, 2, 3, 4, 5, 6, false] }], // 鏍囬
+ [{ color: [] }, { background: [] }], // 瀛椾綋棰滆壊銆佸瓧浣撹儗鏅鑹�
+ [{ align: [] }], // 瀵归綈鏂瑰紡
+ ["clean"], // 娓呴櫎鏂囨湰鏍煎紡
+ ["link", "image", "video"], // 閾炬帴銆佸浘鐗囥�佽棰�
],
},
placeholder: "璇疯緭鍏ュ唴瀹�",
- readOnly: props.readOnly
+ readOnly: props.readOnly,
});
const styles = computed(() => {
@@ -106,15 +107,19 @@
});
const content = ref("");
-watch(() => props.modelValue, (v) => {
- if (v !== content.value) {
- content.value = v == undefined ? "<p></p>" : v;
- }
-}, { immediate: true });
+watch(
+ () => props.modelValue,
+ (v) => {
+ if (v !== content.value) {
+ content.value = v == undefined ? "<p></p>" : v;
+ }
+ },
+ { immediate: true }
+);
// 濡傛灉璁剧疆浜嗕笂浼犲湴鍧�鍒欒嚜瀹氫箟鍥剧墖涓婁紶浜嬩欢
onMounted(() => {
- if (props.type == 'url') {
+ if (props.type == "url") {
let quill = quillEditorRef.value.getQuill();
let toolbar = quill.getModule("toolbar");
toolbar.addHandler("image", (value) => {
@@ -124,6 +129,7 @@
quill.format("image", false);
}
});
+ quill.root.addEventListener("paste", handlePasteCapture, true);
}
});
@@ -156,7 +162,11 @@
// 鑾峰彇鍏夋爣浣嶇疆
let length = quill.selection.savedRange.index;
// 鎻掑叆鍥剧墖锛宺es.url涓烘湇鍔″櫒杩斿洖鐨勫浘鐗囬摼鎺ュ湴鍧�
- quill.insertEmbed(length, "image", import.meta.env.VITE_APP_BASE_API + res.fileName);
+ quill.insertEmbed(
+ length,
+ "image",
+ import.meta.env.VITE_APP_BASE_API + res.fileName
+ );
// 璋冩暣鍏夋爣鍒版渶鍚�
quill.setSelection(length + 1);
} else {
@@ -168,13 +178,44 @@
function handleUploadError() {
proxy.$modal.msgError("鍥剧墖鎻掑叆澶辫触");
}
+
+// 澶嶅埗绮樿创鍥剧墖澶勭悊
+function handlePasteCapture(e) {
+ const clipboard = e.clipboardData || window.clipboardData;
+ if (clipboard && clipboard.items) {
+ for (let i = 0; i < clipboard.items.length; i++) {
+ const item = clipboard.items[i];
+ if (item.type.indexOf("image") !== -1) {
+ e.preventDefault();
+ const file = item.getAsFile();
+ insertImage(file);
+ }
+ }
+ }
+}
+
+function insertImage(file) {
+ const formData = new FormData();
+ formData.append("file", file);
+ axios
+ .post(uploadUrl.value, formData, {
+ headers: {
+ "Content-Type": "multipart/form-data",
+ Authorization: headers.value.Authorization,
+ },
+ })
+ .then((res) => {
+ handleUploadSuccess(res.data);
+ });
+}
</script>
<style>
.editor-img-uploader {
display: none;
}
-.editor, .ql-toolbar {
+.editor,
+.ql-toolbar {
white-space: pre-wrap !important;
line-height: normal !important;
}
--
Gitblit v1.9.3