reactor:将 getWeekTimes、getMonthTimes 抽到 utils 统一复用
parent
349a4bb0a9
commit
49dbce22d1
|
@ -60,7 +60,7 @@
|
|||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import { resetPagination, getWeekTimes, getMonthTimes } from '@/sheep/helper/utils';
|
||||
|
||||
const tabMaps = ['周排行', '月排行'];
|
||||
|
||||
|
@ -130,39 +130,6 @@
|
|||
getBrokerageRankList();
|
||||
});
|
||||
|
||||
// TODO 芋艿:此处可考虑抽离
|
||||
/**
|
||||
* 获得当前周的开始和结束时间
|
||||
*/
|
||||
function getWeekTimes() {
|
||||
const today = new Date();
|
||||
const dayOfWeek = today.getDay();
|
||||
return [
|
||||
new Date(today.getFullYear(), today.getMonth(), today.getDate() - dayOfWeek, 0, 0, 0),
|
||||
new Date(
|
||||
today.getFullYear(),
|
||||
today.getMonth(),
|
||||
today.getDate() + (6 - dayOfWeek),
|
||||
23,
|
||||
59,
|
||||
59,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前月的开始和结束时间
|
||||
*/
|
||||
function getMonthTimes() {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = today.getMonth();
|
||||
const startDate = new Date(year, month, 1, 0, 0, 0);
|
||||
const nextMonth = new Date(year, month + 1, 1);
|
||||
const endDate = new Date(nextMonth.getTime() - 1);
|
||||
return [startDate, endDate];
|
||||
}
|
||||
|
||||
// 加载更多
|
||||
function loadMore() {
|
||||
if (state.loadStatus === 'noMore') {
|
||||
|
|
|
@ -55,8 +55,8 @@
|
|||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import { reactive } from 'vue';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||
import { resetPagination, getWeekTimes, getMonthTimes } from '@/sheep/helper/utils';
|
||||
|
||||
const tabMaps = ['周排行', '月排行'];
|
||||
|
||||
|
@ -129,40 +129,6 @@
|
|||
function formatDate(date) {
|
||||
return sheep.$helper.timeFormat(date, 'yyyy-mm-dd hh:MM:ss');
|
||||
}
|
||||
|
||||
// TODO 芋艿:此处可考虑抽离
|
||||
// 此处可考虑抽离
|
||||
/**
|
||||
* 获得当前周的开始和结束时间
|
||||
*/
|
||||
function getWeekTimes() {
|
||||
const today = new Date();
|
||||
const dayOfWeek = today.getDay();
|
||||
return [
|
||||
new Date(today.getFullYear(), today.getMonth(), today.getDate() - dayOfWeek, 0, 0, 0),
|
||||
new Date(
|
||||
today.getFullYear(),
|
||||
today.getMonth(),
|
||||
today.getDate() + (6 - dayOfWeek),
|
||||
23,
|
||||
59,
|
||||
59,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前月的开始和结束时间
|
||||
*/
|
||||
function getMonthTimes() {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = today.getMonth();
|
||||
const startDate = new Date(year, month, 1, 0, 0, 0);
|
||||
const nextMonth = new Date(year, month + 1, 1);
|
||||
const endDate = new Date(nextMonth.getTime() - 1);
|
||||
return [startDate, endDate];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
@ -309,3 +309,28 @@ export function jsonParse(str) {
|
|||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前周的开始和结束时间
|
||||
*/
|
||||
export function getWeekTimes() {
|
||||
const today = new Date();
|
||||
const dayOfWeek = today.getDay();
|
||||
return [
|
||||
new Date(today.getFullYear(), today.getMonth(), today.getDate() - dayOfWeek, 0, 0, 0),
|
||||
new Date(today.getFullYear(), today.getMonth(), today.getDate() + (6 - dayOfWeek), 23, 59, 59),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前月的开始和结束时间
|
||||
*/
|
||||
export function getMonthTimes() {
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = today.getMonth();
|
||||
const startDate = new Date(year, month, 1, 0, 0, 0);
|
||||
const nextMonth = new Date(year, month + 1, 1);
|
||||
const endDate = new Date(nextMonth.getTime() - 1);
|
||||
return [startDate, endDate];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue