From 2ad44878a510b3c3eabff87f5b9ff9351e3ff942 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Fri, 23 Feb 2024 18:20:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 17 +- src/components/headView.vue | 219 ++++++++++++++---------- src/view/delivery/components/center.vue | 4 +- src/view/delivery/index.vue | 8 +- src/view/indexc/components/center2.vue | 2 +- 5 files changed, 146 insertions(+), 104 deletions(-) diff --git a/src/App.vue b/src/App.vue index ad11222..7a291b5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -39,14 +39,24 @@ const back = ()=>{ } } +// 获取 URL 中的查询参数部分 +const queryString = window.location.search; + +// 解析查询参数字符串 +const searchParams = new URLSearchParams(queryString); + +// 读取名为 id 的参数 +const uid = searchParams.get('local') || localStorage.getItem('local'); + +if(searchParams.get('local')) localStorage.setItem('local', searchParams.get('local')); + const connection = new Push({ url: 'wss://chat.lihaink.cn/tts', // websocket地址 app_key: 'aaea61749929eb53a4bd75a1474c1d27', }); -// 假设用户uid为1 -const uid = 5; + // 浏览器监听user-2频道的消息,也就是用户uid为1的用户消息 -const user_channel = connection.subscribe('user-breed-datav'); +const user_channel = connection.subscribe(uid + 'user-breed-datav'); // 当user-2频道有message事件的消息时 user_channel.on('message', function (data) { @@ -56,7 +66,6 @@ user_channel.on('message', function (data) { if(data.content.event=='back') back(); else mitt.emit(data.content.event, data.content.data); - }); // 断线事件 user_channel.on('close', function () { diff --git a/src/components/headView.vue b/src/components/headView.vue index 1ab37e9..e14f5d1 100644 --- a/src/components/headView.vue +++ b/src/components/headView.vue @@ -8,80 +8,83 @@ import axios from "axios"; import { getStreet } from "@/api/index.js"; import { useAppStore } from "@/store/app.js"; import { useUserStore } from "@/store/user.js"; -import { sendMsg } from "@/api/sendMsg.js" +import { sendMsg } from "@/api/sendMsg.js"; const appStore = useAppStore(); const userSotre = useUserStore(); -const reload = inject('reload'); +const reload = inject("reload"); const info = reactive({ - address: '泸县', - areaName: '泸县', - pinyin: 'luxian' -}) + address: "泸县", + areaName: "泸县", + pinyin: "luxian", +}); const areaListRef = ref(null); // 选择镇 -const choseArea = ref(null) +const choseArea = ref(null); const open = () => { 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); // reload(); - if(route.query.type=='main') { - sendMsg({ channel: 'user-breed-datav', event: 'changMap', data: { - areaName: info.areaName, - name: e.name - }}) + if (route.query.type == "main") { + sendMsg({ + channel: "user-breed-datav", + event: "changMap", + data: { + areaName: info.areaName, + name: e.name, + }, + }); } else { router.push({ - path: '/indexc', + path: "/indexc", query: { - areaCode: route.query.areaCode, + areaCode: route.query.areaCode || appStore.address.areaCode, streetCode: e.code, - name: e.name - } - }) + name: e.name, + }, + }); } -} +}; -const router = useRouter() -const route = useRoute() +const router = useRouter(); +const route = useRoute(); const navTo = () => { - if (route.path == '/') return location.reload(); - else if(route.path == '/indexc'){ + if (route.path == "/") return location.reload(); + else if (route.path == "/indexc") { appStore.setAddress({ areaCode: appStore.address.areaCode, - streetCode: '' - }) - router.push('/?areaCode='+appStore.address.areaCode); + streetCode: "", + }); + router.push("/?areaCode=" + appStore.address.areaCode); let area = appStore.area; - let data = area.find(item => item.code == appStore.address.areaCode); + let data = area.find((item) => item.code == appStore.address.areaCode); info.areaName = data?.name; info.address = data?.name; - } - else if(route.path == '/delivery') { + } else if (route.path == "/delivery") { router.push({ - path: '/indexc', + path: "/indexc", query: { areaCode: route.query.areaCode, streetCode: route.query.streetCode, - name: route.query.name - } - }) + name: route.query.name, + }, + }); } -} +}; let nowTime = ref([]); @@ -94,102 +97,130 @@ 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 list = ref([]) -const initList = async () => { +const list = ref([]); +const initList = async (re = false) => { let street = appStore.street; - if (street?.length == 0) { + if (street?.length == 0 || re) { 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.areaName = data?.name; 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.areaName = data?.name; info.address = data?.name; // list.value = [data, ...street]; list.value = 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 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); + }); +}; // 选择时间 const changeTime = (e) => { console.log(e); -} +}; mitt.on("choserArea", (data) => { appStore.setAddress({ areaCode: data.code, streetCode: "", }); - initList(); + initList(true); router.push({ - path: '/', + path: "/", query: { - areaCode: data.code, - } - }) + areaCode: data.code, + }, + }); }); mitt.on("choseTown", (data) => { - let c = list.value.find(item=>item.name==data.name); - if(!c)return; + let c = list.value.find((item) => item.name == data.name); + console.log(list.value, data, c); + if (!c) return; appStore.setAddress({ areaCode: appStore.address.areaCode, streetCode: c.code, }); initList(); router.push({ - path: '/indexc', + path: "/indexc", query: { areaCode: appStore.address.areaCode, streetCode: c.code, - name: data.name - } - }) + name: data.name, + }, + }); +}); + +mitt.on("goFarmDetail", (data) => { + router.push({ + path: "/delivery", + query: { + areaCode: route.query.areaCode, + streetCode: route.query.streetCode, + name: route.query.name, + id: data.id, + farm_name: data.farm_name, + address: data.longitude + ',' + data.latitude, + }, + }); }); onMounted(() => { @@ -198,8 +229,7 @@ onMounted(() => { areaCode: route.query.areaCode, streetCode: route.query.streetCode || "", }); - } - else if(route.path=='/'){ + } else if (route.path == "/") { appStore.setAddress({ areaCode: appStore.address.areaCode, streetCode: "", @@ -207,24 +237,24 @@ onMounted(() => { } initList(); - mitt.on('push_to', (e)=>{ + mitt.on("push_to", (e) => { appStore.setAddress({ areaCode: e.areaCode, streetCode: e.streetCode, }); initList(); - info.address = e.name - }) + info.address = e.name; + }); // 每秒钟更新一次时间 setInterval(updateClock, 1000); initWeather(); - - mitt.on('changMap', (e)=>{ - if(e.areaName==info.areaName){ - let c = list.value.find(item=>item.name==e.name); - if(c) areaListRef.value.choseTownFn(c); + + mitt.on("changMap", (e) => { + if (e.areaName == info.areaName) { + let c = list.value.find((item) => item.name == e.name); + if (c) areaListRef.value.choseTownFn(c); // router.push({ // path: '/delivery', // query: { @@ -232,8 +262,8 @@ onMounted(() => { // } // }) } - }) -}) + }); +}); diff --git a/src/view/indexc/components/center2.vue b/src/view/indexc/components/center2.vue index aecbacc..ef7cf8d 100644 --- a/src/view/indexc/components/center2.vue +++ b/src/view/indexc/components/center2.vue @@ -501,7 +501,7 @@ const initMap = () => { name: route.query.name, id: params.data.id, farm_name: params.data.name, - local: params.data.value.join(',') + address: params.data.value.join(',') } }) }