Commit 9df6ec87 authored by 陈龙's avatar 陈龙

feat: 实现选择器

parent 5d128a0a
...@@ -5,13 +5,17 @@ ...@@ -5,13 +5,17 @@
** 菜单参数列表:*变量名*(变量说明,数据类型,是否必填,取值范围) ** 菜单参数列表:*变量名*(变量说明,数据类型,是否必填,取值范围)
**/ **/
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Form, Input, DatePicker, InputNumber, Space, Row, Col, Button, message } from 'antd'; import {Form, Input, DatePicker, InputNumber, Space, Row, Col, Button, message, Select} from 'antd';
import moment from 'moment'; import moment from 'moment';
import { submitReportData } from '../api/service/report'; import { submitReportData } from '../api/service/report';
import FileUpload from './Components/fileUpload/fileUpload'; import FileUpload from './Components/fileUpload/fileUpload';
import { reportService } from '../api'; import { reportService } from '../api';
import { isSelect, returnOptions } from './utils/utils';
const { Option } = Select;
// 类型 // 类型
const USER_ID = window.globalConfig.userInfo.OID; const USER_ID = window.globalConfig.userInfo.OID;
const TEXT_ARRAY = ['文本', '标签'];
const DATE_PICKER_ARRAY = ['日期']; const DATE_PICKER_ARRAY = ['日期'];
const DATE_TIME_PICKER_ARRAY = ['日期时刻']; const DATE_TIME_PICKER_ARRAY = ['日期时刻'];
const DATE_TYPE = ['日期', '日期时刻']; // 用来匹配是否需要转为日期对象; const DATE_TYPE = ['日期', '日期时刻']; // 用来匹配是否需要转为日期对象;
...@@ -60,6 +64,16 @@ const ReportEditForm = ({ reportDetails, reportData, onCancel, reportName, modal ...@@ -60,6 +64,16 @@ const ReportEditForm = ({ reportDetails, reportData, onCancel, reportName, modal
} else if (FILE_ARRAY.includes(config.type)) { } else if (FILE_ARRAY.includes(config.type)) {
return <FileUpload schema={{ renderTo: 'File' }} />; return <FileUpload schema={{ renderTo: 'File' }} />;
} else { } else {
if (isSelect(config.configItems)) {
let options = returnOptions(config.configItems);
if (options) {
return <Select>
{
options.map(item => <Option value={item}>{item}</Option>)
}
</Select>;
}
}
return <Input />; return <Input />;
} }
}; };
......
...@@ -249,6 +249,7 @@ const ReportsManage = (props) => { ...@@ -249,6 +249,7 @@ const ReportsManage = (props) => {
const [sorterObject, setSorterObject] = useState({}); const [sorterObject, setSorterObject] = useState({});
const [detailConfig, setDetailConfig] = useState({ url: '', type: '', params: {} }); const [detailConfig, setDetailConfig] = useState({ url: '', type: '', params: {} });
const [controlsHeight, setControlsHeight] = useState(44); const [controlsHeight, setControlsHeight] = useState(44);
const [getNewData, setGetNewData] = useState(false);
const menu = () => { const menu = () => {
const _item = [ const _item = [
{ {
...@@ -812,7 +813,7 @@ const ReportsManage = (props) => { ...@@ -812,7 +813,7 @@ const ReportsManage = (props) => {
.then((res) => { .then((res) => {
if (res.code === 0) { if (res.code === 0) {
message.success('删除成功!'); message.success('删除成功!');
getData(pagination); setGetNewData(!getNewData);
} }
}); });
}, },
...@@ -965,7 +966,7 @@ const ReportsManage = (props) => { ...@@ -965,7 +966,7 @@ const ReportsManage = (props) => {
}, [tableHeaderLevel]); }, [tableHeaderLevel]);
useEffect(() => { useEffect(() => {
if (!isInit) getData(pagination); if (!isInit) getData(pagination);
}, [timeFrom, timeTo, sorterObject, filterObject]); }, [timeFrom, timeTo, sorterObject, filterObject,getNewData]);
useEffect(() => { useEffect(() => {
function getRefHeight() { function getRefHeight() {
if (timer) clearTimeout(timer); if (timer) clearTimeout(timer);
......
...@@ -13,18 +13,31 @@ const isArray = (arr) => { ...@@ -13,18 +13,31 @@ const isArray = (arr) => {
const hasMoney = (configItems) => { const hasMoney = (configItems) => {
if (!configItems) return false; if (!configItems) return false;
let _items = configItems.split('|'); let _items = configItems.split('|');
return !!_items.find((item) => item === '金额'); return !!_items.find(item => item === '金额');
};
const isSelect = (configItems) => {
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(',');
}; };
/** /**
* @description: 用来在summary中处理数值的配置 * @Description: 用来在summary中处理数值的配置
* @params: 参数描述 * @Params: 参数描述
* @date: 2022/8/10 * @Date: 2022/8/10
* @author: ChenLong * @Author: ChenLong
*/ * */
const returnHandledNumber = (configItems, num) => { const returnHandledNumber = (configItems, num) => {
// 精度、前缀、后缀、倍率 // 精度、前缀、后缀、倍率
// $_d|_d%|_d*0.0001|金额|0.00 // $_d|_d%|_d*0.0001|金额|0.00
if (isNaN(Number(num))) return '-'; if (isNaN(num)) return '-';
if (!configItems) return num; if (!configItems) return num;
num = Number(num); num = Number(num);
let _items = configItems.split('|'); let _items = configItems.split('|');
...@@ -33,7 +46,7 @@ const returnHandledNumber = (configItems, num) => { ...@@ -33,7 +46,7 @@ const returnHandledNumber = (configItems, num) => {
let template = '_d'; let template = '_d';
let precision = 0; let precision = 0;
let rate = 1; let rate = 1;
_items.forEach((item) => { _items.forEach(item => {
let _arr = []; let _arr = [];
if (item.match(/_d[^\*]/)) { if (item.match(/_d[^\*]/)) {
// 后缀 // 后缀
...@@ -48,35 +61,27 @@ const returnHandledNumber = (configItems, num) => { ...@@ -48,35 +61,27 @@ const returnHandledNumber = (configItems, num) => {
} }
}); });
// 可能存在NaN的问题 // 可能存在NaN的问题
let final = _items.includes('金额') let final = _items.includes('金额') ? Number((num * rate).toFixed(precision)).toLocaleString() : Number((num * rate).toFixed(precision));
? Number((num * rate).toFixed(precision)).toLocaleString()
: Number((num * rate).toFixed(precision));
return template.replace(/_d/, isString(final) ? final : '-'); return template.replace(/_d/, isString(final) ? final : '-');
}; };
/** /**
* @description: 返回configItems内配置的默认值、默认模式等等 * @Description: 返回configItems内配置的默认值、默认模式等等
* @params: 参数描述 * @Params: 参数描述
* @date: 2022/8/12 * @Date: 2022/8/12
* @author: ChenLong * @Author: ChenLong
* @params: * @params:
* configItems 报表字段的配置 例如 defaultValue=智慧水务 * configItems 报表字段的配置 例如 defaultValue=智慧水务 defaultDateModel=customer|defaultDateValue=2022-01-01,2022-12-31;
* * keysArray 所需要返回的值的key的集合,比如你需要获取configItems中的’defaultValue‘,那么keysArray=['defaultValue'];
* * @Returns:
* defaultDateModel=customer|defaultDateValue=2022-01-01,2022-12-31; * defaultValue 通用参数 默认值
* keysArray
*
*
* 所需要返回的值的key的集合,比如你需要获取configItems中的’defaultValue‘,那么keysArray=['defaultValue'];
* @returns:
* defaultValue 通用参数 默认值
* defaultDateModel 时间参数 默认模式 * defaultDateModel 时间参数 默认模式
* defaultDateValue 时间参数 默认时间 * defaultDateValue 时间参数 默认时间
*/ * */
const returnDefaultValueOrConfigs = (configItems = '', keysArray = []) => { const returnDefaultValueOrConfigs = (configItems = '', keysArray = []) => {
let _map = {}; let _map = {};
let _configItemsArray = configItems.split('|'); let _configItemsArray = configItems.split('|');
keysArray.forEach((key) => { keysArray.forEach(key => {
_map[key] = _configItemsArray.find((item) => item.includes(`${key}=`))?.replace(`${key}=`, ''); _map[key] = _configItemsArray.find(item => item.includes(`${key}=`))?.replace(`${key}=`, '');
}); });
return _map; return _map;
}; };
...@@ -91,22 +96,20 @@ function downloadFunc(url, name, target = '_self') { ...@@ -91,22 +96,20 @@ function downloadFunc(url, name, target = '_self') {
} }
/** /**
* @description: 校验文件的名称是否包含特殊字符 * @Description: 校验文件的名称是否包含特殊字符
* @params: {Object: File} file file对象 { special:Boolean } 是否去除/的匹配 * @Params: {Object: File} file file对象 { special:Boolean } 是否去除/的匹配
* @date: 2021/12/8 * @Date: 2021/12/8
* @author: ChenLong * @Author: ChenLong
* @returns {Object} {type: error | success ,content: 提示...} * @Return {Object} {type: error | success ,content: 提示...}
*/ * */
function filenameVerification(file, special) { function filenameVerification(file, special) {
// 文件名含有特殊字符 提示不能上传 {+,:/?#[]@!$&\\*+;=} // 文件名含有特殊字符 提示不能上传 {+,:/?#[]@!$&\\*+;=}
// 规则对象(flag) // 规则对象(flag)
var flag = !special var flag = !special ? new RegExp('[`~!@#$^&*=|{}\':;\',\\[\\]/?~!@#¥&*——|{}【】‘;:”“\'。,、?]') : new RegExp('[`~!@#$^&*=|{}\':;\',[\\]?~!@#¥&*——|{}【】‘;:”“\'。,、?]');
? new RegExp("[`~!@#$^&*=|{}':;',\\[\\]/?~!@#¥&*——|{}【】‘;:”“'。,、?]")
: new RegExp("[`~!@#$^&*=|{}':;',[\\]?~!@#¥&*——|{}【】‘;:”“'。,、?]");
if (flag.test(file.name)) { if (flag.test(file.name)) {
return { return {
type: 'error', type: 'error',
content: `文件名格式错误,请检查文件名是否含有特殊字符${"~!@#$^&*=|{}':;',\\[\\]/?~!@#¥&*——|{}【】‘;:”“'。,、?"}`, content: `文件名格式错误,请检查文件名是否含有特殊字符${'~!@#$^&*=|{}\':;\',\\[\\]/?~!@#¥&*——|{}【】‘;:”“\'。,、?'}`,
}; };
} }
return { return {
...@@ -125,4 +128,6 @@ export { ...@@ -125,4 +128,6 @@ export {
returnDefaultValueOrConfigs, returnDefaultValueOrConfigs,
downloadFunc, downloadFunc,
filenameVerification, filenameVerification,
}; isSelect,
returnOptions,
};
\ No newline at end of file
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