This commit is contained in:
weipengfei 2024-01-22 18:08:02 +08:00
parent c4b37c31ca
commit 089f5367d6
5 changed files with 215 additions and 147 deletions

View File

@ -1,24 +1,58 @@
<script setup>
import { Push } from '@/common/push'
import mitt from "@/utils/mitt";
import {useRoute} from "vue-router";
import {useRoute, useRouter} from "vue-router";
import { useAppStore } from "@/store/app.js";
const route = useRoute();
const router = useRouter();
console.log(route);
const appSotre = useAppStore();
var connection = new Push({
url: 'ws://192.168.1.24:3131', // websocket
const refresh = ()=>{ //
console.log(route.path=='/index');
if(route.path=='/index'){
if(appSotre.address.areaCode) router.push({
path: '/index',
query:{
areaCode: appSotre.address.areaCode
}
})
else router.push({
path: '/index'
})
}else location.reload();
}
const back = ()=>{
if(route.path!='/index'){
if(appSotre.address.areaCode) router.push({
path: '/index',
query:{
areaCode: appSotre.address.areaCode
}
})
else router.push({
path: '/index'
})
}
}
const connection = new Push({
url: 'wss://chat.lihaink.cn/tts', // websocket
app_key: 'aaea61749929eb53a4bd75a1474c1d27',
});
// uid1
var uid = 5;
const uid = 5;
// user-2uid1
var user_channel = connection.subscribe('user-' + uid);
const user_channel = connection.subscribe('user-' + uid);
// user-2message
user_channel.on('message', function (data) {
mitt.emit(data.content.event, data.content.data);
if(data.content.event=='refresh') refresh();
if(data.content.event=='back') back();
else mitt.emit(data.content.event, data.content.data);
console.log("收到消息--",data)

View File

@ -2,6 +2,7 @@
import { defineProps, defineEmits, ref, nextTick, onMounted, onUnmounted, } from "vue"
import { useRouter } from 'vue-router'
import { useAppStore } from "@/store/app.js";
import mitt from "@/utils/mitt";
const router = useRouter()
const emit = defineEmits(['offAreaList']);
@ -79,6 +80,14 @@ const show = () => {
choseArea.value = !choseArea.value;
}
mitt.on("choseTown", (data) => {
console.log(data, ...props.list);
let town = props.list.find((item) => item.name == data.name);
if (town && town.code) {
choseTownFn(town)
}
});
defineExpose({
open, close, show
})

View File

@ -8,12 +8,12 @@ import { useAppStore } from "@/store/app.js";
import { useUserStore } from "@/store/user.js";
import axios from "axios";
const reload = inject('reload');
const reload = inject("reload");
const info = reactive({
address: '泸县',
pinyin: 'luxian'
})
address: "泸县",
pinyin: "luxian",
});
const appStore = useAppStore();
const userSotre = useUserStore();
@ -21,80 +21,79 @@ const userSotre = useUserStore();
const areaListRef = ref(null);
//
const choseArea = ref(null)
const choseArea = ref(null);
const open = () => {
if (list.value.length > 0) areaListRef.value.show();
}
};
//
const offAreaList = (e) => {
Object.keys(e).forEach(key => {
Object.keys(e).forEach((key) => {
if (e[key]) {
info[key] = e[key];
}
})
});
info.address = e.name;
mitt.emit('map_info', info);
mitt.emit("map_info", info);
reload();
}
};
const list = ref([])
const list = ref([]);
const initList = async () => {
let street = appStore.street;
if (street?.length == 0) {
let { data } = await getStreet({
area_code: appStore.address.areaCode
})
area_code: appStore.address.areaCode,
});
street = data;
appStore.setStreet(street);
}
let area = appStore.area;
if (userSotre.userInfo.street_code) {
let data = street.find(item => item.code == appStore.address.streetCode);
let data = street.find((item) => item.code == appStore.address.streetCode);
info.address = data?.name;
list.value = [];
appStore.setAddress({
areaCode: appStore.address.areaCode,
streetCode: appStore.address.streetCode
})
streetCode: appStore.address.streetCode,
});
} else {
let data = area.find(item => item.code == appStore.address.areaCode);
let data = area.find((item) => item.code == appStore.address.areaCode);
info.address = data?.name;
list.value = [data, ...street];
if (appStore.address.streetCode) {
data = street.find(item => item.code == appStore.address.streetCode);
data = street.find((item) => item.code == appStore.address.streetCode);
info.address = data?.name;
}
appStore.setAddress({
areaCode: appStore.address.areaCode,
streetCode: appStore.address.streetCode
})
streetCode: appStore.address.streetCode,
});
}
mitt.emit('map_info', info);
}
mitt.emit("map_info", info);
};
const initList2 = async () => {
getArea({
city_code: 510500
}).then(res=>{
city_code: 510500,
}).then((res) => {
console.log(res);
// list.value = res.data;
// appStore.setAddress({
// areaCode: res.data[0].code,
// streetCode: ''
// })
})
mitt.emit('map_info', info);
}
});
mitt.emit("map_info", info);
};
const router = useRouter()
const route = useRoute()
const router = useRouter();
const route = useRoute();
const navToDelivery = () => {
if (route.path == '/') {
if (route.path == "/") {
// router.push('/delivery');
return;
}
else router.back();
}
} else router.back();
};
let nowTime = ref([]);
@ -107,41 +106,58 @@ const updateClock = () => {
let m = now.getMonth() + 1;
let d = now.getDate();
nowTime.value[0] = y + '.' + m.toString().padStart(2, '0') + '.' + d.toString().padStart(2, '0');
nowTime.value[0] =
y +
"." +
m.toString().padStart(2, "0") +
"." +
d.toString().padStart(2, "0");
nowTime.value[1] = hours.toString().padStart(2, '0') + ':' +
minutes.toString().padStart(2, '0') + ':' +
seconds.toString().padStart(2, '0');
}
nowTime.value[1] =
hours.toString().padStart(2, "0") +
":" +
minutes.toString().padStart(2, "0") +
":" +
seconds.toString().padStart(2, "0");
};
const logout = () => {
// router.replace('/login')
router.push('/login')
}
router.push("/login");
};
const weather = ref("暂无天气信息")
const weather = ref("暂无天气信息");
const initWeather = (city = 510500) => {
axios.get(`https://restapi.amap.com/v3/weather/weatherInfo?city=${city}&key=5731d3b4c3f34e09226e084ce556e259`).then((res) => {
if (res.data.status == 1) {
weather.value = res.data.lives[0].weather;
}
}).catch((e) => {
console.log(e);
})
}
axios
.get(
`https://restapi.amap.com/v3/weather/weatherInfo?city=${city}&key=5731d3b4c3f34e09226e084ce556e259`
)
.then((res) => {
if (res.data.status == 1) {
weather.value = res.data.lives[0].weather;
}
})
.catch((e) => {
console.log(e);
});
};
mitt.on("choserArea", (data)=>{
console.log(data);
})
mitt.on("choserArea", (data) => {
appStore.setAddress({
areaCode: data.code,
streetCode: "",
});
initList();
});
onMounted(() => {
console.log(route);
if(route.query.areaCode){
console.log('route',route.query.areaCode);
if (route.query.areaCode) {
console.log("route", route.query.areaCode);
appStore.setAddress({
areaCode: route.query.areaCode,
streetCode: route.query.streetCode||''
})
streetCode: route.query.streetCode || "",
});
}
initList();
initList2();
@ -150,7 +166,7 @@ onMounted(() => {
setInterval(updateClock, 1000);
initWeather();
})
});
</script>
<template>

