JS
import React, { useEffect, useState } from 'react'
import styles from './style.less'
import { Table } from 'antd';
const dataSource = [
{
grade: '重要',
time: '人脸识别告警',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '已处理'
},
{
grade: '一般',
time: '人员走散',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '已处理'
},
{
grade: '一般',
time: '违规翻越门禁通道',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '未处理'
},
{
grade: '一般',
time: '违规翻越门禁通道',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '未处理'
},
{
grade: '重要',
time: '人脸识别告警',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '已处理'
},
{
grade: '一般',
time: '哈哈哈',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '未处理'
},
{
grade: '一般',
time: '违规翻越门禁通道',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '未处理'
},
{
grade: '一般',
time: '违规翻越门禁通道',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '未处理'
},
{
grade: '重要',
time: '人脸识别告警',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '已处理'
},
{
grade: '一般',
time: '嘿嘿IEhi额',
type: '2020.11.28 14:26:00',
adress: '2020.11.28 15:23:46',
status: '未处理'
},
];
const columns = [
{
title: '等级',
dataIndex: 'grade',
key: 'grade',
width: 50,
render: text => <div style={text == '重要' ? { background: 'linear-gradient(1deg, #E7474D 0%, #FF0042 100%)' } : { background: 'linear-gradient(180deg, #777C84 0%, #708293 100%)' }} className={styles.grade}><a className={styles.gradeA}>{text}</a></div>,
},
{
title: '事件类型',
dataIndex: 'time',
key: 'time'
},
{
title: '报警时间',
dataIndex: 'type',
key: 'type',
},
{
title: '处理时间',
dataIndex: 'adress',
key: 'adress',
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
render: text => <div className={styles.statusBox}><div style={text == '未处理' ? { background: '#F01E2A' } : null} className={styles.status} ></div ><span className={styles.statusSpan}>{text}</span></div>
}
];
const Index = () =>
{
const [timer, setTimer] = useState(null); // 定时器
// const [count, setCount] = React.useState(0)
useEffect(() =>
{ // 发送数据请求 设置订阅/启动定时器 手动更改 DOM 等 ~
// 如果有真实数据 请在数据请求后 调用此方法
InitialScroll(dataSource)
return () =>
{
clearInterval(timer)
}
}, []) // 检测数组内变量 如果为空 则监控全局
// 开启定时器
const InitialScroll = (data) =>
{
let v = document.getElementsByClassName("ant-table-body")[0];
if (data.length > 3) // 只有当大于三条数据的时候 才会看起滚动
{
let time = setInterval(() =>
{
v.scrollTop += 1.5;
if (Math.ceil(v.scrollTop) >= parseFloat(v.scrollHeight - v.clientHeight))
{
v.scrollTop = 0
// setTimeout(() => { v.scrollTop = 0 }, 1000)
}
}, 100)
setTimer(time) // 定时器保存变量 利于停止
}
}
return (
<div className={styles.container}>
<div className={styles.overall}>
<div onMouseEnter={() =>
{
if (timer) clearTimeout(timer); // 如果之前有定时器 先把之前的定时器取消
clearInterval(timer)
}} onMouseLeave={() =>
{
if (timer) clearTimeout(timer); // 如果之前有定时器 先把之前的定时器取消
InitialScroll(dataSource)
}} className={styles.table}>
<Table id="cyclicScroll" scroll={{ y: 110 }} dataSource={dataSource} columns={columns} pagination={false} rowClassName={(record, index) => index % 2 === 0 ? styles.oddNumber : styles.evenNumbers} />
</div>
</div>
</div >
)
}
export default Index
CSS
.overall {
height: 162px;
box-sizing: border-box;
:global {
::-webkit-scrollbar {
// 改变滚动条宽度
height: 5px;
width: 7px;
overflow-y: auto;
}
::-webkit-scrollbar-thumb {
// 改变滚动条样式
border-radius: 5px;
-webkit-box-shadow: inset 0 0 5px rgba(89, 89, 89, 0.2);
background: #939392;
}
::-webkit-scrollbar-track {
display: none;
-webkit-box-shadow: 0;
border-radius: 0;
background: #f0f2f5;
}
.ant-table-thead>tr>th {
background-color: rgba(40, 108, 224, 0.33);
height: 30px;
font-size: 16px;
font-weight: 400;
color: #37B6FF;
text-align: center;
}
.ant-table-thead>tr>th {
border-bottom: none;
}
.ant-table-tbody>tr>td {
border-bottom: none;
text-align: center;
}
.ant-table-thead>tr>th .ant-table-header-column {
margin-left: 10px;
}
.ant-table-body {
overflow: auto;
}
.ant-table-header {
background: none;
}
.ant-table-fixed-header>.ant-table-content>.ant-table-scroll>.ant-table-body {
background: none;
}
.ant-table-header .ant-table-hide-scrollbar {
overflow: auto;
}
.ant-table-thead>tr.ant-table-row-hover:not(.ant-table-expanded-row):not(.ant-table-row-selected)>td,
.ant-table-tbody>tr.ant-table-row-hover:not(.ant-table-expanded-row):not(.ant-table-row-selected)>td,
.ant-table-thead>tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected)>td,
.ant-table-tbody>tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected)>td {
background: none;
}
.ant-table-thead>tr>th,
.ant-table-tbody>tr>td {
padding: 0px !important;
}
.ant-table-thead>tr>th {
background-color: rgba(40, 108, 224, 0.33);
height: 30px;
font-size: 20px;
font-weight: 400;
color: #37B6FF;
}
.ant-table-placeholder {
padding: 0px !important;
background: none !important;
border-top: none !important;
border-bottom: none
}
.ant-empty-normal {
color: #FFFFFF;
}
.ant-table {
box-sizing: border-box;
margin: 0;
padding: 0;
color: rgba(0, 0, 0, 0.85);
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: 'tnum';
position: relative;
font-size: 14px;
background: rgba(0, 0, 0, 0);
border-radius: 2px;
}
.ant-table-container table>thead>tr:first-child th:last-child {
display: none;
border-top-right-radius: 2px;
}
}
}
.table {
width: 100%;
height: 100%;
}
// 等级
.grade {
margin: 0 auto;
margin-top: -1px;
font-weight: bold;
width: 50px;
height: 20px;
border-radius: 2px;
text-align: center;
line-height: 18px;
.gradeA {
font-size: 16px;
color: #FFFFFF;
}
}
.statusBox {
display: flex;
align-items: center;
justify-content: center;
.status {
width: 6px;
height: 6px;
background: #6DE922;
border-radius: 50%;
margin-right: 5px;
.statusSpan {
font-size: 14px;
// font-family: SourceHanSansSC;
font-weight: 400;
color: #FFFFFF;
}
}
}
.oddNumber {
background: rgba(58, 90, 162, 0.1);
font-size: 16px;
// font-family: PingFang SC;
font-weight: 400;
color: #FFFFFF;
height: 38px;
padding: 0px !important;
font-family: "DINpro";
}
.evenNumbers {
background: rgba(58, 90, 162, 0.33);
font-size: 16px;
// font-family: PingFang SC;
font-weight: 400;
color: #FFFFFF;
height: 38px;
font-family: "DINpro";
}