import React, { useState, useEffect, useRef, Component } from "react";
import { connect } from "dva";
import { Icon, message } from 'antd/lib/index';
import {
initFilter,
extendInclude,
extendOrder
} from "../../../utils/common";
import config from "../../../config.js";
class BI060MapeShow extends React.Component {
constructor(props) {
super(props);
this.state = {
retData: [],//数据源
picIndex: 0,//下一张
picMax: 1,//最大图片数
Title: '',//四色图说明(配置)
RGBCOLOR_TL: '',
OPACITY_TL: '',
};
}
componentDidMount() {
this.loadData();
}
renderSpeedColumn = () => {
return { className: 'redTableCell' }
}
ShowInfo(msg) {
if (msg && msg.length > 0) {
message.info({
content: (
)
})
}
}
loadData = () => {
//信息获取
const json = initFilter(this.props.login.OrgId);
extendOrder(json, "CREATE_TIME", 1);
extendInclude(json, 'Nav_Colors.Nav_ColorPoints');
extendInclude(json, 'Nav_Colors.Nav_Areas.Nav_Area');
this.props.dispatch({
type: "app/getDataByPost",
url: "PC/PCInfo/EntitiesShow",
payload: json,
onlyData: false,
onComplete: (ret) => {
if (ret && ret.IsSuccessful && ret.Data && ret.Data.length > 0) {
var ulPic = document.getElementById('ulPic')
//加载头部信息 并且支持点击
ret.Data.forEach((item, index) => {
var li = document.createElement('li')
li.innerText = item.NAME
li.style.color = "white"
li.style.float = "left"
li.style.fontSize = 20 + 'px'
li.style.paddingLeft = 10 + 'px'
li.style.paddingRight = 10 + 'px'
li.style.render = 2
li.style.marginLeft = 30 + 'px'
li.style.backgroundColor = '#1890ff'
li.style.cursor = "pointer"
li.onclick = () => this.PicShow(index)
ulPic.appendChild(li)
})
this.PicShow(0, null, ret.Data)
} else {
message.error("请先配置四色图信息再查看!");
}
}
})
};
//根据数据显示图片
PicShow = (indexP, opType, DataPic) => {
if (indexP && opType == null && DataPic == null) {
indexP = indexP
} else {
indexP = 0
if (opType == null || opType == undefined) {
} else if (opType == 1) {
indexP = this.state.picIndex + 1
} else if (opType == -1) {
indexP = this.state.picIndex - 1
if (indexP < 0) {
message.error("已经是第一张图");
return false
}
} else {
message.error("操作异常");
return false
}
}
if (DataPic == null || DataPic == undefined) {
DataPic = this.state.retData
}
var picMax = 1
var RGBCOLOR_TL = 'wheat'
var OPACITY_TL = '0.6'
if (DataPic.length > 0) { // 显示图片
picMax = DataPic.length
if (indexP >= picMax) {
message.error("已经是最后一张图片");
}
var ShowInfo = DataPic[indexP]
if (ShowInfo.FILE_PATH) {
const divShow = document.getElementById('divPic');
divShow.style.backgroundImage = 'url(' + config.picServerHost + ShowInfo.FILE_PATH + ')'
divShow.style.width = ShowInfo.WIDTH + 'px'
divShow.style.height = ShowInfo.HEIGHT + 'px'
}
const ulDescribe = document.getElementById('ulDescribe');
// ulDescribe.style.width = ShowInfo.WIDTH + 'px'
//标记删除
var arrNodes = ulDescribe.childNodes;
for (var i = 0; i < arrNodes.length; i++) {
ulDescribe.removeChild(arrNodes[i]);
}
if (ShowInfo.RGBCOLOR_TL != null && ShowInfo.RGBCOLOR_TL != '')
RGBCOLOR_TL = ShowInfo.RGBCOLOR_TL
if (ShowInfo.OPACITY_TL != null && ShowInfo.OPACITY_TL != '')
OPACITY_TL = ShowInfo.OPACITY_TL
var index = 0
const svg = document.getElementById('picSvg');
if (svg.childNodes && svg.childNodes.length > 0) {
for (var i = svg.childNodes.length - 1; i > -1; i--) {
svg.removeChild(svg.childNodes[i])
}
}
svg.style.width = ShowInfo.WIDTH + 'px'
svg.style.height = ShowInfo.HEIGHT + 'px'
if (ShowInfo.Nav_Colors && ShowInfo.Nav_Colors.length > 0) {
ShowInfo.Nav_Colors.forEach(e => {
index++
if (e.RGBCOLOR == null || e.RGBCOLOR != '') {
var points = e.Nav_ColorPoints
if (points == null || points.length < 1) {
message.error("配置区域【" + e.NAME + "】未描点!");
} else {
// 获取SVG中的polygon元素
const polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon');// const polygon = document.getElementById('myPolygon' + index);//找到画布
//点位拼接
let pointsString = points.map(coord => `${coord.X},${coord.Y}`).join(' ');// 注意:points属性的格式是"x1,y1 x2,y2 ..."
polygon.setAttribute('points', pointsString); //描点
polygon.setAttribute('fill', e.RGBCOLOR);//填充颜色
// polygon.setAttribute('stroke', e.RGBCOLOR);//画笔颜色
polygon.setAttribute('stroke-width', 0);//多个区域合成一起画 中间的颜色去除
polygon.setAttribute('stroke', 'none');//画笔颜色
polygon.style.opacity = e.OPACITY//透明度
//点击提示
polygon.onclick = () => {
this.ShowInfo(e.DESCRIBE)
}
svg.appendChild(polygon);
//点位 num 为 1 设置标记
//title配置
if (e.DESCRIBE && e.DESCRIBE.length > 0) {
const title = document.createElementNS('http://www.w3.org/2000/svg', 'title');
// var innerHTML= e.DESCRIBE.replace('
','\n')
title.textContent = e.DESCRIBE_TITLE
polygon.appendChild(title);
}
//直接显示标记
// var XAll = 0
// var YAll = 0
// points.forEach(e => {
// XAll += e.X
// YAll += e.Y
// });
// const mark = document.createElementNS('http://www.w3.org/2000/svg', 'text');
// mark.setAttribute("x", XAll / points.length);
// mark.setAttribute("y", YAll / points.length);
// mark.setAttribute("text-anchor", "middle");
// mark.setAttribute("dominant-baseline", "middle");
// mark.style.fontSize = '16px'
// mark.style.opacity = e.OPACITY
// mark.textContent = e.DESCRIBE_TITLE;
// svg.appendChild(mark);
//画图区域 标记 区域配置编号
const mark = document.createElementNS('http://www.w3.org/2000/svg', 'text');
mark.setAttribute("x", points[0].X);
mark.setAttribute("y", points[0].Y);
mark.setAttribute("text-anchor", "middle");
mark.setAttribute("dominant-baseline", "middle");
mark.style.fontSize = '16px'
mark.style.fontWeight = 'bold'
// mark.style.opacity = e.OPACITY
mark.textContent = e.ZNDEX // + ":" + e.NAME;
svg.appendChild(mark);
//添加 区域的说明
const lidescribe = document.createElement('li')
lidescribe.style.float = "left"
lidescribe.style.marginLeft = '20px'
lidescribe.textContent = e.ZNDEX + ":" + e.NAME;
ulDescribe.appendChild(lidescribe)
}
}
});
}
// picIndex: 0,//下一张
// picMax:1,//最大图片数
this.setState({
retData: DataPic,
picIndex: indexP,
picMax: picMax,
Title: ShowInfo.NAME,
RGBCOLOR_TL: RGBCOLOR_TL,
OPACITY_TL: OPACITY_TL,
})
}
};
render() {
const { Title, picIndex, picMax, RGBCOLOR_TL, OPACITY_TL } = this.state;
return (
{/* {
picIndex > 0 && this.PicShow(0, -1)}>
}
{Title}
{
picMax > (picIndex + 1) && this.PicShow(0, 1)}>
} */}
{/*
*/}
{/*
*/}
);
}
}
export default connect(({ login, app }) => ({ login, app }))(BI060MapeShow);