|
@@ -1,6 +1,6 @@
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { reactive, onMounted, ref, nextTick } from "vue";
|
|
import { reactive, onMounted, ref, nextTick } from "vue";
|
|
|
-import { getDailyStatList, syncDailyStat } from "@/api/stat";
|
|
|
|
|
|
|
+import { getDailyStatList, syncDailyStatBatch } from "@/api/stat";
|
|
|
import { getStationList } from "@/api/station";
|
|
import { getStationList } from "@/api/station";
|
|
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
@@ -10,7 +10,8 @@ defineOptions({ name: "AdminDailyStat" });
|
|
|
const queryRef = ref();
|
|
const queryRef = ref();
|
|
|
|
|
|
|
|
const state = reactive({
|
|
const state = reactive({
|
|
|
- syncDate: "",
|
|
|
|
|
|
|
+ syncDateRange: [] as string[],
|
|
|
|
|
+ syncing: false,
|
|
|
formQuery: {
|
|
formQuery: {
|
|
|
stationId: "",
|
|
stationId: "",
|
|
|
startDate: "",
|
|
startDate: "",
|
|
@@ -47,7 +48,8 @@ const state = reactive({
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
const yesterday = new Date();
|
|
const yesterday = new Date();
|
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
- state.syncDate = yesterday.toISOString().split("T")[0];
|
|
|
|
|
|
|
+ const yesterdayStr = yesterday.toISOString().split("T")[0];
|
|
|
|
|
+ state.syncDateRange = [yesterdayStr, yesterdayStr];
|
|
|
|
|
|
|
|
loadStations();
|
|
loadStations();
|
|
|
loadData();
|
|
loadData();
|
|
@@ -105,26 +107,42 @@ const handleReset = () => {
|
|
|
loadData(true);
|
|
loadData(true);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const disabledSyncDate = (date: Date) => {
|
|
|
|
|
+ const today = new Date();
|
|
|
|
|
+ today.setHours(0, 0, 0, 0);
|
|
|
|
|
+ return date.getTime() >= today.getTime();
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const handleSyncDailyStat = () => {
|
|
const handleSyncDailyStat = () => {
|
|
|
- if (!state.syncDate) {
|
|
|
|
|
- ElMessage.warning("请选择同步日期");
|
|
|
|
|
|
|
+ if (!state.syncDateRange || state.syncDateRange.length !== 2) {
|
|
|
|
|
+ ElMessage.warning("请选择同步日期范围");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const [startDate, endDate] = state.syncDateRange;
|
|
|
|
|
+ const days = Math.floor((new Date(endDate).getTime() - new Date(startDate).getTime()) / 86400000) + 1;
|
|
|
|
|
+ if (days > 30) {
|
|
|
|
|
+ ElMessage.warning("同步日期范围不能超过30天");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ const rangeLabel = startDate === endDate ? startDate : `${startDate} ~ ${endDate}`;
|
|
|
ElMessageBox.confirm(
|
|
ElMessageBox.confirm(
|
|
|
- `确认重新同步 ${state.syncDate} 的统计数据吗?将同步所有站点的数据。`,
|
|
|
|
|
- "重新同步日统计",
|
|
|
|
|
|
|
+ `确认重新同步 ${rangeLabel}(共${days}天)的统计数据吗?将同步所有站点的数据。`,
|
|
|
|
|
+ "批量同步日统计",
|
|
|
{ confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
|
|
{ confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
|
|
|
).then(() => {
|
|
).then(() => {
|
|
|
- const loading = ElMessage({ message: "同步中...", type: "info", duration: 0 });
|
|
|
|
|
- syncDailyStat({ statDate: state.syncDate })
|
|
|
|
|
|
|
+ state.syncing = true;
|
|
|
|
|
+ const loading = ElMessage({ message: `批量同步中(共${days}天)...`, type: "info", duration: 0 });
|
|
|
|
|
+ syncDailyStatBatch({ startDate, endDate })
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
loading.close();
|
|
loading.close();
|
|
|
- ElMessage.success("同步完成");
|
|
|
|
|
|
|
+ state.syncing = false;
|
|
|
|
|
+ ElMessage.success(`同步完成(共${days}天)`);
|
|
|
loadData(true);
|
|
loadData(true);
|
|
|
})
|
|
})
|
|
|
.catch(() => {
|
|
.catch(() => {
|
|
|
loading.close();
|
|
loading.close();
|
|
|
- ElMessage.error("同步失败");
|
|
|
|
|
|
|
+ state.syncing = false;
|
|
|
|
|
+ ElMessage.error("批量同步失败");
|
|
|
});
|
|
});
|
|
|
}).catch(() => {});
|
|
}).catch(() => {});
|
|
|
};
|
|
};
|
|
@@ -194,15 +212,18 @@ const moneyFields = ["totalIncome", "totalRefund", "crossIncome", "crossExpend",
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
<el-form-item>
|
|
|
<el-date-picker
|
|
<el-date-picker
|
|
|
- v-model="state.syncDate"
|
|
|
|
|
- type="date"
|
|
|
|
|
- placeholder="同步日期"
|
|
|
|
|
|
|
+ v-model="state.syncDateRange"
|
|
|
|
|
+ type="daterange"
|
|
|
|
|
+ start-placeholder="开始日期"
|
|
|
|
|
+ end-placeholder="结束日期"
|
|
|
value-format="YYYY-MM-DD"
|
|
value-format="YYYY-MM-DD"
|
|
|
- style="width: 200px"
|
|
|
|
|
|
|
+ :disabled-date="disabledSyncDate"
|
|
|
|
|
+ style="width: 260px"
|
|
|
/>
|
|
/>
|
|
|
<el-button
|
|
<el-button
|
|
|
type="warning"
|
|
type="warning"
|
|
|
:icon="useRenderIcon('ri/loop-right-line')"
|
|
:icon="useRenderIcon('ri/loop-right-line')"
|
|
|
|
|
+ :loading="state.syncing"
|
|
|
@click="handleSyncDailyStat"
|
|
@click="handleSyncDailyStat"
|
|
|
style="margin-left: 8px"
|
|
style="margin-left: 8px"
|
|
|
>
|
|
>
|