宜搭 web会打出一个 资源包
方案一 项目对接
资源包
components 资源
import Coms from '@xxx/yida-web/src/components'
import {
VisionCanvasLBus,
} from '@xxx/yida-web'
const {
// 容器
BaseVisionLContainer,
FormVisionLContainer,
AbsVisionLContainer,
// 组件
LabelText,
ButtonCom,
InputCom,
VisionTable
} = Coms
VisionCanvasLBus.registerComponent(LabelText, 'LabelText')
VisionCanvasLBus.registerComponent(BaseVisionLContainer, 'BaseVisionLContainer')
VisionCanvasLBus.registerComponent(FormVisionLContainer, 'FormVisionLContainer')
VisionCanvasLBus.registerComponent(AbsVisionLContainer, 'AbsVisionLContainer')
VisionCanvasLBus.registerComponent(ButtonCom, 'Button')
VisionCanvasLBus.registerComponent(InputCom, 'Input', ViewInputCom)
VisionCanvasLBus.registerComponent(VisionTable, 'VisionTable', ViewVisionTable)
核心资源
1.npm install @xxx/yida-web
.vision-canvas-demo-container {
display: flex;
height: calc(100vh - 50px);
background-color: #fff;
.vision-canvas-header {
background-color: #fff;
height: 50px;
border-bottom: 1px solid rgb(204, 204, 204);
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
.margin-r-20 {
margin-right: 20px;
}
}
.vision-canvas-demo {
min-width: 1440px;
display: flex;
width: 100%;
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
.vision-canvas-l-left {
flex: none;
width: 48px;
height: 100%;
overflow: hidden;
.ant-collapse-content {
.ant-collapse-content-box {
.viewNode {
border: 1px rgba(0, 0, 0, 0) solid !important;
&:hover {
border: 1px solid #3384F3 !important;
}
}
}
}
}
.vision-canvas-conter {
width: calc(100%);
height: 100%;
overflow: hidden;
>div {
height: 100%;
}
}
.vision-canvas-l-conter {
width: calc(100% - 348px);
height: 100%;
overflow: hidden;
border: 1px solid rgb(204, 204, 204);
padding: 12px;
background: #eceff3;
border: 1px solid #ccc;
border-top: none;
>div {
background-color: #fff;
height: 100%;
position: relative;
overflow: hidden;
}
}
.vision-canvas-l-right {
flex: none;
overflow: hidden;
width: 300px;
position: relative;
height: 100%;
overflow-y: auto;
z-index: 1001;
}
}
}
import {
VisionCanvasLBus,
VisionCanvasL,
} from '@xxx/yida-web'
import '../index.less';
export class ViewTemplate extends React.Component<{
VisionCanvasLBus?: VisionCanvasL,
setLoading: (bool: boolean) => void;
}> {
VisionCanvasLBus = VisionCanvasLBus;
VisionCanvasL: VisionCanvasL | null = null
constructor (props) {
super(props);
this.VisionCanvasLBus = props.VisionCanvasLBus || VisionCanvasLBus
}
componentDidMount () {
// 可以写支持的事件
// this.VisionCanvasLBus.pubSub.subscribe('canvas:didmount', () => {
// console.log('canvas:didmount')
// });
// this.VisionCanvasLBus.pubSub.subscribe('canvas:mouseup', () => {
// console.log('canvas:mouseup')
// });
// this.VisionCanvasLBus.pubSub.subscribe('canvas:click', () => {
// console.log('canvas:click')
// });
// this.VisionCanvasLBus.pubSub.subscribe('canvas:mouseleave', () => {
// console.log('canvas:mouseleave')
// });
// this.VisionCanvasLBus.pubSub.subscribe('canvas:mousemove', () => {
// console.log('canvas:mousemove')
// });
// this.VisionCanvasLBus.pubSub.subscribe('canvas:unmount', () => {
// console.log('canvas:unmount')
// });
// this.VisionCanvasLBus.pubSub.subscribe('node:mousedown', () => {
// console.log('node:mousedown')
// });
// this.VisionCanvasLBus.pubSub.subscribe('node:mousemove', () => {
// console.log('node:mousemove')
// });
// this.VisionCanvasLBus.pubSub.subscribe('node:mouseup', () => {
// console.log('node:mouseup')
// });
}
getConfig () {
if (this.VisionCanvasL) {
// 例子
let __schema = '{"layout":"inline-block","nodes":[],"width":"","height":"","id":"VisionCanvasL_774d107f-f96b-4bb0-8a18-fca0edbb0712","attributeParams":{"params":{},"paramsConfig":[]},"dataSource":{},"dataSourceList":[],"componentIds":{},"formIds":{}}'
// 在这里请求数据,传入数据
(this.VisionCanvasL as VisionCanvasL).setJSONSchema(__schema)
}
}
render () {
return (
<div className='vision-canvas-demo-container'>
<div className='vision-canvas-demo' style={{
top:0,
position: 'fixed',
zIndex: 120,
backgroundColor: '#fff'
}}>
<div className='vision-canvas-conter' style={{ border: '1px solid #ccc' }}>
<VisionCanvasL
layout='inline-block'
moveFlag={false}
ref={(refCanvas) => {
if (refCanvas) {
this.VisionCanvasL = refCanvas;
this.getConfig();
}
}}
/>
</div>
</div>
</div>
)
}
}
数据资源
计划产出接口
/**获取当前页面信息*/
request(`${url}/yida-web-service/${applicationName}/${pageId}`).then(__schema => {
(this.VisionCanvasL as VisionCanvasL).setJSONSchema(__schema)
})
方案二 JS对接方式
yida-web项目会打包出一个umd格式的js,
libraryName:XXXYidaBuild
- applicationName
- version
- hash
通过后台某种方式写入到页面中
/**js方式*/
(function(){
const script = document.createElement("script");
const jsPath = `${url}/yida-web-service/${applicationName}/main.${version}.${hash}.js`
script.src = jsPath;
document.head.appendChild(script);
YidaWeb.render(document.getElementById("root"));
})()
例子
import React from 'react';
export default function() {
let divContainer: HTMLElement | null;
const uuid = () => {
const s = [];
const hexDigits = '0123456789abcdef';
for (let i = 0; i < 36; i += 1) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
// bits 6-7 of the clock_seq_hi_and_reserved to 01
// @ts-ignore
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // eslint-disable-line
s[8] = s[13] = s[18] = s[23] = '-'; // eslint-disable-line
return s.join('');
};
React.useEffect(() => {
const url = 'https://xxx.xxx.com'
if (document) {
if (!document.getElementById('xxx-build-config')) {
const configScript = document.createElement('script')
configScript.id = 'xxx-build-config'
configScript.src = `${url}/yida-web-service/new-admin1/config.js?uuid=${uuid()}`;
document.head.appendChild(configScript);
function mountLoop () {
// @ts-ignore
const XXXYidaBuild = window.XXXYidaBuild
if (!XXXYidaBuild || !document.getElementById('container')) {
setTimeout(() => {
mountLoop()
}, 100)
return
}
if (XXXYidaBuild.mount) {
XXXYidaBuild.mount({
container: 'container',
basename: '/v2/yida',
type: 'browser'
})
}
}
function loop () {
// @ts-ignore
const XXXBuildConfig = window.XXXBuildConfig;
if (!XXXBuildConfig) {
setTimeout(() => {
loop()
}, 100)
return
}
const XXXYidaBuildScript = document.createElement('script')
XXXYidaBuildScript.id = 'xxx-yida-build'
XXXYidaBuildScript.src = `${url}/yida-web-service/new-admin1/main.${XXXBuildConfig.version}.${XXXBuildConfig.hash}.js`;
document.head.appendChild(XXXYidaBuildScript);
mountLoop()
}
loop()
}
}
}, [])
return <>
<div id='container'>加载中...</div>
</>
}