宜搭 web会打出一个 资源包

方案一 项目对接

资源包

components 资源

  1. import Coms from '@xxx/yida-web/src/components'
  2. import {
  3. VisionCanvasLBus,
  4. } from '@xxx/yida-web'
  5. const {
  6. // 容器
  7. BaseVisionLContainer,
  8. FormVisionLContainer,
  9. AbsVisionLContainer,
  10. // 组件
  11. LabelText,
  12. ButtonCom,
  13. InputCom,
  14. VisionTable
  15. } = Coms
  16. VisionCanvasLBus.registerComponent(LabelText, 'LabelText')
  17. VisionCanvasLBus.registerComponent(BaseVisionLContainer, 'BaseVisionLContainer')
  18. VisionCanvasLBus.registerComponent(FormVisionLContainer, 'FormVisionLContainer')
  19. VisionCanvasLBus.registerComponent(AbsVisionLContainer, 'AbsVisionLContainer')
  20. VisionCanvasLBus.registerComponent(ButtonCom, 'Button')
  21. VisionCanvasLBus.registerComponent(InputCom, 'Input', ViewInputCom)
  22. VisionCanvasLBus.registerComponent(VisionTable, 'VisionTable', ViewVisionTable)

核心资源

1.npm install @xxx/yida-web

  1. .vision-canvas-demo-container {
  2. display: flex;
  3. height: calc(100vh - 50px);
  4. background-color: #fff;
  5. .vision-canvas-header {
  6. background-color: #fff;
  7. height: 50px;
  8. border-bottom: 1px solid rgb(204, 204, 204);
  9. width: 100%;
  10. display: flex;
  11. justify-content: space-between;
  12. align-items: center;
  13. .margin-r-20 {
  14. margin-right: 20px;
  15. }
  16. }
  17. .vision-canvas-demo {
  18. min-width: 1440px;
  19. display: flex;
  20. width: 100%;
  21. position: absolute;
  22. top: 50px;
  23. left: 0;
  24. right: 0;
  25. bottom: 0;
  26. .vision-canvas-l-left {
  27. flex: none;
  28. width: 48px;
  29. height: 100%;
  30. overflow: hidden;
  31. .ant-collapse-content {
  32. .ant-collapse-content-box {
  33. .viewNode {
  34. border: 1px rgba(0, 0, 0, 0) solid !important;
  35. &:hover {
  36. border: 1px solid #3384F3 !important;
  37. }
  38. }
  39. }
  40. }
  41. }
  42. .vision-canvas-conter {
  43. width: calc(100%);
  44. height: 100%;
  45. overflow: hidden;
  46. >div {
  47. height: 100%;
  48. }
  49. }
  50. .vision-canvas-l-conter {
  51. width: calc(100% - 348px);
  52. height: 100%;
  53. overflow: hidden;
  54. border: 1px solid rgb(204, 204, 204);
  55. padding: 12px;
  56. background: #eceff3;
  57. border: 1px solid #ccc;
  58. border-top: none;
  59. >div {
  60. background-color: #fff;
  61. height: 100%;
  62. position: relative;
  63. overflow: hidden;
  64. }
  65. }
  66. .vision-canvas-l-right {
  67. flex: none;
  68. overflow: hidden;
  69. width: 300px;
  70. position: relative;
  71. height: 100%;
  72. overflow-y: auto;
  73. z-index: 1001;
  74. }
  75. }
  76. }
  1. import {
  2. VisionCanvasLBus,
  3. VisionCanvasL,
  4. } from '@xxx/yida-web'
  5. import '../index.less';
  6. export class ViewTemplate extends React.Component<{
  7. VisionCanvasLBus?: VisionCanvasL,
  8. setLoading: (bool: boolean) => void;
  9. }> {
  10. VisionCanvasLBus = VisionCanvasLBus;
  11. VisionCanvasL: VisionCanvasL | null = null
  12. constructor (props) {
  13. super(props);
  14. this.VisionCanvasLBus = props.VisionCanvasLBus || VisionCanvasLBus
  15. }
  16. componentDidMount () {
  17. // 可以写支持的事件
  18. // this.VisionCanvasLBus.pubSub.subscribe('canvas:didmount', () => {
  19. // console.log('canvas:didmount')
  20. // });
  21. // this.VisionCanvasLBus.pubSub.subscribe('canvas:mouseup', () => {
  22. // console.log('canvas:mouseup')
  23. // });
  24. // this.VisionCanvasLBus.pubSub.subscribe('canvas:click', () => {
  25. // console.log('canvas:click')
  26. // });
  27. // this.VisionCanvasLBus.pubSub.subscribe('canvas:mouseleave', () => {
  28. // console.log('canvas:mouseleave')
  29. // });
  30. // this.VisionCanvasLBus.pubSub.subscribe('canvas:mousemove', () => {
  31. // console.log('canvas:mousemove')
  32. // });
  33. // this.VisionCanvasLBus.pubSub.subscribe('canvas:unmount', () => {
  34. // console.log('canvas:unmount')
  35. // });
  36. // this.VisionCanvasLBus.pubSub.subscribe('node:mousedown', () => {
  37. // console.log('node:mousedown')
  38. // });
  39. // this.VisionCanvasLBus.pubSub.subscribe('node:mousemove', () => {
  40. // console.log('node:mousemove')
  41. // });
  42. // this.VisionCanvasLBus.pubSub.subscribe('node:mouseup', () => {
  43. // console.log('node:mouseup')
  44. // });
  45. }
  46. getConfig () {
  47. if (this.VisionCanvasL) {
  48. // 例子
  49. let __schema = '{"layout":"inline-block","nodes":[],"width":"","height":"","id":"VisionCanvasL_774d107f-f96b-4bb0-8a18-fca0edbb0712","attributeParams":{"params":{},"paramsConfig":[]},"dataSource":{},"dataSourceList":[],"componentIds":{},"formIds":{}}'
  50. // 在这里请求数据,传入数据
  51. (this.VisionCanvasL as VisionCanvasL).setJSONSchema(__schema)
  52. }
  53. }
  54. render () {
  55. return (
  56. <div className='vision-canvas-demo-container'>
  57. <div className='vision-canvas-demo' style={{
  58. top:0,
  59. position: 'fixed',
  60. zIndex: 120,
  61. backgroundColor: '#fff'
  62. }}>
  63. <div className='vision-canvas-conter' style={{ border: '1px solid #ccc' }}>
  64. <VisionCanvasL
  65. layout='inline-block'
  66. moveFlag={false}
  67. ref={(refCanvas) => {
  68. if (refCanvas) {
  69. this.VisionCanvasL = refCanvas;
  70. this.getConfig();
  71. }
  72. }}
  73. />
  74. </div>
  75. </div>
  76. </div>
  77. )
  78. }
  79. }

