Browse Source

时间

master
hx 1 week ago
parent
commit
fd801ae92a
  1. 37
      src/components/device/TrajectoryDialog.vue
  2. 39
      src/views/device/device/history/index.vue
  3. 37
      src/views/device/device/trajectory/index.vue

37
src/components/device/TrajectoryDialog.vue

@ -32,6 +32,8 @@
:start-placeholder="$t('device.trajectory.filter.startPlaceholder')" :start-placeholder="$t('device.trajectory.filter.startPlaceholder')"
:end-placeholder="$t('device.trajectory.filter.endPlaceholder')" :end-placeholder="$t('device.trajectory.filter.endPlaceholder')"
:clearable="false" :clearable="false"
:editable="false"
:picker-options="locationTimePickerOptions"
unlink-panels unlink-panels
class="trajectory-filter__picker" class="trajectory-filter__picker"
/> />
@ -133,6 +135,7 @@ import { getDeviceTrajectory, getDeviceTrajectoryMapConfig } from "@/api/device/
import { loadAMap } from "@/utils/loadAMap"; import { loadAMap } from "@/utils/loadAMap";
import { loadGoogleMaps } from "@/utils/loadGoogleMaps"; import { loadGoogleMaps } from "@/utils/loadGoogleMaps";
import { loadLeaflet } from "@/utils/loadLeaflet"; import { loadLeaflet } from "@/utils/loadLeaflet";
import { getQueryDayLimitDays } from "@/utils/queryDayLimit";
// Default map centers before trajectory points load. // Default map centers before trajectory points load.
const AMAP_DEFAULT_CENTER = [121.4737, 31.2304]; const AMAP_DEFAULT_CENTER = [121.4737, 31.2304];
@ -186,6 +189,7 @@ export default {
mapsApi: null, mapsApi: null,
mapConfig: null, mapConfig: null,
locationTimeRange: [], locationTimeRange: [],
queryDayLimitDays: null,
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 900, viewportHeight: typeof window !== "undefined" ? window.innerHeight : 900,
dialogWrapperEl: null, dialogWrapperEl: null,
}; };
@ -220,6 +224,11 @@ export default {
tableMaxHeight() { tableMaxHeight() {
return TRAJECTORY_TABLE_HEIGHT; return TRAJECTORY_TABLE_HEIGHT;
}, },
locationTimePickerOptions() {
return {
disabledDate: (time) => this.isDateOutOfQueryDayLimit(time),
};
},
}, },
beforeDestroy() { beforeDestroy() {
this.unbindViewportResize(); this.unbindViewportResize();
@ -230,6 +239,7 @@ export default {
this.bindViewportResize(); this.bindViewportResize();
this.bindDialogWrapper(); this.bindDialogWrapper();
this.activePanel = "map"; this.activePanel = "map";
await this.loadQueryDayLimitConfig();
this.initDefaultLocationTimeRange(); this.initDefaultLocationTimeRange();
if (!this.device || !this.device.id) { if (!this.device || !this.device.id) {
this.loadError = this.$t("device.trajectory.message.missingDevice"); this.loadError = this.$t("device.trajectory.message.missingDevice");
@ -258,6 +268,33 @@ export default {
this.mapConfig = null; this.mapConfig = null;
this.locationTimeRange = []; this.locationTimeRange = [];
}, },
async loadQueryDayLimitConfig() {
const limitDays = await getQueryDayLimitDays();
this.queryDayLimitDays = Number.isFinite(limitDays) ? limitDays : null;
},
getHistoryMinTime() {
if (!Number.isFinite(this.queryDayLimitDays) || this.queryDayLimitDays <= 0) {
return null;
}
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - this.queryDayLimitDays + 1, 0, 0, 0).getTime();
},
getTodayEndTime() {
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999).getTime();
},
isDateOutOfQueryDayLimit(time) {
if (!(time instanceof Date)) {
return false;
}
const minTime = this.getHistoryMinTime();
if (minTime === null) {
return false;
}
const current = time.getTime();
const endTime = this.getTodayEndTime();
return current < minTime || current > endTime;
},
bindViewportResize() { bindViewportResize() {
this.handleViewportResize(); this.handleViewportResize();
if (typeof window !== "undefined") { if (typeof window !== "undefined") {

39
src/views/device/device/history/index.vue

@ -41,6 +41,8 @@
:start-placeholder="$t('device.trajectory.filter.startPlaceholder')" :start-placeholder="$t('device.trajectory.filter.startPlaceholder')"
:end-placeholder="$t('device.trajectory.filter.endPlaceholder')" :end-placeholder="$t('device.trajectory.filter.endPlaceholder')"
:clearable="true" :clearable="true"
:editable="false"
:picker-options="rangePickerOptions"
class="range" class="range"
/> />
</el-form-item> </el-form-item>
@ -107,6 +109,7 @@
<script> <script>
import { listHistoryTrajectory, listHistoryTrajectoryDetail } from "@/api/device/deviceLocation"; import { listHistoryTrajectory, listHistoryTrajectoryDetail } from "@/api/device/deviceLocation";
import { getQueryDayLimitDays } from "@/utils/queryDayLimit";
function getDefaultQuery() { function getDefaultQuery() {
return { return {
@ -131,6 +134,7 @@ export default {
loadingDetail: false, loadingDetail: false,
range: [], range: [],
availableHeight: 760, availableHeight: 760,
queryDayLimitDays: null,
}; };
}, },
computed: { computed: {
@ -140,8 +144,14 @@ export default {
detailTableHeight() { detailTableHeight() {
return Math.max(360, this.layoutHeight - 120); return Math.max(360, this.layoutHeight - 120);
}, },
rangePickerOptions() {
return {
disabledDate: (time) => this.isDateOutOfQueryDayLimit(time),
};
},
}, },
created() { async created() {
await this.loadQueryDayLimitConfig();
this.initRange(); this.initRange();
this.getList(); this.getList();
}, },
@ -152,6 +162,33 @@ export default {
this.unbindViewportResize(); this.unbindViewportResize();
}, },
methods: { methods: {
async loadQueryDayLimitConfig() {
const limitDays = await getQueryDayLimitDays();
this.queryDayLimitDays = Number.isFinite(limitDays) ? limitDays : null;
},
getHistoryMinTime() {
if (!Number.isFinite(this.queryDayLimitDays) || this.queryDayLimitDays <= 0) {
return null;
}
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - this.queryDayLimitDays + 1, 0, 0, 0).getTime();
},
getTodayEndTime() {
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999).getTime();
},
isDateOutOfQueryDayLimit(time) {
if (!(time instanceof Date)) {
return false;
}
const minTime = this.getHistoryMinTime();
if (minTime === null) {
return false;
}
const current = time.getTime();
const endTime = this.getTodayEndTime();
return current < minTime || current > endTime;
},
initRange() { initRange() {
const now = new Date(); const now = new Date();
const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0); const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);

37
src/views/device/device/trajectory/index.vue

@ -65,7 +65,7 @@
<el-radio-button label="amap" :disabled="!hasAmap">{{ $t("device.trajectory.provider.amap") }}</el-radio-button> <el-radio-button label="amap" :disabled="!hasAmap">{{ $t("device.trajectory.provider.amap") }}</el-radio-button>
<el-radio-button label="maptiler" :disabled="!hasMaptiler">{{ $t("device.trajectory.provider.maptiler") }}</el-radio-button> <el-radio-button label="maptiler" :disabled="!hasMaptiler">{{ $t("device.trajectory.provider.maptiler") }}</el-radio-button>
</el-radio-group> </el-radio-group>
<el-date-picker v-model="range" size="small" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" :start-placeholder="$t('device.trajectory.filter.startPlaceholder')" :end-placeholder="$t('device.trajectory.filter.endPlaceholder')" :clearable="false" class="range" /> <el-date-picker v-model="range" size="small" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" :start-placeholder="$t('device.trajectory.filter.startPlaceholder')" :end-placeholder="$t('device.trajectory.filter.endPlaceholder')" :clearable="false" :editable="false" :picker-options="rangePickerOptions" class="range" />
<el-button type="primary" size="mini" :loading="loadingTrack" @click="loadTrack">{{ $t("device.trajectory.page.button.queryTrack") }}</el-button> <el-button type="primary" size="mini" :loading="loadingTrack" @click="loadTrack">{{ $t("device.trajectory.page.button.queryTrack") }}</el-button>
</div> </div>
<el-alert v-if="mapError" :title="mapError" type="warning" :closable="false" show-icon class="map-error" /> <el-alert v-if="mapError" :title="mapError" type="warning" :closable="false" show-icon class="map-error" />
@ -120,6 +120,7 @@ import {
import { import {
loadLeaflet loadLeaflet
} from "@/utils/loadLeaflet"; } from "@/utils/loadLeaflet";
import { getQueryDayLimitDays } from "@/utils/queryDayLimit";
const GOOGLE_TILE_URL = "https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}"; const GOOGLE_TILE_URL = "https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}";
const MAPTILER_URL = "https://api.maptiler.com/maps/streets/{z}/{x}/{y}.png?key="; const MAPTILER_URL = "https://api.maptiler.com/maps/streets/{z}/{x}/{y}.png?key=";
@ -159,7 +160,8 @@ export default {
mapTrajectoryPoints: [], mapTrajectoryPoints: [],
leafletZoomListener: null, leafletZoomListener: null,
amapZoomListener: null, amapZoomListener: null,
availableHeight: 760 availableHeight: 760,
queryDayLimitDays: null
}; };
}, },
computed: { computed: {
@ -180,9 +182,15 @@ export default {
}, },
detailTableHeight() { detailTableHeight() {
return Math.max(360, this.layoutHeight - 300); return Math.max(360, this.layoutHeight - 300);
},
rangePickerOptions() {
return {
disabledDate: (time) => this.isDateOutOfQueryDayLimit(time),
};
} }
}, },
async created() { async created() {
await this.loadQueryDayLimitConfig();
this.initRange(); this.initRange();
await this.fetchMapConfig(); await this.fetchMapConfig();
await this.getDevices(); await this.getDevices();
@ -195,6 +203,31 @@ export default {
this.destroyMap(); this.destroyMap();
}, },
methods: { methods: {
async loadQueryDayLimitConfig() {
const limitDays = await getQueryDayLimitDays();
this.queryDayLimitDays = Number.isFinite(limitDays) ? limitDays : null;
},
getHistoryMinTime() {
if (!Number.isFinite(this.queryDayLimitDays) || this.queryDayLimitDays <= 0) {
return null;
}
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - this.queryDayLimitDays + 1, 0, 0, 0).getTime();
},
getTodayEndTime() {
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999).getTime();
},
isDateOutOfQueryDayLimit(time) {
if (!(time instanceof Date)) return false;
const minTime = this.getHistoryMinTime();
if (minTime === null) {
return false;
}
const current = time.getTime();
const endTime = this.getTodayEndTime();
return current < minTime || current > endTime;
},
bindViewportResize() { bindViewportResize() {
this.updateViewportHeight(); this.updateViewportHeight();
if (typeof window !== "undefined") { if (typeof window !== "undefined") {

Loading…
Cancel
Save