fix: 修复教书先生API接口调用失败 #224
This commit is contained in:
parent
b28f92b99f
commit
a8b1d66330
@ -45,13 +45,12 @@ const hitokotoData = reactive({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 获取一言数据
|
// 获取一言数据
|
||||||
const getHitokotoData = () => {
|
const getHitokotoData = async () => {
|
||||||
getHitokoto()
|
try {
|
||||||
.then((res) => {
|
const result = await getHitokoto();
|
||||||
hitokotoData.text = res.hitokoto;
|
hitokotoData.text = result.hitokoto;
|
||||||
hitokotoData.from = res.from;
|
hitokotoData.from = result.from;
|
||||||
})
|
} catch (error) {
|
||||||
.catch(() => {
|
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: "一言获取失败",
|
message: "一言获取失败",
|
||||||
icon: h(Error, {
|
icon: h(Error, {
|
||||||
@ -61,7 +60,7 @@ const getHitokotoData = () => {
|
|||||||
});
|
});
|
||||||
hitokotoData.text = "这里应该显示一句话";
|
hitokotoData.text = "这里应该显示一句话";
|
||||||
hitokotoData.from = "無名";
|
hitokotoData.from = "無名";
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 更新一言数据
|
// 更新一言数据
|
||||||
|
@ -39,16 +39,17 @@ const weatherData = reactive({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 获取天气数据
|
// 获取天气数据
|
||||||
const getWeatherData = () => {
|
const getWeatherData = async () => {
|
||||||
|
try {
|
||||||
// 获取地理位置信息
|
// 获取地理位置信息
|
||||||
if (!mainKey) {
|
if (!mainKey) {
|
||||||
getOtherWeather()
|
console.log("未配置,使用备用天气接口");
|
||||||
.then((res) => {
|
const result = await getOtherWeather();
|
||||||
console.log(res);
|
console.log(result);
|
||||||
const data = res.result;
|
const data = result.result;
|
||||||
weatherData.adCode = {
|
weatherData.adCode = {
|
||||||
city: data.city.name,
|
city: data.city.city_name || "未知地区",
|
||||||
adcode: data.city.cityId,
|
// adcode: data.city.cityId,
|
||||||
};
|
};
|
||||||
weatherData.weather = {
|
weatherData.weather = {
|
||||||
weather: data.condition.condition,
|
weather: data.condition.condition,
|
||||||
@ -56,37 +57,29 @@ const getWeatherData = () => {
|
|||||||
winddirection: data.condition.windDir,
|
winddirection: data.condition.windDir,
|
||||||
windpower: data.condition.windLevel,
|
windpower: data.condition.windLevel,
|
||||||
};
|
};
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("天气信息获取失败:" + err);
|
|
||||||
onError("天气信息获取失败");
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
getAdcode(mainKey)
|
// 获取 Adcode
|
||||||
.then((res) => {
|
const adCode = await getAdcode(mainKey);
|
||||||
|
console.log(adCode);
|
||||||
|
if (adCode.infocode !== "10000") {
|
||||||
|
throw "地区查询失败";
|
||||||
|
}
|
||||||
weatherData.adCode = {
|
weatherData.adCode = {
|
||||||
city: res.city,
|
city: adCode.city,
|
||||||
adcode: res.adcode,
|
adcode: adCode.adcode,
|
||||||
};
|
};
|
||||||
// 获取天气信息
|
// 获取天气信息
|
||||||
getWeather(mainKey, weatherData.adCode.adcode)
|
const result = await getWeather(mainKey, weatherData.adCode.adcode);
|
||||||
.then((res) => {
|
|
||||||
weatherData.weather = {
|
weatherData.weather = {
|
||||||
weather: res.lives[0].weather,
|
weather: result.lives[0].weather,
|
||||||
temperature: res.lives[0].temperature,
|
temperature: result.lives[0].temperature,
|
||||||
winddirection: res.lives[0].winddirection,
|
winddirection: result.lives[0].winddirection,
|
||||||
windpower: res.lives[0].windpower,
|
windpower: result.lives[0].windpower,
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
} catch (error) {
|
||||||
console.error("天气信息获取失败:" + err);
|
console.error("天气信息获取失败:" + error);
|
||||||
onError("天气信息获取失败");
|
onError("天气信息获取失败");
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("地理位置获取失败:" + err);
|
|
||||||
onError("地理位置获取失败");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user