diff --git a/.gitignore b/.gitignore index 4fad141..2ee863e 100644 --- a/.gitignore +++ b/.gitignore @@ -103,4 +103,8 @@ dist # TernJS port file .tern-port -/**/*.umi \ No newline at end of file +<<<<<<< HEAD +/**/*.umi +======= +.umi/ +>>>>>>> upstream/master diff --git a/src/components/Carousel/index.js b/src/components/Carousel/index.js index 53be0e8..878d01d 100644 --- a/src/components/Carousel/index.js +++ b/src/components/Carousel/index.js @@ -3,35 +3,39 @@ import { Carousel } from 'zarm'; import styles from './index.less'; const XCarousel = memo(props => { - const { - direction, - swipeable, - imgList - } = props - + const { direction, swipeable, autoPlay, isTpl, imgList, tplImg } = props; + const contentRender = () => { return imgList.map((item, i) => { return (
- ) - }) - } + ); + }); + }; - return
- { - // console.log(`onChange: ${index}`); - }} - direction={direction} - swipeable={swipeable} - autoPlay - loop - > - {contentRender()} - + return ( +
+ {isTpl ? ( +
+
-}) + ) : ( + { + // console.log(`onChange: ${index}`); + }} + direction={direction} + swipeable={swipeable} + autoPlay={autoPlay} + loop + > + {contentRender()} + + )} +
+ ); +}); -export default XCarousel; \ No newline at end of file +export default XCarousel; diff --git a/src/components/DynamicEngine/index.js b/src/components/DynamicEngine/index.js index d98a10d..ea032b4 100644 --- a/src/components/DynamicEngine/index.js +++ b/src/components/DynamicEngine/index.js @@ -2,35 +2,38 @@ import { dynamic } from 'umi'; import Loading from '../LoadingCp'; import { useMemo, memo } from 'react'; -const needList = ['Tab', 'Carousel', 'Upload', 'Video'] +const needList = ['Tab', 'Carousel', 'Upload', 'Video']; -const DynamicFunc = (type) => dynamic({ - loader: async function() { - let Component; - if(needList.includes(type)) { - const { default: Graph } = await import(`@/components/${type}`) - Component = Graph - }else { - const Components = await import(`@/components/DynamicEngine/components`) - Component = Components[type] - } +const DynamicFunc = type => + dynamic({ + loader: async function() { + let Component; + if (needList.includes(type)) { + const { default: Graph } = await import(`@/components/${type}`); + Component = Graph; + } else { + const Components = await import(`@/components/DynamicEngine/components`); + Component = Components[type]; + } - return (props) => { - const { config } = props - return - } - }, - loading: () =>
- -
-}) + return props => { + const { config } = props; + return ; + }; + }, + loading: () => ( +
+ +
+ ), + }); -const DynamicEngine = memo((props) => { - const { type, config } = props +const DynamicEngine = memo(props => { + const { type, config } = props; const Dynamic = useMemo(() => { - return DynamicFunc(type) - }, [type]) - return -}) + return DynamicFunc(type); + }, [type, config]); + return ; +}); -export default DynamicEngine \ No newline at end of file +export default DynamicEngine; diff --git a/src/components/DynamicEngine/schema.js b/src/components/DynamicEngine/schema.js index 375173f..65d059b 100644 --- a/src/components/DynamicEngine/schema.js +++ b/src/components/DynamicEngine/schema.js @@ -1,211 +1,218 @@ export default { - "Carousel": { - "editData": [ + Carousel: { + editData: [ { - "key": "direction", - "name": "方向", - "type": "Radio", - "range": [ + key: 'direction', + name: '方向', + type: 'Radio', + range: [ { - key: "top", - text: "从上到下" + key: 'top', + text: '从上到下', }, { - key: "left", - text: "从左到右" - } - ] + key: 'left', + text: '从左到右', + }, + ], }, { - "key": "swipeable", - "name": "是否可拖拽", - "type": "Switch", + key: 'swipeable', + name: '是否可拖拽', + type: 'Switch', }, { - "key": "imgList", - "name": "图片列表", - "type": "DataList", - } + key: 'autoPlay', + name: '是否自动播放', + type: 'Switch', + }, + { + key: 'imgList', + name: '图片列表', + type: 'DataList', + }, ], - "config": { - "direction": "left", - "swipeable": false, - "imgList": [ + config: { + direction: 'left', + swipeable: false, + autoPlay: false, + imgList: [ { - "id": 1, - "title": "趣谈小课1", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "imgUrl": [ + id: 1, + title: '趣谈小课1', + desc: '致力于打造优质小课程', + link: 'xxxxx', + imgUrl: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/1_1740bd7c3dc.png", - } - ] + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/1_1740bd7c3dc.png', + }, + ], }, { - "id": 2, - "title": "趣谈小课1", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "imgUrl": [ + id: 2, + title: '趣谈小课1', + desc: '致力于打造优质小课程', + link: 'xxxxx', + imgUrl: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/2_1740bd8d525.png", - } - ] - } - ] - } + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/2_1740bd8d525.png', + }, + ], + }, + ], + tplImg: 'http://io.nainor.com/uploads/carousal_17442e1420f.png', + }, }, - "Text": { - "editData": [ + Text: { + editData: [ { - "key": "text", - "name": "文字", - "type": "Text" + key: 'text', + name: '文字', + type: 'Text', }, { - "key": "color", - "name": "标题颜色", - "type": "Color" + key: 'color', + name: '标题颜色', + type: 'Color', }, { - "key": "fontSize", - "name": "字体大小", - "type": "Number" + key: 'fontSize', + name: '字体大小', + type: 'Number', }, { - "key": "align", - "name": "对齐方式", - "type": "Select", - "range": [ + key: 'align', + name: '对齐方式', + type: 'Select', + range: [ { - "key": "left", - "text": "左对齐" + key: 'left', + text: '左对齐', }, { - "key": "center", - "text": "居中对齐" + key: 'center', + text: '居中对齐', }, { - "key": "right", - "text": "右对齐" - } - ] + key: 'right', + text: '右对齐', + }, + ], }, { - "key": "lineHeight", - "name": "行高", - "type": "Number" - } + key: 'lineHeight', + name: '行高', + type: 'Number', + }, ], - "config": { - "text": "我是文本", - "color": "rgba(60,60,60,1)", - "fontSize": 18, - "align": "center", - "lineHeight": 2 - } + config: { + text: '我是文本', + color: 'rgba(60,60,60,1)', + fontSize: 18, + align: 'center', + lineHeight: 2, + }, }, - "Tab": { - "editData": [ + Tab: { + editData: [ { - "key": "tabs", - "name": "项目类别", - "type": "MutiText" + key: 'tabs', + name: '项目类别', + type: 'MutiText', }, { - "key": "activeColor", - "name": "激活颜色", - "type": "Color" + key: 'activeColor', + name: '激活颜色', + type: 'Color', }, { - "key": "color", - "name": "文字颜色", - "type": "Color" + key: 'color', + name: '文字颜色', + type: 'Color', }, { - "key": "fontSize", - "name": "文字大小", - "type": "Number" + key: 'fontSize', + name: '文字大小', + type: 'Number', }, { - "key": "imgSize", - "name": "图片大小", - "type": "Number" + key: 'imgSize', + name: '图片大小', + type: 'Number', }, { - "key": "sourceData", - "name": "数据源", - "type": "DataList" - } + key: 'sourceData', + name: '数据源', + type: 'DataList', + }, ], - "config": { - "tabs": ["类别一", "类别二"], - "color": "rgba(153,153,153,1)", - "activeColor": "rgba(0,102,204,1)", - "fontSize": 16, - "imgSize": 100, - "sourceData": [ + config: { + tabs: ['类别一', '类别二'], + color: 'rgba(153,153,153,1)', + activeColor: 'rgba(0,102,204,1)', + fontSize: 16, + imgSize: 100, + sourceData: [ { - "id": 1, - "title": "趣谈小课1", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "type": 0, - "imgUrl": [ + id: 1, + title: '趣谈小课1', + desc: '致力于打造优质小课程', + link: 'xxxxx', + type: 0, + imgUrl: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/1_1740c6fbcd9.png", - } - ] + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/1_1740c6fbcd9.png', + }, + ], }, { - "id": 2, - "title": "趣谈小课2", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "type": 0, - "imgUrl": [ + id: 2, + title: '趣谈小课2', + desc: '致力于打造优质小课程', + link: 'xxxxx', + type: 0, + imgUrl: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/2_1740c7033a9.png", - } - ] + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/2_1740c7033a9.png', + }, + ], }, { - "id": 3, - "title": "趣谈小课3", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "type": 1, - "imgUrl": [ + id: 3, + title: '趣谈小课3', + desc: '致力于打造优质小课程', + link: 'xxxxx', + type: 1, + imgUrl: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/1_1740c6fbcd9.png", - } - ] - } - ] - } + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/1_1740c6fbcd9.png', + }, + ], + }, + ], + }, }, - "Notice": { - "editData": [ + Notice: { + editData: [ { - "key": "text", - "name": "文本", - "type": "Text" + key: 'text', + name: '文本', + type: 'Text', }, // { // "key": "link", @@ -213,393 +220,393 @@ export default { // "type": "Text" // }, { - "key": "speed", - "name": "滚动速度", - "type": "Number" + key: 'speed', + name: '滚动速度', + type: 'Number', }, { - "key": "theme", - "name": "主题", - "type": "Select", - "range": [ + key: 'theme', + name: '主题', + type: 'Select', + range: [ { - "key": "default", - "text": "默认" + key: 'default', + text: '默认', }, { - "key": "warning", - "text": "警告" + key: 'warning', + text: '警告', }, { - "key": "primary", - "text": "主要" + key: 'primary', + text: '主要', }, { - "key": "success", - "text": "成功" + key: 'success', + text: '成功', }, { - "key": "danger", - "text": "危险" - } - ] + key: 'danger', + text: '危险', + }, + ], }, { - "key": "isClose", - "name": "是否可关闭", - "type": "Switch" - } + key: 'isClose', + name: '是否可关闭', + type: 'Switch', + }, ], - "config": { - "text": "通知栏: 趣谈前端上线啦", - "link": "", - "speed": 50, - "theme": "warning", - "isClose": false - } + config: { + text: '通知栏: 趣谈前端上线啦', + link: '', + speed: 50, + theme: 'warning', + isClose: false, + }, }, - "Qrcode": { - "editData": [ + Qrcode: { + editData: [ { - "key": "qrcode", - "name": "二维码", - "type": "Upload" + key: 'qrcode', + name: '二维码', + type: 'Upload', }, { - "key": "text", - "name": "文字", - "type": "Text" + key: 'text', + name: '文字', + type: 'Text', }, { - "key": "color", - "name": "文字颜色", - "type": "Color" + key: 'color', + name: '文字颜色', + type: 'Color', }, { - "key": "fontSize", - "name": "文字大小", - "type": "Number" - } + key: 'fontSize', + name: '文字大小', + type: 'Number', + }, ], - "config": { - "qrcode": [ + config: { + qrcode: [ { - uid: "001", - name: "image.png", - status: "done", - url: "http://io.nainor.com/uploads/code_173e1705e0c.png", - } + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/code_173e1705e0c.png', + }, ], - "text": "二维码", - "color": "rgba(153,153,153,1)", - "fontSize": 14 - } + text: '二维码', + color: 'rgba(153,153,153,1)', + fontSize: 14, + }, }, - "Footer": { - "editData": [ + Footer: { + editData: [ { - "key": "bgColor", - "name": "背景色", - "type": "Color" + key: 'bgColor', + name: '背景色', + type: 'Color', }, { - "key": "height", - "name": "高度", - "type": "Number" + key: 'height', + name: '高度', + type: 'Number', }, { - "key": "text", - "name": "文字", - "type": "Text" + key: 'text', + name: '文字', + type: 'Text', }, { - "key": "fontSize", - "name": "字体大小", - "type": "Number" + key: 'fontSize', + name: '字体大小', + type: 'Number', }, { - "key": "color", - "name": "文字颜色", - "type": "Color" + key: 'color', + name: '文字颜色', + type: 'Color', }, { - "key": "align", - "name": "对齐方式", - "type": "Select", - "range": [ + key: 'align', + name: '对齐方式', + type: 'Select', + range: [ { - "key": "left", - "text": "左对齐" + key: 'left', + text: '左对齐', }, { - "key": "center", - "text": "居中对齐" + key: 'center', + text: '居中对齐', }, { - "key": "right", - "text": "右对齐" - } - ] - } + key: 'right', + text: '右对齐', + }, + ], + }, ], - "config": { - "bgColor": "rgba(0,0,0,1)", - "text": "页脚Footer", - "color": "rgba(255,255,255,1)", - "align": "center", - "fontSize": 16, - "height": 48 - } + config: { + bgColor: 'rgba(0,0,0,1)', + text: '页脚Footer', + color: 'rgba(255,255,255,1)', + align: 'center', + fontSize: 16, + height: 48, + }, }, - "Image": { - "editData": [ + Image: { + editData: [ { - "key": "imgUrl", - "name": "上传", - "type": "Upload" + key: 'imgUrl', + name: '上传', + type: 'Upload', }, { - "key": "round", - "name": "圆角", - "type": "Number" - } + key: 'round', + name: '圆角', + type: 'Number', + }, ], - "config": { - "imgUrl": [ + config: { + imgUrl: [ { - uid: "001", - name: "image.png", - status: "done", - url: "http://io.nainor.com/uploads/4_1740bf4535c.png", - } + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/4_1740bf4535c.png', + }, ], - "round": 0 - } + round: 0, + }, }, - "Header": { - "editData": [ + Header: { + editData: [ { - "key": "bgColor", - "name": "背景色", - "type": "Color" + key: 'bgColor', + name: '背景色', + type: 'Color', }, { - "key": "height", - "name": "高度", - "type": "Number" + key: 'height', + name: '高度', + type: 'Number', }, { - "key": "logo", - "name": "logo", - "type": "Upload" + key: 'logo', + name: 'logo', + type: 'Upload', }, { - "key": "logoText", - "name": "logo文字", - "type": "Text" + key: 'logoText', + name: 'logo文字', + type: 'Text', }, { - "key": "color", - "name": "文字颜色", - "type": "Color" + key: 'color', + name: '文字颜色', + type: 'Color', }, { - "key": "fontSize", - "name": "文字大小", - "type": "Number" - } + key: 'fontSize', + name: '文字大小', + type: 'Number', + }, ], - "config": { - "bgColor": "rgba(0,0,0,1)", - "logo": [ + config: { + bgColor: 'rgba(0,0,0,1)', + logo: [ { - uid: "001", - name: "image.png", - status: "done", - url: "http://io.nainor.com/uploads/3_1740be8a482.png", - } + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/3_1740be8a482.png', + }, ], - "logoText": "页头Header", - "fontSize": 20, - "color": "rgba(255,255,255,1)", - "height": 50 - } + logoText: '页头Header', + fontSize: 20, + color: 'rgba(255,255,255,1)', + height: 50, + }, }, - "List": { - "editData": [ + List: { + editData: [ { - "key": "sourceData", - "name": "数据源", - "type": "DataList" + key: 'sourceData', + name: '数据源', + type: 'DataList', }, { - "key": "round", - "name": "圆角", - "type": "Number" + key: 'round', + name: '圆角', + type: 'Number', }, { - "key": "imgSize", - "name": "图片大小", - "type": "Select", - "range": [ + key: 'imgSize', + name: '图片大小', + type: 'Select', + range: [ { - "key": 60, - "text": "60 x 60" + key: 60, + text: '60 x 60', }, { - "key": 80, - "text": "80 x 80" + key: 80, + text: '80 x 80', }, { - "key": 100, - "text": "100 x 100" + key: 100, + text: '100 x 100', }, { - "key": 120, - "text": "120 x 120" + key: 120, + text: '120 x 120', }, { - "key": 150, - "text": "150 x 150" - } - ] + key: 150, + text: '150 x 150', + }, + ], }, { - "key": "fontSize", - "name": "文字大小", - "type": "Number" + key: 'fontSize', + name: '文字大小', + type: 'Number', }, { - "key": "color", - "name": "文字颜色", - "type": "Color" - } + key: 'color', + name: '文字颜色', + type: 'Color', + }, ], - "config": { - "sourceData": [ + config: { + sourceData: [ { - "id": "1", - "title": "趣谈小课", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "imgUrl": [ + id: '1', + title: '趣谈小课', + desc: '致力于打造优质小课程', + link: 'xxxxx', + imgUrl: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/1_1740c6fbcd9.png", - } - ] + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/1_1740c6fbcd9.png', + }, + ], }, { - "id": "2", - "title": "趣谈小课", - "desc": "致力于打造优质小课程", - "link": "xxxxx", - "imgUrl": [ + id: '2', + title: '趣谈小课', + desc: '致力于打造优质小课程', + link: 'xxxxx', + imgUrl: [ { - "uid": "002", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/1_1740c6fbcd9.png", - } - ] - } + uid: '002', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/1_1740c6fbcd9.png', + }, + ], + }, ], - "round": 0, - "imgSize": 80, - "fontSize": 16, - "color": "rgba(153,153,153,1)" - } + round: 0, + imgSize: 80, + fontSize: 16, + color: 'rgba(153,153,153,1)', + }, }, - "Video": { - "editData": [ + Video: { + editData: [ { - "key": "poster", - "name": "视频封面", - "type": "Upload" + key: 'poster', + name: '视频封面', + type: 'Upload', }, { - "key": "url", - "name": "视频链接", - "type": "Text" - } + key: 'url', + name: '视频链接', + type: 'Text', + }, ], - "config": { - "poster": [ + config: { + poster: [ { - "uid": "001", - "name": "image.png", - "status": "done", - "url": "http://io.nainor.com/uploads/1_1740c6fbcd9.png", - } + uid: '001', + name: 'image.png', + status: 'done', + url: 'http://io.nainor.com/uploads/1_1740c6fbcd9.png', + }, ], - "url": "" - } + url: '', + }, }, - "XProgress": { - "editData": [ + XProgress: { + editData: [ { - "key": "theme", - "name": "主题", - "type": "Select", - "range": [ + key: 'theme', + name: '主题', + type: 'Select', + range: [ { - "key": "success", - "text": "成功" + key: 'success', + text: '成功', }, { - "key": "warning", - "text": "警告" + key: 'warning', + text: '警告', }, { - "key": "danger", - "text": "危险" - } - ] + key: 'danger', + text: '危险', + }, + ], }, { - "key": "shape", - "name": "形状", - "type": "Radio", - "range": [ + key: 'shape', + name: '形状', + type: 'Radio', + range: [ { - "key": "circle", - "text": "圆形" + key: 'circle', + text: '圆形', }, { - "key": "line", - "text": "线形" + key: 'line', + text: '线形', }, { - "key": "semi-circle", - "text": "半圆形" - } - ] + key: 'semi-circle', + text: '半圆形', + }, + ], }, { - "key": "size", - "name": "大小", - "type": "Number" + key: 'size', + name: '大小', + type: 'Number', }, { - "key": "percent", - "name": "进度值", - "type": "Number", - "range": [0, 100] + key: 'percent', + name: '进度值', + type: 'Number', + range: [0, 100], }, { - "key": "strokeWidth", - "name": "线条粗细", - "type": "Number" - } + key: 'strokeWidth', + name: '线条粗细', + type: 'Number', + }, ], - "config": { - "theme": "success", - "shape": "circle", - "size": 200, - "percent": 30, - "strokeWidth": 10 - } - } -} \ No newline at end of file + config: { + theme: 'success', + shape: 'circle', + size: 200, + percent: 30, + strokeWidth: 10, + }, + }, +}; diff --git a/src/pages/editor/Container.js b/src/pages/editor/Container.js index 67d67b2..bb2b112 100644 --- a/src/pages/editor/Container.js +++ b/src/pages/editor/Container.js @@ -1,11 +1,12 @@ -import React, { useState, useEffect, memo, useMemo } from 'react'; -import { Input, Slider, Result, Tabs } from 'antd'; +import React, { useState, useEffect, useCallback, memo, useMemo } from 'react'; +import { Slider, Result, Tabs, Alert } from 'antd'; import { PieChartOutlined, ExpandOutlined, PlayCircleOutlined, HighlightOutlined, } from '@ant-design/icons'; +import TextLoop from 'react-text-loop'; import { connect } from 'dva'; import HeaderComponent from './components/Header'; import SourceBox from './SourceBox'; @@ -17,10 +18,10 @@ import template from 'components/DynamicEngine/template'; import mediaTpl from 'components/DynamicEngine/mediaTpl'; import graphTpl from 'components/DynamicEngine/graphTpl'; import schema from 'components/DynamicEngine/schema'; +import { uuid } from 'utils/tool'; import styles from './index.less'; -const { Search } = Input; const { TabPane } = Tabs; const Container = memo(props => { @@ -68,6 +69,10 @@ const Container = memo(props => { }); }; + const clearData = useCallback(() => { + dispatch({ type: 'editorModal/clearAll' }); + }, []); + const handleDel = id => { dispatch({ type: 'editorModal/delPointData', @@ -94,34 +99,50 @@ const Container = memo(props => { }); return arr; }, []); + // 存储用户唯一信息 + if (!localStorage.getItem('uid') || !sessionStorage.getItem('sid')) { + localStorage.setItem('uid', uuid(8, 10)); + sessionStorage.setItem('sid', uuid(5, 10)); + } + return (
- +
- console.log(value)} enterButton /> + +
Dooring升级啦!
+
Dooring添加自动保存功能
+
已有500+人使用
+
持续迭代中...
+ + } + />
{template.map((value, i) => ( - + ))} {mediaTpl.map((value, i) => ( - + ))} {graphTpl.map((value, i) => ( - + ))} diff --git a/src/pages/editor/SourceBox.js b/src/pages/editor/SourceBox.js index 1cea37e..4d7d39f 100644 --- a/src/pages/editor/SourceBox.js +++ b/src/pages/editor/SourceBox.js @@ -76,7 +76,6 @@ const SourceBox = memo(props => { const opacity = isOver ? 0.7 : 1; const backgroundColor = isOver ? 1 : 0.7; - return (
@@ -101,12 +100,12 @@ const SourceBox = memo(props => {
{ > {pointData.map(value => (
- +
))} diff --git a/src/pages/editor/TargetBox.js b/src/pages/editor/TargetBox.js index a3d689c..4666be3 100644 --- a/src/pages/editor/TargetBox.js +++ b/src/pages/editor/TargetBox.js @@ -1,5 +1,5 @@ import React, { useMemo, memo } from 'react'; -import { useDrag, DragPreviewImage } from 'react-dnd'; +import { useDrag } from 'react-dnd'; import { connect } from 'dva'; import schema from 'components/DynamicEngine/schema'; @@ -30,12 +30,6 @@ const TargetBox = memo(props => { return (
{props.children} - {item.type === 'Carousel' && ( - - )}
); }); diff --git a/src/pages/editor/preview.js b/src/pages/editor/preview.js index 84cce3f..7c23155 100644 --- a/src/pages/editor/preview.js +++ b/src/pages/editor/preview.js @@ -1,69 +1,82 @@ -import React, { memo, useEffect, useState } from 'react' -import GridLayout from 'react-grid-layout' -import DynamicEngine from 'components/DynamicEngine' -import req from '@/utils/req' -import styles from './index.less' +import React, { memo, useEffect, useState } from 'react'; +import GridLayout from 'react-grid-layout'; +import DynamicEngine from 'components/DynamicEngine'; +import req from '@/utils/req'; +import styles from './index.less'; // 可视化组件类型 // const componentTypes = ['Column', 'Pie'] -const isMac = navigator.platform.indexOf('Mac') === 0 +const isMac = navigator.platform.indexOf('Mac') === 0; const pcStyle = { width: isMac ? 395 : 412, - margin: '20px auto', - border: '10px solid #000', - borderRadius: '20px', - height: '684px', - overflow: 'auto' -} + margin: '20px auto', + border: '10px solid #000', + borderRadius: '20px', + height: '684px', + overflow: 'auto', +}; -const PreviewPage = memo((props) => { +const PreviewPage = memo(props => { const [pointData, setPointData] = useState(() => { - let pointDataStr = localStorage.getItem('pointData') - let points - - try{ - points = JSON.parse(pointDataStr) || [] - }catch(err) { - points = [] - } - return points.map(item => ({...item, point: {...item.point, isDraggable: false, isResizable: false } })) - }) + let pointDataStr = localStorage.getItem('pointData'); + let points; - const vw = window.innerWidth + try { + points = JSON.parse(pointDataStr) || []; + } catch (err) { + points = []; + } + return points.map(item => ({ + ...item, + point: { ...item.point, isDraggable: false, isResizable: false }, + })); + }); + + const vw = window.innerWidth; useEffect(() => { - const { tid } = props.location.query - req.get('/visible/preview/get', { params: { tid } }).then(res => { - setPointData(res.map(item => ({...item, point: {...item.point, isDraggable: false, isResizable: false } }))) - }).catch(err => { - setTimeout(() => { - window.close() - }, 3000) - }) - }, []) + const { tid } = props.location.query; + const timer = null; + req + .get('/visible/preview/get', { params: { tid } }) + .then(res => { + setPointData( + res.map(item => ({ + ...item, + point: { ...item.point, isDraggable: false, isResizable: false }, + })), + ); + }) + .catch(err => { + timer = setTimeout(() => { + window.close(); + }, 3000); + }); + return () => { + clearTimeout(timer); + }; + }, []); return (
800 ? pcStyle : {}}> - 800 ? 375 :vw } - margin={[0,0]} + 800 ? 375 : vw} + margin={[0, 0]} id="xx" > - { - pointData.map(value => -
- -
- ) - } + {pointData.map(value => ( +
+ +
+ ))}
- ) -}) + ); +}); -export default PreviewPage +export default PreviewPage;