From 55bd7fb6365909a0cbcf0957333c7876bd791bb9 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期四, 21 十一月 2024 16:35:12 +0800
Subject: [PATCH] 问题整改界面 1. 优化各项状态展示效果 2. 新增左侧关键字筛选功能
---
src/utils/doc.js | 136 +++++++++++++++++++++++++++++++++++----------
1 files changed, 105 insertions(+), 31 deletions(-)
diff --git a/src/utils/doc.js b/src/utils/doc.js
index 5e30908..25115f2 100644
--- a/src/utils/doc.js
+++ b/src/utils/doc.js
@@ -3,9 +3,100 @@
import docxtemplater from 'docxtemplater';
import ImageModule from 'docxtemplater-image-module-free';
import Pizzip from 'pizzip';
-import PizZipUtils from 'pizzip/utils/dist/pizzip-utils';
import FileSaver from 'file-saver';
-import fs from 'fs';
+
+/**
+ * 绛夋瘮渚嬬缉鏀惧浘鐗�
+ * 鏍规嵁鍥剧墖鐨勯暱瀹芥瘮杩涜涓嶅悓鏂瑰紡鐨勭缉鏀�
+ * 濡傛灉瀹藉害澶т簬楂樺害锛堟í鎷嶅浘鐗囷級锛屽垯鎸夌収璁惧畾楂樺害绛夋瘮缂╂斁锛�
+ * 濡傛灉瀹藉害灏忎簬楂樺害锛堢珫鎷嶅浘鐗囷級锛屽垯鎸夌収璁惧畾瀹藉害绛夋瘮缂╂斁锛�
+ * @param {Number} horizontalHeight 璁惧畾楂樺害
+ * @param {Number} verticalWidth 璁惧畾瀹藉害
+ * @param {*} img
+ * @param {*} tagValue
+ * @param {*} tagName
+ * @returns
+ */
+function getSizeProportional(
+ horizontalHeight,
+ verticalWidth,
+ img,
+ tagValue,
+ tagName
+) {
+ return new Promise(function (resolve, reject) {
+ const image = new Image();
+ image.src = tagValue;
+ image.onload = function () {
+ let width = image.width;
+ let height = image.height;
+ // console.log('width height', width, height);
+
+ if (width > height && horizontalHeight && height > horizontalHeight) {
+ const scale = image.height / horizontalHeight;
+ height = horizontalHeight;
+ width = image.width / scale;
+ } else if (width <= height && verticalWidth && width > verticalWidth) {
+ const scale = image.width / verticalWidth;
+ width = verticalWidth;
+ height = image.height / scale;
+ }
+ // console.log('scale', width, height);
+
+ resolve([width, height]);
+ };
+ image.onerror = function (e) {
+ console.log('img, tagValue, tagName : ', img, tagValue, tagName);
+ alert('An error occured while loading ' + tagValue);
+ reject(e);
+ };
+ });
+}
+
+/**
+ * 鍥哄畾澶у皬缂╂斁鍥剧墖
+ * 鏍规嵁鍥剧墖鐨勯暱瀹芥瘮杩涜涓嶅悓鏂瑰紡鐨勭缉鏀�
+ * 濡傛灉瀹藉害澶т簬楂樺害锛堟í鎷嶅浘鐗囷級锛屽垯鎸夌収璁惧畾楂樺害鍜屽楂樻瘮缂╂斁锛�
+ * 濡傛灉瀹藉害灏忎簬楂樺害锛堢珫鎷嶅浘鐗囷級锛屽垯鎸夌収璁惧畾瀹藉害鍜屽楂樻瘮缂╂斁锛�
+ * @param {*} horizontalHeight 璁惧畾楂樺害
+ * @param {*} verticalWidth 璁惧畾瀹藉害
+ * @param {*} scale 缂╂斁姣斾緥锛岄暱杈归櫎鐭竟鐨勬瘮渚嬬郴鏁�
+ * @param {*} img
+ * @param {*} tagValue
+ * @param {*} tagName
+ * @returns
+ */
+function getSizeFixed(
+ horizontalHeight,
+ verticalWidth,
+ scale,
+ img,
+ tagValue,
+ tagName
+) {
+ return new Promise(function (resolve, reject) {
+ const image = new Image();
+ image.src = tagValue;
+ image.onload = function () {
+ let width = image.width;
+ let height = image.height;
+
+ if (width > height && horizontalHeight && height > horizontalHeight && scale) {
+ height = horizontalHeight;
+ width = horizontalHeight * scale;
+ } else if (width <= height && verticalWidth && width > verticalWidth && scale) {
+ width = verticalWidth;
+ height = verticalWidth * scale;
+ }
+ resolve([width, height]);
+ };
+ image.onerror = function (e) {
+ console.log('img, tagValue, tagName : ', img, tagValue, tagName);
+ alert('An error occured while loading ' + tagValue);
+ reject(e);
+ };
+ });
+}
/**
* 鑾峰彇鍥剧墖閰嶇疆淇℃伅
@@ -14,8 +105,8 @@
* @returns
*/
function getImageOptions(options) {
- const horizontalHeight = options ? options.horizontalHeight : undefined
- const verticalWidth = options ? options.verticalWidth : undefined
+ const horizontalHeight = options ? options.horizontalHeight : undefined;
+ const verticalWidth = options ? options.verticalWidth : undefined;
return {
centered: false,
fileType: 'docx',
@@ -30,34 +121,17 @@
});
});
},
+
getSize(img, tagValue, tagName) {
- return new Promise(function (resolve, reject) {
- const image = new Image();
- image.src = tagValue;
- image.onload = function () {
- let width = image.width;
- let height = image.height;
- // console.log('width height', width, height);
-
- if (width > height && horizontalHeight && height > horizontalHeight) {
- const scale = image.height / horizontalHeight;
- height = horizontalHeight;
- width = image.width / scale;
- } else if (width <= height && verticalWidth && width > verticalWidth) {
- const scale = image.width / verticalWidth;
- width = verticalWidth;
- height = image.height / scale;
- }
- // console.log('scale', width, height);
-
- resolve([width, height]);
- };
- image.onerror = function (e) {
- console.log('img, tagValue, tagName : ', img, tagValue, tagName);
- alert('An error occured while loading ' + tagValue);
- reject(e);
- };
- });
+ // return getSizeProportional(horizontalHeight, verticalWidth, img, tagValue, tagName)
+ return getSizeFixed(
+ horizontalHeight,
+ verticalWidth,
+ options.scale,
+ img,
+ tagValue,
+ tagName
+ );
}
};
}
--
Gitblit v1.9.3