|
@@ -70,6 +70,7 @@ import weatherChart from "./weatherChart.vue";
|
|
|
import { useRouter } from "vue-router";
|
|
import { useRouter } from "vue-router";
|
|
|
import { useStore } from "vuex";
|
|
import { useStore } from "vuex";
|
|
|
import farmInfoPopup from "@/views/old_mini/home/components/farmInfoPopup.vue";
|
|
import farmInfoPopup from "@/views/old_mini/home/components/farmInfoPopup.vue";
|
|
|
|
|
+import { convertPointToArray } from "@/utils/index";
|
|
|
const store = useStore();
|
|
const store = useStore();
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
@@ -96,6 +97,8 @@ const handleCommand = ({id, name}) => {
|
|
|
localStorage.setItem('selectedFarmId', id);
|
|
localStorage.setItem('selectedFarmId', id);
|
|
|
localStorage.setItem('selectedFarmName', name);
|
|
localStorage.setItem('selectedFarmName', name);
|
|
|
localStorage.setItem('selectedFarmPoint', selectedFarm.point);
|
|
localStorage.setItem('selectedFarmPoint', selectedFarm.point);
|
|
|
|
|
+ getLocationName();
|
|
|
|
|
+ getWeatherData();
|
|
|
emit('changeGarden',{id, name});
|
|
emit('changeGarden',{id, name});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -136,6 +139,9 @@ async function setFarmByGardenId(gardenIdValue) {
|
|
|
localStorage.setItem('selectedFarmId', farmId.value);
|
|
localStorage.setItem('selectedFarmId', farmId.value);
|
|
|
localStorage.setItem('selectedFarmName', farmName.value);
|
|
localStorage.setItem('selectedFarmName', farmName.value);
|
|
|
localStorage.setItem('selectedFarmPoint', targetFarm.point);
|
|
localStorage.setItem('selectedFarmPoint', targetFarm.point);
|
|
|
|
|
+
|
|
|
|
|
+ getLocationName();
|
|
|
|
|
+ getWeatherData();
|
|
|
emit('changeGarden', { id: farmId.value, name: farmName.value });
|
|
emit('changeGarden', { id: farmId.value, name: farmName.value });
|
|
|
resolve(true);
|
|
resolve(true);
|
|
|
} else {
|
|
} else {
|
|
@@ -191,6 +197,8 @@ function selectFarmFromList(data) {
|
|
|
// 如果没有保存的选择,按优先级选择
|
|
// 如果没有保存的选择,按优先级选择
|
|
|
selectDefaultFarm(data);
|
|
selectDefaultFarm(data);
|
|
|
}
|
|
}
|
|
|
|
|
+ getLocationName();
|
|
|
|
|
+ getWeatherData();
|
|
|
emit('changeGarden',{id: farmId.value, name: farmName.value});
|
|
emit('changeGarden',{id: farmId.value, name: farmName.value});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -237,16 +245,12 @@ function selectDefaultFarm(data) {
|
|
|
localStorage.setItem('selectedFarmId', farmId.value);
|
|
localStorage.setItem('selectedFarmId', farmId.value);
|
|
|
localStorage.setItem('selectedFarmName', farmName.value);
|
|
localStorage.setItem('selectedFarmName', farmName.value);
|
|
|
localStorage.setItem('selectedFarmPoint', data[0].point);
|
|
localStorage.setItem('selectedFarmPoint', data[0].point);
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-onMounted(() => {
|
|
|
|
|
getLocationName();
|
|
getLocationName();
|
|
|
getWeatherData();
|
|
getWeatherData();
|
|
|
-})
|
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
onActivated(() => {
|
|
onActivated(() => {
|
|
|
getFarmList();
|
|
getFarmList();
|
|
|
- getWeatherData();
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 暴露刷新方法供父组件调用
|
|
// 暴露刷新方法供父组件调用
|
|
@@ -260,12 +264,18 @@ const weatherData = ref(null);
|
|
|
const currentWeather = ref({ temp: "--", text: "--", iconDay: "" });
|
|
const currentWeather = ref({ temp: "--", text: "--", iconDay: "" });
|
|
|
const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
|
|
const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
|
|
|
function getLocationName() {
|
|
function getLocationName() {
|
|
|
- const location = store.state.home.miniUserLocation;
|
|
|
|
|
- // 将 location 从"经度,纬度"格式转换为"纬度,经度"格式
|
|
|
|
|
- let formattedLocation = location;
|
|
|
|
|
- if (typeof location === 'string' && location.includes(',')) {
|
|
|
|
|
- const [lng, lat] = location.split(',');
|
|
|
|
|
- formattedLocation = `${lat},${lng}`;
|
|
|
|
|
|
|
+ const farmLocation = convertPointToArray(localStorage.getItem('selectedFarmPoint'));
|
|
|
|
|
+ let formattedLocation = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (farmLocation) {
|
|
|
|
|
+ formattedLocation = `${farmLocation[1]},${farmLocation[0]}`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const location = store.state.home.miniUserLocation;
|
|
|
|
|
+ // 将 location 从"经度,纬度"格式转换为"纬度,经度"格式
|
|
|
|
|
+ if (typeof location === 'string' && location.includes(',')) {
|
|
|
|
|
+ const [lng, lat] = location.split(',');
|
|
|
|
|
+ formattedLocation = `${lat},${lng}`;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
const params = {
|
|
const params = {
|
|
|
key: MAP_KEY,
|
|
key: MAP_KEY,
|
|
@@ -286,7 +296,7 @@ const handleAddGarden = () => {
|
|
|
|
|
|
|
|
// 获取天气数据
|
|
// 获取天气数据
|
|
|
function getWeatherData() {
|
|
function getWeatherData() {
|
|
|
- const point = store.state.home.miniUserLocationPoint;
|
|
|
|
|
|
|
+ const point = localStorage.getItem('selectedFarmPoint') || store.state.home.miniUserLocationPoint;
|
|
|
if (!point) {
|
|
if (!point) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|