export-view.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. /**
  2. * 导出动画弹出框
  3. */
  4. class ExportView {
  5. constructor() {
  6. this.overlay = null;
  7. this.modal = null;
  8. this.previewImage = null;
  9. this.previewPlaceholder = null;
  10. this.cancelBtn = null;
  11. this.confirmBtn = null;
  12. this.floatingAIBtn = null;
  13. this.imageData = null;
  14. this.spritesheetCanvas = null;
  15. this.folderName = null;
  16. this.spritesheetLayout = null;
  17. this.replacedImageData = null;
  18. this.geminiOriginalImageData = null;
  19. this.originalSpritesheetData = null;
  20. this.skipPreviewUI = false;
  21. // 下载确认对话框相关
  22. this.downloadConfirmOverlay = null;
  23. this.downloadConfirmClose = null;
  24. this.downloadOptions = null;
  25. this.init();
  26. }
  27. init() {
  28. this.overlay = document.getElementById('exportOverlay');
  29. this.modal = document.getElementById('exportModal');
  30. this.previewImage = document.getElementById('previewImage');
  31. this.previewPlaceholder = document.getElementById('previewPlaceholder');
  32. this.cancelBtn = document.getElementById('exportCancelBtn');
  33. this.confirmBtn = document.getElementById('exportConfirmBtn');
  34. this.floatingAIBtn = document.getElementById('floatingAIBtn');
  35. // 下载确认对话框元素
  36. this.downloadConfirmOverlay = document.getElementById('downloadConfirmOverlay');
  37. this.downloadConfirmClose = document.getElementById('downloadConfirmClose');
  38. this.downloadOptions = document.querySelectorAll('.download-option');
  39. // 确保对话框初始状态是隐藏的
  40. if (this.downloadConfirmOverlay) {
  41. this.downloadConfirmOverlay.style.display = 'none';
  42. }
  43. // 加载VIP抠图价格
  44. this.loadVIPMattingPrice();
  45. this.bindEvents();
  46. // 初始时禁用确定按钮
  47. if (this.confirmBtn) {
  48. this.confirmBtn.disabled = true;
  49. }
  50. this.reset();
  51. }
  52. bindEvents() {
  53. // 取消按钮(右上角)
  54. this.cancelBtn?.addEventListener('click', () => {
  55. this.close();
  56. });
  57. // 取消按钮(底部操作栏)
  58. this.cancelBtnBottom?.addEventListener('click', () => {
  59. this.close();
  60. });
  61. // 确定按钮(下载)
  62. this.confirmBtn?.addEventListener('click', () => {
  63. this.handleConfirm();
  64. });
  65. // 悬浮AI按钮 - 打开AI生图界面
  66. this.floatingAIBtn?.addEventListener('click', () => {
  67. this.openAIGenerateView();
  68. });
  69. // 点击遮罩层关闭
  70. this.overlay?.addEventListener('click', (e) => {
  71. if (e.target === this.overlay) {
  72. this.close();
  73. }
  74. });
  75. // ESC键关闭 - 直接关闭整个界面
  76. document.addEventListener('keydown', (e) => {
  77. if (e.key === 'Escape') {
  78. this.hideDownloadConfirm();
  79. this.close();
  80. }
  81. });
  82. // 下载确认对话框事件 - 关闭时同时关闭整个界面
  83. this.downloadConfirmClose?.addEventListener('click', () => {
  84. this.hideDownloadConfirm();
  85. this.close();
  86. });
  87. // 点击遮罩层关闭下载确认对话框 - 同时关闭整个界面
  88. this.downloadConfirmOverlay?.addEventListener('click', (e) => {
  89. if (e.target === this.downloadConfirmOverlay) {
  90. this.hideDownloadConfirm();
  91. this.close();
  92. }
  93. });
  94. // 下载选项点击事件
  95. this.downloadOptions?.forEach(option => {
  96. option.addEventListener('click', () => {
  97. const downloadType = option.dataset.option;
  98. this.handleDownloadOption(downloadType);
  99. });
  100. });
  101. // 监听来自父窗口的消息
  102. window.addEventListener('message', (event) => {
  103. if (event.data && event.data.type === 'show-export-preview') {
  104. const skipPreview = !!event.data.skipPreviewUI;
  105. const directDownloadType = event.data.directDownloadType; // 直接下载类型
  106. this.reset();
  107. this.skipPreviewUI = skipPreview;
  108. this.directDownloadType = directDownloadType; // 存储直接下载类型
  109. this.prepareDirectPreview(event.data.imageUrl || event.data.imageData, event.data.fileName);
  110. } else if (event.data && event.data.type === 'generate-export-preview') {
  111. // console.log('[ExportView] 收到生成预览消息:', event.data);
  112. this.reset();
  113. this.skipPreviewUI = !!event.data.skipPreviewUI;
  114. this.folderName = event.data.folderName;
  115. this.generatePreview(event.data.folderName);
  116. }
  117. });
  118. }
  119. /**
  120. * 显示遮罩及弹窗元素
  121. */
  122. showOverlayUI() {
  123. if (this.overlay) {
  124. this.overlay.style.display = 'flex';
  125. }
  126. if (this.modal) {
  127. this.modal.style.display = 'block';
  128. }
  129. if (this.cancelBtn) {
  130. this.cancelBtn.style.display = 'block';
  131. }
  132. if (this.floatingAIBtn) {
  133. this.floatingAIBtn.style.display = 'block';
  134. }
  135. if (this.confirmBtn) {
  136. this.confirmBtn.style.display = 'block';
  137. }
  138. }
  139. /**
  140. * 加载图片
  141. * @param {string} src - 图片地址或base64
  142. * @returns {Promise<HTMLImageElement>}
  143. */
  144. loadImage(src) {
  145. return new Promise((resolve, reject) => {
  146. const img = new Image();
  147. img.crossOrigin = 'anonymous';
  148. img.onload = () => resolve(img);
  149. img.onerror = () => reject(new Error('无法加载图片'));
  150. img.src = src;
  151. });
  152. }
  153. /**
  154. * 生成预览图
  155. * @param {string} folderName - 文件夹名称
  156. */
  157. async generatePreview(folderName) {
  158. if (!folderName) {
  159. // console.warn('[ExportView] 没有提供文件夹名称');
  160. if (this.previewPlaceholder) {
  161. this.previewPlaceholder.textContent = '没有提供文件夹名称';
  162. }
  163. return;
  164. }
  165. // 重置状态(确保每次打开都是全新状态)
  166. this.reset();
  167. // 显示遮罩并重置预览区域
  168. if (!this.skipPreviewUI) {
  169. this.showOverlayUI();
  170. if (this.previewPlaceholder) {
  171. this.previewPlaceholder.style.display = 'flex';
  172. this.previewPlaceholder.classList.remove('hide');
  173. }
  174. if (this.previewImage) {
  175. this.previewImage.style.display = 'none';
  176. this.previewImage.classList.remove('show');
  177. }
  178. } else {
  179. if (this.overlay) {
  180. this.overlay.style.display = 'none';
  181. }
  182. if (this.modal) {
  183. this.modal.style.display = 'none';
  184. }
  185. }
  186. // 保存文件夹名称
  187. this.folderName = folderName;
  188. // 显示加载状态
  189. if (!this.skipPreviewUI) {
  190. if (this.previewPlaceholder) {
  191. this.previewPlaceholder.classList.remove('hide');
  192. }
  193. if (this.previewImage) {
  194. this.previewImage.classList.remove('show');
  195. }
  196. }
  197. try {
  198. // 获取当前登录用户名
  199. const username = this.getCurrentUsername();
  200. if (!username) {
  201. throw new Error('请先登录');
  202. }
  203. // 获取帧列表
  204. const encodedFolderName = encodeURIComponent(folderName);
  205. let apiUrl = `http://localhost:3000/api/frames/${encodedFolderName}`;
  206. if (username) {
  207. apiUrl += `?username=${encodeURIComponent(username)}`;
  208. }
  209. const response = await fetch(apiUrl);
  210. if (!response.ok) {
  211. // 服务端返回错误,解析错误信息并显示
  212. const errorMessage = await this.handleServerError(response, '无法获取帧列表');
  213. throw new Error(errorMessage);
  214. }
  215. const data = await response.json();
  216. const frameNumbers = data.frames || [];
  217. const fileNames = data.fileNames || [];
  218. if (frameNumbers.length === 0) {
  219. throw new Error('该文件夹中没有图片');
  220. }
  221. // 加载所有图片(使用正确的API路径)
  222. const images = [];
  223. for (let i = 0; i < frameNumbers.length; i++) {
  224. const frameNum = frameNumbers[i];
  225. // 使用API路径,从用户目录加载
  226. let imgSrc;
  227. if (fileNames[i]) {
  228. // 使用实际文件名
  229. const imagePath = `${folderName}/${fileNames[i]}`;
  230. imgSrc = `/api/disk/preview?username=${encodeURIComponent(username)}&path=${encodeURIComponent(imagePath)}`;
  231. } else {
  232. // 回退到使用帧号构造文件名
  233. const frameName = frameNum.toString().padStart(2, '0');
  234. const imagePath = `${folderName}/${frameName}.png`;
  235. imgSrc = `/api/disk/preview?username=${encodeURIComponent(username)}&path=${encodeURIComponent(imagePath)}`;
  236. }
  237. const img = await new Promise((resolve, reject) => {
  238. const image = new Image();
  239. image.crossOrigin = 'anonymous';
  240. image.onload = () => resolve(image);
  241. image.onerror = () => reject(new Error(`Failed to load image: ${imgSrc}`));
  242. image.src = imgSrc;
  243. });
  244. images.push({
  245. img: img,
  246. width: img.width,
  247. height: img.height,
  248. frameNum: frameNum
  249. });
  250. }
  251. // 计算布局(简化版,使用简单的网格布局)
  252. const frameWidth = images[0].width;
  253. const frameHeight = images[0].height;
  254. const cols = Math.ceil(Math.sqrt(images.length));
  255. const rows = Math.ceil(images.length / cols);
  256. // 创建 Canvas 并绘制
  257. const canvas = document.createElement('canvas');
  258. canvas.width = frameWidth * cols;
  259. canvas.height = frameHeight * rows;
  260. const ctx = canvas.getContext('2d');
  261. // 保存 canvas 和布局信息用于下载
  262. this.spritesheetCanvas = canvas;
  263. // 填充透明背景
  264. ctx.clearRect(0, 0, canvas.width, canvas.height);
  265. // 保存布局信息(用于生成 JSON)
  266. const layout = [];
  267. // 绘制所有图片
  268. images.forEach((item, index) => {
  269. const col = index % cols;
  270. const row = Math.floor(index / cols);
  271. const x = col * frameWidth;
  272. const y = row * frameHeight;
  273. ctx.drawImage(item.img, x, y);
  274. // 保存布局信息
  275. layout.push({
  276. x: x,
  277. y: y,
  278. width: item.width,
  279. height: item.height,
  280. frameNum: item.frameNum
  281. });
  282. });
  283. // 保存布局信息
  284. this.spritesheetLayout = {
  285. layout: layout,
  286. sheetWidth: canvas.width,
  287. sheetHeight: canvas.height
  288. };
  289. // 转换为 base64
  290. const imageUrl = await new Promise((resolve) => {
  291. canvas.toBlob((blob) => {
  292. const url = URL.createObjectURL(blob);
  293. resolve(url);
  294. }, 'image/png');
  295. });
  296. // 保存原始 spritesheet 的 base64 数据
  297. this.originalSpritesheetData = await new Promise((resolve) => {
  298. canvas.toBlob((blob) => {
  299. const reader = new FileReader();
  300. reader.onload = () => resolve(reader.result);
  301. reader.readAsDataURL(blob);
  302. }, 'image/png');
  303. });
  304. // 显示预览图
  305. this.showPreview(imageUrl);
  306. // 如果已经有参考图,显示替换按钮
  307. if (this.referenceImageData && this.replaceBtn) {
  308. this.replaceBtn.style.display = 'block';
  309. }
  310. // 预览图生成完成后,自动显示下载选项对话框
  311. setTimeout(() => {
  312. this.showDownloadConfirm();
  313. // 通知父窗口内容已准备好
  314. if (window.parent && window.parent !== window) {
  315. window.parent.postMessage({ type: 'export-view-ready' }, '*');
  316. }
  317. }, 300);
  318. } catch (error) {
  319. // console.error('[ExportView] 生成预览图失败:', error);
  320. if (this.previewPlaceholder) {
  321. // 隐藏加载动画,显示错误信息
  322. const spinner = this.previewPlaceholder.querySelector('.loading-spinner');
  323. const loadingText = this.previewPlaceholder.querySelector('.loading-text');
  324. if (spinner) spinner.style.display = 'none';
  325. if (loadingText) {
  326. loadingText.textContent = '生成预览图失败: ' + error.message;
  327. loadingText.style.color = '#ef4444';
  328. }
  329. this.previewPlaceholder.classList.remove('hide');
  330. }
  331. }
  332. }
  333. /**
  334. * 处理直接传入的图片预览(AI 历史等)
  335. * @param {string} imageUrl - 图片URL或base64
  336. * @param {string} fileName - 基础文件名
  337. */
  338. async prepareDirectPreview(imageUrl, fileName) {
  339. if (!imageUrl) {
  340. this.showAlert('没有可预览的图片');
  341. return;
  342. }
  343. try {
  344. if (!this.skipPreviewUI) {
  345. this.showOverlayUI();
  346. if (this.previewPlaceholder) {
  347. this.previewPlaceholder.style.display = 'flex';
  348. this.previewPlaceholder.classList.remove('hide');
  349. }
  350. }
  351. const img = await this.loadImage(imageUrl);
  352. const canvas = document.createElement('canvas');
  353. canvas.width = img.width;
  354. canvas.height = img.height;
  355. const ctx = canvas.getContext('2d');
  356. ctx.clearRect(0, 0, canvas.width, canvas.height);
  357. ctx.drawImage(img, 0, 0);
  358. this.spritesheetCanvas = canvas;
  359. this.spritesheetLayout = {
  360. layout: [{
  361. x: 0,
  362. y: 0,
  363. width: img.width,
  364. height: img.height,
  365. frameNum: 1
  366. }],
  367. sheetWidth: img.width,
  368. sheetHeight: img.height
  369. };
  370. const safeName = (fileName || 'ai-image').toString().replace(/[^a-zA-Z0-9_-]/g, '_') || 'ai-image';
  371. this.folderName = safeName;
  372. this.originalSpritesheetData = canvas.toDataURL('image/png');
  373. this.imageData = imageUrl;
  374. if (!this.skipPreviewUI) {
  375. if (this.previewImage) {
  376. this.previewImage.src = imageUrl;
  377. this.previewImage.style.display = 'block';
  378. this.previewImage.classList.add('show');
  379. }
  380. if (this.previewPlaceholder) {
  381. this.previewPlaceholder.style.display = 'none';
  382. this.previewPlaceholder.classList.add('hide');
  383. }
  384. }
  385. if (this.confirmBtn) {
  386. this.confirmBtn.disabled = false;
  387. }
  388. // 如果有直接下载类型,直接开始下载
  389. if (this.directDownloadType) {
  390. // 通知父窗口内容已准备好
  391. if (window.parent && window.parent !== window) {
  392. window.parent.postMessage({ type: 'export-view-ready' }, '*');
  393. }
  394. const delay = 50;
  395. setTimeout(() => this.handleDownloadOption(this.directDownloadType), delay);
  396. } else {
  397. const delay = this.skipPreviewUI ? 50 : 200;
  398. setTimeout(() => {
  399. this.showDownloadConfirm();
  400. // 通知父窗口内容已准备好
  401. if (window.parent && window.parent !== window) {
  402. window.parent.postMessage({ type: 'export-view-ready' }, '*');
  403. }
  404. }, delay);
  405. }
  406. } catch (error) {
  407. console.error('[ExportView] 处理直接预览失败:', error);
  408. this.showAlert(`加载预览失败: ${error.message}`);
  409. this.close();
  410. }
  411. }
  412. /**
  413. * 计算宽高比
  414. * @param {number} width - 宽度
  415. * @param {number} height - 高度
  416. * @returns {string} 宽高比字符串(例如:16:9)
  417. */
  418. calculateAspectRatio(width, height) {
  419. // 计算最大公约数
  420. const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
  421. const divisor = gcd(width, height);
  422. const ratioWidth = width / divisor;
  423. const ratioHeight = height / divisor;
  424. // 如果比例太大,使用简化版本
  425. if (ratioWidth > 100 || ratioHeight > 100) {
  426. // 使用小数形式
  427. const ratio = width / height;
  428. return ratio.toFixed(2) + ':1';
  429. }
  430. return `${ratioWidth}:${ratioHeight}`;
  431. }
  432. /**
  433. * 显示预览图(Spritesheet)- 简化版,不再显示预览界面
  434. * @param {string} imageUrl - 图片URL或base64数据
  435. */
  436. showPreview(imageUrl) {
  437. if (!imageUrl) {
  438. return;
  439. }
  440. // 保存图片数据
  441. this.imageData = imageUrl;
  442. }
  443. /**
  444. * 生成 JSON 数据
  445. * @param {string} folderName - 文件夹名称
  446. * @param {Array} layout - 布局信息数组
  447. * @param {number} sheetWidth - Spritesheet 宽度
  448. * @param {number} sheetHeight - Spritesheet 高度
  449. * @returns {string} JSON 字符串
  450. */
  451. generateJSON(folderName, layout, sheetWidth, sheetHeight) {
  452. const frames = {};
  453. layout.forEach((item, index) => {
  454. // 使用实际的帧号,确保与原始文件名一致
  455. const frameNum = item.frameNum ? item.frameNum.toString().padStart(2, '0') : (index + 1).toString().padStart(2, '0');
  456. const frameName = `${frameNum}.png`;
  457. const x = item.x;
  458. const y = item.y;
  459. const width = item.width;
  460. const height = item.height;
  461. // 标准的 TexturePacker JSON 格式,Cocos Creator 3.8 完全兼容
  462. frames[frameName] = {
  463. frame: {
  464. x: x,
  465. y: y,
  466. w: width,
  467. h: height
  468. },
  469. rotated: false,
  470. trimmed: false,
  471. spriteSourceSize: { x: 0, y: 0, w: width, h: height },
  472. sourceSize: { w: width, h: height }
  473. };
  474. });
  475. // Cocos Creator 3.8 兼容的 TexturePacker JSON 格式
  476. const json = {
  477. frames: frames,
  478. meta: {
  479. app: "https://www.codeandweb.com/texturepacker",
  480. version: "1.0",
  481. image: `${folderName}.png`,
  482. format: "RGBA8888",
  483. size: { w: sheetWidth, h: sheetHeight },
  484. scale: 1
  485. }
  486. };
  487. return JSON.stringify(json, null, 2);
  488. }
  489. /**
  490. * 将 Blob 转换为 Base64
  491. * @param {Blob} blob - Blob 对象
  492. * @returns {Promise<string>} Base64 字符串
  493. */
  494. blobToBase64(blob) {
  495. return new Promise((resolve, reject) => {
  496. const reader = new FileReader();
  497. reader.onloadend = () => {
  498. try {
  499. let base64 = reader.result;
  500. // 移除 data:image/png;base64, 前缀(如果存在)
  501. if (base64 && base64.includes(',')) {
  502. base64 = base64.split(',')[1];
  503. }
  504. if (!base64) {
  505. reject(new Error('Base64 转换失败:结果为空'));
  506. return;
  507. }
  508. resolve(base64);
  509. } catch (error) {
  510. reject(new Error(`Base64 转换失败: ${error.message}`));
  511. }
  512. };
  513. reader.onerror = () => {
  514. reject(new Error('文件读取失败'));
  515. };
  516. reader.readAsDataURL(blob);
  517. });
  518. }
  519. /**
  520. * 下载文件
  521. * @param {Blob} data - 文件数据
  522. * @param {string} filename - 文件名
  523. * @param {string} mimeType - MIME 类型
  524. */
  525. downloadFile(data, filename, mimeType) {
  526. const blob = new Blob([data], { type: mimeType });
  527. const url = URL.createObjectURL(blob);
  528. const a = document.createElement('a');
  529. a.href = url;
  530. a.download = filename;
  531. document.body.appendChild(a);
  532. a.click();
  533. document.body.removeChild(a);
  534. URL.revokeObjectURL(url);
  535. }
  536. /**
  537. * 显示下载确认对话框
  538. */
  539. showDownloadConfirm() {
  540. // 确保预览遮罩被隐藏,避免只看到一条空白横条
  541. if (this.overlay) {
  542. this.overlay.style.display = 'none';
  543. }
  544. if (this.modal) {
  545. this.modal.style.display = 'none';
  546. }
  547. if (this.downloadConfirmOverlay) {
  548. console.log('[ExportView] 显示下载确认对话框');
  549. // 确保价格已加载
  550. this.loadVIPMattingPrice();
  551. this.downloadConfirmOverlay.style.display = 'flex';
  552. } else {
  553. console.error('[ExportView] 下载确认对话框元素未找到');
  554. }
  555. }
  556. /**
  557. * 隐藏下载确认对话框
  558. */
  559. hideDownloadConfirm() {
  560. if (this.downloadConfirmOverlay) {
  561. this.downloadConfirmOverlay.style.display = 'none';
  562. }
  563. }
  564. /**
  565. * 打开AI生图界面
  566. */
  567. openAIGenerateView() {
  568. if (!this.originalSpritesheetData) {
  569. this.showAlert('请先生成预览图');
  570. return;
  571. }
  572. // 通知父窗口打开AI生图界面
  573. if (window.parent && window.parent !== window) {
  574. window.parent.postMessage({
  575. type: 'open-ai-generate-view',
  576. folderName: this.folderName,
  577. spritesheetData: this.originalSpritesheetData,
  578. spritesheetLayout: this.spritesheetLayout
  579. }, '*');
  580. }
  581. }
  582. /**
  583. * 处理下载选项选择
  584. * @param {string} downloadType - 下载类型:'original', 'normal', 'vip'
  585. */
  586. async handleDownloadOption(downloadType) {
  587. // 如果是VIP抠图,先检查用户Ani币是否足够
  588. if (downloadType === 'vip') {
  589. const username = this.getCurrentUsername();
  590. if (!username) {
  591. this.showAlert('请先登录');
  592. return;
  593. }
  594. try {
  595. // 获取VIP抠图价格
  596. const pricingResponse = await fetch('/api/product-pricing');
  597. if (!pricingResponse.ok) {
  598. throw new Error('获取价格失败');
  599. }
  600. const pricingResult = await pricingResponse.json();
  601. if (!pricingResult.success || !pricingResult.products) {
  602. throw new Error('获取价格失败');
  603. }
  604. const vipMattingProduct = pricingResult.products.find(p => p.id === 'vip-matting');
  605. const price = vipMattingProduct ? (vipMattingProduct.price || 0) : 0;
  606. // 如果价格为0,直接继续
  607. if (price === 0) {
  608. // 继续执行VIP抠图流程
  609. } else {
  610. // 检查用户点数
  611. const pointsResponse = await fetch(`/api/user/points?username=${encodeURIComponent(username)}`);
  612. if (!pointsResponse.ok) {
  613. throw new Error('获取点数失败');
  614. }
  615. const pointsResult = await pointsResponse.json();
  616. if (!pointsResult.success) {
  617. throw new Error('获取点数失败');
  618. }
  619. const userPoints = pointsResult.points || 0;
  620. if (userPoints < price) {
  621. // 点数不足,弹出充值界面
  622. if (window.parent && window.parent !== window) {
  623. window.parent.postMessage({
  624. type: 'open-recharge-view',
  625. needPoints: price,
  626. currentPoints: userPoints
  627. }, '*');
  628. }
  629. this.hideDownloadConfirm();
  630. return;
  631. }
  632. // 点数充足,弹出确认对话框
  633. let confirmed = false;
  634. if (window.parent && window.parent.GlobalConfirm) {
  635. confirmed = await window.parent.GlobalConfirm.show(
  636. `确定要花费 ${price} Ani币使用VIP抠图吗?`
  637. );
  638. } else {
  639. confirmed = confirm(`确定要花费 ${price} Ani币使用VIP抠图吗?`);
  640. }
  641. if (!confirmed) {
  642. return;
  643. }
  644. // 扣除点数
  645. const deductResponse = await fetch('/api/user/deduct-points', {
  646. method: 'POST',
  647. headers: {
  648. 'Content-Type': 'application/json'
  649. },
  650. body: JSON.stringify({
  651. username: username,
  652. points: price
  653. })
  654. });
  655. if (!deductResponse.ok) {
  656. const deductResult = await deductResponse.json();
  657. throw new Error(deductResult.message || '扣除点数失败');
  658. }
  659. const deductResult = await deductResponse.json();
  660. if (!deductResult.success) {
  661. throw new Error(deductResult.message || '扣除点数失败');
  662. }
  663. // 通知父窗口刷新点数
  664. if (window.parent && window.parent !== window) {
  665. window.parent.postMessage({ type: 'refresh-points' }, '*');
  666. }
  667. }
  668. // VIP抠图:提交到队列,显示飞走动画
  669. await this.submitVIPMattingToQueue(username);
  670. return; // 直接返回,不继续执行后续的即时处理逻辑
  671. } catch (error) {
  672. console.error('[ExportView] VIP抠图购买检查失败:', error);
  673. this.showAlert(error.message || '操作失败,请稍后重试');
  674. return;
  675. }
  676. }
  677. this.hideDownloadConfirm();
  678. try {
  679. // 显示加载状态(但不隐藏预览图片)
  680. // 使用全局 Loading 提示,不干扰预览图显示
  681. if (window.parent && window.parent.postMessage) {
  682. window.parent.postMessage({
  683. type: 'global-loading',
  684. action: 'show',
  685. text: downloadType === 'original' ? '正在准备下载...' : '正在处理图片...'
  686. }, '*');
  687. }
  688. let processedImageBase64;
  689. // 确定使用的图片源
  690. if (this.geminiOriginalImageData) {
  691. // 如果有 Gemini 图片,使用 Gemini 图片
  692. const geminiImageBase64 = this.geminiOriginalImageData.replace(/^data:image\/\w+;base64,/, '');
  693. if (downloadType === 'original') {
  694. // 源文件下载:直接使用原始图片
  695. processedImageBase64 = geminiImageBase64;
  696. } else if (downloadType === 'normal') {
  697. // 普通抠图:调用 rembg-matting.py
  698. const response = await fetch('http://localhost:3000/api/matting-normal', {
  699. method: 'POST',
  700. headers: {
  701. 'Content-Type': 'application/json'
  702. },
  703. body: JSON.stringify({
  704. imageBase64: geminiImageBase64
  705. })
  706. });
  707. if (!response.ok) {
  708. const errorMessage = await this.handleServerError(response, '普通抠图失败');
  709. throw new Error(errorMessage);
  710. }
  711. const result = await response.json();
  712. if (!result.success || !result.imageData) {
  713. throw new Error('普通抠图处理失败');
  714. }
  715. processedImageBase64 = result.imageData;
  716. } else if (downloadType === 'vip') {
  717. // VIP抠图:调用 BiRefNet
  718. const response = await fetch('http://localhost:3000/api/matting-vip', {
  719. method: 'POST',
  720. headers: {
  721. 'Content-Type': 'application/json'
  722. },
  723. body: JSON.stringify({
  724. imageBase64: geminiImageBase64
  725. })
  726. });
  727. if (!response.ok) {
  728. const errorMessage = await this.handleServerError(response, 'VIP抠图失败');
  729. throw new Error(errorMessage);
  730. }
  731. const result = await response.json();
  732. if (!result.success || !result.imageData) {
  733. throw new Error('VIP抠图处理失败');
  734. }
  735. processedImageBase64 = result.imageData;
  736. }
  737. } else {
  738. // 如果没有 Gemini 图片,使用原始 spritesheet
  739. const imageBlob = await new Promise((resolve, reject) => {
  740. this.spritesheetCanvas.toBlob((blob) => {
  741. if (blob) {
  742. resolve(blob);
  743. } else {
  744. reject(new Error('Canvas 转换失败'));
  745. }
  746. }, 'image/png');
  747. });
  748. // 将图片转换为 Base64
  749. const originalImageBase64 = await this.blobToBase64(imageBlob);
  750. if (downloadType === 'original') {
  751. // 源文件下载:直接使用原始 spritesheet
  752. processedImageBase64 = originalImageBase64;
  753. } else if (downloadType === 'normal') {
  754. // 普通抠图:对原始 spritesheet 进行抠图
  755. const response = await fetch('http://localhost:3000/api/matting-normal', {
  756. method: 'POST',
  757. headers: {
  758. 'Content-Type': 'application/json'
  759. },
  760. body: JSON.stringify({
  761. imageBase64: originalImageBase64
  762. })
  763. });
  764. if (!response.ok) {
  765. const errorMessage = await this.handleServerError(response, '普通抠图失败');
  766. throw new Error(errorMessage);
  767. }
  768. const result = await response.json();
  769. if (!result.success || !result.imageData) {
  770. throw new Error('普通抠图处理失败');
  771. }
  772. processedImageBase64 = result.imageData;
  773. } else if (downloadType === 'vip') {
  774. // VIP抠图:对原始 spritesheet 进行 VIP 抠图
  775. const response = await fetch('http://localhost:3000/api/matting-vip', {
  776. method: 'POST',
  777. headers: {
  778. 'Content-Type': 'application/json'
  779. },
  780. body: JSON.stringify({
  781. imageBase64: originalImageBase64
  782. })
  783. });
  784. if (!response.ok) {
  785. const errorMessage = await this.handleServerError(response, 'VIP抠图失败');
  786. throw new Error(errorMessage);
  787. }
  788. const result = await response.json();
  789. if (!result.success || !result.imageData) {
  790. throw new Error('VIP抠图处理失败');
  791. }
  792. processedImageBase64 = result.imageData;
  793. }
  794. }
  795. // 生成 JSON 数据
  796. const folderName = this.folderName.split('/').pop() || 'spritesheet';
  797. const jsonData = this.generateJSON(
  798. folderName,
  799. this.spritesheetLayout.layout,
  800. this.spritesheetLayout.sheetWidth,
  801. this.spritesheetLayout.sheetHeight
  802. );
  803. // 发送到服务器打包
  804. const response = await fetch('http://localhost:3000/api/pack', {
  805. method: 'POST',
  806. headers: {
  807. 'Content-Type': 'application/json'
  808. },
  809. body: JSON.stringify({
  810. folderName: folderName,
  811. imageData: processedImageBase64,
  812. jsonData: jsonData
  813. })
  814. });
  815. if (!response.ok) {
  816. const errorMessage = await this.handleServerError(response, '打包失败');
  817. throw new Error(errorMessage);
  818. }
  819. // 获取 ZIP 文件的 Blob
  820. const zipBlob = await response.blob();
  821. // 下载 ZIP 文件
  822. this.downloadFile(zipBlob, `${folderName}.zip`, 'application/zip');
  823. // 隐藏全局 Loading 提示
  824. if (window.parent && window.parent.postMessage) {
  825. window.parent.postMessage({
  826. type: 'global-loading',
  827. action: 'hide'
  828. }, '*');
  829. }
  830. // 下载完成后,不关闭弹出框,不刷新图片
  831. // 显示成功提示
  832. this.showAlert('下载成功!');
  833. } catch (error) {
  834. // console.error('[ExportView] 下载失败:', error);
  835. // 隐藏全局 Loading 提示
  836. if (window.parent && window.parent.postMessage) {
  837. window.parent.postMessage({
  838. type: 'global-loading',
  839. action: 'hide'
  840. }, '*');
  841. }
  842. this.showAlert(`下载失败: ${error.message}`);
  843. }
  844. }
  845. /**
  846. * 处理下载按钮点击
  847. */
  848. async handleConfirm() {
  849. // console.log('[ExportView] 用户点击下载按钮');
  850. if (!this.spritesheetCanvas || !this.spritesheetLayout) {
  851. // console.warn('[ExportView] 没有可下载的 Spritesheet');
  852. return;
  853. }
  854. // 总是显示下载确认对话框,让用户选择下载方式
  855. console.log('[ExportView] 显示下载选项对话框');
  856. this.showDownloadConfirm();
  857. }
  858. /**
  859. * 下载 Spritesheet(原始逻辑)
  860. */
  861. async downloadSpritesheet() {
  862. try {
  863. // 生成 JSON 数据
  864. const folderName = this.folderName.split('/').pop() || 'spritesheet';
  865. const jsonData = this.generateJSON(
  866. folderName,
  867. this.spritesheetLayout.layout,
  868. this.spritesheetLayout.sheetWidth,
  869. this.spritesheetLayout.sheetHeight
  870. );
  871. // 确定使用哪个图片:如果有替换后的图片,使用替换后的;否则使用原始的
  872. let imageBase64;
  873. if (this.replacedImageData) {
  874. // 使用替换后的图片(移除 data:image/png;base64, 前缀)
  875. imageBase64 = this.replacedImageData.replace(/^data:image\/\w+;base64,/, '');
  876. } else {
  877. // 使用原始 spritesheet
  878. const imageBlob = await new Promise((resolve, reject) => {
  879. this.spritesheetCanvas.toBlob((blob) => {
  880. if (blob) {
  881. resolve(blob);
  882. } else {
  883. reject(new Error('Canvas 转换失败'));
  884. }
  885. }, 'image/png');
  886. });
  887. // 将图片转换为 Base64
  888. imageBase64 = await this.blobToBase64(imageBlob);
  889. }
  890. // 验证数据
  891. if (!imageBase64 || typeof imageBase64 !== 'string' || imageBase64.trim().length === 0) {
  892. throw new Error('图片数据无效');
  893. }
  894. if (!jsonData || typeof jsonData !== 'string' || jsonData.trim().length === 0) {
  895. throw new Error('JSON 数据无效');
  896. }
  897. // 发送到服务器打包
  898. const response = await fetch('http://localhost:3000/api/pack', {
  899. method: 'POST',
  900. headers: {
  901. 'Content-Type': 'application/json'
  902. },
  903. body: JSON.stringify({
  904. folderName: folderName,
  905. imageData: imageBase64,
  906. jsonData: jsonData
  907. })
  908. });
  909. if (!response.ok) {
  910. const errorMessage = await this.handleServerError(response, '打包失败');
  911. throw new Error(errorMessage);
  912. }
  913. // 获取 ZIP 文件的 Blob
  914. const zipBlob = await response.blob();
  915. // 下载 ZIP 文件
  916. this.downloadFile(zipBlob, `${folderName}.zip`, 'application/zip');
  917. // 下载完成后,不关闭弹出框,不刷新图片
  918. // 显示成功提示
  919. this.showAlert('下载成功!');
  920. } catch (error) {
  921. // console.error('[ExportView] 下载失败:', error);
  922. this.showAlert(`下载失败: ${error.message}`);
  923. }
  924. }
  925. /**
  926. * 关闭弹出框
  927. */
  928. close() {
  929. // console.log('[ExportView] 关闭导出弹出框');
  930. // 清空所有数据
  931. this.reset();
  932. // 隐藏界面元素
  933. if (this.overlay) {
  934. this.overlay.style.display = 'none';
  935. }
  936. if (this.modal) {
  937. this.modal.style.display = 'none';
  938. }
  939. this.hideDownloadConfirm();
  940. // 通知父窗口关闭弹出框
  941. if (window.parent && window.parent !== window) {
  942. window.parent.postMessage({
  943. type: 'close-export-view'
  944. }, '*');
  945. }
  946. }
  947. /**
  948. * 获取当前登录用户名
  949. */
  950. getCurrentUsername() {
  951. try {
  952. const loginDataStr = localStorage.getItem('loginData');
  953. if (!loginDataStr) {
  954. return null;
  955. }
  956. const loginData = JSON.parse(loginDataStr);
  957. const now = Date.now();
  958. // 检查是否过期
  959. if (now >= loginData.expireTime) {
  960. localStorage.removeItem('loginData');
  961. return null;
  962. }
  963. return loginData.user ? loginData.user.username : null;
  964. } catch (error) {
  965. console.error('[ExportView] 获取用户名失败:', error);
  966. return null;
  967. }
  968. }
  969. /**
  970. * 重置所有数据和UI状态
  971. */
  972. reset() {
  973. // 清空数据属性
  974. this.imageData = null;
  975. this.spritesheetCanvas = null;
  976. this.folderName = null;
  977. this.spritesheetLayout = null;
  978. this.replacedImageData = null;
  979. this.geminiOriginalImageData = null;
  980. this.originalSpritesheetData = null;
  981. this.skipPreviewUI = false;
  982. this.directDownloadType = null;
  983. // 重置AI按钮状态
  984. if (this.floatingAIBtn) {
  985. this.floatingAIBtn.disabled = true;
  986. }
  987. // 重置预览图区域
  988. if (this.previewImage) {
  989. this.previewImage.src = '';
  990. this.previewImage.classList.remove('show');
  991. }
  992. if (this.previewPlaceholder) {
  993. const spinner = this.previewPlaceholder.querySelector('.loading-spinner');
  994. const loadingText = this.previewPlaceholder.querySelector('.loading-text');
  995. if (spinner) spinner.style.display = 'block';
  996. if (loadingText) {
  997. loadingText.textContent = '正在生成预览图...';
  998. loadingText.style.color = '#6b7280';
  999. }
  1000. this.previewPlaceholder.classList.remove('hide');
  1001. }
  1002. // 重置按钮状态
  1003. if (this.confirmBtn) {
  1004. this.confirmBtn.disabled = true;
  1005. }
  1006. }
  1007. /**
  1008. * 加载VIP抠图价格
  1009. */
  1010. async loadVIPMattingPrice() {
  1011. try {
  1012. const response = await fetch('/api/product-pricing');
  1013. if (response.ok) {
  1014. const result = await response.json();
  1015. if (result.success && result.products) {
  1016. const vipMattingProduct = result.products.find(p => p.id === 'vip-matting');
  1017. const priceEl = document.getElementById('vipMattingPrice');
  1018. if (vipMattingProduct && priceEl) {
  1019. const price = vipMattingProduct.price || 0;
  1020. if (price > 0) {
  1021. priceEl.textContent = `${price} Ani币`;
  1022. } else {
  1023. priceEl.textContent = '免费';
  1024. }
  1025. }
  1026. }
  1027. }
  1028. } catch (error) {
  1029. console.error('[ExportView] 加载VIP抠图价格失败:', error);
  1030. const priceEl = document.getElementById('vipMattingPrice');
  1031. if (priceEl) {
  1032. priceEl.textContent = '-';
  1033. }
  1034. }
  1035. }
  1036. /**
  1037. * 提交VIP抠图任务到队列
  1038. * @param {string} username - 用户名
  1039. */
  1040. async submitVIPMattingToQueue(username) {
  1041. try {
  1042. // 准备图片数据
  1043. let imageBase64;
  1044. if (this.geminiOriginalImageData) {
  1045. imageBase64 = this.geminiOriginalImageData.replace(/^data:image\/\w+;base64,/, '');
  1046. } else if (this.spritesheetCanvas) {
  1047. const imageBlob = await new Promise((resolve, reject) => {
  1048. this.spritesheetCanvas.toBlob((blob) => {
  1049. if (blob) {
  1050. resolve(blob);
  1051. } else {
  1052. reject(new Error('Canvas 转换失败'));
  1053. }
  1054. }, 'image/png');
  1055. });
  1056. imageBase64 = await this.blobToBase64(imageBlob);
  1057. } else {
  1058. throw new Error('没有可处理的图片');
  1059. }
  1060. // 获取文件名
  1061. const folderName = this.folderName ? this.folderName.split('/').pop() : 'vip-matting';
  1062. // 提交到VIP抠图队列API
  1063. const response = await fetch('/api/vip-matting/queue', {
  1064. method: 'POST',
  1065. headers: { 'Content-Type': 'application/json' },
  1066. body: JSON.stringify({
  1067. username: username,
  1068. imageBase64: imageBase64,
  1069. fileName: folderName,
  1070. jsonData: this.spritesheetLayout ? this.generateJSON(
  1071. folderName,
  1072. this.spritesheetLayout.layout,
  1073. this.spritesheetLayout.sheetWidth,
  1074. this.spritesheetLayout.sheetHeight
  1075. ) : null
  1076. })
  1077. });
  1078. if (!response.ok) {
  1079. const errorData = await response.json().catch(() => ({}));
  1080. throw new Error(errorData.message || 'VIP抠图任务提交失败');
  1081. }
  1082. const result = await response.json();
  1083. if (result.success && result.taskId) {
  1084. // 隐藏对话框
  1085. this.hideDownloadConfirm();
  1086. // 显示飞走动画
  1087. this.showVIPMattingFlyAnimation();
  1088. // 通知父窗口刷新任务历史
  1089. if (window.parent && window.parent !== window) {
  1090. window.parent.postMessage({ type: 'refresh-ai-history' }, '*');
  1091. }
  1092. // 关闭导出视图
  1093. setTimeout(() => {
  1094. this.close();
  1095. }, 500);
  1096. } else {
  1097. throw new Error(result.message || 'VIP抠图任务提交失败');
  1098. }
  1099. } catch (error) {
  1100. console.error('[ExportView] VIP抠图队列提交失败:', error);
  1101. this.showAlert(error.message || 'VIP抠图任务提交失败,请稍后重试');
  1102. }
  1103. }
  1104. /**
  1105. * 显示VIP抠图飞走动画
  1106. */
  1107. showVIPMattingFlyAnimation() {
  1108. let targetDocument = document;
  1109. let targetWindow = window;
  1110. try {
  1111. if (window.parent && window.parent !== window && window.parent.document) {
  1112. targetDocument = window.parent.document;
  1113. targetWindow = window.parent;
  1114. }
  1115. } catch (e) {}
  1116. const flyElement = targetDocument.createElement('div');
  1117. flyElement.innerHTML = `
  1118. <div style="display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; white-space: nowrap;">
  1119. <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  1120. <path d="M12 2L15.09 8.26L22 9.27L17 14.14L18.18 21.02L12 17.77L5.82 21.02L7 14.14L2 9.27L8.91 8.26L12 2Z"/>
  1121. </svg>
  1122. <span>VIP抠图任务</span>
  1123. </div>
  1124. `;
  1125. let startLeft = targetWindow.innerWidth / 2;
  1126. let startTop = targetWindow.innerHeight / 2;
  1127. flyElement.style.cssText = `
  1128. position: fixed;
  1129. left: ${startLeft}px;
  1130. top: ${startTop}px;
  1131. z-index: 999999;
  1132. pointer-events: none;
  1133. transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  1134. opacity: 1;
  1135. transform: scale(1);
  1136. background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  1137. color: white;
  1138. padding: 12px 20px;
  1139. border-radius: 12px;
  1140. box-shadow: 0 8px 32px rgba(139, 92, 246, 0.4);
  1141. display: flex;
  1142. align-items: center;
  1143. gap: 8px;
  1144. `;
  1145. targetDocument.body.appendChild(flyElement);
  1146. requestAnimationFrame(() => {
  1147. flyElement.style.left = `${targetWindow.innerWidth - 100}px`;
  1148. flyElement.style.top = '50px';
  1149. flyElement.style.opacity = '0';
  1150. flyElement.style.transform = 'scale(0.3)';
  1151. });
  1152. setTimeout(() => {
  1153. if (window.parent && window.parent.HintView) {
  1154. window.parent.HintView.success('VIP抠图任务已添加到「我的」-「任务历史」,请稍后查看', 3000);
  1155. }
  1156. }, 300);
  1157. setTimeout(() => {
  1158. if (flyElement.parentNode) {
  1159. flyElement.parentNode.removeChild(flyElement);
  1160. }
  1161. }, 1000);
  1162. }
  1163. /**
  1164. * 显示提示信息(使用全局 Alert 组件,直接调用)
  1165. * @param {string} message - 提示信息
  1166. * @param {number} duration - 显示时长(毫秒),默认2000
  1167. */
  1168. showAlert(message, duration = 2000) {
  1169. // 直接调用父窗口的 GlobalAlert(不通过 postMessage)
  1170. try {
  1171. // 优先使用父窗口的 GlobalAlert
  1172. if (window.parent && window.parent !== window && window.parent.GlobalAlert) {
  1173. window.parent.GlobalAlert.show(message, duration);
  1174. return;
  1175. }
  1176. // 如果不在 iframe 中,直接使用当前窗口的 GlobalAlert
  1177. if (window.GlobalAlert) {
  1178. window.GlobalAlert.show(message, duration);
  1179. return;
  1180. }
  1181. // 降级处理
  1182. console.log('[Alert]', message);
  1183. } catch (error) {
  1184. console.error('[ExportView] 显示 alert 失败:', error);
  1185. alert(message);
  1186. }
  1187. }
  1188. // 统一的错误处理函数:解析服务端错误响应并显示
  1189. async handleServerError(response, defaultMessage = '操作失败') {
  1190. let errorMessage = defaultMessage;
  1191. try {
  1192. // 尝试解析 JSON 错误响应
  1193. const errorData = await response.json().catch(() => null);
  1194. if (errorData) {
  1195. // 优先使用服务端返回的 message
  1196. if (errorData.message) {
  1197. errorMessage = errorData.message;
  1198. } else if (errorData.error) {
  1199. errorMessage = errorData.error;
  1200. } else if (typeof errorData === 'string') {
  1201. errorMessage = errorData;
  1202. }
  1203. }
  1204. } catch (e) {
  1205. // 如果解析失败,使用默认消息或状态码
  1206. if (response.status) {
  1207. errorMessage = `${defaultMessage} (状态码: ${response.status})`;
  1208. }
  1209. }
  1210. this.showAlert(errorMessage);
  1211. return errorMessage;
  1212. }
  1213. }
  1214. // 初始化
  1215. window.ExportView = new ExportView();