This commit is contained in:
weipengfei 2024-02-23 18:20:10 +08:00
parent 4428b1af3a
commit 2ad44878a5
5 changed files with 146 additions and 104 deletions

View File

@ -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({ const connection = new Push({
url: 'wss://chat.lihaink.cn/tts', // websocket url: 'wss://chat.lihaink.cn/tts', // websocket
app_key: 'aaea61749929eb53a4bd75a1474c1d27', app_key: 'aaea61749929eb53a4bd75a1474c1d27',
}); });
// uid1
const uid = 5;
// user-2uid1 // user-2uid1
const user_channel = connection.subscribe('user-breed-datav'); const user_channel = connection.subscribe(uid + 'user-breed-datav');
// user-2message // user-2message
user_channel.on('message', function (data) { user_channel.on('message', function (data) {
@ -56,7 +66,6 @@ user_channel.on('message', function (data) {
if(data.content.event=='back') back(); if(data.content.event=='back') back();
else mitt.emit(data.content.event, data.content.data); else mitt.emit(data.content.event, data.content.data);
}); });
// 线 // 线
user_channel.on('close', function () { user_channel.on('close', function () {

View File

@ -8,80 +8,83 @@ import axios from "axios";
import { getStreet } from "@/api/index.js"; import { getStreet } from "@/api/index.js";
import { useAppStore } from "@/store/app.js"; import { useAppStore } from "@/store/app.js";
import { useUserStore } from "@/store/user.js"; import { useUserStore } from "@/store/user.js";
import { sendMsg } from "@/api/sendMsg.js" import { sendMsg } from "@/api/sendMsg.js";
const appStore = useAppStore(); const appStore = useAppStore();
const userSotre = useUserStore(); const userSotre = useUserStore();
const reload = inject('reload'); const reload = inject("reload");
const info = reactive({ const info = reactive({
address: '泸县', address: "泸县",
areaName: '泸县', areaName: "泸县",
pinyin: 'luxian' pinyin: "luxian",
}) });
const areaListRef = ref(null); const areaListRef = ref(null);
// //
const choseArea = ref(null) const choseArea = ref(null);
const open = () => { const open = () => {
areaListRef.value.show(); areaListRef.value.show();
} };
// //
const offAreaList = (e) => { const offAreaList = (e) => {
Object.keys(e).forEach(key => { Object.keys(e).forEach((key) => {
if (e[key]) { if (e[key]) {
info[key] = e[key]; info[key] = e[key];
} }
}) });
info.address = e.name; info.address = e.name;
// mitt.emit('map_info', info); // mitt.emit('map_info', info);
// reload(); // reload();
if(route.query.type=='main') { if (route.query.type == "main") {
sendMsg({ channel: 'user-breed-datav', event: 'changMap', data: { sendMsg({
areaName: info.areaName, channel: "user-breed-datav",
name: e.name event: "changMap",
}}) data: {
areaName: info.areaName,
name: e.name,
},
});
} else { } else {
router.push({ router.push({
path: '/indexc', path: "/indexc",
query: { query: {
areaCode: route.query.areaCode, areaCode: route.query.areaCode || appStore.address.areaCode,
streetCode: e.code, streetCode: e.code,
name: e.name name: e.name,
} },
}) });
} }
} };
const router = useRouter() const router = useRouter();
const route = useRoute() const route = useRoute();
const navTo = () => { const navTo = () => {
if (route.path == '/') return location.reload(); if (route.path == "/") return location.reload();
else if(route.path == '/indexc'){ else if (route.path == "/indexc") {
appStore.setAddress({ appStore.setAddress({
areaCode: appStore.address.areaCode, areaCode: appStore.address.areaCode,
streetCode: '' streetCode: "",
}) });
router.push('/?areaCode='+appStore.address.areaCode); router.push("/?areaCode=" + appStore.address.areaCode);
let area = appStore.area; 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.areaName = data?.name;
info.address = data?.name; info.address = data?.name;
} } else if (route.path == "/delivery") {
else if(route.path == '/delivery') {
router.push({ router.push({
path: '/indexc', path: "/indexc",
query: { query: {
areaCode: route.query.areaCode, areaCode: route.query.areaCode,
streetCode: route.query.streetCode, streetCode: route.query.streetCode,
name: route.query.name name: route.query.name,
} },
}) });
} }
} };
let nowTime = ref([]); let nowTime = ref([]);
@ -94,102 +97,130 @@ const updateClock = () => {
let m = now.getMonth() + 1; let m = now.getMonth() + 1;
let d = now.getDate(); 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') + ':' + nowTime.value[1] =
minutes.toString().padStart(2, '0') + ':' + hours.toString().padStart(2, "0") +
seconds.toString().padStart(2, '0'); ":" +
} minutes.toString().padStart(2, "0") +
":" +
seconds.toString().padStart(2, "0");
};
const logout = () => { const logout = () => {
// router.replace('/login') // router.replace('/login')
router.push('/login') router.push("/login");
} };
const list = ref([]) const list = ref([]);
const initList = async () => { const initList = async (re = false) => {
let street = appStore.street; let street = appStore.street;
if (street?.length == 0) { if (street?.length == 0 || re) {
let { data } = await getStreet({ let { data } = await getStreet({
area_code: appStore.address.areaCode area_code: appStore.address.areaCode,
}) });
street = data; street = data;
appStore.setStreet(street); appStore.setStreet(street);
} }
let area = appStore.area; let area = appStore.area;
if (userSotre.userInfo.street_code) { 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.areaName = data?.name;
info.address = data?.name; info.address = data?.name;
list.value = []; list.value = [];
appStore.setAddress({ appStore.setAddress({
areaCode: appStore.address.areaCode, areaCode: appStore.address.areaCode,
streetCode: appStore.address.streetCode streetCode: appStore.address.streetCode,
}) });
} else { } 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.areaName = data?.name;
info.address = data?.name; info.address = data?.name;
// list.value = [data, ...street]; // list.value = [data, ...street];
list.value = street; list.value = street;
if (appStore.address.streetCode) { 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; info.address = data?.name;
} }
appStore.setAddress({ appStore.setAddress({
areaCode: appStore.address.areaCode, 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) => { const initWeather = (city = 510500) => {
axios.get(`https://restapi.amap.com/v3/weather/weatherInfo?city=${city}&key=5731d3b4c3f34e09226e084ce556e259`).then((res) => { axios
if (res.data.status == 1) { .get(
weather.value = res.data.lives[0].weather; `https://restapi.amap.com/v3/weather/weatherInfo?city=${city}&key=5731d3b4c3f34e09226e084ce556e259`
} )
}).catch((e) => { .then((res) => {
console.log(e); if (res.data.status == 1) {
}) weather.value = res.data.lives[0].weather;
} }
})
.catch((e) => {
console.log(e);
});
};
// //
const changeTime = (e) => { const changeTime = (e) => {
console.log(e); console.log(e);
} };
mitt.on("choserArea", (data) => { mitt.on("choserArea", (data) => {
appStore.setAddress({ appStore.setAddress({
areaCode: data.code, areaCode: data.code,
streetCode: "", streetCode: "",
}); });
initList(); initList(true);
router.push({ router.push({
path: '/', path: "/",
query: { query: {
areaCode: data.code, areaCode: data.code,
} },
}) });
}); });
mitt.on("choseTown", (data) => { mitt.on("choseTown", (data) => {
let c = list.value.find(item=>item.name==data.name); let c = list.value.find((item) => item.name == data.name);
if(!c)return; console.log(list.value, data, c);
if (!c) return;
appStore.setAddress({ appStore.setAddress({
areaCode: appStore.address.areaCode, areaCode: appStore.address.areaCode,
streetCode: c.code, streetCode: c.code,
}); });
initList(); initList();
router.push({ router.push({
path: '/indexc', path: "/indexc",
query: { query: {
areaCode: appStore.address.areaCode, areaCode: appStore.address.areaCode,
streetCode: c.code, 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(() => { onMounted(() => {
@ -198,8 +229,7 @@ onMounted(() => {
areaCode: route.query.areaCode, areaCode: route.query.areaCode,
streetCode: route.query.streetCode || "", streetCode: route.query.streetCode || "",
}); });
} } else if (route.path == "/") {
else if(route.path=='/'){
appStore.setAddress({ appStore.setAddress({
areaCode: appStore.address.areaCode, areaCode: appStore.address.areaCode,
streetCode: "", streetCode: "",
@ -207,24 +237,24 @@ onMounted(() => {
} }
initList(); initList();
mitt.on('push_to', (e)=>{ mitt.on("push_to", (e) => {
appStore.setAddress({ appStore.setAddress({
areaCode: e.areaCode, areaCode: e.areaCode,
streetCode: e.streetCode, streetCode: e.streetCode,
}); });
initList(); initList();
info.address = e.name info.address = e.name;
}) });
// //
setInterval(updateClock, 1000); setInterval(updateClock, 1000);
initWeather(); initWeather();
mitt.on('changMap', (e)=>{ mitt.on("changMap", (e) => {
if(e.areaName==info.areaName){ if (e.areaName == info.areaName) {
let c = list.value.find(item=>item.name==e.name); let c = list.value.find((item) => item.name == e.name);
if(c) areaListRef.value.choseTownFn(c); if (c) areaListRef.value.choseTownFn(c);
// router.push({ // router.push({
// path: '/delivery', // path: '/delivery',
// query: { // query: {
@ -232,8 +262,8 @@ onMounted(() => {
// } // }
// }) // })
} }
}) });
}) });
</script> </script>
<template> <template>
@ -249,7 +279,10 @@ onMounted(() => {
<img class="icon" src="/src/assets/head_img/icon.png" alt="" /> <img class="icon" src="/src/assets/head_img/icon.png" alt="" />
<div class="item">{{ nowTime[1] }}</div> <div class="item">{{ nowTime[1] }}</div>
</div> </div>
<div class="head-title"><img class="logo" src="/src/assets/head_img/logo.png"/> <span>吟龙养殖溯源系统可视化大屏</span></div> <div class="head-title">
<img class="logo" src="/src/assets/head_img/logo.png" />
<span>吟龙养殖溯源系统可视化大屏</span>
</div>
<div class="right"> <div class="right">
<div class="item" @click.stop="open" style="position: relative"> <div class="item" @click.stop="open" style="position: relative">
<img src="/src/assets/head_img/location.png" alt="" /> <img src="/src/assets/head_img/location.png" alt="" />
@ -307,11 +340,11 @@ onMounted(() => {
height: 100%; height: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
.logo{ .logo {
height: 2.5rem; height: 2.5rem;
width: 2.5rem; width: 2.5rem;
} }
span{ span {
padding-bottom: 0.5rem; padding-bottom: 0.5rem;
padding-left: 0.5rem; padding-left: 0.5rem;
} }

View File

@ -547,10 +547,10 @@ onMounted(() => {
// name: '', // name: '',
// value: [105.36, 29.20] // value: [105.36, 29.20]
// } // }
if(route.query.local){ if(route.query.address){
dataValue[0] = { dataValue[0] = {
name: route.query.farm_name, name: route.query.farm_name,
value: route.query.local.split(',') value: route.query.address.split(',')
}; };
console.log(dataValue); console.log(dataValue);
} }

View File

@ -14,15 +14,15 @@ const key = ref(Date.now());
<div class="center"> <div class="center">
<div class="item item_c"> <div class="item item_c">
<div style="height: 61%; display: flex; justify-content: space-between"> <div style="height: 61%; display: flex; justify-content: space-between">
<leftItme :key="route.query.name+key+'f'" style="width: 35%"></leftItme> <leftItme :key="route.query.farm_name+key+'f'" style="width: 35%"></leftItme>
<centerItme :key="route.query.name+key+'c'" style="width: 64%"></centerItme> <centerItme :key="route.query.farm_name+key+'c'" style="width: 64%"></centerItme>
</div> </div>
<div style="height: 36%"> <div style="height: 36%">
<bottomItme :key="route.query.name+key+'b'" style="width: 100%"></bottomItme> <bottomItme :key="route.query.farm_name+key+'b'" style="width: 100%"></bottomItme>
</div> </div>
</div> </div>
<div class="item"> <div class="item">
<rightItme :key="route.query.name+key+'r'" style="height: 98%"></rightItme> <rightItme :key="route.query.farm_name+key+'r'" style="height: 98%"></rightItme>
</div> </div>
</div> </div>
</template> </template>

View File

@ -501,7 +501,7 @@ const initMap = () => {
name: route.query.name, name: route.query.name,
id: params.data.id, id: params.data.id,
farm_name: params.data.name, farm_name: params.data.name,
local: params.data.value.join(',') address: params.data.value.join(',')
} }
}) })
} }