Commit 2bfa621e authored by tjy's avatar tjy

抽取公共方法 获取时间范围

parent c66dbba8
......@@ -36,7 +36,7 @@ import moment from 'moment';
import { PublicApi } from '@/services/api';
import style from './index.less';
import UploadModal from '@/components/UploadModal';
import timeRange from '@/utils/index';
import { timeRange } from '@/utils/index';
const { Option } = Select;
......@@ -284,94 +284,23 @@ const memberMaintain: React.FC<[]> = () => {
status: filter.memberStatus || 0,
outerStatus: filter.outerStatus || 0,
innerStatus: filter.innerStatus || 0,
current: params.current,
pageSize: params.pageSize,
};
console.log(obj);
setSearchForm(obj);
};
useEffect(() => {
return console.log(timeRange());
if (!isFirst) return;
let st = '',
et = '',
execute = false;
switch (searchForm.timeRange) {
case 0:
execute = false;
setIsFirst(false);
setSearchForm({ ...searchForm, startDate: '', endDate: '' });
break;
case 1:
execute = true;
st = et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break;
case 2:
execute = true;
st = moment()
.startOf('days')
.format('YYYY-MM-DD');
et = moment()
.subtract(6, 'days')
.format('YYYY-MM-DD');
break;
case 3:
execute = true;
st = moment()
.startOf('days')
.format('YYYY-MM-DD');
et = moment()
.startOf('month')
.format('YYYY-MM-DD');
break;
case 4:
execute = true;
st =
moment()
.subtract(2, 'month')
.format('YYYY-MM') + '-01';
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break;
case 5:
execute = true;
st =
moment()
.subtract(5, 'month')
.format('YYYY-MM') + '-01';
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break;
case 6:
execute = true;
st = moment()
.startOf('years')
.format('YYYY-MM-DD');
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break;
case 7:
execute = true;
st = moment()
.years(moment().years() - 1)
.startOf('years')
.format('YYYY-MM-DD');
et = moment()
.years(moment().years() - 1)
.endOf('years')
.format('YYYY-MM-DD');
break;
}
if (execute) {
let timeRanges = timeRange(searchForm.timeRange);
if (searchForm.timeRange == 0) {
setIsFirst(false);
} else {
setIsFirst(false);
setSearchForm({ ...searchForm, startDate: st, endDate: et });
}
setSearchForm({
...searchForm,
startDate: timeRanges.st,
endDate: timeRanges.et,
});
}, [searchForm.timeRange]);
useEffect(() => {
......@@ -441,8 +370,8 @@ const memberMaintain: React.FC<[]> = () => {
<StandardTable
tableProps={{
rowKey: 'memberId',
// onChange: (pagination: any, filter: any) =>
// handleSearch(pagination, filter),
onChange: (pagination: any, filter: any) =>
handleSearch(pagination, filter),
}}
columns={columns}
currentRef={ref}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
import moment from 'moment';
function isArray(arr: any) {
return Array.isArray(arr)
......@@ -7,24 +8,68 @@ function isObject(obj: any) {
return Object.prototype.toString.call(obj) === '[object Object]'
}
function timeRange(val: number) {
export function timeRange(val: number) {
let st = '', et = '';
switch (val) {
case 0:
st = et = ''
break
case 1:
st = et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break
case 2:
st = moment()
.subtract(6, 'days')
.format('YYYY-MM-DD');
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break
case 3:
st = moment()
.startOf('month')
.format('YYYY-MM-DD');
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break
case 4:
st =
moment()
.subtract(2, 'month')
.format('YYYY-MM') + '-01';
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break
case 5:
st =
moment()
.subtract(5, 'month')
.format('YYYY-MM') + '-01';
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break
case 6:
st = moment()
.startOf('year')
.format('YYYY-MM-DD');
et = moment()
.startOf('days')
.format('YYYY-MM-DD');
break
case 7:
st = moment()
.years(moment().years() - 1)
.startOf('year')
.format('YYYY-MM-DD');
et = moment()
.years(moment().years() - 1)
.endOf('year')
.format('YYYY-MM-DD');
break
}
return { st, et }
......@@ -41,6 +86,5 @@ export function omit(obj: any, arr: string[]) {
export default {
isArray,
isObject,
omit,
timeRange
omit
}
\ 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