download.ts 20 KB

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