Commit 0e78cabf by zhangxw

项目初始化

1 parent dc894454
{
"endOfLine": "auto"
}
\ No newline at end of file
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"],
plugins: [
[
"import",
{
libraryName: "vant",
libraryDirectory: "es",
style: true,
},
"vant",
],
],
};
This diff could not be displayed because it is too large.
......@@ -3,13 +3,23 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "vue-cli-service serve",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
"animate.css": "^3.7.0",
"axios": "^0.27.2",
"babel-plugin-import": "^1.13.5",
"clipboard": "^2.0.11",
"core-js": "^3.8.3",
"vue": "^3.2.13"
"moment": "^2.29.1",
"vant": "^3.5.2",
"vue": "^3.2.13",
"vue-router": "^4.0.3",
"vuex": "^4.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.16",
......@@ -21,7 +31,11 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.0.3",
"prettier": "^2.4.1"
"prettier": "^2.4.1",
"sass": "1.26.8",
"sass-loader": "^10.0.3",
"unplugin-vue-components": "^0.20.1",
"webpack-spritesmith": "^0.5.2"
},
"eslintConfig": {
"root": true,
......
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
</body>
</html>
\ No newline at end of file
module.exports = function (data) {
// console.log(data.sprites);
const shared =
`.icon {display: inline-block;background-image: url(I);background-size: Wpx Hpx;}`
.replace("I", data.sprites[0].image)
.replace("W", data.sprites[0].total_width)
.replace("H", data.sprites[0].total_height);
const perSprite = data.sprites
.map(function (sprite) {
let style = `.icon-N { width: Wpx; height: Hpx; background-position: Xpx Ypx; }`;
if (/\-active$/g.test(sprite.name)) {
style = `.icon-A.active { width: Wpx; height: Hpx; background-position: Xpx Ypx; }
.icon-A:active { width: Wpx; height: Hpx; background-position: Xpx Ypx; }`;
}
return style
.replace(/N/g, sprite.name)
.replace(/A/g, sprite.name.replace(/\-active$/g, ""))
.replace(/W/g, sprite.width)
.replace(/H/g, sprite.height)
.replace(/X/g, sprite.offset_x)
.replace(/Y/g, sprite.offset_y);
})
.join("\n");
return shared + "\n" + perSprite;
};
<template>
<img alt="Vue logo" src="./assets/logo.png" />
<HelloWorld msg="Welcome to Your Vue.js App" />
<Loading v-show="LOADING"></Loading>
<router-view v-slot="{ Component }" class="warp-content">
<keep-alive :include="['IndexPage']">
<component :is="Component" />
</keep-alive>
</router-view>
</template>
<script>
import HelloWorld from "./components/HelloWorld.vue";
import { useStore } from "vuex";
import { computed } from "vue";
import Loading from "@/components/loading.vue";
export default {
name: "App",
components: {
HelloWorld,
Loading,
},
setup() {
const store = useStore();
const LOADING = computed(() => store.state.LOADING);
return {
LOADING,
};
},
};
</script>
<style>
<style lang="scss">
* {
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
// min-height: 100%;
// min-height: 100%;
}
.warp-content {
height: 100%;
}
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
height: 100%;
// min-height: 100%;
}
.curr-marker {
display: inline-block;
width: 24px;
height: 24px;
background: url("./assets/images/curr-marker.gif") 0 0 no-repeat;
z-index: 999;
}
.van-dialog__confirm {
color: var(--base-color) !important;
}
.map-container {
width: 100%;
height: 100%;
position: fixed;
z-index: 100;
}
</style>
import request from "./request";
// 获取所有车辆数据
export const GET_ALL_CAR_LIST = (params) => {
return request(params, "");
};
// 搜索车辆数据
export const GET_CAR_DATA_BYSEARCH = (params) => {
return request(params, "/miniappserver/monitor/search");
};
// 获取车辆位置详细信息
export const GET_CAR_LOCATION_INFO = (params) => {
return request(params, "/trialdrive/api/vehicle/location");
};
// 获取常驻地数据
export const GET_RESIDENT_DATA = (params) => {
return request(params, "");
};
// 获取轨迹回放数据
export const GET_REPLAY_DATA = (params) => {
return request(params, "/devicemonitor/api/track/playback");
};
import HTTP from "@/utils/http";
const axiosHttp = new HTTP();
function request(data = {}, url, method = "GET") {
return new Promise((resolve, reject) => {
var reqMethod =
method.toLocaleLowerCase() === "get" ? "axiosGet" : "axiosPost";
axiosHttp[reqMethod]({
url: url,
data: data,
success(data) {
resolve(data);
},
error(error) {
reject(error);
},
});
});
}
export default request;
:root {
--van-tabs-bottom-bar-width: 28px !important;
--van-tabs-bottom-bar-color: #0077FF !important;
--base-color: #0077FF;
--base-background-color: #C0C5CC ;
--van-text-link-color: #0077FF !important;
--van-blue: #0077FF !important;
--van-search-input-height: 32px !important;
}
\ No newline at end of file
.icon {display: inline-block;background-image: url(sprite.png);background-size: 188px 164px;}
.icon-checked { width: 20px; height: 20px; background-position: -128px -60px; }
.icon-device { width: 14px; height: 14px; background-position: -168px -60px; }
.icon-locate-sm { width: 14px; height: 14px; background-position: -68px -60px; }
.icon-location { width: 24px; height: 24px; background-position: -164px -80px; }
.icon-off-car { width: 52px; height: 52px; background-position: -60px -80px; }
.icon-off-line { width: 20px; height: 20px; background-position: -148px -60px; }
.icon-offline-time { width: 14px; height: 14px; background-position: -82px -60px; }
.icon-on-car { width: 52px; height: 52px; background-position: -112px -80px; }
.icon-on-line { width: 24px; height: 24px; background-position: -164px -104px; }
.icon-online-time { width: 14px; height: 14px; background-position: -96px -60px; }
.icon-refresh-car { width: 24px; height: 24px; background-position: 0px -140px; }
.icon-replay-pause { width: 60px; height: 60px; background-position: -68px 0px; }
.icon-replay-play { width: 60px; height: 60px; background-position: -128px 0px; }
.icon-replay-refresh { width: 60px; height: 60px; background-position: 0px -80px; }
.icon-share { width: 68px; height: 80px; background-position: 0px 0px; }
.icon-typeList { width: 14px; height: 14px; background-position: -110px -60px; }
\ No newline at end of file
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br />
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener"
>vue-cli documentation</a
>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
target="_blank"
rel="noopener"
>babel</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
target="_blank"
rel="noopener"
>eslint</a
>
</li>
</ul>
<h3>Essential Links</h3>
<ul>
<li>
<a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
</li>
<li>
<a href="https://forum.vuejs.org" target="_blank" rel="noopener"
>Forum</a
>
</li>
<li>
<a href="https://chat.vuejs.org" target="_blank" rel="noopener"
>Community Chat</a
>
</li>
<li>
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener"
>Twitter</a
>
</li>
<li>
<a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
</li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li>
<a href="https://router.vuejs.org" target="_blank" rel="noopener"
>vue-router</a
>
</li>
<li>
<a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-devtools#vue-devtools"
target="_blank"
rel="noopener"
>vue-devtools</a
>
</li>
<li>
<a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener"
>vue-loader</a
>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
rel="noopener"
>awesome-vue</a
>
</li>
</ul>
</div>
</template>
<script>
export default {
name: "HelloWorld",
props: {
msg: String,
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
<template>
<div class="loading">
<van-loading type="spinner" color="#1989fa" />
</div>
</template>
<script>
import { Loading } from "vant";
export default {
name: "LOADING",
components: {
["van-loading"]: Loading,
},
};
</script>
<style lang="scss" scoped>
.loading {
position: fixed;
z-index: 9999;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
</style>
<template>
<div>
<slot name="mapBox"></slot>
<slot name="screenBox"></slot>
<div v-show="isUploaded">
<a class="map-cmd-icon location" @click="getLocation">
<span class="icon icon-location"></span>
</a>
<a class="map-cmd-icon refresh-car" @click="refresh">
<span class="icon icon-refresh-car"></span>
</a>
</div>
</div>
</template>
<script>
import { onMounted, ref } from "vue";
export default {
name: "mapContent",
props: {},
setup(props, context) {
let map = null;
const isUploaded = ref(false);
let checkLoadedTimeoutId = "";
const satelActive = ref(null);
const roadActive = ref(null);
onMounted(() => {});
const initMap = (id) => {
let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap;
if (AMap && typeof AMap.Map == "function") {
window.AMap = AMap;
init(id);
} else {
checkLoadedTimeoutId = check();
}
};
checkLoadedTimeoutId = check();
};
const init = (id) => {
map = new window.AMap.Map(id);
isUploaded.value = true;
context.emit("getData", map);
return map;
};
let currMarker = null;
// 获取定位
const getLocation = () => {
map.plugin("AMap.Geolocation", function () {
var geolocation = new window.AMap.Geolocation({
enableHighAccuracy: true,
timeout: 10000,
buttonOffset: new window.AMap.Pixel(10, 20),
zoomToAccuracy: true,
buttonPosition: "RB",
});
geolocation.getCurrentPosition();
window.AMap.event.addListener(geolocation, "complete", (data) => {
if (currMarker) {
currMarker.setMap(null);
}
currMarker = new window.AMap.Marker({
position: data.position,
content: '<span class="curr-marker"></span>',
map: map,
offset: new window.AMap.Pixel(-12, -12),
});
map.setFitView();
});
window.AMap.event.addListener(geolocation, "error", () => {});
});
};
// 刷新
const refresh = () => {
context.emit("refreshCb", map);
};
return {
initMap,
init,
checkLoadedTimeoutId,
getLocation,
satelActive,
roadActive,
refresh,
isUploaded,
};
},
};
</script>
<style lang="scss" scoped>
.map-cmd-icon {
width: 40px;
height: 40px;
background: #fff;
border-radius: 50%;
position: fixed;
z-index: 101;
display: flex;
align-items: center;
justify-content: center;
}
.location {
bottom: 180px;
right: 20px;
}
.refresh-car {
bottom: 240px;
right: 20px;
}
.map-type-list {
position: fixed;
top: 50px;
right: 10px;
z-index: 101;
background-color: #fff;
border: 1px solid #eee;
padding: 4px;
a {
display: block;
border-bottom: 1px solid #eee;
}
:last-child {
border-bottom: 0;
}
}
.map-size-list {
position: fixed;
top: 150px;
right: 10px;
z-index: 101;
background-color: #fff;
border: 1px solid #eee;
padding: 4px;
a {
display: block;
border-bottom: 1px solid #eee;
}
:last-child {
border-bottom: 0;
}
}
</style>
export default {
name: "ElMarker",
props: {
mark: {
type: [String, Object],
},
},
render() {
let label = typeof this.mark === "string" ? this.mark : this.mark.text;
return (
<div class="el-slider__marks-text" style={this.mark.style || {}}>
{label}
</div>
);
},
};
<template>
<div>
<van-overlay
:show="showOverlay"
@click="showOverlay = false"
:z-index="100000"
>
<span class="icon icon-share"></span>
<p class="tip">“点击右上角转发/分享”</p>
</van-overlay>
<slot></slot>
</div>
</template>
<script>
import { ref, defineComponent } from "vue";
export default defineComponent({
name: "SharePage",
props: {
isShowOverlay: {
type: Boolean,
default: false,
},
},
setup(props) {
const showOverlay = ref(false);
const share = () => {
showOverlay.value = true;
};
if (props.isShowOverlay) {
showOverlay.value = true;
}
return {
showOverlay,
share,
};
},
});
</script>
<style lang="scss" scoped>
.icon-share {
position: absolute;
top: 20px;
right: 65px;
}
.tip {
margin-top: 105px;
text-align: center;
color: #fff;
font-size: 16px;
}
</style>
.el-slider {
width: 100%;
height: 32px;
display: flex;
align-items: center;
}
.el-slider__runway {
flex: 1;
height: 2px;
background-color: #e4e7eb;
border-radius: 2px;
position: relative;
cursor: pointer;
}
.el-slider__input {
flex-shrink: 0;
width: 130px;
}
.el-slider__bar {
height: var(--el-slider-height);
background-color: var(--el-slider-main-bg-color);
border-top-left-radius: var(--el-slider-border-radius);
border-bottom-left-radius: var(--el-slider-border-radius);
position: absolute;
}
.el-slider__button-wrapper {
height: var(--el-slider-button-wrapper-size);
width: var(--el-slider-button-wrapper-size);
position: absolute;
z-index: 1;
top: var(--el-slider-button-wrapper-offset);
transform: translateX(-50%);
background-color: transparent;
text-align: center;
-webkit-user-select: none;
user-select: none;
line-height: normal;
outline: 0;
}
.el-slider__button-wrapper::after {
display: inline-block;
content: "";
height: 100%;
vertical-align: middle;
}
.el-slider__button-wrapper.hover,
.el-slider__button-wrapper:hover {
cursor: grab;
}
.el-slider__button-wrapper.dragging {
cursor: grabbing;
}
.el-slider__button {
display: inline-block;
width: var(--el-slider-button-size);
height: var(--el-slider-button-size);
vertical-align: middle;
border: solid 2px var(--el-slider-main-bg-color);
background-color: var(--el-color-white);
border-radius: 50%;
box-sizing: border-box;
transition: var(--el-transition-duration-fast);
-webkit-user-select: none;
user-select: none;
}
.el-slider__button.dragging,
.el-slider__button.hover,
.el-slider__button:hover {
transform: scale(1.2);
}
.el-slider__button.hover,
.el-slider__button:hover {
cursor: grab;
}
.el-slider__button.dragging {
cursor: grabbing;
}
.el-slider__stop {
position: absolute;
top: -6px;
height: 10px;
width: 10px;
border-radius: 10px;
background-color: #fff;
border: 2px solid #e4e7eb;
}
.el-slider__marks {
top: 0;
left: 12px;
width: 18px;
height: 100%;
}
.el-slider__marks-text {
position: absolute;
transform: translateX(-50%);
font-size: 14px;
color: var(--el-color-info);
margin-top: 15px;
}
.el-slider.is-vertical {
position: relative;
height: 100%;
flex: 0;
}
.el-slider.is-vertical .el-slider__runway {
width: var(--el-slider-height);
height: 100%;
margin: 0 16px;
}
.el-slider.is-vertical .el-slider__bar {
width: var(--el-slider-height);
height: auto;
border-radius: 0 0 3px 3px;
}
.el-slider.is-vertical .el-slider__button-wrapper {
top: auto;
left: var(--el-slider-button-wrapper-offset);
transform: translateY(50%);
}
.el-slider.is-vertical .el-slider__stop {
transform: translateY(50%);
}
.el-slider.is-vertical .el-slider__marks-text {
margin-top: 0;
left: 15px;
transform: translateY(50%);
}
.el-slider--large {
height: 40px;
}
.el-slider--small {
height: 24px;
}
\ No newline at end of file
<template>
<div
class="el-slider__button-wrapper"
@mouseenter="handleMouseEnter"
@mouseleave="handleMouseLeave"
@mousedown="onButtonDown"
@touchstart="onButtonDown"
:class="{ hover: hovering, dragging: dragging }"
:style="wrapperStyle"
ref="button"
tabindex="0"
@focus="handleMouseEnter"
@blur="handleMouseLeave"
></div>
</template>
<script>
export default {
name: "ElSliderButton",
components: {},
props: {
value: {
type: Number,
default: 0,
},
vertical: {
type: Boolean,
default: false,
},
tooltipClass: String,
},
data() {
return {
hovering: false,
dragging: false,
isClick: false,
startX: 0,
currentX: 0,
startY: 0,
currentY: 0,
startPosition: 0,
newPosition: null,
oldValue: this.value,
};
},
computed: {
disabled() {
return this.$parent.sliderDisabled;
},
max() {
return this.$parent.max;
},
min() {
return this.$parent.min;
},
step() {
return this.$parent.step;
},
showTooltip() {
return this.$parent.showTooltip;
},
precision() {
return this.$parent.precision;
},
currentPosition() {
return `${((this.value - this.min) / (this.max - this.min)) * 100}%`;
},
enableFormat() {
return this.$parent.formatTooltip instanceof Function;
},
formatValue() {
return (
(this.enableFormat && this.$parent.formatTooltip(this.value)) ||
this.value
);
},
wrapperStyle() {
return this.vertical
? { bottom: this.currentPosition }
: { left: this.currentPosition };
},
},
watch: {
dragging(val) {
this.$parent.dragging = val;
},
},
methods: {
displayTooltip() {
this.$refs.tooltip && (this.$refs.tooltip.showPopper = true);
},
hideTooltip() {
this.$refs.tooltip && (this.$refs.tooltip.showPopper = false);
},
handleMouseEnter() {
this.hovering = true;
this.displayTooltip();
},
handleMouseLeave() {
this.hovering = false;
this.hideTooltip();
},
onButtonDown(event) {
console.log(event);
if (this.disabled) return;
event.preventDefault();
this.onDragStart(event);
window.addEventListener("mousemove", this.onDragging);
window.addEventListener("touchmove", this.onDragging);
window.addEventListener("mouseup", this.onDragEnd);
window.addEventListener("touchend", this.onDragEnd);
window.addEventListener("contextmenu", this.onDragEnd);
},
onDragStart(event) {
this.dragging = true;
this.isClick = true;
if (event.type === "touchstart") {
event.clientY = event.touches[0].clientY;
event.clientX = event.touches[0].clientX;
}
if (this.vertical) {
this.startY = event.clientY;
} else {
this.startX = event.clientX;
}
this.startPosition = parseFloat(this.currentPosition);
this.newPosition = this.startPosition;
},
onDragging(event) {
if (this.dragging) {
this.isClick = false;
this.displayTooltip();
this.$parent.resetSize();
let diff = 0;
if (event.type === "touchmove") {
event.clientY = event.touches[0].clientY;
event.clientX = event.touches[0].clientX;
}
if (this.vertical) {
this.currentY = event.clientY;
diff =
((this.startY - this.currentY) / this.$parent.sliderSize) * 100;
} else {
this.currentX = event.clientX;
diff =
((this.currentX - this.startX) / this.$parent.sliderSize) * 100;
}
this.newPosition = this.startPosition + diff;
this.setPosition(this.newPosition);
}
},
onDragEnd() {
if (this.dragging) {
/*
* 防止在 mouseup 后立即触发 click,导致滑块有几率产生一小段位移
* 不使用 preventDefault 是因为 mouseup 和 click 没有注册在同一个 DOM 上
*/
setTimeout(() => {
this.dragging = false;
this.hideTooltip();
if (!this.isClick) {
this.setPosition(this.newPosition);
this.$parent.emitChange();
}
}, 0);
window.removeEventListener("mousemove", this.onDragging);
window.removeEventListener("touchmove", this.onDragging);
window.removeEventListener("mouseup", this.onDragEnd);
window.removeEventListener("touchend", this.onDragEnd);
window.removeEventListener("contextmenu", this.onDragEnd);
}
},
setPosition(newPosition) {
if (newPosition === null || isNaN(newPosition)) return;
if (newPosition < 0) {
newPosition = 0;
} else if (newPosition > 100) {
newPosition = 100;
}
const lengthPerStep = 100 / ((this.max - this.min) / this.step);
const steps = Math.round(newPosition / lengthPerStep);
let value =
steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
value = parseFloat(value.toFixed(this.precision));
this.$emit("input", value);
this.$nextTick(() => {
this.displayTooltip();
this.$refs.tooltip && this.$refs.tooltip.updatePopper();
});
if (!this.dragging && this.value !== this.oldValue) {
this.oldValue = this.value;
}
},
},
};
</script>
<style scoped>
@import "./slider.css";
</style>
<template>
<div
class="el-slider"
role="slider"
:aria-valuemin="min"
:aria-valuemax="max"
>
<div
class="el-slider__runway"
:style="runwayStyle"
@click="onSliderClick"
ref="slider"
>
<div class="el-slider__bar" :style="barStyle"></div>
<slider-button
v-model="firstValue"
:tooltip-class="tooltipClass"
ref="button1"
>
</slider-button>
<div
class="el-slider__stop"
v-for="(item, key) in stops"
:key="key"
:style="getStopStyle(item)"
></div>
<template v-if="markList.length > 0">
<div>
<div
v-for="(item, key) in markList"
:style="getStopStyle(item.position)"
class="el-slider__stop el-slider__marks-stop"
:key="key"
></div>
</div>
<div class="el-slider__marks">
<slider-marker
:mark="item.mark"
v-for="(item, key) in markList"
:key="key"
:style="getStopStyle(item.position)"
>
</slider-marker>
</div>
</template>
</div>
</div>
</template>
<script>
import SliderButton from "./sliderButton.vue";
import SliderMarker from "./marker";
export default {
name: "ElSlider",
inject: {
elForm: {
default: "",
},
},
props: {
min: {
type: Number,
default: 0,
},
max: {
type: Number,
default: 100,
},
step: {
type: Number,
default: 1,
},
value: {
type: [Number, Array],
default: 0,
},
height: {
type: String,
},
debounce: {
type: Number,
default: 300,
},
label: {
type: String,
},
tooltipClass: String,
marks: Object,
},
components: {
SliderButton,
SliderMarker,
},
data() {
return {
firstValue: null,
secondValue: null,
oldValue: null,
dragging: false,
sliderSize: 1,
};
},
watch: {
value(val, oldVal) {
console.log(val);
if (
this.dragging ||
(Array.isArray(val) &&
Array.isArray(oldVal) &&
val.every((item, index) => item === oldVal[index]))
) {
return;
}
this.setValues();
},
dragging(val) {
if (!val) {
this.setValues();
}
},
firstValue(val) {
if (this.range) {
this.$emit("input", [this.minValue, this.maxValue]);
} else {
this.$emit("input", val);
}
},
secondValue() {
if (this.range) {
this.$emit("input", [this.minValue, this.maxValue]);
}
},
min() {
this.setValues();
},
max() {
this.setValues();
},
},
methods: {
valueChanged() {
if (this.range) {
return ![this.minValue, this.maxValue].every(
(item, index) => item === this.oldValue[index]
);
} else {
return this.value !== this.oldValue;
}
},
setValues() {
if (this.min > this.max) {
console.error(
"[Element Error][Slider]min should not be greater than max."
);
return;
}
const val = this.value;
if (this.range && Array.isArray(val)) {
if (val[1] < this.min) {
this.$emit("input", [this.min, this.min]);
} else if (val[0] > this.max) {
this.$emit("input", [this.max, this.max]);
} else if (val[0] < this.min) {
this.$emit("input", [this.min, val[1]]);
} else if (val[1] > this.max) {
this.$emit("input", [val[0], this.max]);
} else {
this.firstValue = val[0];
this.secondValue = val[1];
if (this.valueChanged()) {
this.dispatch("ElFormItem", "el.form.change", [
this.minValue,
this.maxValue,
]);
this.oldValue = val.slice();
}
}
} else if (!this.range && typeof val === "number" && !isNaN(val)) {
if (val < this.min) {
this.$emit("input", this.min);
} else if (val > this.max) {
this.$emit("input", this.max);
} else {
this.firstValue = val;
if (this.valueChanged()) {
this.dispatch("ElFormItem", "el.form.change", val);
this.oldValue = val;
}
}
}
},
setPosition(percent) {
const targetValue = this.min + (percent * (this.max - this.min)) / 100;
if (!this.range) {
this.$refs.button1.setPosition(percent);
return;
}
let button;
if (
Math.abs(this.minValue - targetValue) <
Math.abs(this.maxValue - targetValue)
) {
button = this.firstValue < this.secondValue ? "button1" : "button2";
} else {
button = this.firstValue > this.secondValue ? "button1" : "button2";
}
this.$refs[button].setPosition(percent);
},
onSliderClick(event) {
console.log(event);
if (this.dragging) return;
this.resetSize();
const sliderOffsetLeft = this.$refs.slider.getBoundingClientRect().left;
this.setPosition(
((event.clientX - sliderOffsetLeft) / this.sliderSize) * 100
);
this.emitChange();
},
resetSize() {
if (this.$refs.slider) {
this.sliderSize =
this.$refs.slider[`client${this.vertical ? "Height" : "Width"}`];
}
},
emitChange() {
this.$nextTick(() => {
this.$emit(
"change",
this.range ? [this.minValue, this.maxValue] : this.value
);
});
},
getStopStyle(position) {
return this.vertical
? { bottom: position + "%" }
: { left: position + "%" };
},
},
computed: {
stops() {
const stopCount = (this.max - this.min) / this.step;
const stepWidth = (100 * this.step) / (this.max - this.min);
const result = [];
for (let i = 1; i < stopCount; i++) {
result.push(i * stepWidth);
}
if (this.range) {
return result.filter((step) => {
return (
step < (100 * (this.minValue - this.min)) / (this.max - this.min) ||
step > (100 * (this.maxValue - this.min)) / (this.max - this.min)
);
});
} else {
return result.filter(
(step) =>
step > (100 * (this.firstValue - this.min)) / (this.max - this.min)
);
}
},
markList() {
if (!this.marks) {
return [];
}
const marksKeys = Object.keys(this.marks);
return marksKeys
.map(parseFloat)
.sort((a, b) => a - b)
.filter((point) => point <= this.max && point >= this.min)
.map((point) => ({
point,
position: ((point - this.min) * 100) / (this.max - this.min),
mark: this.marks[point],
}));
},
minValue() {
return Math.min(this.firstValue, this.secondValue);
},
maxValue() {
return Math.max(this.firstValue, this.secondValue);
},
barSize() {
return this.range
? `${(100 * (this.maxValue - this.minValue)) / (this.max - this.min)}%`
: `${(100 * (this.firstValue - this.min)) / (this.max - this.min)}%`;
},
barStart() {
return this.range
? `${(100 * (this.minValue - this.min)) / (this.max - this.min)}%`
: "0%";
},
precision() {
let precisions = [this.min, this.max, this.step].map((item) => {
let decimal = ("" + item).split(".")[1];
return decimal ? decimal.length : 0;
});
return Math.max.apply(null, precisions);
},
runwayStyle() {
return this.vertical ? { height: this.height } : {};
},
barStyle() {
return this.vertical
? {
height: this.barSize,
bottom: this.barStart,
}
: {
width: this.barSize,
left: this.barStart,
};
},
},
mounted() {
let valuetext;
if (this.range) {
if (Array.isArray(this.value)) {
this.firstValue = Math.max(this.min, this.value[0]);
this.secondValue = Math.min(this.max, this.value[1]);
} else {
this.firstValue = this.min;
this.secondValue = this.max;
}
this.oldValue = [this.firstValue, this.secondValue];
valuetext = `${this.firstValue}-${this.secondValue}`;
} else {
if (typeof this.value !== "number" || isNaN(this.value)) {
this.firstValue = this.min;
} else {
this.firstValue = Math.min(this.max, Math.max(this.min, this.value));
}
this.oldValue = this.firstValue;
valuetext = this.firstValue;
}
this.$el.setAttribute("aria-valuetext", valuetext);
// label screen reader
this.$el.setAttribute(
"aria-label",
this.label ? this.label : `slider between ${this.min} and ${this.max}`
);
this.resetSize();
window.addEventListener("resize", this.resetSize);
},
beforeUnmount() {
window.removeEventListener("resize", this.resetSize);
},
};
</script>
<style scoped>
@import "./slider.css";
</style>
<template>
<div>
<van-tabs v-model:active="active" @click-tab="onTabClick">
<van-tab
v-for="(item, index) in tabRoutes"
:title="item.title"
:key="index"
:name="item.name"
>
<slot :name="item.name"></slot>
</van-tab>
</van-tabs>
<div v-show="active === 'share'">
<share ref="shareRefs" :isShowOverlay="true">
<div id="shareContainer" class="map-container"></div>
</share>
</div>
</div>
</template>
<script>
import { defineComponent, nextTick, ref } from "vue";
import routes from "@/router/routes";
import { useRoute } from "vue-router";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant";
export default defineComponent({
name: "TopTab",
setup() {
const tabRoutes = ref([]);
const active = ref(null);
const route = useRoute();
let routeQuery = route.query;
let map = null;
let checkLoadedTimeoutId = "";
tabRoutes.value = routes.tabRoutes;
active.value = routeQuery.tabItem;
const onTabClick = (e) => {
if (e.name === "share") {
nextTick(() => {
console.log(active.value);
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
if (map) return;
initMap("shareContainer");
});
});
}
};
const initMap = (id) => {
let check = () => {
checkLoadedTimeoutId && window.clearTimeout(checkLoadedTimeoutId);
let AMap = window.AMap;
if (AMap && typeof AMap.Map == "function") {
window.AMap = AMap;
init(id);
} else {
checkLoadedTimeoutId = check();
}
};
checkLoadedTimeoutId = check();
};
const init = (id) => {
console.log(id);
map = new window.AMap.Map(id);
console.log(map);
return map;
};
return {
tabRoutes,
active,
onTabClick,
};
},
});
</script>
<style lang="scss">
.van-tabs__wrap {
border-bottom: 1px solid #f0f2f5;
}
</style>
export const MAP_KEY = "c3c66897b0c7c3170ba7f3b596e76e6b";
// 地图插件
export const MAP_PLUGINS = [
"AMap.ToolBar",
"AMap.Geocoder",
"AMap.MapType",
"AMap.Geolocation",
];
export const CONSTANT = {
MAP_KEY,
MAP_PLUGINS,
AMAP_URL: `https://webapi.amap.com/maps?v=1.4.8&key=${MAP_KEY}&plugin=${MAP_PLUGINS.toString()}`,
};
import { createApp } from "vue";
import App from "./App.vue";
createApp(App).mount("#app");
import store from "./store";
import "@/assets/spritesmith-generated/sprite.css";
import router from "./router";
import { vant } from "@/utils/vant.config";
import "@/assets/css/style.css";
const app = createApp(App);
vant(app);
app.use(store).use(router).mount("#app");
router.beforeEach((to, from, next) => {
console.log(to);
if (to.meta.title) {
document.title = to.meta.title;
}
next();
});
import { createRouter, createWebHistory } from "vue-router";
import routes from "./routes";
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes: routes.baseRoutes.concat(routes.tabRoutes),
});
export default router;
const baseRoutes = [
{
path: "/",
redirect: "/index",
},
{
path: "/index",
name: "index",
meta: {
title: "找车",
},
component: () => import("../views/index.vue"),
},
{
path: "/info",
name: "info",
meta: {
title: "找车",
},
component: () => import("../views/info.vue"),
},
];
const tabRoutes = [
{
path: "/replay",
name: "replay",
title: "轨迹回放",
component: () => import("../views/replay.vue"),
},
{
path: "/resident",
name: "resident",
title: "常驻地",
component: () => import("../views/resident.vue"),
},
{
path: "/monitor",
name: "monitor",
title: "实时监控",
component: () => import("../views/monitor.vue"),
},
{
path: "/deviceFreq",
name: "deviceFreq",
title: "设备调频",
component: () => import("../views/monitor.vue"),
},
{
path: "/fence",
name: "fence",
title: "电子围栏",
component: () => import("../views/monitor.vue"),
},
{
path: "/share",
name: "share",
title: "分享找车",
component: () => import("../views/monitor.vue"),
},
];
export default {
tabRoutes,
baseRoutes,
};
import { createStore } from "vuex";
export default createStore({
state: {
LOADING: false,
},
mutations: {
showLoading(state) {
state.LOADING = true;
},
hideLoading(state) {
state.LOADING = false;
},
},
});
import axios from "axios";
import { Dialog } from "vant";
import store from "@/store";
// 测试 https://eshield.test.glsx.com.cn
// 开发
// 线上
const BASE_URL = "https://eshield.test.glsx.com.cn";
const instance = axios.create({
// 创建axios实例,在这里可以设置请求的默认配置
timeout: 10 * 60 * 1000, // 设置超时时间60s
retry: 3,
retryDelay: 1000,
});
// 统一设置post请求头
instance.defaults.headers.post["Content-Type"] = "application/json";
/** 添加请求拦截器 **/
instance.interceptors.request.use(
(config) => {
store.commit("showLoading");
config.headers["Authorization"] = localStorage.getItem("token") || "";
return config;
},
(error) => {
store.commit("hideLoading");
console.log("请求错误,原因:", error);
return Promise.reject(error);
}
);
/** 添加响应拦截器 **/
instance.interceptors.response.use(
(response) => {
store.commit("hideLoading");
const serverCode = response.data.code,
token = response.headers["authorization"];
if (token || token === "") {
localStorage.setItem("token", token);
}
if (serverCode === 200) {
if (response.status) {
return Promise.resolve(response);
}
return Promise.resolve(response.data);
} else {
Dialog({ message: response.data.message });
return Promise.reject(response.data.message);
}
},
(error) => {
store.commit("hideLoading");
const errRes = error.response;
if (errRes) {
Dialog({ message: "请求失败" });
return Promise.reject(error);
} else {
Dialog({ message: "请求失败" });
return Promise.reject(new Error("请求失败"));
}
}
);
const getBaseUrl = () => {
return new Promise((resolve) => {
resolve(BASE_URL);
});
};
const HTTP_POST = (baseUrl, options) => {
instance({
url: baseUrl + options.url,
method: "post",
data: JSON.stringify(options.data),
})
.then((res) => {
options.success(res.data);
})
.catch((err) => {
options.error(err);
});
};
const HTTP_GET = (baseUrl, options) => {
instance({
url: baseUrl + options.url,
method: "get",
params: options.data,
})
.then((res) => {
options.success(res.data);
})
.catch((err) => {
options.error(err);
});
};
export default class HTTP {
axiosPost(options) {
getBaseUrl().then((baseUrl) => {
HTTP_POST(baseUrl, options);
});
}
axiosGet(options) {
getBaseUrl().then((baseUrl) => {
HTTP_GET(baseUrl, options);
});
}
}
let map = null;
function MapService() {
map = null;
}
MapService.prototype = {
init: (id) => {
map = new window.AMap.Map(id);
return map;
},
// 卫星地图切换
satelEvent: (satelActive) => {
let layers = map.getLayers();
let satelLayer = [new window.AMap.TileLayer.Satellite()];
let flag = true;
layers.filter((val) => {
if (val.CLASS_NAME === "AMap.TileLayer.Satellite") {
satelActive.value = false;
flag = false;
map.remove(satelLayer);
}
});
if (flag) {
satelActive.value = true;
map.add(satelLayer);
}
},
// 获取定位
getLocationEvent: (currMarker) => {
map.plugin("AMap.Geolocation", function () {
var geolocation = new window.AMap.Geolocation({
enableHighAccuracy: true,
timeout: 10000,
buttonOffset: new window.AMap.Pixel(10, 20),
zoomToAccuracy: true,
buttonPosition: "RB",
});
geolocation.getCurrentPosition();
window.AMap.event.addListener(geolocation, "complete", (data) => {
if (currMarker) {
currMarker.setMap(null);
}
currMarker = new window.AMap.Marker({
position: data.position,
content: '<span class="curr-marker"></span>',
map: map,
offset: new window.AMap.Pixel(-12, -12),
});
map.setFitView();
});
window.AMap.event.addListener(geolocation, "error", () => {});
});
},
// 切换路况
roadStatusEvent: (roadActive) => {
let layers = map.getLayers();
let roadLayer = [new window.AMap.TileLayer.Traffic()];
let flag = true;
layers.filter((val) => {
if (val.CLASS_NAME === "AMap.TileLayer.Traffic") {
roadActive.value = false;
flag = false;
map.remove(roadLayer);
}
});
if (flag) {
roadActive.value = true;
map.add(roadLayer);
}
},
// 地图放大
mapPlusEvent: () => {
map.zoomIn();
},
// 地图缩小
mapMinusEvent: () => {
map.zoomOut();
},
// 刷新
refresheEvent: (context) => {
context.emit("refreshCb", map);
},
};
const mapService = new MapService();
export default mapService;
const MAPGEO = {
geocoder: null,
getGeocoder: function () {
let AMap = window.AMap;
return new Promise((resolve) => {
AMap.service("AMap.Geocoder", function () {
//回调函数
var geocoder = new AMap.Geocoder({
batch: true,
});
MAPGEO.geocoder = geocoder;
resolve(geocoder);
});
});
},
transferAddressByGroup(obj, cb) {
if (!this.geocoder) {
this.getGeocoder().then(() => {
this.transfer(obj, cb);
});
} else {
this.transfer(obj, cb);
}
},
transfer(obj, cb) {
const data = obj.data;
obj.len = data.length;
obj.times = obj.len > 20 ? Math.ceil(obj.len / 20) : 1;
obj.totalNum = 0;
for (let i = 0; i < obj.times; i++) {
let lnglatArr = [];
let initIdx = i * 20;
let maxIdx = i === obj.times - 1 ? obj.len : (i + 1) * 20;
for (let idx = initIdx; idx < maxIdx; idx++) {
lnglatArr.push([
data[idx].lastlng || data[idx].elng,
data[idx].lastlat || data[idx].elat,
]);
}
(function (initIdx) {
geocoderGetAdr(lnglatArr, initIdx);
})(initIdx);
}
function geocoderGetAdr(arr, initIdx) {
const timeoutId = window.setTimeout(() => {
MAPGEO.geocoder.getAddress(arr, function (status, result) {
if (status === "complete" && result.info === "OK") {
//获取地址成功
result.regeocodes.forEach((item, idx) => {
data[initIdx + idx].transferAddress = item.formattedAddress;
obj.totalNum++;
});
if (obj.totalNum === obj.len) {
cb && cb(data);
//ifPlay && obj.init(data)
//EventBus.$emit('uiMap.replay.transferAdrDone');
}
} else {
geocoderGetAdr(arr, initIdx);
}
});
});
obj.timeoutIds.push(timeoutId);
}
},
};
export default MAPGEO;
import moment from "moment";
// 设置moment的语言环境配置
moment.locale("zh-cn", {
week: {
dow: 1,
doy: 4,
},
});
export default moment;
import {
Popup,
List,
Search,
Overlay,
Picker,
Icon,
Button,
DatetimePicker,
Progress,
RadioGroup,
Radio,
Slider,
} from "vant";
export function vant(app) {
app.use(Popup);
app.use(List);
app.use(Search);
app.use(Overlay);
app.use(Picker);
app.use(Icon);
app.use(Button);
app.use(DatetimePicker);
app.use(Progress);
app.use(RadioGroup);
app.use(Radio);
app.use(Slider);
}
<template>
<div>
<mapContent @refreshCb="refreshCb" ref="mapContentRefs">
<template #mapBox>
<div id="container" class="map-container"></div>
</template>
</mapContent>
<!-- 搜索区域 -->
<div class="search-box">
<div class="search-header">
<div
class="select-box"
:class="carItem ? 'text' : ''"
@click="isShowList = !isShowList"
>
<span>{{
carItem ? carItem.ownerName + " | " + carItem.name : "请选择"
}}</span>
<span class="arrow-icon"><van-icon name="arrow-down" /></span>
</div>
</div>
<div
class="search-content"
v-show="isShowList"
:class="isShowList ? '' : 'hidden'"
>
<van-search
class="search-input"
v-model="keyWord"
placeholder="请输入姓名或车牌号搜索"
/>
<van-list
class="list-box"
v-model:loading="loading"
:finished="finished"
finished-text="没有更多了"
@load="getCarList"
:immediate-check="false"
>
<van-cell v-for="item in list" @click="getCarInfo(item)" :key="item">
<div
class="list-item"
:class="(carItem && carItem.id) === item.id ? 'active' : ''"
>
<i v-if="item.offLineDuration" class="icon icon-off-line"></i>
<i v-else class="icon icon-on-line"></i>
<div class="item-right">
<span class="item-text">{{
item.ownerName + " | " + item.name
}}</span>
<span
v-if="(carItem && carItem.id) === item.id"
class="slectedicon"
><i class="icon icon-checked"></i
></span>
</div>
</div>
</van-cell>
</van-list>
</div>
</div>
<share ref="shareRefs" />
</div>
</template>
<script>
import { ref, defineComponent, onMounted } from "vue";
import mapContent from "@/components/mapContent.vue";
import share from "@/components/share.vue";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant";
import MAPGEO from "@/utils/mapgeo";
import wx from "wx";
import { useRouter } from "vue-router";
import { Dialog, Toast } from "vant";
import "vant/es/toast/style";
import { GET_CAR_LOCATION_INFO } from "@/api/index";
export default defineComponent({
name: "IndexPage",
components: {
mapContent,
share,
},
setup() {
const mapContentRefs = ref(null);
const shareRefs = ref(null);
const isShowList = ref(false);
const keyWord = ref("");
const loading = ref(false);
const finished = ref(false);
const list = ref([]);
const carItem = ref(null);
const loginUserId = ref("");
const isShareDead = ref(1);
const showMore = ref(false);
const carInfoList = ref([]);
const router = useRouter();
let map = null;
const refreshCb = () => {
map.clearMap();
if (Object.keys(carItem.value).length > 0) {
getCarInfo(carItem.value);
}
};
onMounted(() => {
getCarList();
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("container");
});
});
const onSearch = () => {
// 获取车辆数据
console.log(1123);
};
const getCarInfo = (it) => {
carItem.value = it;
isShowList.value = false;
map = map ? map : mapContentRefs.value.init("container");
GET_CAR_LOCATION_INFO({ sns: "Sr1PRLqA32LCbSWZDch+Sg==" }).then((res) => {
if (res.code === 200) {
if (res.data.length > 0) {
const markers = [];
let locates = [];
res.data.forEach((item) => {
item.locationType = "gpsLocation";
if (
item.gpsLocation &&
item.gpsLocation.elng &&
item.gpsLocation.elat
) {
locates.push(item.gpsLocation);
item.gpsLocation.transferAddress = "";
}
if (
item.bsLocation &&
item.bsLocation.elng &&
item.bsLocation.elat
) {
locates.push(item.bsLocation);
item.bsLocation.transferAddress = "";
}
if (
item.wifiLocation &&
item.wifiLocation.elng &&
item.wifiLocation.elat
) {
locates.push(item.wifiLocation);
item.wifiLocation.transferAddress = "";
}
markers.push(drawMarker(item, map, locates));
});
MAPGEO.transferAddressByGroup(
{ data: locates, timeoutIds: [] },
() => {
map.setFitView(markers);
}
);
} else {
Dialog({ message: "暂无数据" });
}
}
});
// let res = {
// data: [
// {
// sn: "39106110001",
// status: 1,
// statusTime: "0天0小时0分19秒",
// source: 1,
// battery: null,
// power: 15,
// alarmTypeSet: null,
// gpsLocation: {
// lng: "113.984752",
// lat: "22.590434",
// elng: "113.989711",
// elat: "22.587525",
// blng: "113.996172",
// blat: "22.593823",
// dateTime: "2022-06-30 15:49:28",
// address: "广东省深圳市南山区塘朗站(环中线)",
// alt: "214",
// dir: "170",
// storeTime: "2022-06-30 15:49:28",
// speed: "0",
// },
// bsLocation: {
// lng: "113.983448",
// lat: "22.587246",
// elng: "113.988404",
// elat: "22.584333",
// blng: "113.994867",
// blat: "22.590618",
// dateTime: "2022-06-30 16:12:40",
// address: "广东省深圳市南山区入口",
// alt: null,
// dir: null,
// storeTime: "2022-06-30 16:12:38",
// speed: null,
// },
// wifiLocation: null,
// hasWifi: false,
// encryptSn: "Sr1PRLqA32LCbSWZDch+Sg==",
// vin: "FVN20220629000001",
// ownerName: "谢俊琼",
// shopName: "测试店面",
// licensePlate: null,
// },
// {
// sn: "17107120001",
// status: 2,
// statusTime: "44天22小时30分47秒",
// source: 1,
// power: 60,
// battery: null,
// alarmTypeSet: null,
// gpsLocation: {
// lng: "113.987688",
// lat: "22.591266",
// elng: "113.992654",
// elat: "22.588366",
// blng: "113.999111",
// blat: "22.594687",
// dateTime: "2022-05-16 17:42:10",
// address: "广东省深圳市南山区华晖&#8226;云门",
// alt: "0",
// dir: "0",
// storeTime: "2022-05-16 17:42:10",
// speed: "0",
// },
// bsLocation: {
// lng: "113.982816",
// lat: "22.588568",
// elng: "113.987771",
// elat: "22.585654",
// blng: "113.994236",
// blat: "22.591932",
// dateTime: "2022-03-10 13:08:20",
// address: "广东省深圳市南山区深圳市圣丰塑胶模具厂",
// alt: null,
// dir: null,
// storeTime: "2022-03-10 13:08:19",
// speed: null,
// },
// wifiLocation: null,
// hasWifi: false,
// encryptSn: "2RAxRr1EYpXBQSTtg+2vKw==",
// vin: "FVN20220629000001",
// ownerName: "谢俊琼",
// shopName: "测试店面",
// licensePlate: null,
// },
// ],
// };
};
const drawMarker = (item, map, locates) => {
item.locationType = "gpsLocation";
//修改数据格式方便获取
locates.forEach((val) => {
if (
val.elat === item[item.locationType].elat &&
val.elng === item[item.locationType].elng
) {
item[item.locationType].transferAddress = val.transferAddress;
}
});
var lnglat = new window.AMap.LngLat(
item[item.locationType].elng,
item[item.locationType].elat
);
var marker = new window.AMap.Marker({
position: lnglat,
content:
item.deviceType === "无线设备"
? '<span class="icon icon-off-car"></span>'
: '<span class="icon icon-on-car"></span>',
map: map,
offset: new window.AMap.Pixel(-13, -18),
});
var carInfoWindowTpl = `<div class="car-info-window">`;
carInfoWindowTpl += `<div class="main-info">`;
carInfoWindowTpl += `<h4 class="info-title"><div>${item.ownerName}</div><div>${item.vin}</div></h4>`;
carInfoWindowTpl += `<div class="info-list">`;
// if (item.isFreq !== 2) {
// if (item.power && item.power < 20) {
// carInfoWindowTpl += `<div class="battery empty">
// <span style="width:${item.power}%" class="fill"></span>
// <span class="icon icon-battery-empty"></span>
// <span class="text">不足</span>
// </div>`;
// } else if (item.power) {
// carInfoWindowTpl += `<div class="battery">
// <span style="width:${item.power}%" class="fill"></span>
// <span class="icon icon-battery-enough"></span>
// <span class="text">${item.power}</span>
// </div>`;
// }
// }
carInfoWindowTpl += `<p class="device-info"><i class="icon icon-device"></i><span class="label">${
item.source == 1 ? "有线设备" : "无线设备"
}</span><span>${item.sn}</span></p>`;
if (item[item.locationType].offLineDuration) {
carInfoWindowTpl += `<p class="offline-info"><i class="icon icon-offline-time"></i><span class="label">离线时长</span><span>${
item[item.locationType].offLineDuration
}</span></p>`;
}
carInfoWindowTpl += `<p class="time-info"><i class="icon icon-online-time"></i><span class="label">在线时间</span><span>${
item[item.locationType].dateTime
}</span></p>
<p class="locate-info"><i class="icon icon-locate-sm"></i><span class="label">详细地址</span><span data-tranferAddress></span></p>`;
if (item.hasWifi) {
carInfoWindowTpl += `<p p class="list-info" > <i class="icon icon-typeList"></i><span class="label">定位类型</span>
<a data-GPS><span class="radio active"></span>GPS</a>
<a data-GPRS><span class="radio"></span></i>基站</a>
<a data-WIFI><span class="radio"></span></i>WIFI</a>
</p>`;
} else {
carInfoWindowTpl += `<p p class="list-info" > <i class="icon icon-typeList"></i><span class="label">定位类型</span>
<a data-GPS><span class="radio active"></span><span>GPS</span></a>
<a data-GPRS><span class="radio"></span><span>基站</span></a>
</p>`;
}
carInfoWindowTpl += `</div>
</div>
<div class="cmd-list">
<div class="cmd-list-top">
<a data-car-location>车辆追踪</a>
<a data-replay>轨迹回放</a>
<a data-resident>常驻地</a>
<a data-monitor>实时监控</a>
</div>
<div class="cmd-list-bottom">
<a data-freq>设备调频</a>
<a data-fence>电子围栏</a>
<a data-share>分享找车</a>
</div>
</div>
</div>`;
let infoDiv = document.createElement("div");
infoDiv.innerHTML = carInfoWindowTpl;
let infoWindow = new window.AMap.InfoWindow({
isCustom: true,
position: lnglat,
content: infoDiv,
offset: new window.AMap.Pixel(0, -20),
});
const move = (newLnglat) => {
marker.setPosition(newLnglat);
infoWindow.setPosition(newLnglat);
map.setCenter(newLnglat);
};
//信息窗体内容更新
let GPSBtn = infoDiv.querySelector("[data-GPS]");
let GPRSBtn = infoDiv.querySelector("[data-GPRS]");
let WIFIBtn = infoDiv.querySelector("[data-WIFI]");
let carLocationBtn = infoDiv.querySelector("[data-car-location]");
let carReplayBtn = infoDiv.querySelector("[data-replay]");
let carResidentBtn = infoDiv.querySelector("[data-resident]");
let carMonitorBtn = infoDiv.querySelector("[data-monitor]");
let carFreqBtn = infoDiv.querySelector("[data-freq]");
let carFenceBtn = infoDiv.querySelector("[data-fence]");
let shareBtn = infoDiv.querySelector("[data-share]");
let GPSIcon = GPSBtn.querySelector(".radio");
let GPRSIcon = GPRSBtn.querySelector(".radio");
let WIFIIcon = WIFIBtn && WIFIBtn.querySelector(".radio");
// 地址赋值
const setAddress = () => {
let Address = infoDiv.querySelector("[data-tranferAddress]");
Address.textContent = item[item.locationType].transferAddress;
};
if (item.source == 1) {
// 有线设备
carFreqBtn && carFreqBtn.classList.add("disabled");
} else {
carFenceBtn && carFenceBtn.classList.add("carFenceBtn");
}
// 点击GPS
GPSBtn &&
(GPSBtn.onclick = () => {
check(() => {
item.locationType = "gpsLocation";
let gpsObj = item[item.locationType];
GPSIcon && GPSIcon.classList.add("active");
GPRSIcon && GPRSIcon.classList.remove("active");
WIFIIcon && WIFIIcon.classList.remove("active");
var newLnglat = new window.AMap.LngLat(gpsObj.elng, gpsObj.elat);
// 窗体 marker移动
setAddress();
move(newLnglat);
});
});
// 点击基站
GPRSBtn &&
(GPRSBtn.onclick = () => {
check(() => {
item.locationType = "bsLocation";
let gprsObj = item[item.locationType];
GPRSIcon && GPRSIcon.classList.add("active");
GPSIcon && GPSIcon.classList.remove("active");
WIFIIcon && WIFIIcon.classList.remove("active");
var newLnglat = new window.AMap.LngLat(gprsObj.elng, gprsObj.elat);
// 窗体 marker移动
setAddress();
move(newLnglat);
});
});
// 点击WIFI
WIFIBtn &&
(WIFIBtn.onclick = () => {
check(() => {
item.locationType = "wifiLocation";
let wifiObj = item[item.locationType];
WIFIIcon && WIFIIcon.classList.add("active");
GPSIcon && GPSIcon.classList.remove("active");
GPRSIcon && GPRSIcon.classList.remove("active");
var newLnglat = new window.AMap.LngLat(wifiObj.elng, wifiObj.elat);
// 窗体 marker移动
setAddress();
move(newLnglat);
});
});
// 车辆追踪
carLocationBtn &&
(carLocationBtn.onclick = () => {
let lng = item[item.locationType].elng;
let lat = item[item.locationType].elat;
check(() => {
wx.miniProgram.navigateTo({
url: `../../pages/trace/trace?lat=${lat}&lng=${lng}`,
});
});
});
// 轨迹回放
carReplayBtn &&
(carReplayBtn.onclick = () => {
check(() => {
router.push({
name: "info",
query: { sn: item.sn, tabItem: "replay" },
});
});
});
// 常驻地
carResidentBtn &&
(carResidentBtn.onclick = () => {
check(() => {
router.push({
name: "info",
query: { sn: item.sn, tabItem: "resident" },
});
});
});
// 实时监控
carMonitorBtn &&
(carMonitorBtn.onclick = () => {
let currSn = item.sn;
check(() => {
router.push({
name: "info",
query: { sn: currSn, tabItem: "monitor" },
});
});
});
// 设备调频
(carFreqBtn && carFreqBtn).onclick = () => {
let currSn = item.sn;
let vehicleid = item.vehicleid;
if (item.source === 1) {
// 仅无线设备可调频
return;
} else {
router.push({
name: "info",
query: { sn: currSn, vehicleid: vehicleid, tabItem: "freq" },
});
}
};
// 电子围栏
(carFenceBtn && carFenceBtn).onclick = () => {
let currSn = item.sn;
if (loginUserId.value) {
return;
} else {
router.push({
name: "info",
query: { sn: currSn, tabItem: "fence" },
});
}
};
// 分享找车
shareBtn.onclick = () => {
shareRefs.value.share();
};
//点击车辆打开信息窗体
marker.on("click", () => {
setTimeout(() => {
map.setCenter(infoWindow.getPosition());
});
if (infoWindow.getIsOpen()) {
infoWindow.close();
} else {
infoWindow.open(map);
}
setAddress();
});
return marker;
};
const check = (cb) => {
if (loginUserId.value && isShareDead.value) {
Toast("该分享已失效");
return;
}
cb();
};
// 加载更多
const getCarList = () => {
setTimeout(() => {
for (let i = 0; i < 10; i++) {
if (i % 2) {
list.value.push({
id: i,
device: [{ type: "有线设备", sn: "1500628541" }],
name: "鄂ADB1383",
ownerName: "张三",
offLineDuration: 1,
sns: "1500628541",
sqbh: "skgd_220420134847279",
standno: "LA9XL44B0HBLG6389",
vehicleId: "985962",
workOrderId: null,
});
} else {
list.value.push({
id: i,
device: [{ type: "有线设备", sn: "1500628541" }],
name: "鄂ADB1383",
ownerName: "李四",
offLineDuration: null,
sns: "1500628541",
sqbh: "skgd_220420134847279",
standno: "LA9XL44B0HBLG6389",
vehicleId: "985962",
workOrderId: null,
});
}
}
// 加载状态结束
loading.value = false;
// 数据全部加载完成
if (list.value.length >= 40) {
finished.value = true;
}
}, 1000);
};
return {
refreshCb,
isShowList,
mapContentRefs,
keyWord,
loading,
finished,
list,
onSearch,
getCarList,
getCarInfo,
showMore,
loginUserId,
check,
share,
shareRefs,
carInfoList,
carItem,
};
},
});
</script>
<style lang="scss" scoped>
.search-box {
width: 100%;
z-index: 102;
position: fixed;
.search-header {
box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.06);
background-color: rgba(255, 255, 255, 1);
border-radius: 6px;
height: 44px;
margin: 12px 12px 0 12px;
.select-box {
color: #b8bdc2;
font-size: 14px;
padding: 0 16px;
line-height: 44px;
display: flex;
justify-content: space-between;
.arrow-icon {
color: #9ca4ad;
}
}
.select-box.text {
color: #111111;
}
}
.search-content {
max-height: 516px;
margin-top: 8px;
border-radius: 12px;
background: #fff;
overflow: hidden;
.search-input {
border-radius: 12px;
}
.list-box {
// height: calc(100% - 65px);
max-height: 450px;
overflow-y: auto;
.list-item {
height: 52px;
padding: 0 14px;
display: flex;
align-items: center;
.item-right {
margin-left: 10px;
display: flex;
justify-content: space-between;
width: 100%;
.slectedicon {
display: inline-block;
width: 20px;
height: 20px;
}
}
.off-line {
display: inline-block;
width: 15px;
height: 15px;
border-radius: 50%;
background: #999;
margin-right: 10px;
}
.line-status {
background: #37c060;
}
}
.list-item.active {
background: #ecf5fe;
}
}
}
}
</style>
<style lang="scss">
.car-info-window {
width: 280px;
background-color: #fff;
border-radius: 10px;
border: 1px solid #ececec;
color: #111111;
word-break: break-all;
user-select: text;
.main-info {
padding: 10px;
}
.info-list {
position: relative;
font-size: 12px;
padding-top: 10px;
p {
display: flex;
align-items: flex-start;
line-height: 100%;
margin: 8px 0;
span {
color: #111111;
}
.label {
color: #6c737a;
width: 52px;
margin-right: 8px;
margin-left: 5px;
}
a {
display: flex;
justify-items: center;
align-items: center;
}
}
.list-info {
align-items: center;
a {
margin-right: 10px;
}
.radio {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 5px;
border: 1px solid #c4c8cc;
}
.radio.active {
width: 4px;
height: 4px;
border: 5px solid var(--base-color);
}
}
}
.info-title {
font-weight: normal;
border-bottom: 1px solid #f5f6f7;
padding-bottom: 10px;
font-size: 14px;
color: #333;
div {
color: #111111;
font-weight: 600;
margin-bottom: 5px;
}
:last-child {
font-weight: 500;
}
}
.cmd-list {
font-size: 0px;
border-top: 1px solid #f5f6f7;
.cmd-list-top {
border-bottom: 1px solid #f5f6f7;
padding: 14px 12px;
a {
font-size: 12px;
display: inline-block;
width: 25%;
text-align: center;
box-sizing: border-box;
border-right: 1px solid #f5f6f7;
}
:last-child {
border-right: none;
}
a.disabled {
color: #6c737a;
}
}
.cmd-list-bottom {
padding: 14px 12px;
a {
font-size: 12px;
display: inline-block;
width: 25%;
text-align: center;
box-sizing: border-box;
border-right: 1px solid #ececec;
}
:last-child {
border-right: none;
}
a.disabled {
color: #6c737a;
}
}
}
// .battery {
// position: absolute;
// top: 10px;
// right: 0px;
// width: 37px;
// height: 19px;
// span {
// position: absolute;
// top: 0;
// left: 0;
// width: 100%;
// height: 100%;
// }
// .bg {
// background-size: 37px 19px;
// }
// .fill {
// background-color: #d4f1dc;
// }
// .text {
// color: #37c060;
// font-size: 12px;
// text-align: center;
// line-height: 19px;
// }
// }
// .empty {
// .fill {
// background-color: #f0d0d0;
// }
// .text {
// color: #df2222;
// line-height: 19px;
// }
// }
}
.van-cell {
padding: 0;
}
.van-search__content {
height: var(--van-search-input-height);
display: flex;
align-items: center;
}
</style>
<template>
<topTab ref="tabRefs">
<template #replay>
<replay />
</template>
<template #monitor>
<monitor />
</template>
<template #resident>
<resident />
</template>
<!-- <template #fence>
<fence />
</template> -->
</topTab>
</template>
<script>
import { defineComponent } from "vue";
import topTab from "@/components/top-tab.vue";
import replay from "./replay.vue";
import monitor from "./monitor.vue";
import resident from "./resident.vue";
// import fence from "./fence.vue";
export default defineComponent({
name: "InfoPage",
components: {
topTab,
replay,
monitor,
resident,
// fence,
},
setup() {},
});
</script>
<style lang="scss" scoped></style>
<template>
<div>
<mapContent @refreshCb="refreshCb" @getData="getData" ref="mapContentRefs">
<template #mapBox>
<div id="monitorContainer" class="map-container"></div>
</template>
</mapContent>
<transition name="van-fade"> </transition>
<div class="toggle-bottom" :class="isShowAllList ? '' : 'hidden'">
<div class="toggle-btn" @click="showHideList">
<van-icon
:name="
!isShowAllList && locationList.length > 2
? 'arrow-up'
: 'arrow-down'
"
/>
</div>
<div class="list-content">
<div
class="list-item"
v-for="(item, index) in locationList"
:key="index"
>
<p class="title">{{ item.transferAddress }}</p>
<p class="time">{{ item.time }}</p>
</div>
</div>
</div>
</div>
</template>
<script>
import { defineComponent, onMounted, ref } from "vue";
import mapContent from "@/components/mapContent.vue";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant";
import { GET_RESIDENT_DATA } from "@/api/index";
import { useRoute } from "vue-router";
import MAPGEO from "@/utils/mapgeo";
import { Dialog } from "vant";
import "vant/es/dialog/style";
export default defineComponent({
name: "MonitorPage",
components: {
mapContent,
},
setup() {
const route = useRoute();
const mapContentRefs = ref(null);
const isShowAllList = ref(false);
const locationList = ref([]);
let currentMap = null;
let routeQuery = route.query;
let polyLineArr = ref([]);
let carMarker = null;
let firstPosLng = "";
let firstPosLat = "";
let beginMarker = null;
let polyLine = null;
const timeoutId = ref(null);
const refreshCb = (map) => {
map.clearMap();
getData();
polyLineArr.value = [];
carMarker = null;
firstPosLng = "";
firstPosLat = "";
beginMarker = null;
polyLine = null;
locationList.value = [];
timeoutId.value && clearTimeout(timeoutId.value);
};
onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("monitorContainer");
});
});
// 获取数据
const getData = (map) => {
currentMap = map ? map : currentMap;
init(currentMap);
GET_RESIDENT_DATA({ sns: routeQuery.sn }).then((res) => {
if (res.code === 200) {
if (res.data.length > 0) {
init(currentMap);
} else {
Dialog({ message: "暂无数据" });
}
}
});
};
// marker渲染
const init = (currentMap) => {
let data = [
{
totalDuration: 2032460,
totalTimes: 1,
time: "2022-07-01 15:30:26",
longitude: "114.0736",
latitude: "30.606778",
blat: "30.610309854203035",
blng: "114.08589711310412",
elat: "30.604489843507423",
elng: "114.07934400356585",
name: "鄂ADB1383",
standNo: "LA9XL44B0HBLG6389",
sn: "1500628541",
address: "湖北省武汉市东西湖区慈惠路毛家台(公交站)",
},
];
MAPGEO.transferAddressByGroup(
{
data: data,
timeoutIds: [],
},
() => {
data.forEach((val) => {
var lnglat = new window.AMap.LngLat(val.elng, val.elat);
polyLineArr.value.push(lnglat);
locationList.value.push(val);
if (!carMarker) {
firstPosLng = val.elng;
firstPosLat = val.elat;
carMarker = new window.AMap.Marker({
position: lnglat,
content: '<span class="icon icon-car"></span>',
map: currentMap,
offset: new window.AMap.Pixel(-8.5, -13),
});
beginMarker = new window.AMap.Marker({
position: lnglat,
content: '<span class="icon icon-begin"></span>',
map: currentMap,
offset: new window.AMap.Pixel(-8.5, -13),
visible: false,
});
} else {
carMarker.setPosition(lnglat);
if (firstPosLng !== val.elng || firstPosLat !== val.elat) {
beginMarker.show();
}
if (!polyLine) {
polyLine = new window.AMap.Polyline({
map: currentMap,
strokeWeight: 2,
strokeColor: "#0b94db",
strokeStyle: "solid",
strokeDasharray: [10, 10],
});
}
polyLine.setPath(polyLineArr);
}
});
currentMap.setFitView();
timeoutId.value = setTimeout(function () {
init(currentMap);
}, 10 * 1000);
if (locationList.value.length > 6) locationList.value.shift();
}
);
};
// 显示隐藏实时地址列表数据
const showHideList = () => {
isShowAllList.value = !isShowAllList.value;
};
return {
mapContentRefs,
getData,
refreshCb,
init,
showHideList,
isShowAllList,
locationList,
};
},
});
</script>
<style lang="scss" scoped>
.toggle-bottom {
position: fixed;
width: 100%;
left: 0px;
bottom: 0px;
z-index: 300;
display: flex;
border-radius: 20px;
max-height: 455px;
align-items: center;
flex-flow: column;
background-color: #fff;
padding-top: 10px;
.list-content {
padding-left: 10px;
overflow-y: scroll;
.list-item {
padding: 5px 10px 5px 0;
border-bottom: 1px solid #ececec;
.title {
color: #000;
font-size: 16px;
}
.time {
color: #666;
.navigate {
padding-left: 16px;
background-size: 12px 12px;
float: right;
margin-left: 10px;
}
.copy-adr {
padding-left: 16px;
background-size: 12px 12px;
float: right;
}
}
}
:last-child {
border: none;
}
}
}
.toggle-bottom.hidden {
max-height: 160px;
}
</style>
<template>
<div>
<div class="tab">
<div class="tabbar">
<div class="tabbar-item" @click="showTimeDialog = !showTimeDialog">
轨迹时间
</div>
<div class="tabbar-item" @click="showSpeedPicker = true">
回放速度
<!-- <span class="speed-text" id="speedText">{{
speedItem[speedId].text
}}</span>
<van-icon name="arrow-down" /> -->
</div>
</div>
</div>
<!-- <van-popup v-model:show="showSpeedPicker" round position="bottom">
<van-picker
:columns="speedItem"
@cancel="showSpeedPicker = false"
@confirm="onConfirm"
/>
</van-popup> -->
<div class="speedSelect" v-show="showSpeedPicker">
<!-- <div class="speed-list" v-for="(item, index) in speedItem" :key="index">
<span class="dot" :class="speedId === item.value ? 'active' : ''">
<span>{{ item.text }}</span>
</span>
<span class="line"></span>
</div> -->
<elSlider v-model="speedId" :max="3" :marks="speedItem" :step="1" />
</div>
<div
class="time-content"
v-show="showTimeDialog"
:class="showTimeDialog ? '' : 'hidden'"
>
<div class="time-btn-list">
<span
class="time_btn"
v-for="(item, index) in timeBtnList"
:key="index"
:class="timeSelected === index ? 'active' : ''"
@click="selectTime(index)"
>{{ item }}</span
>
</div>
<div class="custom-time">
<span class="time-text">自定义时间</span
><input
v-model="customTime"
class="time-input"
placeholder="请选择日期"
@click="showTimePicker = true"
type="text"
readonly
/>
</div>
<div class="footer">
<van-button
type="default"
class="time-btn"
size="small"
@click="showTimeDialog = false"
>取消</van-button
>
<van-button
type="primary"
class="time-btn"
size="small"
@click="getCarReplayData"
>确认</van-button
>
</div>
</div>
<van-popup v-model:show="showTimePicker" round position="bottom">
<van-datetime-picker
v-model="currentDate"
type="date"
title="选择年月日"
@confirm="timeConfirm"
@cancel="showTimePicker = false"
/>
</van-popup>
<mapContent @refreshCb="refreshCb" ref="mapContentRefs">
<template #mapBox>
<div id="replayContainer" class="map-container"></div>
</template>
</mapContent>
<div class="btn-control">
<a class="icon icon-replay-play" v-if="!isPlay" @click="play"></a>
<a class="icon icon-replay-pause" v-else @click="pause"></a>
<a class="icon icon-replay-refresh" @click="replayPath"></a>
<!-- <div class="btn_">
<span v-if="!isPlay" @click="play"
><van-icon name="play-circle-o"
/></span>
<span v-if="isPlay" @click="pause"
><van-icon name="pause-circle-o"
/></span>
<span @click="replayPath"><van-icon name="stop-circle-o" /></span>
</div>
<van-progress
class="progress-content"
:percentage="percentage"
pivot-text=""
/> -->
</div>
</div>
</template>
<script>
import { defineComponent, onMounted, ref, reactive } from "vue";
import mapContent from "@/components/mapContent.vue";
import elSlider from "@/components/speedSlider.vue";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant";
import { Toast } from "vant";
import moment from "@/utils/moment";
import "vant/es/toast/style";
import "vant/es/dialog/style";
import "vant/es/progress/style";
import { GET_REPLAY_DATA } from "@/api/index";
import carPng from "@/assets/images/car.png";
import { useRoute } from "vue-router";
export default defineComponent({
name: "ReplayPage",
components: {
mapContent,
elSlider,
},
setup() {
const mapContentRefs = ref(null);
const showSpeedPicker = ref(false);
const speedId = ref(0);
const eParams = ref({});
const timeSelected = ref(null);
const showTimeDialog = ref(false);
const showTimePicker = ref(false);
const currentDate = ref(new Date());
let timeBtnList = ["24小时", "3天", "7天"];
const customTime = ref("");
const route = useRoute();
const percentage = ref(0); // 轨迹播放进度
let map = null;
let routeQuery = route.query;
const replay = reactive({
PathS: null, //轨迹构造器
pathSimplifierIns: null, //轨迹实例
navg: null, //轨迹巡航器
dis: null, // 轨迹距离
speed: null,
});
const isPlay = ref(false);
const speedItem = [
{
text: "慢",
value: 0,
},
{
text: "正常",
value: 1,
},
{
text: "快",
value: 2,
},
{
text: "很快",
value: 3,
},
];
const refreshCb = () => {
if (replay.navg) {
replay.navg.destroy();
}
if (replay.pathSimplifierIns) {
replay.pathSimplifierIns.setData({
path: [],
});
}
percentage.value = 0;
getCarReplayData();
};
onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
AMapUI: {
version: "1.1",
plugins: ["overlay/SimpleMarker"],
},
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("replayContainer");
window.AMapUI.load(
["ui/misc/PathSimplifier"],
function (PathSimplifier) {
if (!PathSimplifier.supportCanvas) {
alert("当前环境不支持 Canvas!");
return;
}
replay.PathS = PathSimplifier;
}
);
});
});
// 查询参数
const getParams = () => {
console.log(routeQuery);
eParams.value = {
speed: speedId.value,
time: timeSelected.value || customTime.value,
locationType: 0,
startTime: "2022-06-27 00:00:00",
endTime: "2022-07-04 23:59:59",
// sn: routeQuery.sn,
sn: "Sr1PRLqA32LCbSWZDch+Sg==",
};
};
// 点击快捷时间选择
const selectTime = (e) => {
timeSelected.value = e;
};
// 自定义时间选择确定
const timeConfirm = (e) => {
customTime.value = moment(e).format("YYYY-MM-DD");
showTimePicker.value = false;
timeSelected.value = null;
};
// 轨迹时间弹窗关闭
const onBeforeClose = (action) => {
if (action === "confirm") {
return customTime.value || timeSelected.value;
}
};
// 获取车辆轨迹
const getCarReplayData = () => {
if (!customTime.value && !timeSelected.value) {
return Toast("请选择一个时间段");
}
getParams();
GET_REPLAY_DATA({ ...eParams.value }).then((res) => {
showTimeDialog.value = false;
if (res.code === 200) {
if (res.data.length > 0) {
var replayData = [];
res.data.forEach(function (item) {
var arr = [];
arr.push(item.elng);
arr.push(item.elat);
replayData.push(arr);
});
initPath(replayData);
}
} else if (res.data.length > 0) {
Toast("暂无轨迹数据");
}
});
};
// 根据距离 实时计算速度
const speedEvent = (idx, dis) => {
let timeArr = [
[40, 30, 16],
[30, 20, 12],
[20, 12, 8],
[5, 3, 2],
]; // 慢 正常 快 很快
let speed;
if (dis >= 100) {
// 100公里以上
speed = Math.floor((dis / timeArr[idx][0]) * 3600);
} else if (dis > 10 && dis < 100) {
// 10-100公里
speed = Math.floor((dis / timeArr[idx][1]) * 3600);
} else {
// 10公里以内
speed = Math.floor((dis / timeArr[idx][2]) * 3600);
}
return speed;
};
const initPath = (replayData) => {
map = map ? map : mapContentRefs.value.init("replayContainer");
replay.dis = window.AMap.GeometryUtil.distanceOfLine(replayData) / 1000; // 算出轨迹的距离(km)
if (replay.PathS) {
replay.pathSimplifierIns = new replay.PathS({
zIndex: 100,
map: map, //所属的地图实例
getPath: function (pathData) {
//返回轨迹数据中的节点坐标信息,[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
return pathData.path;
},
renderOptions: {
//轨迹线的样式
pathLineStyle: {
strokeStyle: "#0b94db",
lineWidth: 6,
dirArrowStyle: true,
},
},
});
replay.pathSimplifierIns.setData([
{
path: replayData,
},
]);
replay.pathSimplifierIns.show();
replay.speed = speedEvent(speedId.value, replay.dis);
//创建一个巡航器
replay.navg = replay.pathSimplifierIns.createPathNavigator(
0, //关联第1条轨迹
{
loop: false, //循环播放
speed: speedEvent(speedId.value, replay.dis),
pathNavigatorStyle: {
width: 17,
height: 26,
//使用图片
content: replay.PathS.Render.Canvas.getImageContent(carPng),
initRotateDegree: 180,
},
}
);
replay.navg.on("pause", function () {
isPlay.value = false;
});
replay.navg.on("move", function () {
progressEvent();
});
}
};
const onChange = (e) => {
console.log(e);
};
// 速度切换
const onConfirm = (e) => {
speedId.value = e.value;
showSpeedPicker.value = false;
if (replay.navg) {
replay.navg.setSpeed(speedEvent(e.value, replay.dis));
if (!isPlay.value) {
play();
}
}
};
// 播放轨迹
const play = () => {
if (replay.navg) {
if (replay.navg.getCursor().idx === replay.navg.getPathEndIdx()) {
replay.navg.start();
} else if (replay.navg.getNaviStatus() === "pause") {
replay.navg.resume();
} else {
replay.navg.start();
}
isPlay.value = true;
}
};
// 暂停
const pause = () => {
if (replay.navg) {
replay.navg.pause();
isPlay.value = false;
}
};
// 重新播放
const replayPath = () => {
if (replay.navg) {
replay.navg.start();
isPlay.value = true;
}
};
// 播放进度条处理
const progressEvent = () => {
let moveDis = replay.navg.getMovedDistance();
let allDis = replay.dis * 1000;
percentage.value =
(moveDis / allDis) * 100 > 100 ? 100 : (moveDis / allDis) * 100;
};
return {
mapContentRefs,
showSpeedPicker,
onConfirm,
speedItem,
speedId,
refreshCb,
getCarReplayData,
getParams,
timeSelected,
showTimeDialog,
showTimePicker,
currentDate,
timeConfirm,
timeBtnList,
selectTime,
customTime,
onBeforeClose,
initPath,
speedEvent,
play,
pause,
replayPath,
isPlay,
percentage,
progressEvent,
onChange,
};
},
});
</script>
<style lang="scss" scoped>
.tab {
.tabbar {
font-size: 0px;
display: flex;
border-bottom: 1px solid #f0f2f5;
position: relative;
color: #666;
z-index: 1000;
.tabbar-item {
flex: 1;
font-size: 14px;
text-align: center;
border-right: 1px solid #eee;
padding: 10px 0;
.speed-text {
margin-right: 5px;
}
}
.tabbar-item:last-child {
border-right: none;
}
}
}
.time-content {
background: #fff;
position: fixed;
top: 84px;
right: 0;
left: 0;
z-index: 301;
padding: 20px;
color: #999;
.time-btn-list {
display: flex;
justify-content: space-between;
text-align: center;
margin-bottom: 20px;
.time_btn {
border: 1px solid #999;
border-radius: 5px;
width: 80px;
}
.active {
border: 1px solid var(--base-color);
color: var(--base-color);
}
}
.custom-time {
display: flex;
align-items: center;
.time-text {
margin-right: 10px;
}
.time-input {
text-align: center;
display: inline-block;
width: 240px;
height: 28px;
border: 1px solid #999;
border-radius: 5px;
}
}
.footer {
display: flex;
padding-top: 20px;
justify-content: center;
.time-btn {
margin: 0 10px;
width: 100px;
border-radius: 5px;
}
}
}
.speedSelect {
height: 90px;
display: flex;
align-items: center;
margin: 0 30px;
}
.btn-control {
position: fixed;
background: #fff;
width: 100%;
height: 60px;
bottom: 0px;
z-index: 300;
padding: 0 20px;
display: flex;
align-items: center;
span {
display: inline-block;
margin-right: 5px;
width: 30px;
height: 30px;
i {
font-size: 25px;
color: var(--base-color);
}
}
.progress-content {
width: 70%;
}
}
</style>
<template>
<div>
<div class="tab">
<div class="tabbar">
<div
class="tabbar-item"
:class="seledtedItem === 7 ? 'active' : ''"
@click="getParams(7)"
>
7天
</div>
<div
class="tabbar-item"
:class="seledtedItem === 30 ? 'active' : ''"
@click="getParams(30)"
>
30天
</div>
<div
class="tabbar-item"
:class="seledtedItem === 99 ? 'active' : ''"
@click="showTimePicker = true"
>
<span class="speed-text" id="speedText">{{ currentDateText }}</span>
</div>
</div>
</div>
<van-popup v-model:show="showTimePicker" round position="bottom">
<van-datetime-picker
v-model="currentDate"
type="year-month"
title="选择年月"
@confirm="timeConfirm"
@cancel="showTimePicker = false"
/>
</van-popup>
<mapContent @refreshCb="refreshCb" @getData="getData" ref="mapContentRefs">
<template #mapBox>
<div id="residentContainer" class="map-container"></div>
</template>
<template #screenBox>
<div class="screenBtn">
<van-icon name="more-o" />
</div>
</template>
</mapContent>
<div class="toggle-bottom" :class="isShowAllList ? '' : 'hidden'">
<div class="toggle-btn" @click="showHideList">
<van-icon
:name="
!isShowAllList && residentList.length > 2
? 'arrow-up'
: 'arrow-down'
"
/>
</div>
<div class="list-content">
<div
class="list-item"
v-for="(item, index) in residentList"
:key="index"
>
<p class="title">{{ item.transferAddress }}</p>
<p class="time">
停留({{ parseInt(item.totalDuration / 3600) }})小时
<a class="navigate" @click="navigation(item)"
><i class="icon icon-navigate"></i>导航</a
>
<a
class="copy-adr"
@click="copyAddress"
:data-clipboard-text="item.transferAddress"
><i class="icon icon-copy"></i>复制</a
>
</p>
</div>
</div>
</div>
</div>
</template>
<script>
import { defineComponent, onMounted, ref } from "vue";
import mapContent from "@/components/mapContent.vue";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "../constant";
import moment from "@/utils/moment";
import { GET_RESIDENT_DATA } from "@/api/index";
import { useRoute } from "vue-router";
import MAPGEO from "@/utils/mapgeo";
import wx from "wx";
import Clipboard from "clipboard";
import { Toast, Dialog } from "vant";
import "vant/es/toast/style";
import "vant/es/dialog/style";
export default defineComponent({
name: "ResidentPage",
components: {
mapContent,
},
setup() {
const route = useRoute();
const showTimePicker = ref(false);
const mapContentRefs = ref(null);
const currentDate = ref(new Date());
const currentDateText = ref("自定义");
const seledtedItem = ref(7);
const isShowAllList = ref(false);
const residentList = ref([]);
let currentMap = null;
let routeQuery = route.query;
let markerArr = [];
const oParams = ref({
sn: routeQuery.sn,
sTime: moment().subtract("day", 7).format("YYYY-MM-DD HH:mm:ss"),
eTime: moment().format("YYYY-MM-DD HH:mm:ss"),
});
const refreshCb = (map) => {
map.clearMap();
getData();
};
onMounted(() => {
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.8",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
mapContentRefs.value.initMap("residentContainer");
});
});
// 时间选择确定
const timeConfirm = (e) => {
seledtedItem.value = 99;
currentDateText.value = moment(e).format("YYYY-MM");
showTimePicker.value = false;
getParams();
};
// 查询参数
const getParams = (num) => {
if (num) {
if (num === seledtedItem.value) return;
seledtedItem.value = num;
oParams.value = {
sn: routeQuery.sn,
eTime: moment().format("YYYY-MM-DD HH:mm:ss"),
sTime: moment().subtract("day", num).format("YYYY-MM-DD HH:mm:ss"),
};
} else {
seledtedItem.value = 99;
oParams.value = {
sn: routeQuery.sn,
eTime: moment(currentDate.value).format("YYYY-MM-DD HH:mm:ss"),
sTime: moment(currentDate.value)
.endOf("month")
.format("YYYY-MM-DD HH:mm:ss"),
};
}
getData();
};
// 获取数据
const getData = (map) => {
currentMap = map ? map : currentMap;
console.log(oParams);
init(currentMap);
GET_RESIDENT_DATA({ ...oParams.value }).then((res) => {
if (res.code === 200) {
if (res.data.length > 0) {
init(currentMap);
} else {
Dialog({ message: "暂无数据" });
}
}
});
};
// marker渲染
const init = (currentMap) => {
let data = [
{
totalDuration: 2032460,
totalTimes: 1,
longitude: "114.0736",
latitude: "30.606778",
blat: "30.610309854203035",
blng: "114.08589711310412",
elat: "30.604489843507423",
elng: "114.07934400356585",
name: "鄂ADB1383",
standNo: "LA9XL44B0HBLG6389",
sn: "1500628541",
address: "湖北省武汉市东西湖区慈惠路毛家台(公交站)",
},
{
totalDuration: 70657,
totalTimes: 5,
longitude: "114.269152",
latitude: "30.4717",
blat: "30.475120735401635",
blng: "114.28106673829616",
elat: "30.469204494124334",
elng: "114.27455549242231",
name: "鄂ADB1383",
standNo: "LA9XL44B0HBLG6389",
sn: "1500628541",
address: "湖北省武汉市洪山区城开青菱城市花园二期(武汉)",
},
{
totalDuration: 67351,
totalTimes: 4,
longitude: "114.27008",
latitude: "30.481154",
blat: "30.4845642911033",
blng: "114.28200904532856",
elat: "30.47866175313912",
elng: "114.27548450027317",
name: "鄂ADB1383",
standNo: "LA9XL44B0HBLG6389",
sn: "1500628541",
address: "湖北省武汉市洪山区天地源荷景苑",
},
];
MAPGEO.transferAddressByGroup(
{
data: data,
timeoutIds: [],
},
() => {
for (var i = 0, len = data.length; i < len; i++) {
var item = data[i];
(function (item) {
var lnglat = new window.AMap.LngLat(item.elng, item.elat);
var marker = new window.AMap.Marker({
position: lnglat,
content: '<span class="icon icon-resident"></span>',
map: currentMap,
offset: new window.AMap.Pixel(-8.5, -13),
});
var infoWindow = new window.AMap.InfoWindow({
isCustom: true,
position: lnglat,
content: `<div class="marker-info-window"><p>${item.transferAddress}</p></div>`,
offset: new window.AMap.Pixel(0, -20),
});
marker.on("click", function () {
if (infoWindow.getIsOpen()) {
infoWindow.close();
} else {
infoWindow.open(currentMap);
}
});
markerArr.push(marker);
})(item);
}
residentList.value = data;
currentMap.setFitView();
}
);
};
// 导航
const navigation = (data) => {
wx.miniProgram.navigateTo({
url: `../../pages/trace/trace?lat=${data.elat}&lng=${data.elng}`,
});
};
// 复制地址
const copyAddress = () => {
let clipboard = new Clipboard(".copy-adr");
clipboard.on("success", () => {
clipboard.destroy();
Toast("复制地址成功");
});
};
// 显示隐藏常驻地列表数据
const showHideList = () => {
isShowAllList.value = !isShowAllList.value;
};
return {
mapContentRefs,
showTimePicker,
getData,
refreshCb,
currentDate,
currentDateText,
init,
timeConfirm,
seledtedItem,
oParams,
getParams,
navigation,
copyAddress,
showHideList,
isShowAllList,
residentList,
};
},
});
</script>
<style lang="scss" scoped>
.tab {
.tabbar {
font-size: 0px;
display: flex;
border-bottom: 1px solid #eee;
position: relative;
color: #666;
z-index: 1000;
.tabbar-item {
flex: 1;
font-size: 14px;
text-align: center;
border-right: 1px solid #eee;
padding: 10px 0;
.speed-text {
margin-right: 5px;
}
}
.tabbar-item.active {
border-bottom: 2px solid var(--base-color);
color: var(--base-color);
}
.tabbar-item:last-child {
border-right: none;
}
}
}
.toggle-bottom {
position: fixed;
width: 100%;
left: 0px;
bottom: 0px;
z-index: 300;
display: flex;
border-radius: 20px;
max-height: 455px;
align-items: center;
flex-flow: column;
background-color: #fff;
padding-top: 10px;
.list-content {
background-color: #fff;
padding-left: 10px;
overflow-y: scroll;
.list-item {
padding: 5px 10px 5px 0;
border-bottom: 1px solid #ececec;
.title {
color: #000;
font-size: 16px;
}
.time {
color: #666;
.navigate {
padding-left: 16px;
background-size: 12px 12px;
float: right;
margin-left: 10px;
}
.copy-adr {
padding-left: 16px;
background-size: 12px 12px;
float: right;
}
}
}
:last-child {
border: none;
}
}
}
.toggle-bottom.hidden {
max-height: 165px;
}
</style>
<style lang="scss">
.marker-info-window {
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
border-radius: 4px;
padding: 10px;
}
</style>
const { defineConfig } = require("@vue/cli-service");
const Spritesmith = require("webpack-spritesmith");
const path = require("path");
const templateFunction = require("./sprite");
const { VantResolver } = require("unplugin-vue-components/resolvers");
const ComponentsPlugin = require("unplugin-vue-components/webpack");
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
port: 9527,
proxy: {
"/api": {
target: "https://eshield.test.glsx.com.cn/",
ws: true,
changeOrigin: true,
pathRewrite: { "^/api": "" },
},
},
},
chainWebpack: (config) => {
config.plugin("webpack-spritesmith").use(Spritesmith, [
{
src: {
cwd: path.resolve(__dirname, "src/assets/icon"),
glob: "*.png",
},
target: {
image: path.resolve(
__dirname,
"src/assets/spritesmith-generated/sprite.png"
),
css: [
[
path.resolve(
__dirname,
"src/assets/spritesmith-generated/sprite.css"
),
{
format: "function_based_template",
},
],
],
},
customTemplates: {
function_based_template: templateFunction,
},
apiOptions: {
cssImageRef: "sprite.png",
},
},
]);
},
configureWebpack: {
plugins: [
ComponentsPlugin({
resolvers: [VantResolver()],
}),
],
externals: {
wx: "wx",
},
},
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!