From 331a457727d39e19eac5cd2f5c10f6b3a004bf8d Mon Sep 17 00:00:00 2001 From: yy2205 <2238220225@qq.com> Date: Thu, 22 May 2025 16:55:01 +0800 Subject: [PATCH] =?UTF-8?q?base64=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/processImage/index.ts | 2 +- src/utils/base64.ts | 27 +++++++++++++++++++++++++++ src/views/ECG/ECGForm.vue | 9 ++++----- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/utils/base64.ts diff --git a/src/api/processImage/index.ts b/src/api/processImage/index.ts index 35752afa..c62dd3ca 100644 --- a/src/api/processImage/index.ts +++ b/src/api/processImage/index.ts @@ -72,7 +72,7 @@ export const processImageApi = { enableWatermark:1, } }, - processImg: async (params: any) => { + processImg: async (params: string) => { try { const response = await axios({ method: 'post', diff --git a/src/utils/base64.ts b/src/utils/base64.ts new file mode 100644 index 00000000..7bb9a7d7 --- /dev/null +++ b/src/utils/base64.ts @@ -0,0 +1,27 @@ +/** + * 将字符串转换为 base64 编码 + * @param {string} str 需要编码的字符串 + * @returns {string} base64 编码后的字符串 + */ +export const encodeBase64 = (str) => { + try { + return btoa(unescape(encodeURIComponent(str))); + } catch (error) { + console.error('Base64 编码失败:', error); + return ''; + } +}; + +/** + * 将 base64 编码的字符串解码 + * @param {string} str base64 编码的字符串 + * @returns {string} 解码后的原始字符串 + */ +export const decodeBase64 = (str) => { + try { + return decodeURIComponent(escape(atob(str))); + } catch (error) { + console.error('Base64 解码失败:', error); + return ''; + } +}; diff --git a/src/views/ECG/ECGForm.vue b/src/views/ECG/ECGForm.vue index 1ea1ec44..415f6a8b 100644 --- a/src/views/ECG/ECGForm.vue +++ b/src/views/ECG/ECGForm.vue @@ -581,12 +581,9 @@ import { WarningApi, WarningVO } from '@/api/system/warning' import ECGCopmareDialog from '@/views/ECG/ECGCompare.vue' import ECGApplyforRepair from '@/views/ECG/ECGModify/ECGApplyforRepair.vue' import useClipboard from 'vue-clipboard3' //复制组件 -import ECGSB from '@/views/ECG/ECGSB.vue' import { ElLoading } from 'element-plus' -import { log } from 'console' import { processImageApi } from '@/api/processImage' -import jsPDF from 'jspdf' -import VuePdfEmbed from 'vue-pdf-embed' +import {encodeBase64} from "@/utils/base64" const { toClipboard } = useClipboard() const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 @@ -738,7 +735,9 @@ async function process() { data.watermarkText = data.step + queryParams.value.doctorDiagResult // console.log(data) data.imagePath = processImageApi.urlToAddress(data.imagePath) - const processResponse = await processImageApi.processImg(data) + let str = JSON.stringify(data) + let str64 = encodeBase64(str) + const processResponse = await processImageApi.processImg(str64) console.log("processResponse",processResponse) // 1. 解析外层 JSON 的 data 字符串