seal.vue 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  1. <template>
  2. <div class="app-container">
  3. <div class="tool-card">
  4. <div class="converter-layout">
  5. <!-- 右侧: 预览 & Canvas 结果 -->
  6. <div id="captureTarget" style="position: fixed; left: -100000px">
  7. <div v-html="editableHtml"> </div>
  8. </div>
  9. <div class="preview-panel">
  10. <div class="canvas-result">
  11. <canvas id="outputCanvas" v-show="canvasGenerated"></canvas>
  12. <!-- <div class="canvas-buttons" v-if="canvasGenerated">
  13. <button @click="downloadCanvasAsImage" class="download">
  14. 📥 下载图片
  15. </button>
  16. <button @click="exportToPDF" class="pdf"> 📄 导出PDF </button>
  17. <button @click="printCanvas" class="print"> 🖨️ 打印 </button>
  18. </div> -->
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. <!-- 图片素材区域 -->
  24. <div class="images-panel">
  25. <!-- 公用章 -->
  26. <div class="seal-section">
  27. <div class="panel-title">公用章</div>
  28. <div class="images-grid">
  29. <div
  30. v-for="(img, index) in publicImages"
  31. :key="'public-' + index"
  32. class="drag-item"
  33. draggable="true"
  34. @dragstart="handleDragStart($event, img, index, 'public')"
  35. >
  36. <img :src="img.imgUrl" :alt="img.name" />
  37. <div class="drag-item-name">{{ img.name }}</div>
  38. </div>
  39. <div v-if="!publicImages.length" class="no-data">暂无公用章</div>
  40. </div>
  41. </div>
  42. <!-- 个人章 -->
  43. <div class="seal-section">
  44. <div class="panel-title">个人章</div>
  45. <div class="images-grid">
  46. <div
  47. v-for="(img, index) in privateImages"
  48. :key="'private-' + index"
  49. class="drag-item"
  50. draggable="true"
  51. @dragstart="handleDragStart($event, img, index, 'private')"
  52. >
  53. <img :src="img.imgUrl" :alt="img.name" />
  54. <div class="drag-item-name">{{ img.name }}</div>
  55. </div>
  56. <div v-if="!privateImages.length" class="no-data">暂无个人章</div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import {
  64. getSealPage,
  65. getPrivateSealPage
  66. } from '@/api/bpm/components/sealManagement';
  67. import { getUserDetail } from '@/api/system/organization/index';
  68. // 引入 html2canvas 和 jsPDF
  69. import html2canvas from 'html2canvas';
  70. import jsPDF from 'jspdf';
  71. // const imageUrl = [
  72. // require('@/assets/0.jpg'),
  73. // require('@/assets/1.jpg'),
  74. // require('@/assets/2.jpg'),
  75. // require('@/assets/3.jpg'),
  76. // require('@/assets/4.jpg'),
  77. // require('@/assets/5.jpg')
  78. // ]; // 使用相对路径或别名路径
  79. // // 默认精美的示例HTML + CSS (内联样式丰富,展示能力)
  80. // const DEFAULT_HTML = `
  81. // <div class="container">
  82. // <div class="img-area">
  83. // <img class="my-photo" alt="loading" src="${imageUrl[0]}">
  84. // </div>
  85. // <div class="img-area">
  86. // <img class="my-photo" alt="loading" src="${imageUrl[1]}">
  87. // </div>
  88. // <div class="img-area">
  89. // <img class="my-photo" alt="loading" src="${imageUrl[2]}">
  90. // </div> <div class="img-area">
  91. // <img class="my-photo" alt="loading" src="${imageUrl[3]}">
  92. // </div> <div class="img-area">
  93. // <img class="my-photo" alt="loading" src="${imageUrl[4]}">
  94. // </div> <div class="img-area">
  95. // <img class="my-photo" alt="loading" src="${imageUrl[5]}">
  96. // </div>
  97. // </div>
  98. // `;
  99. export default {
  100. name: 'HtmlToCanvas',
  101. data() {
  102. return {
  103. editableHtml: '',
  104. previewHtml: '',
  105. canvasGenerated: false,
  106. publicImages: [],
  107. privateImages: [],
  108. droppedImages: [],
  109. selectedImage: null,
  110. baseCanvasData: null, // 缓存基础内容的 Canvas 数据
  111. _isMoving: false, // 是否正在移动图片
  112. _currentMoveImageId: null, // 当前正在移动的图片ID
  113. _moveHandler: null, // 移动事件处理函数引用
  114. _mouseUpHandler: null, // 鼠标释放事件处理函数引用
  115. _dragOverHandler: null, // dragover事件处理函数引用
  116. _dropHandler: null, // drop事件处理函数引用
  117. _contextMenuHandler: null // contextmenu事件处理函数引用
  118. };
  119. },
  120. created() {
  121. // 获取公用章列表
  122. getSealPage({
  123. size: 999,
  124. pageNum: 1,
  125. status: 1,
  126. approvalStatus: 2,
  127. sealHolderId: this.$store.state.user.info.userId
  128. }).then((res) => {
  129. this.publicImages = res.list;
  130. });
  131. // 获取个人章列表
  132. getUserDetail(this.$store.state.user.info.userId).then((res) => {
  133. if (res.signature?.[0]) {
  134. this.privateImages = [
  135. {
  136. imgUrl: res.signature[0].url,
  137. name: res.name
  138. }
  139. ];
  140. console.log(this.privateImages, 'this.privateImages ');
  141. }
  142. });
  143. },
  144. mounted() {
  145. // 组件挂载后自动渲染一次
  146. this.$nextTick(() => {
  147. this.renderToCanvas();
  148. });
  149. // 保存组件实例引用,用于事件处理器
  150. window._aaComponentInstance = this;
  151. // 创建全局安全移除函数
  152. window._safeRemoveElement = function (element) {
  153. try {
  154. if (
  155. element &&
  156. element.parentNode &&
  157. document.body.contains(element)
  158. ) {
  159. element.parentNode.removeChild(element);
  160. return true;
  161. }
  162. } catch (err) {
  163. console.warn('安全移除元素时发生警告:', err);
  164. }
  165. return false;
  166. };
  167. },
  168. beforeDestroy() {
  169. // 清理移动事件监听器
  170. this._cancelMove();
  171. // 清理 Canvas 事件监听器
  172. const canvas = document.getElementById('outputCanvas');
  173. if (canvas) {
  174. if (this._dragOverHandler) {
  175. canvas.removeEventListener('dragover', this._dragOverHandler);
  176. }
  177. if (this._dropHandler) {
  178. canvas.removeEventListener('drop', this._dropHandler);
  179. }
  180. if (this._contextMenuHandler) {
  181. canvas.removeEventListener('contextmenu', this._contextMenuHandler);
  182. }
  183. }
  184. // 清理引用
  185. if (window._aaComponentInstance === this) {
  186. window._aaComponentInstance = null;
  187. }
  188. if (window._safeRemoveElement) {
  189. window._safeRemoveElement = null;
  190. }
  191. },
  192. methods: {
  193. // 获取组件实例
  194. getComponentInstance() {
  195. return window._aaComponentInstance || this;
  196. },
  197. // 安全的移除DOM元素
  198. safeRemoveElement(elementId) {
  199. try {
  200. const element = document.getElementById(elementId);
  201. if (window._safeRemoveElement) {
  202. return window._safeRemoveElement(element);
  203. }
  204. // 回退方案
  205. if (
  206. element &&
  207. element.parentNode &&
  208. document.body.contains(element)
  209. ) {
  210. element.parentNode.removeChild(element);
  211. return true;
  212. }
  213. return false;
  214. } catch (err) {
  215. console.warn(`移除元素 ${elementId} 时发生警告:`, err);
  216. return false;
  217. }
  218. },
  219. // 安全移除所有菜单
  220. safeRemoveAllMenus() {
  221. try {
  222. const existingMenus = document.querySelectorAll('[id^="menu_"]');
  223. // 使用倒序循环,避免在移除时影响NodeList
  224. for (let i = existingMenus.length - 1; i >= 0; i--) {
  225. const menu = existingMenus[i];
  226. if (menu && document.body.contains(menu) && menu.parentNode) {
  227. try {
  228. menu.parentNode.removeChild(menu);
  229. } catch (err) {
  230. console.warn('移除菜单时发生警告:', err);
  231. }
  232. }
  233. }
  234. } catch (err) {
  235. console.warn('移除所有菜单时发生错误:', err);
  236. }
  237. },
  238. // 设置 Canvas 拖放区域和点击事件
  239. setupCanvasDropZone() {
  240. const canvas = document.getElementById('outputCanvas');
  241. if (!canvas) {
  242. console.log('Canvas 元素不存在');
  243. return;
  244. }
  245. console.log('设置拖放区域和点击事件,Canvas ID:', canvas.id);
  246. console.log('Canvas 尺寸:', canvas.width, 'x', canvas.height);
  247. console.log(
  248. 'Canvas 可见性:',
  249. canvas.style.display,
  250. canvas.style.visibility
  251. );
  252. console.log('Canvas 位置:', canvas.getBoundingClientRect());
  253. // 先移除旧的事件监听器,防止重复绑定
  254. if (this._dragOverHandler) {
  255. canvas.removeEventListener('dragover', this._dragOverHandler);
  256. }
  257. if (this._dropHandler) {
  258. canvas.removeEventListener('drop', this._dropHandler);
  259. }
  260. if (this._contextMenuHandler) {
  261. canvas.removeEventListener('contextmenu', this._contextMenuHandler);
  262. }
  263. // 创建事件处理函数并保存引用
  264. this._dragOverHandler = (e) => {
  265. e.preventDefault();
  266. e.dataTransfer.dropEffect = 'copy';
  267. };
  268. this._dropHandler = (e) => {
  269. e.preventDefault();
  270. console.log('触发 drop 事件');
  271. const imageData = e.dataTransfer.getData('imageData');
  272. console.log('获取到的 imageData:', imageData);
  273. if (imageData) {
  274. const data = JSON.parse(imageData);
  275. console.log('解析后的数据:', data);
  276. this.addImageToCanvas(data, e.offsetX, e.offsetY);
  277. }
  278. };
  279. this._contextMenuHandler = (e) => {
  280. e.preventDefault();
  281. this.handleCanvasRightClick(e);
  282. };
  283. // 添加新的事件监听器
  284. canvas.addEventListener('dragover', this._dragOverHandler);
  285. canvas.addEventListener('drop', this._dropHandler);
  286. canvas.addEventListener('contextmenu', this._contextMenuHandler);
  287. },
  288. // 处理拖拽开始
  289. handleDragStart(e, img, index, type) {
  290. const data = {
  291. url: img.imgUrl,
  292. name: img.name,
  293. version: img.version,
  294. imgId: type == 'public' ? img.id : ''
  295. };
  296. e.dataTransfer.setData('imageData', JSON.stringify(data));
  297. e.dataTransfer.effectAllowed = 'copy';
  298. console.log('拖拽开始:', data);
  299. },
  300. // 添加图片到 Canvas
  301. addImageToCanvas(data, x, y) {
  302. const canvas = document.getElementById('outputCanvas');
  303. if (!canvas || !this.canvasGenerated) {
  304. console.log('请先渲染 Canvas');
  305. return;
  306. }
  307. console.log('Canvas 尺寸:', canvas.width, canvas.height);
  308. console.log('拖放位置:', x, y);
  309. const ctx = canvas.getContext('2d');
  310. const img = new Image();
  311. img.crossOrigin = 'anonymous';
  312. img.onload = () => {
  313. console.log('图片加载成功,原始尺寸:', img.width, img.height);
  314. // 默认图片大小为 100x100
  315. const width = 100;
  316. const height = 100;
  317. const posX = x - width / 2;
  318. const posY = y - height / 2;
  319. console.log('绘制位置:', posX, posY, '尺寸:', width, height);
  320. // 绘制图片
  321. ctx.drawImage(img, posX, posY, width, height);
  322. const imageId = `img_${Date.now()}_${Math.random()
  323. .toString(36)
  324. .substr(2, 9)}`;
  325. this.droppedImages.push({
  326. id: imageId,
  327. imgId: data.imgId,
  328. imgUrl: data.url,
  329. version: data.version,
  330. x: posX,
  331. y: posY,
  332. width,
  333. height,
  334. originalWidth: img.width,
  335. originalHeight: img.height
  336. });
  337. console.log('已添加的图片数量:', this.droppedImages.length);
  338. this.$message({
  339. showClose: true,
  340. message: '操作成功',
  341. type: 'success'
  342. });
  343. // 设置图片可再次拖动和调整(通过右键菜单)
  344. // 不再创建覆盖层,仅通过右键菜单操作
  345. };
  346. img.onerror = (err) => {
  347. console.error('图片加载失败:', err);
  348. this.$message({
  349. showClose: true,
  350. message: '操作失败',
  351. type: 'error'
  352. });
  353. // this.showMessage('⚠️ 图片加载失败', 'error');
  354. };
  355. img.src = data.url;
  356. },
  357. // 重新绘制整个 Canvas
  358. redrawCanvas() {
  359. const canvas = document.getElementById('outputCanvas');
  360. if (!canvas || !this.canvasGenerated) return;
  361. const ctx = canvas.getContext('2d');
  362. try {
  363. // 清空 Canvas
  364. ctx.clearRect(0, 0, canvas.width, canvas.height);
  365. // 如果有缓存的基础内容,直接绘制
  366. if (this.baseCanvasData) {
  367. ctx.drawImage(this.baseCanvasData, 0, 0);
  368. } else {
  369. // 如果没有缓存,重新渲染基础内容
  370. console.warn('没有缓存的基础内容,可能需要重新渲染');
  371. return;
  372. }
  373. // 重新绘制所有拖入的图片
  374. this.droppedImages.forEach((image) => {
  375. const img = new Image();
  376. img.onload = () => {
  377. ctx.drawImage(img, image.x, image.y, image.width, image.height);
  378. };
  379. img.src = image.imgUrl;
  380. });
  381. console.log(
  382. 'Canvas 已快速重绘,包含基础内容和',
  383. this.droppedImages.length,
  384. '张图片'
  385. );
  386. // 确保事件监听仍然有效
  387. setTimeout(() => {
  388. this.setupCanvasDropZone();
  389. }, 100);
  390. } catch (error) {
  391. console.error('重新绘制 Canvas 失败:', error);
  392. }
  393. },
  394. // 显示图片控制菜单
  395. showImageControls(imageId, x, y) {
  396. console.log('显示图片控制菜单,位置:', x, y, '图片ID:', imageId);
  397. // 保存组件实例引用
  398. const self = this;
  399. // 先移除可能存在的其他菜单
  400. this.safeRemoveAllMenus();
  401. // 定义菜单选项(使用局部变量 self)
  402. const options = [
  403. { text: '放大', action: () => self.resizeImage(imageId, 1.2) },
  404. { text: '缩小', action: () => self.resizeImage(imageId, 0.8) },
  405. { text: '移动', action: () => self.startMoveImage(imageId, x, y) },
  406. { text: '删除', action: () => self.removeImage(imageId) }
  407. ];
  408. const menu = document.createElement('div');
  409. menu.id = `menu_${imageId}`;
  410. menu.style.position = 'fixed';
  411. // 调整位置,避免菜单超出屏幕边界
  412. const menuWidth = 120;
  413. const menuHeight = options.length * 40 + 16; // 估算高度
  414. let left = x;
  415. let top = y;
  416. // 如果菜单会超出右侧边界,向左移动
  417. if (left + menuWidth > window.innerWidth) {
  418. left = window.innerWidth - menuWidth - 10;
  419. }
  420. // 如果菜单会超出底部边界,向上移动
  421. if (top + menuHeight > window.innerHeight) {
  422. top = window.innerHeight - menuHeight - 10;
  423. }
  424. menu.style.left = `${left}px`;
  425. menu.style.top = `${top}px`;
  426. menu.style.background = 'white';
  427. menu.style.border = '1px solid #e2e8f0';
  428. menu.style.borderRadius = '8px';
  429. menu.style.padding = '8px 0';
  430. menu.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.1)';
  431. menu.style.zIndex = '9999'; // 使用更高的 z-index
  432. menu.style.minWidth = `${menuWidth}px`;
  433. menu.style.opacity = '1';
  434. menu.style.visibility = 'visible';
  435. menu.style.display = 'block';
  436. console.log('菜单位置 - 原始:', x, y, '调整后:', left, top);
  437. options.forEach((option) => {
  438. const item = document.createElement('div');
  439. item.innerText = option.text;
  440. item.style.padding = '8px 16px';
  441. item.style.cursor = 'pointer';
  442. item.style.fontSize = '14px';
  443. item.style.color = '#374151';
  444. item.addEventListener('mouseenter', () => {
  445. item.style.background = '#f3f4f6';
  446. });
  447. item.addEventListener('mouseleave', () => {
  448. item.style.background = 'white';
  449. });
  450. item.addEventListener('click', () => {
  451. option.action();
  452. // 直接移除当前菜单
  453. const menuToRemove = document.getElementById(`menu_${imageId}`);
  454. if (window._safeRemoveElement) {
  455. window._safeRemoveElement(menuToRemove);
  456. }
  457. });
  458. menu.appendChild(item);
  459. });
  460. document.body.appendChild(menu);
  461. console.log('菜单已添加到 DOM,父元素:', menu.parentElement?.tagName);
  462. // 点击其他地方关闭菜单
  463. const closeMenu = (e) => {
  464. console.log('closeMenu 被调用,目标:', e.target);
  465. const currentMenu = document.getElementById(`menu_${imageId}`);
  466. if (!currentMenu || !document.body.contains(currentMenu)) {
  467. // 菜单已经不存在,移除监听器
  468. document.removeEventListener('click', closeMenu);
  469. return;
  470. }
  471. if (e.target !== currentMenu && !currentMenu.contains(e.target)) {
  472. // 使用全局安全函数移除菜单
  473. if (window._safeRemoveElement) {
  474. window._safeRemoveElement(currentMenu);
  475. }
  476. document.removeEventListener('click', closeMenu);
  477. }
  478. };
  479. setTimeout(() => {
  480. console.log('添加全局点击监听器');
  481. document.addEventListener('click', closeMenu);
  482. }, 0);
  483. },
  484. // 调整图片大小
  485. resizeImage(imageId, factor) {
  486. const imageIndex = this.droppedImages.findIndex(
  487. (img) => img.id === imageId
  488. );
  489. if (imageIndex === -1) return;
  490. const image = this.droppedImages[imageIndex];
  491. image.width *= factor;
  492. image.height *= factor;
  493. this.redrawCanvas();
  494. },
  495. // 处理 Canvas 右键点击
  496. handleCanvasRightClick(e) {
  497. console.log('Canvas 右键点击事件触发');
  498. const canvas = document.getElementById('outputCanvas');
  499. if (!canvas) {
  500. console.log('Canvas 元素不存在');
  501. return;
  502. }
  503. console.log(
  504. 'Canvas 元素存在,droppedImages 数量:',
  505. this.droppedImages.length
  506. );
  507. if (this.droppedImages.length === 0) {
  508. console.log('没有已添加的图片');
  509. return;
  510. }
  511. const rect = canvas.getBoundingClientRect();
  512. console.log('Canvas 边界矩形:', rect);
  513. const scaleX = canvas.width / rect.width;
  514. const scaleY = canvas.height / rect.height;
  515. // 计算点击位置相对于 Canvas 的坐标
  516. const clickX = (e.clientX - rect.left) * scaleX;
  517. const clickY = (e.clientY - rect.top) * scaleY;
  518. console.log('右键点击位置 - 屏幕:', e.clientX, e.clientY);
  519. console.log('右键点击位置 - Canvas相对:', clickX, clickY);
  520. // 查找点击到的图片
  521. let clickedImage = null;
  522. for (const image of this.droppedImages) {
  523. console.log(
  524. '检查图片:',
  525. image.id,
  526. '位置:',
  527. image.x,
  528. image.y,
  529. '尺寸:',
  530. image.width,
  531. image.height
  532. );
  533. if (
  534. clickX >= image.x &&
  535. clickX <= image.x + image.width &&
  536. clickY >= image.y &&
  537. clickY <= image.y + image.height
  538. ) {
  539. clickedImage = image;
  540. break;
  541. }
  542. }
  543. if (clickedImage) {
  544. console.log('点击到图片:', clickedImage.id);
  545. this.showImageControls(clickedImage.id, e.clientX, e.clientY);
  546. } else {
  547. console.log('未点击到任何图片');
  548. // 可以在这里添加其他右键功能,比如添加新图片等
  549. }
  550. },
  551. // 开始移动图片
  552. startMoveImage(imageId, menuX, menuY) {
  553. console.log('开始移动图片,图片ID:', imageId);
  554. // 关闭菜单
  555. this.safeRemoveElement(`menu_${imageId}`);
  556. const canvas = document.getElementById('outputCanvas');
  557. if (!canvas) {
  558. console.error('Canvas 元素未找到');
  559. return;
  560. }
  561. const imageIndex = this.droppedImages.findIndex(
  562. (img) => img.id === imageId
  563. );
  564. if (imageIndex === -1) {
  565. console.error('图片未找到,ID:', imageId);
  566. return;
  567. }
  568. const image = this.droppedImages[imageIndex];
  569. console.log('找到图片:', image);
  570. // 如果已经在移动中,先移除旧的事件监听器
  571. if (this._isMoving) {
  572. this._cancelMove();
  573. }
  574. // 设置移动状态标志
  575. this._isMoving = true;
  576. this._currentMoveImageId = imageId;
  577. // 创建一个临时指示器
  578. const indicator = document.createElement('div');
  579. indicator.id = `move_indicator_${imageId}`;
  580. indicator.style.position = 'fixed';
  581. indicator.style.left = `${menuX}px`;
  582. indicator.style.top = `${menuY}px`;
  583. indicator.style.width = '40px';
  584. indicator.style.height = '40px';
  585. indicator.style.background = 'rgba(59, 130, 246, 0.3)';
  586. indicator.style.border = '2px dashed #3b82f6';
  587. indicator.style.borderRadius = '50%';
  588. indicator.style.zIndex = '3000';
  589. indicator.style.pointerEvents = 'none';
  590. document.body.appendChild(indicator);
  591. console.log('指示器已创建并添加到DOM');
  592. // 显示提示
  593. this.$message({
  594. showClose: true,
  595. message: '📍 移动鼠标调整位置,释放鼠标完成移动',
  596. type: 'info'
  597. });
  598. // 保存事件处理函数引用,用于后续移除
  599. this._moveHandler = (e) => {
  600. console.log('moveHandler 被调用,鼠标位置:', e.clientX, e.clientY);
  601. const rect = canvas.getBoundingClientRect();
  602. const scaleX = canvas.width / rect.width;
  603. const scaleY = canvas.height / rect.height;
  604. // 计算相对于 canvas 的位置
  605. const newX = (e.clientX - rect.left) * scaleX - image.width / 2;
  606. const newY = (e.clientY - rect.top) * scaleY - image.height / 2;
  607. // 限制在 canvas 范围内
  608. image.x = Math.max(0, Math.min(newX, canvas.width - image.width));
  609. image.y = Math.max(0, Math.min(newY, canvas.height - image.height));
  610. // 更新指示器位置
  611. indicator.style.left = `${e.clientX - 20}px`;
  612. indicator.style.top = `${e.clientY - 20}px`;
  613. // 使用组件实例引用
  614. const component = window._aaComponentInstance || this;
  615. if (component && component.redrawCanvas) {
  616. component.redrawCanvas();
  617. }
  618. };
  619. this._mouseUpHandler = (e) => {
  620. console.log(
  621. 'mouseUpHandler 被调用,位置:',
  622. e.clientX,
  623. e.clientY,
  624. '目标:',
  625. e.target
  626. );
  627. // 无论在哪里释放鼠标,都完成移动
  628. console.log('鼠标释放,完成移动');
  629. // 确保只处理一次
  630. if (indicator.parentNode) {
  631. console.log('指示器仍在DOM中,移除事件监听器');
  632. document.removeEventListener('mousemove', this._moveHandler);
  633. document.removeEventListener('mouseup', this._mouseUpHandler);
  634. indicator.remove();
  635. // 重置移动状态
  636. this._isMoving = false;
  637. this._currentMoveImageId = null;
  638. this._moveHandler = null;
  639. this._mouseUpHandler = null;
  640. // 使用组件实例引用
  641. const component = window._aaComponentInstance || this;
  642. if (component) {
  643. this.$message({
  644. showClose: true,
  645. message: '图片已移动',
  646. type: 'success'
  647. });
  648. }
  649. } else {
  650. console.log('指示器已不在DOM中');
  651. }
  652. };
  653. // 确保事件只绑定一次
  654. console.log('绑定事件监听器');
  655. document.removeEventListener('mousemove', this._moveHandler);
  656. document.removeEventListener('mouseup', this._mouseUpHandler);
  657. document.addEventListener('mousemove', this._moveHandler);
  658. document.addEventListener('mouseup', this._mouseUpHandler);
  659. },
  660. // 删除图片
  661. removeImage(imageId) {
  662. const imageIndex = this.droppedImages.findIndex(
  663. (img) => img.id === imageId
  664. );
  665. if (imageIndex === -1) return;
  666. this.droppedImages.splice(imageIndex, 1);
  667. // 删除控制菜单
  668. this.safeRemoveElement(`menu_${imageId}`);
  669. // 如果正在移动这张图片,取消移动状态
  670. if (this._currentMoveImageId === imageId) {
  671. this._cancelMove();
  672. }
  673. this.redrawCanvas();
  674. this.$message({
  675. showClose: true,
  676. message: '🗑️ 图片已删除',
  677. type: 'success'
  678. });
  679. },
  680. // 取消移动操作
  681. _cancelMove() {
  682. if (this._moveHandler) {
  683. document.removeEventListener('mousemove', this._moveHandler);
  684. }
  685. if (this._mouseUpHandler) {
  686. document.removeEventListener('mouseup', this._mouseUpHandler);
  687. }
  688. // 移除指示器
  689. if (this._currentMoveImageId) {
  690. const indicator = document.getElementById(
  691. `move_indicator_${this._currentMoveImageId}`
  692. );
  693. if (indicator && indicator.parentNode) {
  694. indicator.remove();
  695. }
  696. }
  697. // 重置状态
  698. this._isMoving = false;
  699. this._currentMoveImageId = null;
  700. this._moveHandler = null;
  701. this._mouseUpHandler = null;
  702. },
  703. // 渲染Canvas核心函数
  704. async renderToCanvas() {
  705. const targetElement = document.getElementById('captureTarget');
  706. if (!targetElement) {
  707. console.warn('未找到目标元素');
  708. return;
  709. }
  710. // 显示加载状态
  711. const canvasResultDiv = document.querySelector('.canvas-result');
  712. const originalMsg = canvasResultDiv.querySelector('p');
  713. if (originalMsg) originalMsg.style.display = 'none';
  714. // 添加加载提示
  715. let loadingMsg = document.getElementById('tempLoadingMsg');
  716. if (!loadingMsg) {
  717. loadingMsg = document.createElement('div');
  718. loadingMsg.id = 'tempLoadingMsg';
  719. loadingMsg.innerText = '⏳ 渲染中,请稍候...';
  720. loadingMsg.style.padding = '12px';
  721. loadingMsg.style.color = '#2563eb';
  722. loadingMsg.style.fontSize = '14px';
  723. canvasResultDiv.appendChild(loadingMsg);
  724. }
  725. try {
  726. // 使用 html2canvas 进行转换
  727. const canvas = await html2canvas(targetElement, {
  728. scale: 1, // 1倍分辨率,避免过大
  729. backgroundColor: '#ffffff',
  730. useCORS: true, // 尝试跨域图片
  731. logging: false,
  732. allowTaint: false,
  733. imageTimeout: 5000,
  734. windowWidth: targetElement.scrollWidth,
  735. windowHeight: targetElement.scrollHeight
  736. });
  737. // 移除加载提示
  738. const temp = document.getElementById('tempLoadingMsg');
  739. if (temp) temp.remove();
  740. // 获取输出canvas元素并绘制
  741. const outputCanvas = document.getElementById('outputCanvas');
  742. outputCanvas.width = canvas.width;
  743. outputCanvas.height = canvas.height;
  744. // 移除内联样式,使用实际像素尺寸
  745. outputCanvas.style.width = canvas.width + 'px';
  746. outputCanvas.style.height = canvas.height + 'px';
  747. const ctx = outputCanvas.getContext('2d');
  748. ctx.clearRect(0, 0, outputCanvas.width, outputCanvas.height);
  749. ctx.drawImage(canvas, 0, 0);
  750. // 保存基础内容的 Canvas 数据(用于快速重绘)
  751. this.baseCanvasData = canvas;
  752. this.canvasGenerated = true;
  753. // 设置 Canvas 拖放区域和事件监听
  754. this.setupCanvasDropZone();
  755. // 显示成功提示
  756. // this.showMessage('✅ 渲染成功!可下载图片', 'success');
  757. } catch (error) {
  758. console.error('html2canvas 渲染失败: ', error);
  759. const temp = document.getElementById('tempLoadingMsg');
  760. if (temp) temp.remove();
  761. this.canvasGenerated = false;
  762. // this.showMessage('⚠️ 渲染失败,请检查HTML结构或外部资源', 'error');
  763. }
  764. },
  765. // 导出为 PDF(使用 jsPDF)
  766. exportToPDF() {
  767. const outputCanvas = document.getElementById('outputCanvas');
  768. if (
  769. !this.canvasGenerated ||
  770. !outputCanvas ||
  771. outputCanvas.width === 0
  772. ) {
  773. // this.showMessage(
  774. // '请先点击"渲染至Canvas"生成图像后再导出PDF',
  775. // 'error'
  776. // );
  777. return;
  778. }
  779. try {
  780. const imgData = outputCanvas.toDataURL('image/png');
  781. // 使用 Canvas 的 CSS 尺寸(显示尺寸),而不是内部像素尺寸
  782. const canvasWidth =
  783. parseFloat(outputCanvas.style.width) || outputCanvas.width;
  784. const canvasHeight =
  785. parseFloat(outputCanvas.style.height) || outputCanvas.height;
  786. // 创建 PDF 实例,横向或纵向根据 Canvas 尺寸决定
  787. const orientation = canvasWidth > canvasHeight ? 'l' : 'p';
  788. // 使用 'mm' 单位,并根据 96 DPI 转换为毫米
  789. // 96 DPI 下:1px = 25.4 / 96 mm ≈ 0.2646 mm
  790. const DPI = 96;
  791. const pxToMm = 25.4 / DPI;
  792. const pdfWidth = canvasWidth * pxToMm;
  793. const pdfHeight = canvasHeight * pxToMm;
  794. const pdf = new jsPDF(orientation, 'mm', [pdfWidth, pdfHeight]);
  795. // 将 Canvas 图片添加到 PDF
  796. pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
  797. // 获取 PDF 文件流并触发事件
  798. const pdfBlob = pdf.output('blob');
  799. const pdfFile = new File([pdfBlob], `canvas-${Date.now()}.pdf`, {
  800. type: 'application/pdf'
  801. });
  802. // 触发 PDF 生成事件,父组件可以监听此事件
  803. this.$emit('pdf-generated', {
  804. pdfFile,
  805. droppedImages: this.droppedImages
  806. });
  807. // 保存 PDF
  808. // const timestamp = new Date()
  809. // .toISOString()
  810. // .slice(0, 19)
  811. // .replace(/:/g, '-');
  812. // pdf.save(`canvas-${timestamp}.pdf`);
  813. // this.showMessage('✅ PDF 导出成功', 'success');
  814. } catch (err) {
  815. console.error('PDF 导出失败', err);
  816. // this.showMessage('PDF 导出失败,请稍后重试', 'error');
  817. }
  818. },
  819. // 重新渲染基础内容(当 HTML 内容变化时调用)
  820. async refreshBaseContent() {
  821. try {
  822. const targetElement = document.getElementById('captureTarget');
  823. if (!targetElement) return;
  824. const newCanvas = await html2canvas(targetElement, {
  825. scale: 1,
  826. backgroundColor: '#ffffff',
  827. useCORS: true,
  828. logging: false,
  829. allowTaint: false,
  830. imageTimeout: 5000,
  831. width: 1000,
  832. windowWidth: targetElement.scrollWidth,
  833. windowHeight: targetElement.scrollHeight
  834. });
  835. this.baseCanvasData = newCanvas;
  836. // 更新主 Canvas
  837. const outputCanvas = document.getElementById('outputCanvas');
  838. if (outputCanvas && this.canvasGenerated) {
  839. const ctx = outputCanvas.getContext('2d');
  840. ctx.clearRect(0, 0, outputCanvas.width, outputCanvas.height);
  841. ctx.drawImage(newCanvas, 0, 0);
  842. // 重新绘制所有拖入的图片
  843. this.droppedImages.forEach((image) => {
  844. const img = new Image();
  845. img.onload = () => {
  846. ctx.drawImage(img, image.x, image.y, image.width, image.height);
  847. };
  848. img.src = image.imgUrl;
  849. });
  850. }
  851. console.log('基础内容已更新');
  852. } catch (error) {
  853. console.error('更新基础内容失败:', error);
  854. }
  855. },
  856. // 获取 PDF 文件流(用于直接上传)
  857. getPDFFile() {
  858. const outputCanvas = document.getElementById('outputCanvas');
  859. if (
  860. !this.canvasGenerated ||
  861. !outputCanvas ||
  862. outputCanvas.width === 0
  863. ) {
  864. // this.showMessage(
  865. // '请先点击"渲染至Canvas"生成图像后再获取PDF',
  866. // 'error'
  867. // );
  868. return Promise.reject(new Error('Canvas 未生成'));
  869. }
  870. return new Promise((resolve, reject) => {
  871. try {
  872. const imgData = outputCanvas.toDataURL('image/png');
  873. const canvasWidth = outputCanvas.width;
  874. const canvasHeight = outputCanvas.height;
  875. // 创建 PDF 实例
  876. const orientation = canvasWidth > canvasHeight ? 'l' : 'p';
  877. const pdf = new jsPDF(orientation, 'px', [
  878. canvasWidth,
  879. canvasHeight
  880. ]);
  881. // 将 Canvas 图片添加到 PDF
  882. pdf.addImage(imgData, 'PNG', 0, 0, canvasWidth, canvasHeight);
  883. // 获取 PDF 文件流
  884. const pdfBlob = pdf.output('blob');
  885. const pdfFile = new File([pdfBlob], `canvas-${Date.now()}.pdf`, {
  886. type: 'application/pdf'
  887. });
  888. resolve(pdfFile);
  889. } catch (err) {
  890. console.error('获取 PDF 文件流失败', err);
  891. reject(err);
  892. }
  893. });
  894. },
  895. // 打印 Canvas / 另存为 PDF
  896. printCanvas() {
  897. const outputCanvas = document.getElementById('outputCanvas');
  898. if (
  899. !this.canvasGenerated ||
  900. !outputCanvas ||
  901. outputCanvas.width === 0
  902. ) {
  903. // this.showMessage('请先点击"渲染至Canvas"生成图像后再打印', 'error');
  904. return;
  905. }
  906. try {
  907. // 创建新窗口用于打印
  908. const printWindow = window.open('', '_blank');
  909. const dataUrl = outputCanvas.toDataURL('image/png');
  910. printWindow.document.write(`
  911. <!DOCTYPE html>
  912. <html>
  913. <head>
  914. <title>打印图片</title>
  915. <style>
  916. body {
  917. margin: 0;
  918. padding: 20px;
  919. display: flex;
  920. justify-content: center;
  921. align-items: center;
  922. }
  923. img {
  924. max-width: 100%;
  925. height: auto;
  926. }
  927. @media print {
  928. body {
  929. padding: 0;
  930. }
  931. img {
  932. max-width: 100%;
  933. page-break-inside: avoid;
  934. }
  935. }
  936. </style>
  937. </head>
  938. <body>
  939. <img src="${dataUrl}" onload="window.print(); window.close();" />
  940. </body>
  941. </html>
  942. `);
  943. printWindow.document.close();
  944. // this.showMessage('✅ 已打开打印窗口,可选择另存为PDF', 'success');
  945. } catch (err) {
  946. console.error('打印失败', err);
  947. // this.showMessage('打印失败,请检查浏览器设置', 'error');
  948. }
  949. },
  950. init(html) {
  951. this.editableHtml = html;
  952. this.previewHtml = html;
  953. this.$nextTick(() => {
  954. this.renderToCanvas();
  955. });
  956. }
  957. }
  958. };
  959. </script>
  960. <style scoped>
  961. * {
  962. margin: 0;
  963. padding: 0;
  964. box-sizing: border-box;
  965. }
  966. .app-container {
  967. max-width: 1400px;
  968. width: 100%;
  969. margin: 0 auto;
  970. padding: 24px 20px;
  971. min-height: 100vh;
  972. display: flex;
  973. justify-content: center;
  974. align-items: center;
  975. background: linear-gradient(145deg, #e0eafc 0%, #cfdef3 100%);
  976. }
  977. .tool-card {
  978. background: rgba(255, 255, 255, 0.92);
  979. backdrop-filter: blur(2px);
  980. border-radius: 2rem;
  981. box-shadow: 0 25px 45px -12px rgba(0, 0, 0, 0.3),
  982. 0 1px 2px rgba(0, 0, 0, 0.05);
  983. overflow: hidden;
  984. padding: 1.8rem 2rem 2rem 2rem;
  985. width: 100%;
  986. }
  987. h1 {
  988. font-size: 2rem;
  989. font-weight: 700;
  990. background: linear-gradient(135deg, #1a2a6c, #3b82f6, #8b5cf6);
  991. background-clip: text;
  992. -webkit-background-clip: text;
  993. color: transparent;
  994. letter-spacing: -0.3px;
  995. margin-bottom: 0.35rem;
  996. }
  997. .sub {
  998. color: #4a5568;
  999. border-left: 4px solid #3b82f6;
  1000. padding-left: 14px;
  1001. margin-bottom: 1.8rem;
  1002. font-weight: 500;
  1003. font-size: 0.95rem;
  1004. }
  1005. .converter-layout {
  1006. display: flex;
  1007. justify-content: center;
  1008. }
  1009. .editor-panel {
  1010. flex: 1.2;
  1011. min-width: 280px;
  1012. background: #f8fafc;
  1013. border-radius: 1.5rem;
  1014. padding: 1.25rem;
  1015. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  1016. border: 1px solid #e2e8f0;
  1017. }
  1018. .panel-title {
  1019. font-weight: 600;
  1020. font-size: 1.2rem;
  1021. color: #0f172a;
  1022. margin-bottom: 1rem;
  1023. display: flex;
  1024. align-items: center;
  1025. gap: 8px;
  1026. border-bottom: 2px solid #cbd5e1;
  1027. padding-bottom: 8px;
  1028. }
  1029. .html-editor {
  1030. width: 100%;
  1031. height: 360px;
  1032. background: #1e293b;
  1033. color: #e2e8f0;
  1034. font-family: 'Fira Code', 'Cascadia Code', monospace;
  1035. font-size: 13px;
  1036. line-height: 1.5;
  1037. padding: 1rem;
  1038. border-radius: 1rem;
  1039. border: none;
  1040. resize: vertical;
  1041. outline: none;
  1042. margin-bottom: 1rem;
  1043. box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
  1044. }
  1045. .html-editor:focus {
  1046. border: 1px solid #3b82f6;
  1047. background: #0f172a;
  1048. }
  1049. .toolbar {
  1050. display: flex;
  1051. gap: 12px;
  1052. flex-wrap: wrap;
  1053. margin-top: 8px;
  1054. margin-bottom: 16px;
  1055. }
  1056. button {
  1057. background: white;
  1058. border: 1px solid #cbd5e1;
  1059. padding: 8px 18px;
  1060. border-radius: 40px;
  1061. font-weight: 600;
  1062. font-size: 0.85rem;
  1063. cursor: pointer;
  1064. transition: 0.2s;
  1065. color: #1e293b;
  1066. display: inline-flex;
  1067. align-items: center;
  1068. gap: 6px;
  1069. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  1070. }
  1071. button.primary {
  1072. background: #3b82f6;
  1073. border-color: #3b82f6;
  1074. color: white;
  1075. box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
  1076. }
  1077. button.primary:hover {
  1078. background: #2563eb;
  1079. transform: translateY(-1px);
  1080. }
  1081. button.download {
  1082. background: #10b981;
  1083. border-color: #10b981;
  1084. color: white;
  1085. }
  1086. button.download:hover {
  1087. background: #059669;
  1088. transform: translateY(-1px);
  1089. }
  1090. button.pdf {
  1091. background: #8b5cf6;
  1092. border-color: #8b5cf6;
  1093. color: white;
  1094. }
  1095. button.pdf:hover {
  1096. background: #7c3aed;
  1097. transform: translateY(-1px);
  1098. }
  1099. button.print {
  1100. background: #8b5cf6;
  1101. border-color: #8b5cf6;
  1102. color: white;
  1103. }
  1104. button.print:hover {
  1105. background: #7c3aed;
  1106. transform: translateY(-1px);
  1107. }
  1108. .canvas-buttons {
  1109. display: flex;
  1110. gap: 12px;
  1111. justify-content: center;
  1112. margin-top: 16px;
  1113. }
  1114. button:hover {
  1115. background: #f1f5f9;
  1116. transform: translateY(-1px);
  1117. }
  1118. .info-message {
  1119. font-size: 0.8rem;
  1120. color: #2563eb;
  1121. background: #eff6ff;
  1122. padding: 6px 12px;
  1123. border-radius: 40px;
  1124. display: inline-block;
  1125. }
  1126. .preview-panel {
  1127. flex: 1;
  1128. min-width: 0;
  1129. background: #ffffff;
  1130. border-radius: 1.5rem;
  1131. padding: 1.25rem;
  1132. box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  1133. border: 1px solid #eef2ff;
  1134. display: flex;
  1135. flex-direction: column;
  1136. }
  1137. .images-panel {
  1138. flex: 0 0 300px;
  1139. background: #ffffff;
  1140. border-radius: 1.5rem;
  1141. padding: 1.25rem;
  1142. box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  1143. border: 1px solid #eef2ff;
  1144. display: flex;
  1145. flex-direction: column;
  1146. position: fixed;
  1147. right: 2rem;
  1148. top: 40px;
  1149. max-height: calc(100vh - 80px);
  1150. overflow-y: auto;
  1151. z-index: 100;
  1152. }
  1153. .seal-section {
  1154. margin-bottom: 1rem;
  1155. }
  1156. .seal-section:last-child {
  1157. margin-bottom: 0;
  1158. }
  1159. .no-data {
  1160. grid-column: 1 / -1;
  1161. text-align: center;
  1162. color: #94a3b8;
  1163. padding: 20px 0;
  1164. font-size: 14px;
  1165. }
  1166. .images-grid {
  1167. display: grid;
  1168. grid-template-columns: repeat(2, 1fr);
  1169. gap: 12px;
  1170. /* flex: 1; */
  1171. overflow-y: auto;
  1172. }
  1173. .drag-item {
  1174. background: #f8fafc;
  1175. border: 2px solid #e2e8f0;
  1176. border-radius: 12px;
  1177. padding: 8px;
  1178. cursor: move;
  1179. transition: all 0.2s;
  1180. display: flex;
  1181. flex-direction: column;
  1182. align-items: center;
  1183. height: 130px; /* 固定高度:图片80px + 内边距8px*2 + 文字区域 */
  1184. justify-content: space-between;
  1185. }
  1186. .drag-item:hover {
  1187. border-color: #3b82f6;
  1188. background: #eff6ff;
  1189. transform: translateY(-2px);
  1190. box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
  1191. }
  1192. .drag-item img {
  1193. width: 100%;
  1194. height: 80px;
  1195. object-fit: contain; /* 改为contain,确保完整显示图片 */
  1196. border-radius: 8px;
  1197. pointer-events: none;
  1198. background-color: #f1f5f9; /* 添加背景色,防止透明图片看不清 */
  1199. }
  1200. .drag-item-name {
  1201. font-size: 12px;
  1202. color: #64748b;
  1203. margin-top: 6px;
  1204. text-align: center;
  1205. overflow: hidden;
  1206. text-overflow: ellipsis;
  1207. white-space: nowrap;
  1208. width: 100%;
  1209. line-height: 1.4;
  1210. padding: 0 4px;
  1211. max-height: 32px; /* 限制文字最大高度 */
  1212. }
  1213. .preview-header {
  1214. display: flex;
  1215. justify-content: space-between;
  1216. align-items: baseline;
  1217. margin-bottom: 1rem;
  1218. flex-wrap: wrap;
  1219. }
  1220. .badge {
  1221. background: #e6f0ff;
  1222. padding: 4px 12px;
  1223. border-radius: 30px;
  1224. font-size: 0.75rem;
  1225. font-weight: 500;
  1226. color: #1e40af;
  1227. }
  1228. .canvas-area {
  1229. background: #f1f5f9;
  1230. border-radius: 1.2rem;
  1231. padding: 1rem;
  1232. text-align: center;
  1233. min-height: 280px;
  1234. }
  1235. .target-element {
  1236. background: white;
  1237. border-radius: 1rem;
  1238. padding: 1rem;
  1239. box-shadow: 0 6px 14px rgba(0, 0, 0, 0.05);
  1240. max-width: 100%;
  1241. overflow: auto;
  1242. }
  1243. hr {
  1244. margin: 0.8rem 0;
  1245. border-color: #e2e8f0;
  1246. }
  1247. .canvas-result {
  1248. margin-top: 1rem;
  1249. background: #ffffffd9;
  1250. border-radius: 1rem;
  1251. padding: 0.8rem;
  1252. text-align: center;
  1253. }
  1254. .canvas-result p {
  1255. font-size: 0.8rem;
  1256. color: #475569;
  1257. }
  1258. canvas {
  1259. border-radius: 12px;
  1260. box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
  1261. background: white;
  1262. }
  1263. footer {
  1264. margin-top: 1.5rem;
  1265. text-align: center;
  1266. font-size: 0.75rem;
  1267. color: #334155;
  1268. }
  1269. @media (max-width: 780px) {
  1270. .tool-card {
  1271. padding: 1rem;
  1272. }
  1273. .html-editor {
  1274. height: 260px;
  1275. }
  1276. .converter-layout {
  1277. justify-content: center;
  1278. /* flex-wrap: wrap;
  1279. padding-right: 0;
  1280. gap: 1rem; */
  1281. }
  1282. .images-panel {
  1283. position: relative;
  1284. right: auto;
  1285. top: auto;
  1286. width: 100%;
  1287. max-height: 300px; /* 在小屏幕下限制最大高度 */
  1288. order: 2; /* 在移动端将图片区域放在底部 */
  1289. margin-top: 1rem;
  1290. }
  1291. .drag-item {
  1292. height: 120px; /* 在小屏幕下稍微减小高度 */
  1293. }
  1294. .drag-item img {
  1295. height: 70px; /* 在小屏幕下减小图片高度 */
  1296. }
  1297. }
  1298. </style>