Commit 0e78cabf by zhangxw

项目初始化

1 parent dc894454
{
"endOfLine": "auto"
}
\ No newline at end of file \ No newline at end of file
module.exports = { module.exports = {
presets: ["@vue/cli-plugin-babel/preset"], 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 @@ ...@@ -3,13 +3,23 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vue-cli-service serve",
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "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", "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": { "devDependencies": {
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",
...@@ -21,7 +31,11 @@ ...@@ -21,7 +31,11 @@
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.0.3", "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": { "eslintConfig": {
"root": true, "root": true,
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang=""> <html lang="">
<head>
<meta charset="utf-8"> <head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<title><%= htmlWebpackPlugin.options.title %></title> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
</head> <title>
<body> <%= htmlWebpackPlugin.options.title %>
<noscript> </title>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> </head>
</noscript>
<div id="app"></div> <body>
<!-- built files will be auto injected --> <noscript>
</body> <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
</html> 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 \ 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> <template>
<img alt="Vue logo" src="./assets/logo.png" /> <Loading v-show="LOADING"></Loading>
<HelloWorld msg="Welcome to Your Vue.js App" /> <router-view v-slot="{ Component }" class="warp-content">
<keep-alive :include="['IndexPage']">
<component :is="Component" />
</keep-alive>
</router-view>
</template> </template>
<script> <script>
import HelloWorld from "./components/HelloWorld.vue"; import { useStore } from "vuex";
import { computed } from "vue";
import Loading from "@/components/loading.vue";
export default { export default {
name: "App", name: "App",
components: { components: {
HelloWorld, Loading,
},
setup() {
const store = useStore();
const LOADING = computed(() => store.state.LOADING);
return {
LOADING,
};
}, },
}; };
</script> </script>
<style> <style lang="scss">
* {
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
// min-height: 100%;
// min-height: 100%;
}
.warp-content {
height: 100%;
}
#app { #app {
font-family: Avenir, Helvetica, Arial, sans-serif; height: 100%;
-webkit-font-smoothing: antialiased; // min-height: 100%;
-moz-osx-font-smoothing: grayscale; }
text-align: center; .curr-marker {
color: #2c3e50; display: inline-block;
margin-top: 60px; 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> </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 \ 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 \ 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 \ 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 { createApp } from "vue";
import App from "./App.vue"; import App from "./App.vue";
import store from "./store";
createApp(App).mount("#app"); 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>
<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>
const { defineConfig } = require("@vue/cli-service"); 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({ module.exports = defineConfig({
transpileDependencies: true, 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!