mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-20 07:14:23 +00:00
feat: plugin preview
This commit is contained in:
parent
3e4254c9d3
commit
18f149e0e8
24
packages/plugin-sample-preview/demo/usage.md
Normal file
24
packages/plugin-sample-preview/demo/usage.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
title: 基本使用
|
||||||
|
order: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
````jsx
|
||||||
|
import React, { PureComponent } from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import SamplePreview from '@ali/lowcode-plugin-sample-preview';
|
||||||
|
|
||||||
|
class Demo extends PureComponent {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SamplePreview />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReactDOM.render((
|
||||||
|
<Demo />
|
||||||
|
), mountNode);
|
||||||
|
````
|
||||||
@ -9,6 +9,7 @@
|
|||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "build-scripts start",
|
||||||
"build": "build-scripts build --skip-demo",
|
"build": "build-scripts build --skip-demo",
|
||||||
"test": "ava",
|
"test": "ava",
|
||||||
"test:snapshot": "ava --update-snapshots"
|
"test:snapshot": "ava --update-snapshots"
|
||||||
@ -29,7 +30,8 @@
|
|||||||
"@types/react-dom": "^16.9.4",
|
"@types/react-dom": "^16.9.4",
|
||||||
"build-plugin-component": "^0.2.11",
|
"build-plugin-component": "^0.2.11",
|
||||||
"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",
|
||||||
|
"@ali/lowcode-react-renderer": "^0.8.0"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://registry.npm.alibaba-inc.com"
|
"registry": "https://registry.npm.alibaba-inc.com"
|
||||||
|
|||||||
@ -1,35 +1,45 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Button } from '@alifd/next';
|
import { Button, Dialog } from '@alifd/next';
|
||||||
import { PluginProps } from '@ali/lowcode-types';
|
// import { PluginProps } from '@ali/lowcode-types';
|
||||||
import { Designer } from '@ali/lowcode-designer';
|
// import { Designer } from '@ali/lowcode-designer';
|
||||||
|
// import ReactRenderer from '@ali/lowcode-react-renderer';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
const SamplePreview = ({ editor }: PluginProps) => {
|
const SamplePreview = ({ editor }: PluginProps) => {
|
||||||
const handleClick = () => {
|
const [data, setData] = useState({});
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const handleClick = async () => {
|
||||||
|
if (!editor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const designer = editor.get(Designer);
|
const designer = editor.get(Designer);
|
||||||
if (designer) {
|
if (designer) {
|
||||||
console.info('save schema:', designer.schema);
|
console.info('save schema:', designer.schema);
|
||||||
localStorage.setItem('lce-dev-store', JSON.stringify(designer.schema));
|
|
||||||
fetch('http://30.5.157.206:3000/legao/save.json', {
|
const { components } = await editor.get('assets');
|
||||||
method: 'POST',
|
setData({
|
||||||
body: JSON.stringify(designer.schema),
|
schema: designer.schema,
|
||||||
headers: new Headers({
|
components,
|
||||||
'Content-Type': 'application/json',
|
});
|
||||||
}),
|
setVisible(true);
|
||||||
mode: 'cors',
|
|
||||||
})
|
|
||||||
.then((res) => res.json())
|
|
||||||
.then(() => {
|
|
||||||
window.open('http://30.5.157.206:3333/', 'preview');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { schema, components } = data;
|
||||||
return (
|
return (
|
||||||
<div className="lowcode-plugin-sample-preview">
|
<div className="lowcode-plugin-sample-preview">
|
||||||
<Button type="primary" onClick={handleClick}>
|
<Button type="primary" onClick={handleClick}>
|
||||||
预览
|
预览
|
||||||
</Button>
|
</Button>
|
||||||
|
<Dialog
|
||||||
|
visible={visible}
|
||||||
|
footer={false}
|
||||||
|
>
|
||||||
|
<ReactRenderer
|
||||||
|
schema={schema}
|
||||||
|
components={components}
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user