数据资源
计划产出接口

  1. /**获取当前页面信息*/
  2. request(`${url}/yida-web-service/${applicationName}/${pageId}`).then(__schema => {
  3. (this.VisionCanvasL as VisionCanvasL).setJSONSchema(__schema)
  4. })

方案二 JS对接方式

yida-web项目会打包出一个umd格式的js,
libraryName:XXXYidaBuild

  • applicationName
  • version
  • hash

通过后台某种方式写入到页面中

  1. /**js方式*/
  2. (function(){
  3. const script = document.createElement("script");
  4. const jsPath = `${url}/yida-web-service/${applicationName}/main.${version}.${hash}.js`
  5. script.src = jsPath;
  6. document.head.appendChild(script);
  7. YidaWeb.render(document.getElementById("root"));
  8. })()

例子

  1. import React from 'react';
  2. export default function() {
  3. let divContainer: HTMLElement | null;
  4. const uuid = () => {
  5. const s = [];
  6. const hexDigits = '0123456789abcdef';
  7. for (let i = 0; i < 36; i += 1) {
  8. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  9. }
  10. s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
  11. // bits 6-7 of the clock_seq_hi_and_reserved to 01
  12. // @ts-ignore
  13. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // eslint-disable-line
  14. s[8] = s[13] = s[18] = s[23] = '-'; // eslint-disable-line
  15. return s.join('');
  16. };
  17. React.useEffect(() => {
  18. const url = 'https://xxx.xxx.com'
  19. if (document) {
  20. if (!document.getElementById('xxx-build-config')) {
  21. const configScript = document.createElement('script')
  22. configScript.id = 'xxx-build-config'
  23. configScript.src = `${url}/yida-web-service/new-admin1/config.js?uuid=${uuid()}`;
  24. document.head.appendChild(configScript);
  25. function mountLoop () {
  26. // @ts-ignore
  27. const XXXYidaBuild = window.XXXYidaBuild
  28. if (!XXXYidaBuild || !document.getElementById('container')) {
  29. setTimeout(() => {
  30. mountLoop()
  31. }, 100)
  32. return
  33. }
  34. if (XXXYidaBuild.mount) {
  35. XXXYidaBuild.mount({
  36. container: 'container',
  37. basename: '/v2/yida',
  38. type: 'browser'
  39. })
  40. }
  41. }
  42. function loop () {
  43. // @ts-ignore
  44. const XXXBuildConfig = window.XXXBuildConfig;
  45. if (!XXXBuildConfig) {
  46. setTimeout(() => {
  47. loop()
  48. }, 100)
  49. return
  50. }
  51. const XXXYidaBuildScript = document.createElement('script')
  52. XXXYidaBuildScript.id = 'xxx-yida-build'
  53. XXXYidaBuildScript.src = `${url}/yida-web-service/new-admin1/main.${XXXBuildConfig.version}.${XXXBuildConfig.hash}.js`;
  54. document.head.appendChild(XXXYidaBuildScript);
  55. mountLoop()
  56. }
  57. loop()
  58. }
  59. }
  60. }, [])
  61. return <>
  62. <div id='container'>加载中...</div>
  63. </>
  64. }