原文地址: https://blog.csdn.net/qq_43651437/article/details/105796023
0. $ cnpm install @jiaminghi/data-view-react
1. webapp\app\containers\Display\components\Setting\Form\constants.ts
import slide from 'assets/json/slideSettings/slide.json'
import chart from 'assets/json/slideSettings/chart.json'
import rectangle from 'assets/json/slideSettings/rectangle.json'
import label from 'assets/json/slideSettings/label.json'
import video from 'assets/json/slideSettings/video.json'
import timer from 'assets/json/slideSettings/timer.json'
import decoration3 from 'assets/json/slideSettings/decoration3.json'
import BorderBox from 'assets/json/slideSettings/borderBox.json'
export enum SecondaryGraphTypes {
Rectangle = 20,
Label = 21,
Video = 22,
Timer = 23,
Decoration = 24,
BorderBox = 25
}
export enum GraphTypes {
Slide,
Chart,
Secondary
}
export const slideSettings = {
[GraphTypes.Slide]: slide,
[GraphTypes.Chart]: chart,
[SecondaryGraphTypes.Rectangle]: rectangle,
[SecondaryGraphTypes.Label]: label,
[SecondaryGraphTypes.Video]: video,
[SecondaryGraphTypes.Timer]: timer,
[SecondaryGraphTypes.Decoration]: decoration3,
[SecondaryGraphTypes.BorderBox]: BorderBox
}
2. webapp/app/containers/Display/components/Layer/Content/SecondaryGraph/DevBorderBox.tsx
import { LayerContext } from '../../util'
import React, { useContext, useState, useEffect } from 'react'
import moment from 'moment'
import { useLabelStyle } from './hooks'
import * as datav from '@jiaminghi/data-view-react'
const DevBorderBox: React.FC = () => {
//获取参数
const { layer: { params } } = useContext(LayerContext)
const { color, titleContent ,dev_type,titleWidth} = params
if(dev_type == "BorderBox1"){
return
}
if(dev_type == "BorderBox2"){
return
}
if(dev_type == "BorderBox3"){
return
}
if(dev_type == "BorderBox4"){
return
}
if(dev_type == "BorderBox4(reverse)"){
return
}
if(dev_type == "BorderBox5"){
return
}
if(dev_type == "BorderBox5(reverse)"){
return
}
if(dev_type == "BorderBox6"){
return
}
if(dev_type == "BorderBox7"){
return
}
if(dev_type == "BorderBox8"){
return
}
if(dev_type == "BorderBox9"){
return
}
if(dev_type == "BorderBox10"){
return
}
if(dev_type == "BorderBox11"){
return
}
if(dev_type == "BorderBox12"){
return
}
if(dev_type == "BorderBox13"){
return
}
}
export default DevBorderBox
webapp/app/containers/Display/components/Layer/Content/SecondaryGraph/DevDecoration.tsx
import { LayerContext } from '../../util'
import React, { useContext, useState, useEffect } from 'react'
import moment from 'moment'
import { useLabelStyle } from './hooks'
import * as datav from '@jiaminghi/data-view-react'
const DevDecoration: React.FC = () => {
//获取参数
const { layer: { params } } = useContext(LayerContext)
const { color, dev_type } = params
const labelStyle = useLabelStyle(params)
if(dev_type == "Decoration1"){
return
}
if(dev_type == "Decoration2"){
return
}
if(dev_type == "Decoration2(reverse)"){
return
}
if(dev_type == "Decoration3"){
return
}
if(dev_type == "Decoration4"){
return
}
if(dev_type == "Decoration4(reverse)"){
return
}
if(dev_type == "Decoration5"){
return {params.contentText}
}
if(dev_type == "Decoration6"){
return
}
if(dev_type == "Decoration7"){
return {params.contentText}
}
if(dev_type == "Decoration8"){
return
}
if(dev_type == "Decoration8(reverse)"){
return
}
if(dev_type == "Decoration9"){
return {params.contentText}
}
if(dev_type == "Decoration10"){
return
}
if(dev_type == "Decoration11"){
return {params.contentText}
}
}
export default DevDecoration
3. webapp/app/containers/Display/components/Layer/Content/SecondaryGraph/index.ts
export { default as Rectangle } from './Rectangle'
export { default as Label } from './Label'
export { default as Video } from './Video'
export { default as Timer } from './Timer'
export { default as DevDecoration } from './DevDecoration'
export { default as DevBorderBox } from './DevBorderBox'
4. webapp/app/containers/Display/components/Layer/LayerCore.tsx
import React, { useContext } from 'react'
import { LayerContext } from './util'
import { GraphTypes, SecondaryGraphTypes } from '../Setting'
import { Chart, Rectangle, Label, Video, Timer,DevDecoration,DevBorderBox } from './Content'
const LayerCore: React.FC = (props) => {
const { layer, operationInfo } = useContext(LayerContext)
const { type, subType } = layer
if (type === GraphTypes.Chart) {
return
}
if (type === GraphTypes.Secondary) {
switch (subType) {
case SecondaryGraphTypes.Rectangle:
return
case SecondaryGraphTypes.Label:
return
case SecondaryGraphTypes.Video:
return
case SecondaryGraphTypes.Timer:
return
case SecondaryGraphTypes.Decoration:
return
case SecondaryGraphTypes.BorderBox:
return
}
}
return
}
export default LayerCore
5. webapp\app\containers\Display\components\Toolbar\Chart.tsx
import React, { useContext, useCallback, useMemo } from 'react'
import { Button, Icon, Dropdown, Menu } from 'antd'
const ButtonGroup = Button.Group
import IconFont from 'components/IconFont'
import { DisplayToolbarContext } from './util'
import { GraphTypes, SecondaryGraphTypes } from '../constants'
import { ClickParam } from 'antd/lib/menu'
const SecondaryGraphIcons = [
{
name: '矩形',
icon: 'icon-rounded-rect',
type: SecondaryGraphTypes.Rectangle
},
{
name: '标签',
icon: 'icon-rect-text',
type: SecondaryGraphTypes.Label
},
{
name: '视频',
icon: 'icon-video',
type: SecondaryGraphTypes.Video
},
{
name: '装饰',
icon: 'icon-rounded-rect',
type: SecondaryGraphTypes.Decoration
},{
name: '边框',
icon: 'icon-rounded-rect',
type: SecondaryGraphTypes.BorderBox
}
]
interface IChartProps {
onAdd: (type: GraphTypes, subType?: SecondaryGraphTypes) => void
}
const Chart: React.FC = (props) => {
const { size, comment } = useContext(DisplayToolbarContext)
const { onAdd } = props
const addChart = useCallback(() => {
onAdd(GraphTypes.Chart)
}, [onAdd])
//辅助图形里面的item点击事件
const addSecondary = useCallback(
(param: ClickParam) => {
onAdd(GraphTypes.Secondary, +param.key as SecondaryGraphTypes)
},
[onAdd]
)
//添加辅助图形里面的图形
const overlay = (
)
return (
)
}
export default Chart
6. webapp\app\assets\json\slideSettings\decoration3.json
{
"name": "Decoration3",
"title": "装饰3",
"params": [{
"name": "size",
"title": "装饰尺寸",
"items": [{
"name": "width",
"title": "宽度(像素)",
"component": "inputnumber",
"default": 200
}, {
"name": "height",
"title": "高度(像素)",
"component": "inputnumber",
"default": 120
}]
}, {
"name": "position",
"title": "矩形位置",
"items": [{
"name": "positionX",
"title": "x轴位置(像素)",
"component": "inputnumber",
"labelCol": 15,
"wrapperCol": 8
}, {
"name": "positionY",
"title": "y轴位置(像素)",
"component": "inputnumber",
"labelCol": 15,
"wrapperCol": 8
}]
},{
"name": "colors",
"title": "颜色",
"items": [{
"name": "color",
"title": "装饰颜色",
"component": "colorPicker",
"default": [0,0,0],
"labelCol": 10
}]
}, {
"name": "dev_type",
"title": "装饰",
"items": [{
"name": "dev_type",
"title": "装饰样式",
"component": "select",
"values": [{
"name": "第一种",
"value": "Decoration1"
}, {
"name": "第二种",
"value": "Decoration2"
}, {
"name": "第二种(反转)",
"value": "Decoration2(reverse)"
}, {
"name": "第三种",
"value": "Decoration3"
},{
"name": "第四种",
"value": "Decoration4"
}, {
"name": "第四种(反转)",
"value": "Decoration4(reverse)"
}, {
"name": "第五种",
"value": "Decoration5"
}, {
"name": "第六种",
"value": "Decoration6"
}, {
"name": "第七种",
"value": "Decoration7"
}, {
"name": "第八种",
"value": "Decoration8"
}, {
"name": "第八种(反转)",
"value": "Decoration8(reverse)"
}
, {
"name": "第九种",
"value": "Decoration9"
}
, {
"name": "第十种",
"value": "Decoration10"
}
, {
"name": "第十一种",
"value": "Decoration11"
}],
"default": "Decoration6"
}]
}, {
"name": "content",
"title": "文本",
"items": [{
"name": "contentText",
"tip": "输入文本",
"title": "文本内容",
"component": "input",
"default": "",
"wrapperCol": 24
}]
}, {
"name": "font",
"title": "文字",
"items": [{
"name": "fontFamily",
"title": "字体",
"component": "select",
"values": [{
"name": "默认",
"value": ""
}, {
"name": "微软雅黑",
"value": "Microsoft Yahei"
}, {
"name": "宋体",
"value": "SimSun"
}, {
"name": "黑体",
"value": "Heiti"
}, {
"name": "华文细黑",
"value": "STXihei"
}, {
"name": "Verdana",
"value": "Verdana"
}, {
"name": "Arial",
"value": "Arial"
}, {
"name": "Times New Roman",
"value": "Times New Roman"
}, {
"name": "Times",
"value": "Times"
}, {
"name": "MS Sans Serif",
"value": "MS Sans Serif"
}],
"default": "",
"wrapperCol": 24
}, {
"name": "fontColor",
"title": "字体颜色",
"component": "colorPicker",
"default": [0,0,0],
"labelCol": 10,
"wrapperCol": 14
}, {
"name": "fontSize",
"title": "字体大小",
"component": "inputnumber",
"default": 40,
"placeholder": "像素",
"labelCol": 10,
"wrapperCol": 14
},{
"name": "fontWeight",
"title": "字体粗细",
"component": "select",
"values": [{
"name": "normal",
"value": "normal"
}, {
"name": "bold",
"value": "bold"
}, {
"name": "bolder",
"value": "bolder"
}, {
"name": "lighter",
"value": "lighter"
}, {
"name": "100",
"value": "100"
}, {
"name": "200",
"value": "200"
}, {
"name": "300",
"value": "300"
}, {
"name": "400",
"value": "400"
}, {
"name": "500",
"value": "500"
}, {
"name": "600",
"value": "600"
}, {
"name": "700",
"value": "700"
}, {
"name": "800",
"value": "800"
}, {
"name": "900",
"value": "900"
}],
"default": "normal",
"labelCol": 10,
"wrapperCol": 14
}, {
"name": "textStyle",
"title": "样式",
"component": "checkboxGroup",
"values": [{
"label": "斜体",
"value": "italic"
}, {
"label": "下划线",
"value": "underline"
}],
"default": [],
"labelCol": 10,
"wrapperCol": 14
}
]
}]
}
webapp\app\assets\json\slideSettings\borderBox.json
{
"name": "BorderBox3",
"title": "bord边框2",
"params": [{
"name": "size",
"title": "边框尺寸",
"items": [{
"name": "width",
"title": "宽度(像素)",
"component": "inputnumber",
"default": 200
}, {
"name": "height",
"title": "高度(像素)",
"component": "inputnumber",
"default": 120
}]
}, {
"name": "position",
"title": "矩形位置",
"items": [{
"name": "positionX",
"title": "x轴位置(像素)",
"component": "inputnumber",
"labelCol": 15,
"wrapperCol": 8
}, {
"name": "positionY",
"title": "y轴位置(像素)",
"component": "inputnumber",
"labelCol": 15,
"wrapperCol": 8
}]
},{
"name": "colors",
"title": "颜色",
"items": [{
"name": "color",
"title": "边框颜色",
"component": "colorPicker",
"default": [0,0,0],
"labelCol": 10
}]
}, {
"name": "dev_type",
"title": "边框",
"items": [{
"name": "dev_type",
"title": "边框样式",
"component": "select",
"values": [{
"name": "第一种",
"value": "BorderBox1"
}, {
"name": "第二种",
"value": "BorderBox2"
}, {
"name": "第三种",
"value": "BorderBox3"
},{
"name": "第四种",
"value": "BorderBox4"
}, {
"name": "第四种(反转)",
"value": "BorderBox4(reverse)"
}, {
"name": "第五种",
"value": "BorderBox5"
}, {
"name": "第五种(反转)",
"value": "BorderBox5(reverse)"
},{
"name": "第六种",
"value": "BorderBox6"
}, {
"name": "第七种",
"value": "BorderBox7"
}, {
"name": "第八种",
"value": "BorderBox8"
}, {
"name": "第九种",
"value": "BorderBox9"
}
, {
"name": "第十种",
"value": "BorderBox10"
}
, {
"name": "第十一种",
"value": "BorderBox11"
}, {
"name": "第十二种",
"value": "BorderBox12"
}, {
"name": "第十三种",
"value": "BorderBox13"
}],
"default": "BorderBox6"
}]
},{
"name": "title",
"title": "标题",
"items": [{
"name": "titleContent",
"title": "标题文字",
"tip": "输入文本",
"component": "input",
"default": "",
"wrapperCol": 24
},{
"name": "titleWidth",
"title": "标题宽度",
"component": "inputnumber",
"labelCol": 15,
"wrapperCol": 8
}]
}]
}
7. webapp\app\containers\Display\components\types.ts ILayerParams接口下 添加属性字段 color、dev_type
color: string[]
dev_type:String