perf: 调整
This commit is contained in:
@ -33,7 +33,7 @@
|
||||
<div class="filter-row flex">
|
||||
<div class="filter-row-item flex items-center">
|
||||
<span class="label">时间筛选</span>
|
||||
<DatePicker.RangePicker v-model:value="query.data_time" allowClear format="YYYY-MM-DD" class="!w-240px" />
|
||||
<DatePicker.RangePicker v-model="data_time" allowClear format="YYYY-MM-DD" class="!w-240px" @change="onDateChange" />
|
||||
</div>
|
||||
<Button type="primary" ghost class="mr-12px" @click="handleSearch">
|
||||
<template #icon>
|
||||
@ -80,6 +80,8 @@ import PlanSelect from '@/views/components/common/PlanSelect.vue';
|
||||
const { TabPane } = Tabs;
|
||||
const { Option } = Select;
|
||||
const accountType = ref("1");
|
||||
const data_time = ref([]);
|
||||
const operators = ref([]);
|
||||
|
||||
const onLoading = ref(true);
|
||||
|
||||
@ -108,6 +110,19 @@ const handleTabClick = (value) => {
|
||||
accountType.value = value;
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
const onDateChange = (date) => {
|
||||
if (!date) {
|
||||
query.data_time = [];
|
||||
handleSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
const [start, end] = date;
|
||||
const FORMAT_DATE = 'YYYY-MM-DD';
|
||||
query.data_time = [dayjs(start).startOf('day').format(FORMAT_DATE), dayjs(end).endOf('day').format(FORMAT_DATE)];
|
||||
handleSearch();
|
||||
};
|
||||
const mergeChartData = (apiResponse) => {
|
||||
console.log(apiResponse, 'apiResponse');
|
||||
chartConfigs.value = chartConfigs.value.map((config) => {
|
||||
@ -221,14 +236,15 @@ const chartConfigs = ref([
|
||||
},
|
||||
]);
|
||||
const handleReset = async () => {
|
||||
data_time.value = [];
|
||||
query.platform = undefined;
|
||||
query.operator_id = undefined;
|
||||
query.data_time = [];
|
||||
query.ids = [];
|
||||
query.placement_account_id = [];
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
const operators = ref([]);
|
||||
onMounted(() => {
|
||||
handleSearch();
|
||||
getOperators();
|
||||
|
||||
@ -53,12 +53,11 @@
|
||||
<div class="filter-row-item">
|
||||
<span class="label">时间筛选</span>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="query.data_time"
|
||||
size="medium"
|
||||
:allow-clear="false"
|
||||
v-model="data_time"
|
||||
:allowClear="false"
|
||||
format="YYYY-MM-DD"
|
||||
class="w-240px"
|
||||
@change="handleSearch"
|
||||
@change="onDateChange"
|
||||
/>
|
||||
</div>
|
||||
<div class="filter-row-item">
|
||||
@ -80,6 +79,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import dayjs from 'dayjs';
|
||||
import { reactive, defineEmits, defineProps } from 'vue';
|
||||
import { Button, Input, DatePicker } from 'ant-design-vue';
|
||||
import {
|
||||
@ -104,12 +104,21 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const emits = defineEmits(['onSearch', 'onReset', 'update:query']);
|
||||
|
||||
// // 同步父组件传入的初始值
|
||||
// watch(
|
||||
// () => props.query.data_time,
|
||||
// (newVal) => {
|
||||
// if (newVal && newVal.length > 0) {
|
||||
// data_time.value = newVal;
|
||||
// }
|
||||
// },
|
||||
// { immediate: true }
|
||||
// );
|
||||
// const tags = ref([]);
|
||||
const groups = ref([]);
|
||||
const operators = ref([]);
|
||||
const placementAccounts = ref([]);
|
||||
// const dataTime = ref([]);
|
||||
const data_time = ref([]);
|
||||
|
||||
const handleSearch = () => {
|
||||
emits('update:query', props.query);
|
||||
@ -118,7 +127,26 @@ const handleSearch = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const onDateChange = (date) => {
|
||||
// query.data_time = date;
|
||||
if (!date) {
|
||||
props.query.data_time = [];
|
||||
handleSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
const [start, end] = date;
|
||||
const FORMAT_DATE = 'YYYY-MM-DD';
|
||||
props.query.data_time = [
|
||||
dayjs(start).startOf('day').format(FORMAT_DATE),
|
||||
dayjs(end).endOf('day').format(FORMAT_DATE),
|
||||
];
|
||||
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
data_time.value = [];
|
||||
emits('onReset');
|
||||
};
|
||||
|
||||
@ -135,6 +163,13 @@ const getOperators = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getYesterdayDays = () => {
|
||||
const today = new Date();
|
||||
const last7Days = new Date(today);
|
||||
last7Days.setDate(today.getDate() - 1);
|
||||
return [last7Days.toISOString().split('T')[0], today.toISOString().split('T')[0]];
|
||||
};
|
||||
|
||||
const getAccounts = async () => {
|
||||
const { code, data } = await getPlacementAccountsList();
|
||||
if (code === 200) {
|
||||
@ -143,6 +178,9 @@ const getAccounts = async () => {
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const defaultTime = getYesterdayDays();
|
||||
data_time.value = defaultTime;
|
||||
|
||||
getGroups();
|
||||
getOperators();
|
||||
getAccounts();
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
<div class="filter-row flex mb-20px">
|
||||
<div class="filter-row-item flex items-center">
|
||||
<span class="label">时间筛选</span>
|
||||
<DatePicker.RangePicker v-model:value="query.data_time" size="medium" allowClear format="YYYY-MM-DD" class="w-310" />
|
||||
<DatePicker.RangePicker v-model="data_time" size="medium" allowClear format="YYYY-MM-DD" class="w-310" @change="onDateChange" />
|
||||
</div>
|
||||
|
||||
<div class="filter-row-item flex items-center">
|
||||
@ -66,6 +66,9 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
const emits = defineEmits(['onSearch', 'onReset', 'update:query']);
|
||||
|
||||
const data_time = ref([]);
|
||||
|
||||
// 获取最近7天的日期
|
||||
const getLast7Days = () => {
|
||||
const today = new Date();
|
||||
@ -76,6 +79,19 @@ const getLast7Days = () => {
|
||||
const handleSearch = () => {
|
||||
emits('onSearch', props.query);
|
||||
};
|
||||
|
||||
const onDateChange = (date) => {
|
||||
if (!date) {
|
||||
props.query.data_time = [];
|
||||
handleSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
const [start, end] = date;
|
||||
const FORMAT_DATE = 'YYYY-MM-DD';
|
||||
props.query.data_time = [dayjs(start).startOf('day').format(FORMAT_DATE), dayjs(end).endOf('day').format(FORMAT_DATE)];
|
||||
handleSearch();
|
||||
};
|
||||
// 使用 computed 实现 v-model
|
||||
const localQuery = computed({
|
||||
get: () => props.query,
|
||||
@ -83,10 +99,14 @@ const localQuery = computed({
|
||||
});
|
||||
|
||||
const handleReset = () => {
|
||||
data_time.value = [];
|
||||
emits('onReset');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
localQuery.value.data_time = getLast7Days();
|
||||
const defaultTime = getLast7Days();
|
||||
data_time.value = defaultTime;
|
||||
localQuery.value.data_time = defaultTime;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user