fix: 🐛 codeout btn fix

This commit is contained in:
春希 2020-07-20 22:24:00 +08:00
parent e65a038795
commit afda7d4259
2 changed files with 43 additions and 25 deletions

View File

@ -48,6 +48,7 @@
"@types/events": "^3.0.0", "@types/events": "^3.0.0",
"@types/react": "^16.8.3", "@types/react": "^16.8.3",
"@types/react-dom": "^16.8.2", "@types/react-dom": "^16.8.2",
"@types/streamsaver": "^2.0.0",
"build-plugin-fusion": "^0.1.0", "build-plugin-fusion": "^0.1.0",
"build-plugin-moment-locales": "^0.1.0", "build-plugin-moment-locales": "^0.1.0",
"build-plugin-react-app": "^1.1.2", "build-plugin-react-app": "^1.1.2",

View File

@ -2,25 +2,40 @@
/* eslint-disable @typescript-eslint/no-empty-interface */ /* eslint-disable @typescript-eslint/no-empty-interface */
import React from 'react'; import React from 'react';
import { Button } from '@alifd/next'; import { Button } from '@alifd/next';
import { PluginProps } from '@ali/lowcode-types'; import { PluginProps, NpmInfo } from '@ali/lowcode-types';
import { Designer } from '@ali/lowcode-designer'; import { Designer } from '@ali/lowcode-designer';
import streamSaver from 'streamsaver'; import streamSaver from 'streamsaver';
import './codeout.scss'; import './codeout.scss';
interface BasicSection {
componentName: string;
title: string;
description?: string;
docUrl?: string;
screenshot?: string;
icon?: string;
tags?: string[];
devMode?: 'proCode' | 'lowCode';
npm: NpmInfo;
[k: string]: any;
}
const CODEOUT_SERVICE_HOST = '30.8.52.239:3000'; const CODEOUT_SERVICE_HOST = '30.8.52.239:3000';
const Codeout = ({ editor }: PluginProps) => { const Codeout = ({ editor }: PluginProps) => {
const handleClick = () => { const handleClick = () => {
const designer = editor.get(Designer); const designer = editor.get(Designer);
if (designer) { if (designer) {
const assets = editor.get('assets'); const assets = editor.get('assets') as { components: BasicSection[] };
console.log(assets.components); const components = assets.components;
const componentsMap = assets.components.map((c) => ({ const componentsMap = components
componentName: c.componentName, .filter((c) => !!c.npm)
...(c.npm || {}), .map((c) => ({
})); componentName: c.componentName,
...(c.npm || {}),
}));
const fullSchema = { const fullSchema = {
...designer.schema, ...designer.schema,
@ -35,24 +50,26 @@ const Codeout = ({ editor }: PluginProps) => {
}; };
console.info('codeout schema:', fullSchema); console.info('codeout schema:', fullSchema);
// fetch(`http://${CODEOUT_SERVICE_HOST}/api/generate/project`, { fetch(`http://${CODEOUT_SERVICE_HOST}/api/generate/project`, {
// method: 'POST', method: 'POST',
// body: JSON.stringify({ schema: JSON.stringify(fullSchema) }), body: JSON.stringify({ schema: JSON.stringify(fullSchema) }),
// headers: new Headers({ headers: new Headers({
// 'Content-Type': 'application/json', 'Content-Type': 'application/json',
// }), }),
// mode: 'cors', mode: 'cors',
// }).then((res) => { }).then((res) => {
// const fileStream = streamSaver.createWriteStream('demoProject.zip'); const fileStream = streamSaver.createWriteStream('demoProject.zip');
// res.body.pipeTo(fileStream).then( if (res.body !== null) {
// () => { res.body.pipeTo(fileStream).then(
// console.log('success'); () => {
// }, console.log('success');
// (err) => { },
// console.log(err); (err) => {
// }, console.log(err);
// ); },
// }); );
}
});
} }
}; };