View File

@ -3,12 +3,13 @@ import { createRouter, createWebHistory } from "vue-router"
const routes = [
{
path: '/',
name: 'index',
name: 'app',
component: () => import('../layout/index.vue'),
redirect: 'index',
children: [
{
path: '/',
name: '',
path: '/index',
name: 'index',
component: () => import('../view/index/index.vue')
},
{

View File

@ -9,22 +9,22 @@ const loading = ref(true);
const props = defineProps({
list: {
type: Object,
default: () => []
default: () => [],
},
open: {
type: String,
default: ''
}
})
default: ()=>"",
},
});
const initMap = () => {
AMapLoader.load({
key: "4f8f55618010007147aab96fc72bb408", // WebKey load
version: "2.0", // JSAPI 1.4.15
plugins: ['AMap.Geocoder'], // 使'AMap.Scale'
plugins: ["AMap.Geocoder"], // 使'AMap.Scale'
Loca: {
version: '2.0.0'
}
version: "2.0.0",
},
})
.then((AMap) => {
map = new AMap.Map("container", {
@ -35,98 +35,102 @@ const initMap = () => {
mapStyle: "amap://styles/darkblue",
});
//
map.on('complete', () => {
map.on("complete", () => {
//
setTimeout(() => {
loading.value = false;
}, 500)
}, 500);
});
map.setPitch(30);
let geocoder = new AMap.Geocoder();
if (props.open.length>0) {
let geocoder = new AMap.Geocoder();
geocoder.getLocation(props.open, function (status, result) {
if (status === "complete" && result.info === "OK") {
// result.geocodes
let latlong = result.geocodes[0].location;
let start = [latlong.lng, latlong.lat];
let line = [];
map.setCenter(start);
// AMap.Icon
const icon = new AMap.Icon({
size: new AMap.Size(50, 60), //
// vue3/vite require
image: new URL(
"/src/assets/delivery_img/icon10.png",
import.meta.url
).href, // Icon
imageSize: new AMap.Size(50, 60), //
imageOffset: new AMap.Pixel(0, 0),
});
// Marker
const marker = new AMap.Marker({
position: start, // [116.39, 39.9]
icon: icon,
offset: new AMap.Pixel(-25, -60), //
});
geocoder.getLocation(props.open, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
// result.geocodes
let latlong = result.geocodes[0].location;
let start = [latlong.lng, latlong.lat];
let line = [];
map.setCenter(start);
//
map.add(marker);
// AMap.Icon
const icon = new AMap.Icon({
size: new AMap.Size(50, 60), //
// vue3/vite require
image: new URL('/src/assets/delivery_img/icon10.png', import.meta.url).href, // Icon
imageSize: new AMap.Size(50, 60), //
imageOffset: new AMap.Pixel(0, 0)
});
// Marker
const marker = new AMap.Marker({
position: start, // [116.39, 39.9]
icon: icon,
offset: new AMap.Pixel(-25, -60), //
});
//
map.add(marker);
props.list.forEach(item => {
geocoder.getLocation(item, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
// result.geocodes
let geocodes = result.geocodes[0].location;
line.push([geocodes.lng, geocodes.lat]);
if (line.length == props.list.length) {
initLine(start, line);
props.list.forEach((item) => {
geocoder.getLocation(item, function (status, result) {
if (status === "complete" && result.info === "OK") {
// result.geocodes
let geocodes = result.geocodes[0].location;
line.push([geocodes.lng, geocodes.lat]);
if (line.length == props.list.length) {
initLine(start, line);
}
} else {
//
console.log("获取经纬度失败");
}
} else {
//
console.log('获取经纬度失败');
}
})
})
} else {
//
console.log('获取经纬度失败');
}
});
});
});
} else {
//
console.log("获取经纬度失败", props);
// setTimeout(() => {
// initMap();
// }, 2000);
}
setTimeout(() => {
loading.value = false;
}, 500);
});
}
})
.catch((e) => {
console.log(e);
});
}
};
const initLine = (start = [], line = []) => {
let features = [];
line.forEach((item => {
line.forEach((item) => {
features.push({
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
start,
item
]
}
},)
}))
type: "Feature",
properties: {},
geometry: {
type: "LineString",
coordinates: [start, item],
},
});
});
// Loca
let loca = new Loca.Container({
map: map
map: map,
});
//
let dataSource = new Loca.GeoJSONSource({
// url: 'xxx.geojson', 使 data
data: {
"type": "FeatureCollection",
"features": features
type: "FeatureCollection",
features: features,
},
});
@ -140,9 +144,9 @@ const initLine = (start = [], line = []) => {
depth: true,
});
pulseLink.setSource(dataSource)
pulseLink.setSource(dataSource);
pulseLink.setStyle({
unit: 'meter',
unit: "meter",
dash: [80, 0, 80, 0],
lineWidth: function () {
return [30, 5];
@ -158,17 +162,21 @@ const initLine = (start = [], line = []) => {
},
flowLength: 300,
lineColors: function (index, feat) {
return ['rgba(47, 194, 250, 0.20)', 'rgba(91, 219, 246, 0.70)', 'rgba(0, 156, 255, 0.20)'];
return [
"rgba(47, 194, 250, 0.20)",
"rgba(91, 219, 246, 0.70)",
"rgba(0, 156, 255, 0.20)",
];
},
maxHeightScale: 0.4, //
headColor: 'rgba(91, 219, 246, 1)',
trailColor: 'rgba(255, 255,0,0)',
headColor: "rgba(91, 219, 246, 1)",
trailColor: "rgba(255, 255,0,0)",
});
//
loca.add(pulseLink);
loca.animate.start();
}
};
onMounted(() => {
initMap();
@ -182,13 +190,13 @@ onUnmounted(() => {
<template>
<div class="c-box">
<div id="container"></div>
<div class="loading" v-if="loading">
<div class="loading" v-show="loading">
<dv-loading>加载中...</dv-loading>
</div>
</div>
</template>
<style scoped lang ="scss">
<style scoped lang="scss">
.c-box {
width: 100%;
height: 100%;