download.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. import { cdn, upCdn } from '@/services/api';
  2. import { checkData } from '@/services/utils';
  3. import axios from 'axios';
  4. // import { MessagePlugin } from 'tdesign-vue-next';
  5. import { useUser } from '@/services/user';
  6. import JSZip from 'jszip';
  7. import { Pen, getGlobalColor, isShowChild } from '@meta2d/core';
  8. export const img_cdn = 'https://assets.le5lecdn.com';
  9. export const img_upCdn = 'https://drive.le5lecdn.com';
  10. const { user, signout } = useUser();
  11. const components = [
  12. 'inputDom',
  13. 'selectDom',
  14. 'menuDom',
  15. 'headMenuDom',
  16. 'sliderVerifyDom',
  17. 'dropdownDom',
  18. 'flvPlayerDom',
  19. 'countdown',
  20. 'swiperDom',
  21. 'threeDSence',
  22. 'rtspPlayerDom',
  23. 'timeline',
  24. 'swiperline',
  25. 'tab',
  26. 'radio',
  27. 'checkbox',
  28. 'calendar',
  29. 'indicator',
  30. 'progress',
  31. 'pagination',
  32. 'steps',
  33. 'notification',
  34. 'list',
  35. 'tree',
  36. 'rockerSwitch',
  37. 'roundSwitch',
  38. 'breadcrumb',
  39. 'transferSwitch',
  40. 'pie3D',
  41. 'hikVideo',
  42. 'thermometer',
  43. 'watermeter',
  44. 'indicatorLight',
  45. 'toggleSwitch',
  46. 'knifeSwitch',
  47. 'compass',
  48. 'thermometer1',
  49. 'airSwitch',
  50. 'waterTank',
  51. ];
  52. export const getDownloadList = (meta2dData: any, path: string = 'v') => {
  53. const lists = new Set();
  54. //TODO 加一个type区分是数据/还是接口
  55. //背景图片
  56. // const meta2dData = meta2d.data();
  57. let img = meta2dData.bkImage;
  58. if (img) {
  59. if (
  60. img.startsWith('/') ||
  61. img.startsWith(img_cdn) ||
  62. img.startsWith(img_upCdn)
  63. ) {
  64. let _img = img.replace(img_cdn, '').replace(img_upCdn, '');
  65. if (_img.startsWith('/v/')) {
  66. _img = _img.slice(2);
  67. }
  68. lists.add({
  69. url: img,
  70. path: `/view/projects/assets` + _img,
  71. });
  72. meta2dData.bkImage = `/view/projects/assets` + _img;
  73. }
  74. }
  75. //图片图元(image strokeImage backgroundImage)
  76. const imageKeys = ['image', 'strokeImage', 'backgroundImage'];
  77. const images: string[] = [];
  78. for (const pen of meta2dData.pens) {
  79. for (const i of imageKeys) {
  80. const image = pen[i];
  81. if (image) {
  82. if (
  83. image.startsWith('/') ||
  84. image.startsWith(img_cdn) ||
  85. image.startsWith(img_upCdn)
  86. ) {
  87. // 只考虑相对路径下的 image ,绝对路径图片无需下载
  88. let _img = image.replace(img_cdn, '').replace(img_upCdn, '');
  89. if (_img.startsWith('/v/')) {
  90. _img = _img.slice(2);
  91. }
  92. if (!images.includes(image)) {
  93. // let _img = image.replace(cdn, '').replace(upCdn, '');
  94. lists.add({
  95. url: image,
  96. path: `/view/projects/assets` + _img,
  97. });
  98. }
  99. pen[i] = `/view/projects/assets` + _img;
  100. }
  101. }
  102. }
  103. }
  104. if(path === 'v'){ //iframe嵌入的页面无需再次下载
  105. //其他文件
  106. const files = [
  107. '/view/assets/index.js',
  108. '/view/assets/index.css',
  109. '/view/css/index.css',
  110. '/view/css/t/font_2395018_nng9x1qhat.css',
  111. '/view/css/t/font_2073009_teagntehxt.css',
  112. '/view/js/marked.min.js',
  113. '/view/js/echarts.min.js',
  114. '/view/js/lcjs.iife.js',
  115. '/view/js/highcharts.js',
  116. '/view/js/highcharts-more.js',
  117. '/view/js/r.js',
  118. '/view/index.html',
  119. '/view/favicon.ico',
  120. '/view/view.conf',
  121. '/view/离线部署包使用说明.pdf',
  122. '/view/assets/cloudy.env',
  123. '/view/assets/default.env',
  124. '/view/assets/dusk.env',
  125. '/view/assets/night.env',
  126. '/view/assets/sunny.env',
  127. '/view/assets/cloudy.jpg',
  128. '/view/assets/dusk.jpg',
  129. '/view/assets/night.jpg',
  130. '/view/assets/sunny.jpg',
  131. '/view/assets/luopan.png',
  132. '/view/assets/Rain.png',
  133. '/view/assets/zhizhen.png',
  134. '/view/assets/默认环境光.png',
  135. '/view/assets/draco_decoder_gltf.js',
  136. '/view/assets/draco_wasm_wrapper_gltf.js',
  137. '/view/assets/draco_decoder_gltf.wasm',
  138. ];
  139. files.forEach((file) => {
  140. lists.add({
  141. url: (cdn ? cdn : '') + file,
  142. path: file,
  143. });
  144. });
  145. }
  146. //数据
  147. // const data: any = meta2d.data();
  148. if (meta2dData._id) delete meta2dData._id;
  149. if (meta2dData.id) delete meta2dData.id;
  150. if ((meta2dData as any).image) delete (meta2dData as any).image;
  151. checkData(meta2dData);
  152. lists.add({
  153. data: JSON.stringify(meta2dData)
  154. .replaceAll(img_cdn, '')
  155. .replaceAll(img_upCdn, ''),
  156. path: `/view/projects/${path}`,
  157. });
  158. return lists;
  159. };
  160. export const getPayList = (meta2dData: any) => {
  161. const pngs = new Set<string>();
  162. const jsPens = new Set<string>();
  163. const iotPens = new Set<string>();
  164. const svgPens = new Set<string>();
  165. for (const pen of meta2dData.pens) {
  166. if (pen.image) {
  167. if (
  168. pen.image.startsWith(`${img_cdn}/png/`) ||
  169. pen.image.startsWith('/png/')
  170. ) {
  171. pngs.add(pen.image.replace(img_cdn, ''));
  172. }
  173. } else if (pen.subClassName && pen.fullname) {
  174. if(!['箭头','拓扑图未分类','工具'].includes(pen.subClassName)){
  175. jsPens.add(pen.name);
  176. }
  177. } else if (components.includes(pen.name)) {
  178. iotPens.add(pen.name);
  179. } else if (pen.svgUrl) {
  180. if (
  181. pen.svgUrl.startsWith(`${img_cdn}/svg/`) ||
  182. pen.svgUrl.startsWith('/svg/')
  183. ) {
  184. svgPens.add(pen.svgUrl.replace(img_cdn, ''));
  185. }
  186. }
  187. }
  188. if (![...svgPens].length) {
  189. //判断是否为老数据
  190. if (meta2dData.paths) {
  191. let keys = [];
  192. for (let key of Object.keys(meta2dData.paths)) {
  193. let path = meta2dData.paths[key];
  194. if (
  195. path.indexOf('-1.18Zm4-1') !== -1 ||
  196. path.indexOf('-1.19Zm4-1') !== -1 ||
  197. path.indexOf('2.85ZM') !== -1 ||
  198. path.indexOf('-1-2.39.3') !== -1
  199. ) {
  200. keys.push(key);
  201. }
  202. }
  203. let flag = meta2dData.pens.some(
  204. (pen) => pen.name === 'svgPath' && keys.includes(pen.pathId)
  205. );
  206. if (flag) {
  207. svgPens.add('*'); //需要购买所有
  208. }
  209. }
  210. }
  211. return {
  212. pngs: [...pngs],
  213. jsPens: [...jsPens],
  214. iotPens: [...iotPens],
  215. svgPens: [...svgPens],
  216. };
  217. };
  218. //获取已购买
  219. export const getComponentPurchased = async (list: any) => {
  220. let _list = [];
  221. list.pngs.forEach((item) => {
  222. _list.push({
  223. type: '图片图元',
  224. name: item,
  225. });
  226. });
  227. list.jsPens.forEach((item) => {
  228. _list.push({
  229. type: 'JS线性图元',
  230. name: item,
  231. });
  232. });
  233. list.iotPens.forEach((item) => {
  234. _list.push({
  235. type: '控件',
  236. name: item,
  237. });
  238. });
  239. if ([...list.svgPens].includes('*')) {
  240. _list.push({
  241. type: 'SVG线性图元',
  242. });
  243. } else {
  244. list.svgPens.forEach((item) => {
  245. _list.push({
  246. type: 'SVG线性图元',
  247. name: item,
  248. });
  249. });
  250. }
  251. if(!_list.length){
  252. return [];
  253. }
  254. const res: any = await axios.post('/api/paid/2d/component?pageSize=1000', {
  255. list: _list,
  256. });
  257. if (res.error) {
  258. return [];
  259. }
  260. // let purchasedPngs = res.list.filter((item) => list.pngs.has(item));
  261. // let purchasedJs = res.list.filter((item) => list.jsPens.has(item));
  262. // let purchasedIot = res.list.filter((item) => list.iotPens.has(item));
  263. // let purchasedSvg = res.list.filter((item) => list.svgPens.has(item));
  264. // let price =
  265. // ([...list.pngs].length - purchasedPngs.length) * 50 +
  266. // ([...list.jsPens].length - purchasedJs.length) * 10 +
  267. // ([...list.iotPens].length - purchasedIot.length) * 70+
  268. // ([...list.svgPens].length - purchasedSvg.length) * 10;
  269. return res.list;
  270. };
  271. export const get2dComponentJs = async (names: string[] = components) => {
  272. let list = [];
  273. names.forEach((item) => {
  274. list.push({
  275. type: '控件',
  276. name: item,
  277. });
  278. });
  279. const res: any = await axios.post(
  280. '/api/2d-component.js',
  281. {
  282. // list,
  283. },
  284. {
  285. responseType: 'blob',
  286. }
  287. );
  288. return res;
  289. };
  290. export const getTemPngs = async (names: string[]) => {
  291. const res: any = await axios.post('/api/file/presign', {
  292. names,
  293. });
  294. return res;
  295. };
  296. export const getGoods = async () => {
  297. const res: any = await axios.get('/api/goods/2d/component/types');
  298. // console.log("res",res);
  299. return res;
  300. };
  301. export const getDeployGoods = async () => {
  302. const ret:any = await axios.post('/api/goods/list',{
  303. type:'私有部署'
  304. });
  305. return ret.list;
  306. }
  307. export enum Frame {
  308. vue2,
  309. vue3,
  310. react,
  311. html,
  312. }
  313. // export const _preFrameDownload = async (type: Frame) => {
  314. // frameFlag = type;
  315. // // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  316. // zip3D(
  317. // type === Frame.vue3 ? 'toVue3' : type === Frame.vue2 ? 'toVue2' : 'toReact'
  318. // );
  319. // zip2D(
  320. // type === Frame.vue3
  321. // ? 'downloadVue3'
  322. // : type === Frame.vue2
  323. // ? 'downloadVue2'
  324. // : 'downloadReact'
  325. // );
  326. // const data: any = meta2d.data();
  327. // if (data._id) delete data._id;
  328. // if (data.id) delete data.id;
  329. // if (data.image) delete data.image;
  330. // data.userId = user.id;
  331. // checkData(data);
  332. // const [{ default: JSZip }, { saveAs }] = await Promise.all([
  333. // import('jszip'),
  334. // import('file-saver'),
  335. // ]);
  336. // const zip = new JSZip();
  337. // let _fileName =
  338. // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  339. // 'le5le.meta2d';
  340. // //处理付费svg
  341. // if (Object.keys(data.paths).length >= 3) {
  342. // //简单判断有无svg图元
  343. // const res: any = await axios.post('/api/paid/2d/component?pageSize=1000', {
  344. // type: 'SVG线性图元',
  345. // });
  346. // if (res.list.length === 1 && !res.list[0].name) {
  347. // //已经购买全部
  348. // for (let key of Object.keys(data.paths)) {
  349. // let path = data.paths[key];
  350. // if (
  351. // path.indexOf('-1.18Zm4-1') !== -1 ||
  352. // path.indexOf('-1.19Zm4-1') !== -1 ||
  353. // path.indexOf('2.85ZM') !== -1 ||
  354. // path.indexOf('-1-2.39.3') !== -1
  355. // ) {
  356. // data.paths[key] = '';
  357. // }
  358. // }
  359. // } else {
  360. // //购买部分
  361. // let purchasedList = res.list.map((i) => i.name);
  362. // data.pens.forEach((pen) => {
  363. // if (pen.name === 'svgPath' && pen.svgUrl) {
  364. // if (purchasedList.includes(pen.svgUrl.replace(img_cdn, ''))) {
  365. // pen.pathId = null;
  366. // }
  367. // }
  368. // });
  369. // }
  370. // }
  371. // const _zip: any = zip.folder(`${_fileName}`);
  372. // _zip.file(
  373. // `${
  374. // type === Frame.vue3
  375. // ? 'meta2d-vue3'
  376. // : type === Frame.vue2
  377. // ? 'meta2d-vue2'
  378. // : 'meta2d-react'
  379. // }/public/json/data.json`,
  380. // JSON.stringify(data).replaceAll(img_cdn, '').replaceAll(img_upCdn, '')
  381. // );
  382. // await Promise.all([
  383. // zipJs(_zip),
  384. // zipBkImg(_zip),
  385. // zipImages(_zip, meta2d.store.data.pens),
  386. // type === Frame.vue3
  387. // ? zipVue3Files(_zip)
  388. // : type === Frame.vue2
  389. // ? zipVue2Files(_zip)
  390. // : zipReactFiles(_zip),
  391. // zipIotPens(_zip),
  392. // ]);
  393. // const blob = await zip.generateAsync({ type: 'blob' });
  394. // saveAs(blob, `${_fileName}.zip`);
  395. // frameFlag = -1;
  396. // };
  397. // async function zipIotPens(zip: JSZip) {
  398. // //处理控件
  399. // const js = await get2dComponentJs();
  400. // zip.file(
  401. // `${
  402. // frameFlag === Frame.vue3
  403. // ? 'meta2d-vue3'
  404. // : frameFlag === Frame.vue2
  405. // ? 'meta2d-vue2'
  406. // : 'meta2d-react'
  407. // }/public/js/2d-components.js`,
  408. // js,
  409. // { createFolders: true }
  410. // );
  411. // const res: Blob = await axios.get( cdn+'/view/js/r.js', {
  412. // responseType: 'blob',
  413. // });
  414. // zip.file(
  415. // `${
  416. // frameFlag === Frame.vue3
  417. // ? 'meta2d-vue3'
  418. // : frameFlag === Frame.vue2
  419. // ? 'meta2d-vue2'
  420. // : 'meta2d-react'
  421. // }/public/js/r.js`,
  422. // res,
  423. // { createFolders: true }
  424. // );
  425. // }
  426. // async function zipJs(zip: JSZip) {
  427. // const files = ['/view/js/marked.min.js', '/view/js/lcjs.iife.js'];
  428. // await Promise.all(
  429. // files.map(async (filePath) => {
  430. // const res: Blob = await axios.get(cdn+filePath, {
  431. // responseType: 'blob',
  432. // });
  433. // zip.file(
  434. // `${
  435. // frameFlag === Frame.vue3
  436. // ? 'meta2d-vue3'
  437. // : frameFlag === Frame.vue2
  438. // ? 'meta2d-vue2'
  439. // : 'meta2d-react'
  440. // }/public` + filePath.replace('/view', ''),
  441. // res,
  442. // { createFolders: true }
  443. // );
  444. // })
  445. // );
  446. // }
  447. export async function zipBkImg(zip: JSZip) {
  448. let img = meta2d.store.data.bkImage;
  449. if (img) {
  450. if (img.startsWith('/') || img.startsWith(img_cdn) || img.startsWith(img_upCdn)) {
  451. const pngs = await getTemPngs([img.replace(img_cdn, '').replace(img_upCdn, '')]);
  452. await zipImage(zip, img, pngs[img.replace(img_cdn, '').replace(img_upCdn, '')]);
  453. }
  454. }
  455. }
  456. async function zipImage(zip: JSZip, image: string, temImage?: string) {
  457. const res: Blob = await axios.get(temImage || image, {
  458. responseType: 'blob',
  459. // params: {
  460. // isZip: true,
  461. // },
  462. });
  463. zip.file(
  464. (cdn ? image.replace(cdn, '').replace(upCdn, '') : image),
  465. res,
  466. {
  467. createFolders: true,
  468. }
  469. );
  470. }
  471. // const zip3D = (name: string) => {
  472. // const pen_3d = meta2d.store.data.pens.filter(
  473. // (pen) =>
  474. // pen.name === 'iframe' &&
  475. // (pen.tags.includes('meta3d') || pen.iframe.indexOf('/3d') !== -1)
  476. // );
  477. // if (pen_3d && pen_3d.length) {
  478. // //存在3d场景
  479. // pen_3d.forEach((pen) => {
  480. // //发送消息
  481. // // let params = queryURLParams(pen.iframe.split('?')[1]);
  482. // (
  483. // pen.calculative.singleton.div.children[0] as HTMLIFrameElement
  484. // ).contentWindow.postMessage(
  485. // JSON.stringify({
  486. // type: 1,
  487. // name,
  488. // // id: params.id,
  489. // }),
  490. // '*'
  491. // );
  492. // });
  493. // }
  494. // };
  495. // const zip2D = (name: string) => {
  496. // const pen_2d = meta2d.store.data.pens.filter(
  497. // (pen) =>
  498. // pen.name === 'iframe' &&
  499. // pen.iframe.indexOf('/2d') !== -1 || pen.iframe.indexOf('data=2d') !== -1 ||
  500. // pen.iframe.indexOf('/view/v') !== -1 ||pen.iframe.indexOf('data=v') !== -1||
  501. // pen.iframe.indexOf('/preview') !== -1)
  502. // );
  503. // if (pen_2d && pen_2d.length) {
  504. // //存在3d场景
  505. // pen_2d.forEach((pen) => {
  506. // //发送消息
  507. // // let params = queryURLParams(pen.iframe.split('?')[1]);
  508. // (
  509. // pen.calculative.singleton.div.children[0] as HTMLIFrameElement
  510. // ).contentWindow.postMessage(
  511. // JSON.stringify({
  512. // name,
  513. // type: 1,
  514. // }),
  515. // '*'
  516. // );
  517. // });
  518. // }
  519. // };
  520. /**
  521. * 图片放到 zip 里
  522. * @param pens 可以是非具有 calculative 的 pen
  523. */
  524. export async function zipImages(zip: JSZip, pens: Pen[]) {
  525. if (!pens) {
  526. return;
  527. }
  528. // 不止 image 上有图片, strokeImage ,backgroundImage 也有图片
  529. const imageKeys = [
  530. {
  531. string: 'image',
  532. },
  533. { string: 'strokeImage' },
  534. { string: 'backgroundImage' },
  535. ] as const;
  536. const images: string[] = [];
  537. for (const pen of pens) {
  538. for (const i of imageKeys) {
  539. const image = pen[i.string];
  540. if (image) {
  541. // HTMLImageElement 无法精确控制图片格式
  542. if (
  543. image.startsWith('/') ||
  544. image.startsWith(cdn) ||
  545. image.startsWith(upCdn)
  546. ) {
  547. // 只考虑相对路径下的 image ,绝对路径图片无需下载
  548. if (!images.includes(image)) {
  549. images.push(image);
  550. }
  551. }
  552. }
  553. }
  554. // 无需递归遍历子节点,现在所有的节点都在外层
  555. }
  556. //付费pngs
  557. const pngs = await getTemPngs(
  558. images.map((i) => i.replace(img_cdn, '').replace(img_upCdn, ''))
  559. );
  560. await Promise.all(
  561. images.map((image) =>
  562. zipImage(zip, image, pngs[image.replace(img_cdn, '').replace(img_upCdn, '')])
  563. )
  564. );
  565. }
  566. //新
  567. // async function zipVue3Files(zip: JSZip) {
  568. // const files = [
  569. // '/view/meta2d-vue3/src/components/Meta2d.vue',
  570. // '/view/meta2d-vue3/src/App.vue',
  571. // '/view/meta2d-vue3/src/main.js',
  572. // '/view/meta2d-vue3/src/style.css',
  573. // '/view/meta2d-vue3/index.html',
  574. // '/view/meta2d-vue3/package.json',
  575. // '/view/meta2d-vue3/README.md',
  576. // '/view/meta2d-vue3/vite.config.js',
  577. // ] as const;
  578. // // 文件同时加载
  579. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  580. // }
  581. // async function zipVue2Files(zip: JSZip) {
  582. // const files = [
  583. // '/view/meta2d-vue2/src/components/Meta2d.vue',
  584. // '/view/meta2d-vue2/src/App.vue',
  585. // '/view/meta2d-vue2/src/main.js',
  586. // // '/view/meta2d-vue2/src/style.css',
  587. // '/view/meta2d-vue2/public/index.html',
  588. // '/view/meta2d-vue2/package.json',
  589. // '/view/meta2d-vue2/README.md',
  590. // // '/view/meta2d-vue3/vite.config.js',
  591. // ] as const;
  592. // // 文件同时加载
  593. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  594. // }
  595. // async function zipReactFiles(zip: JSZip) {
  596. // const files = [
  597. // '/view/meta2d-react/src/index.css',
  598. // '/view/meta2d-react/src/index.js',
  599. // '/view/meta2d-react/src/Meta2d.css',
  600. // '/view/meta2d-react/src/Meta2d.jsx',
  601. // '/view/meta2d-react/package.json',
  602. // '/view/meta2d-react/README.md',
  603. // '/view/meta2d-react/public/index.html',
  604. // ] as const;
  605. // // 文件同时加载
  606. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  607. // }
  608. // async function zipFile(zip: JSZip, filePath: string) {
  609. // const res: Blob = await axios.get(
  610. // (cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1)) + filePath,
  611. // {
  612. // responseType: 'blob',
  613. // }
  614. // );
  615. // zip.file(filePath.replace('/view', ''), res, { createFolders: true });
  616. // }
  617. export const getFrameDownloadList =(meta2dData: any, path: string = 'v',type:Frame, flag_3d=false) => {
  618. const lists = new Set();
  619. let img = meta2dData.bkImage;
  620. if (img) {
  621. if (
  622. img.startsWith('/') ||
  623. img.startsWith(img_cdn) ||
  624. img.startsWith(img_upCdn)
  625. ) {
  626. let _img = img.replace(img_cdn, '').replace(img_upCdn, '');
  627. if (_img.startsWith('/v/')) {
  628. _img = _img.slice(2);
  629. }
  630. lists.add({
  631. url: img,
  632. path: (`${
  633. type === Frame.vue3
  634. ? 'meta2d-vue3'
  635. : type === Frame.vue2
  636. ? 'meta2d-vue2'
  637. : 'meta2d-react'
  638. }/public`) + _img,
  639. });
  640. meta2dData.bkImage = _img;
  641. }
  642. }
  643. //图片图元(image strokeImage backgroundImage)
  644. const imageKeys = ['image', 'strokeImage', 'backgroundImage'];
  645. const images: string[] = [];
  646. for (const pen of meta2dData.pens) {
  647. for (const i of imageKeys) {
  648. const image = pen[i];
  649. if (image) {
  650. if (
  651. image.startsWith('/') ||
  652. image.startsWith(img_cdn) ||
  653. image.startsWith(img_upCdn)
  654. ) {
  655. // 只考虑相对路径下的 image ,绝对路径图片无需下载
  656. let _img = image.replace(img_cdn, '').replace(img_upCdn, '');
  657. if (_img.startsWith('/v/')) {
  658. _img = _img.slice(2);
  659. }
  660. let path = (`${
  661. type === Frame.vue3
  662. ? 'meta2d-vue3'
  663. : type === Frame.vue2
  664. ? 'meta2d-vue2'
  665. : 'meta2d-react'
  666. }/public`) + _img
  667. if (!images.includes(image)) {
  668. // let _img = image.replace(cdn, '').replace(upCdn, '');
  669. lists.add({
  670. url: image,
  671. path,
  672. });
  673. }
  674. pen[i] = _img;
  675. }
  676. }
  677. }
  678. }
  679. let folderName =type===Frame.vue3?'meta2d-vue3':type===Frame.vue2?'meta2d-vue2': 'meta2d-react';
  680. if(path === 'v'){ //iframe嵌入的页面无需再次下载
  681. //其他文件
  682. let files = [];
  683. let files_3d = [];
  684. switch (type) {
  685. case Frame.vue3:
  686. files =[
  687. '/view/meta2d-vue3/src/router/index.ts',
  688. '/view/meta2d-vue3/src/views/2d/Meta2d.vue',
  689. '/view/meta2d-vue3/src/App.vue',
  690. '/view/meta2d-vue3/src/main.ts',
  691. '/view/meta2d-vue3/src/style.css',
  692. '/view/meta2d-vue3/index.html',
  693. '/view/meta2d-vue3/package.json',
  694. '/view/meta2d-vue3/README.md',
  695. '/view/meta2d-vue3/tsconfig.json',
  696. '/view/meta2d-vue3/tsconfig.node.json',
  697. '/view/meta2d-vue3/vite.config.ts',
  698. ];
  699. if(flag_3d){
  700. //存在3d场景
  701. files_3d.push(...[
  702. '/meta2d-vue3/src/plugins/meta3d/index.ts',
  703. '/meta2d-vue3/src/plugins/meta3d/meta3d.css',
  704. '/meta2d-vue3/src/plugins/meta3d/meta3d.js',
  705. // '/view/meta2d-vue3/src/views/3d/Meta3d.vue',
  706. // '/meta2d-vue3/public/meta3d/js/draco_decoder_gltf.js',
  707. // '/meta2d-vue3/public/meta3d/js/draco_decoder_gltf.wasm',
  708. // '/meta2d-vue3/public/meta3d/js/draco_wasm_wrapper_gltf.js',
  709. ]);
  710. files.push( '/view/meta2d-vue3/src/views/3d/Meta3d.vue',)
  711. }
  712. break;
  713. case Frame.vue2:
  714. files =[
  715. '/view/meta2d-vue2/src/router/index.js',
  716. '/view/meta2d-vue2/src/views/2d/Meta2d.vue',
  717. '/view/meta2d-vue2/src/App.vue',
  718. '/view/meta2d-vue2/src/main.js',
  719. '/view/meta2d-vue2/index.html',
  720. '/view/meta2d-vue2/package.json',
  721. '/view/meta2d-vue2/README.md',
  722. '/view/meta2d-vue2/vite.config.js'
  723. ];
  724. if(flag_3d){
  725. files_3d.push(...[
  726. '/meta2d-vue2/src/plugins/meta3d/index.js',
  727. '/meta2d-vue2/src/plugins/meta3d/meta3d.css',
  728. '/meta2d-vue2/src/plugins/meta3d/meta3d.js',
  729. // '/meta2d-vue2/src/views/3d/Meta3d.vue',
  730. // '/meta2d-vue2/public/meta3d/js/draco_decoder_gltf.js',
  731. // '/meta2d-vue2/public/meta3d/js/draco_decoder_gltf.wasm',
  732. // '/meta2d-vue2/public/meta3d/js/draco_wasm_wrapper_gltf.js',
  733. ]);
  734. files.push( '/view/meta2d-vue2/src/views/3d/Meta3d.vue',)
  735. }
  736. break;
  737. case Frame.react:
  738. files =[
  739. '/view/meta2d-react/src/router/index.tsx',
  740. '/view/meta2d-react/src/views/2d/Meta2d.tsx',
  741. '/view/meta2d-react/src/App.tsx',
  742. '/view/meta2d-react/src/index.css',
  743. '/view/meta2d-react/src/main.tsx',
  744. '/view/meta2d-react/index.html',
  745. '/view/meta2d-react/package.json',
  746. '/view/meta2d-react/README.md',
  747. '/view/meta2d-react/tsconfig.json',
  748. '/view/meta2d-react/tsconfig.node.json',
  749. '/view/meta2d-react/vite.config.ts',
  750. ];
  751. if(flag_3d){
  752. files_3d.push(...[
  753. '/meta2d-react/src/plugins/meta3d/index.ts',
  754. '/meta2d-react/src/plugins/meta3d/meta3d.css',
  755. '/meta2d-react/src/plugins/meta3d/meta3d.js',
  756. // '/meta2d-react/src/views/3d/Meta3d.tsx',
  757. // '/meta2d-react/public/meta3d/js/draco_decoder_gltf.js',
  758. // '/meta2d-react/public/meta3d/js/draco_decoder_gltf.wasm',
  759. // '/meta2d-react/public/meta3d/js/draco_wasm_wrapper_gltf.js',
  760. ]);
  761. files.push('/view/meta2d-react/src/views/3d/Meta3d.tsx',)
  762. }
  763. break;
  764. default:
  765. break;
  766. }
  767. files.forEach((file) => {
  768. lists.add({
  769. url: (cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1)) + file,
  770. path: file.replace('/view', ''),
  771. });
  772. });
  773. if(flag_3d){
  774. files_3d.forEach((file) => {
  775. lists.add({
  776. url: (cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1)) + '/view/meta3d/'+file.split('/meta3d/')[1],
  777. path: file,
  778. });
  779. })
  780. }
  781. let jsFiles = [
  782. '/view/js/marked.min.js',
  783. // '/view/js/echarts.min.js',
  784. '/view/js/lcjs.iife.js',
  785. // '/view/js/highcharts.js',
  786. // '/view/js/highcharts-more.js',
  787. '/view/js/r.js',
  788. '/view/icon/font_2395018_nng9x1qhat.css',
  789. '/view/icon/font_2073009_teagntehxt.css',
  790. // '/view/assets/cloudy.env',
  791. // '/view/assets/default.env',
  792. // '/view/assets/dusk.env',
  793. // '/view/assets/night.env',
  794. // '/view/assets/sunny.env',
  795. // '/view/assets/cloudy.jpg',
  796. // '/view/assets/dusk.jpg',
  797. // '/view/assets/night.jpg',
  798. // '/view/assets/sunny.jpg',
  799. // '/view/assets/luopan.png',
  800. // '/view/assets/Rain.png',
  801. // '/view/assets/zhizhen.png',
  802. // '/view/assets/默认环境光.png',
  803. // '/view/assets/draco_decoder_gltf.js',
  804. // '/view/assets/draco_wasm_wrapper_gltf.js',
  805. // '/view/assets/draco_decoder_gltf.wasm',
  806. ]
  807. jsFiles.forEach((file) => {
  808. lists.add({
  809. url: (cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1))+ file,
  810. path:`/${folderName}/public${file.replace('/view', '')}`,
  811. });
  812. });
  813. }
  814. //图纸数据
  815. if (meta2dData._id) delete meta2dData._id;
  816. if (meta2dData.id) delete meta2dData.id;
  817. if ((meta2dData as any).image) delete (meta2dData as any).image;
  818. lists.add({
  819. data: JSON.stringify(meta2dData)
  820. .replaceAll(img_cdn, '')
  821. .replaceAll(img_upCdn, ''),
  822. path: `/${folderName}/public/json/${path}.json`,
  823. });
  824. return lists;
  825. };