Commit f38802ff authored by 陈龙's avatar 陈龙

feat: 提交AssemblyScroll变更

parent e0af2891
......@@ -13,6 +13,7 @@ import 'swiper/swiper.min.css';
import 'swiper/components/pagination/pagination.min.css';
import 'swiper/components/navigation/navigation.min.css';
import SwiperCore, {Autoplay, Pagination, Navigation} from 'swiper/core';
import {isFunction, isString} from "../../BasicReport/src/ReportsManage/utils/utils";
SwiperCore.use([Autoplay, Pagination, Navigation]);
/*
......@@ -95,65 +96,72 @@ const AlarmScrollAssembly = (props) => {
}, []);
return (
<>
{realTimeDataList && realTimeDataList.length ? <div
className={classnames(styles.alarScrollAssembly, (realTimeDataList?.length > 1000 ? styles.moreThan1000 : styles.lessThan1000))}
id={'alarmListDiv'}>
<Swiper
slidesPerView={1}
modules={[Pagination]}
pagination={{
type: 'fraction',
formatFractionCurrent: (num) => `第${num}条`,
formatFractionTotal: (num) => `共${num}条`,
}}
navigation
autoplay={{
delay: 3000,
disableOnInteraction: false,
}}
loop
direction="vertical"
onSlideChange={(e) => {
if (e.activeIndex === realTimeDataList.length - 1) getData();
}}
>
{realTimeDataList.map((item, index) => {
return (
<SwiperSlide
key={index}
virtualIndex={index}
onClick={() => {
setCurrentInfo(item);
setModalVisible(true);
}}
>
<InfoItem key={index} info={item}/>
</SwiperSlide>
);
})}
</Swiper>
{modalVisible && (
<Modal
visible={modalVisible}
onCancel={() => setModalVisible(false)}
width={'80%'}
destroyOnClose
{realTimeDataList && realTimeDataList.length ? <>
{
props.prefix ? <span>{props.prefix}</span> : ''
}
<div
className={classnames(styles.alarScrollAssembly, (realTimeDataList?.length > 1000 ? styles.moreThan1000 : styles.lessThan1000))}
id={'alarmListDiv'}>
<Swiper
slidesPerView={1}
modules={[Pagination]}
pagination={{
type: 'fraction',
formatFractionCurrent: (num) => `第${num}条`,
formatFractionTotal: (num) => `共${num}条`,
}}
navigation
autoplay={{
delay: 3000,
disableOnInteraction: false,
}}
loop
direction="vertical"
onSlideChange={(e) => {
if (e.activeIndex === realTimeDataList.length - 1) getData();
}}
>
<NormChart
info={currentInfo}
deviceType={currentInfo.deviceType}
deviceCode={currentInfo.stationCode}
/>
</Modal>
)}
</div> : ''}
{realTimeDataList.map((item, index) => {
return (
<SwiperSlide
key={index}
virtualIndex={index}
onClick={() => {
setCurrentInfo(item);
setModalVisible(true);
}}
>
<InfoItem key={index} info={item}/>
</SwiperSlide>
);
})}
</Swiper>
{modalVisible && (
<Modal
visible={modalVisible}
onCancel={() => setModalVisible(false)}
width={'80%'}
destroyOnClose
>
<NormChart
info={currentInfo}
deviceType={currentInfo.deviceType}
deviceCode={currentInfo.stationCode}
/>
</Modal>
)}
</div>
</> : ''}
</>
);
};
AlarmScrollAssembly.defaultProps = {
deviceType: '二供泵房,二供机组',
prefix: ''
};
AlarmScrollAssembly.propTypes = {
deviceType: PropTypes.string,
prefix: PropTypes.string
};
export default AlarmScrollAssembly;
const isObject = (obj) => {
return Object.prototype.toString.call(obj) === '[object Object]';
return Object.prototype.toString.call(obj) === '[object Object]';
};
const isString = (obj) => {
return Object.prototype.toString.call(obj) === '[object String]';
return Object.prototype.toString.call(obj) === '[object String]';
};
const isNumber = (num) => {
return Object.prototype.toString.call(num) === '[object Number]';
return Object.prototype.toString.call(num) === '[object Number]';
};
const isArray = (arr) => {
return Object.prototype.toString.call(arr) === '[object Array]';
return Object.prototype.toString.call(arr) === '[object Array]';
};
const isFunction = (obj) => {
return Object.prototype.toString.call(obj) === '[object Function]';
}
const hasMoney = (configItems) => {
if (!configItems) return false;
let _items = configItems.split('|');
return !!_items.find((item) => item === '金额');
if (!configItems) return false;
let _items = configItems.split('|');
return !!_items.find((item) => item === '金额');
};
const isSelect = (configItems) => {
if (!configItems) return false;
let _items = configItems.split('|');
return !!_items.find((item) => item === 'renderAsSelect');
if (!configItems) return false;
let _items = configItems.split('|');
return !!_items.find((item) => item === 'renderAsSelect');
};
// options=name1[.value1],name2[.value2],name3[.value3];
const returnOptions = (configItems) => {
if (!configItems) return false;
let _items = configItems.split('|');
let _options = _items.find((item) => item.includes('options='));
if (!_options) return false;
return _options.replace('options=', '').split(',');
if (!configItems) return false;
let _items = configItems.split('|');
let _options = _items.find((item) => item.includes('options='));
if (!_options) return false;
return _options.replace('options=', '').split(',');
};
const returnRows = (configItems) => {
if (!configItems) return 3;
let _items = configItems.split('|');
let _options = _items.find((item) => item.includes('rows='));
if (!_options) return 3;
let _rows = Number(_options.replace('rows=', ''));
return !isNaN(_rows) && _rows >= 1 ? _rows : 3;
if (!configItems) return 3;
let _items = configItems.split('|');
let _options = _items.find((item) => item.includes('rows='));
if (!_options) return 3;
let _rows = Number(_options.replace('rows=', ''));
return !isNaN(_rows) && _rows >= 1 ? _rows : 3;
};
const returnCols = (configItems) => {
if (!configItems) return 1;
let _items = configItems.split('|');
let _options = _items.find((item) => item.includes('cols='));
if (!_options) return 1;
let _cols = Number(_options.replace('cols=', ''));
return !isNaN(_cols) && _cols <= 3 && _cols >= 0 ? _cols : 1;
if (!configItems) return 1;
let _items = configItems.split('|');
let _options = _items.find((item) => item.includes('cols='));
if (!_options) return 1;
let _cols = Number(_options.replace('cols=', ''));
return !isNaN(_cols) && _cols <= 3 && _cols >= 0 ? _cols : 1;
};
/**
* @description: 用来在summary中处理数值的配置
......@@ -51,36 +54,36 @@ const returnCols = (configItems) => {
* @author: ChenLong
*/
const returnHandledNumber = (configItems, num, isSummary) => {
// 精度、前缀、后缀、倍率
// $_d|_d%|_d*0.0001|金额|0.00
if (isNaN(num)) return '-';
if (!configItems) return num;
num = Number(num);
let _items = configItems.split('|');
/* let prefix = '';
let suffix = '';*/
let template = '_d';
let precision = 0;
let rate = 1;
_items.forEach((item) => {
let _arr = [];
if (item.match(/_d[^\*]/)) {
// 后缀
template = item;
} else if (item.match(/^_d\*/)) {
// 倍率
let _rate = item.replace(/_d\*/, '');
rate = _rate && isSummary ? Number(_rate) : 1; // 总结栏计算需要计算倍率,其他不用
} else if (item.match(/^0\./)) {
// 精度
precision = item.replace('0.', '').length;
}
});
// 可能存在NaN的问题
let final = _items.includes('金额')
? Number((num * rate).toFixed(precision)).toLocaleString()
: Number((num * rate).toFixed(precision)).toLocaleString();
return template.replace(/_d/, isString(final) ? final : '-');
// 精度、前缀、后缀、倍率
// $_d|_d%|_d*0.0001|金额|0.00
if (isNaN(num)) return '-';
if (!configItems) return num;
num = Number(num);
let _items = configItems.split('|');
/* let prefix = '';
let suffix = '';*/
let template = '_d';
let precision = 0;
let rate = 1;
_items.forEach((item) => {
let _arr = [];
if (item.match(/_d[^\*]/)) {
// 后缀
template = item;
} else if (item.match(/^_d\*/)) {
// 倍率
let _rate = item.replace(/_d\*/, '');
rate = _rate && isSummary ? Number(_rate) : 1; // 总结栏计算需要计算倍率,其他不用
} else if (item.match(/^0\./)) {
// 精度
precision = item.replace('0.', '').length;
}
});
// 可能存在NaN的问题
let final = _items.includes('金额')
? Number((num * rate).toFixed(precision)).toLocaleString()
: Number((num * rate).toFixed(precision)).toLocaleString();
return template.replace(/_d/, isString(final) ? final : '-');
};
/**
* @description: 返回configItems内配置的默认值、默认模式等等
......@@ -100,21 +103,21 @@ const returnHandledNumber = (configItems, num, isSummary) => {
* defaultDateValue 时间参数 默认时间
*/
const returnDefaultValueOrConfigs = (configItems = '', keysArray = []) => {
let _map = {};
let _configItemsArray = configItems.split('|');
keysArray.forEach((key) => {
_map[key] = _configItemsArray.find((item) => item.includes(`${key}=`))?.replace(`${key}=`, '');
});
return _map;
let _map = {};
let _configItemsArray = configItems.split('|');
keysArray.forEach((key) => {
_map[key] = _configItemsArray.find((item) => item.includes(`${key}=`))?.replace(`${key}=`, '');
});
return _map;
};
function downloadFunc(url, name, target = '_self') {
const a = document.createElement('a');
a.href = url;
a.target = target;
a.download = name;
a.click();
a.remove();
const a = document.createElement('a');
a.href = url;
a.target = target;
a.download = name;
a.click();
a.remove();
}
/**
......@@ -125,35 +128,36 @@ function downloadFunc(url, name, target = '_self') {
* @returns {Object} {type: error | success ,content: 提示...}
*/
function filenameVerification(file, special) {
// 文件名含有特殊字符 提示不能上传 {+,:/?#[]@!$&\\*+;=}
// 规则对象(flag)
var flag = !special
? new RegExp("[`~!@#$^&*=|{}':;',\\[\\]/?~!@#¥&*——|{}【】‘;:”“'。,、?]")
: new RegExp("[`~!@#$^&*=|{}':;',[\\]?~!@#¥&*——|{}【】‘;:”“'。,、?]");
if (flag.test(file.name)) {
// 文件名含有特殊字符 提示不能上传 {+,:/?#[]@!$&\\*+;=}
// 规则对象(flag)
var flag = !special
? new RegExp("[`~!@#$^&*=|{}':;',\\[\\]/?~!@#¥&*——|{}【】‘;:”“'。,、?]")
: new RegExp("[`~!@#$^&*=|{}':;',[\\]?~!@#¥&*——|{}【】‘;:”“'。,、?]");
if (flag.test(file.name)) {
return {
type: 'error',
content: `文件名格式错误,请检查文件名是否含有特殊字符${"~!@#$^&*=|{}':;',\\[\\]/?~!@#¥&*——|{}【】‘;:”“'。,、?"}`,
};
}
return {
type: 'error',
content: `文件名格式错误,请检查文件名是否含有特殊字符${"~!@#$^&*=|{}':;',\\[\\]/?~!@#¥&*——|{}【】‘;:”“'。,、?"}`,
type: 'success',
content: `上传成功!`,
};
}
return {
type: 'success',
content: `上传成功!`,
};
}
export {
isObject,
isString,
isNumber,
hasMoney,
isArray,
returnHandledNumber,
returnDefaultValueOrConfigs,
downloadFunc,
filenameVerification,
isSelect,
returnOptions,
returnRows,
returnCols,
isObject,
isString,
isNumber,
hasMoney,
isArray,
isFunction,
returnHandledNumber,
returnDefaultValueOrConfigs,
downloadFunc,
filenameVerification,
isSelect,
returnOptions,
returnRows,
returnCols,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment