修复配网时城市输入乱码的问题
This commit is contained in:
@@ -139,6 +139,7 @@ async def lcd_set(request):
|
|||||||
elif k == "ui_type":
|
elif k == "ui_type":
|
||||||
display.ui_type = v
|
display.ui_type = v
|
||||||
config.set(k, v)
|
config.set(k, v)
|
||||||
|
config.write()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ack["status"] = "error"
|
ack["status"] = "error"
|
||||||
ack["message"] = str(e)
|
ack["message"] = str(e)
|
||||||
@@ -212,7 +213,7 @@ async def fetch_weather_data(city=None):
|
|||||||
|
|
||||||
# 从配置文件获取城市,如果没有提供则使用配置中的值
|
# 从配置文件获取城市,如果没有提供则使用配置中的值
|
||||||
if not city:
|
if not city:
|
||||||
city = config.get("city") or "北京"
|
city = config.get("cityid") or "北京"
|
||||||
|
|
||||||
print(f"正在获取{city}天气数据...")
|
print(f"正在获取{city}天气数据...")
|
||||||
# 从配置获取API基础URL,默认使用官方API
|
# 从配置获取API基础URL,默认使用官方API
|
||||||
|
|||||||
@@ -119,11 +119,13 @@ class HTTPServer(BaseServer):
|
|||||||
ssid = unquote(params.get(b"ssid", None))
|
ssid = unquote(params.get(b"ssid", None))
|
||||||
password = unquote(params.get(b"password", ""))
|
password = unquote(params.get(b"password", ""))
|
||||||
city = unquote(params.get(b"city", None))
|
city = unquote(params.get(b"city", None))
|
||||||
|
cityid = params.get(b"city", None)
|
||||||
|
|
||||||
# 使用全局Config实例保存配置
|
# 使用全局Config实例保存配置
|
||||||
config.set("ssid", ssid)
|
config.set("ssid", ssid)
|
||||||
config.set("password", password)
|
config.set("password", password)
|
||||||
config.set("city", city)
|
config.set("city", city)
|
||||||
|
config.set("cityid", cityid)
|
||||||
if config.write():
|
if config.write():
|
||||||
print("Configuration saved successfully")
|
print("Configuration saved successfully")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ placeholder="例如:北京"
|
|||||||
可输入城市名称或城市ID(<a
|
可输入城市名称或城市ID(<a
|
||||||
href="https://mapopen-website-wiki.cdn.bcebos.com/cityList/weather_district_id.csv"
|
href="https://mapopen-website-wiki.cdn.bcebos.com/cityList/weather_district_id.csv"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
download
|
||||||
>查看城市ID列表</a
|
>查看城市ID列表</a
|
||||||
>)
|
>)
|
||||||
</small></div><div class="form-group"><label class="form-label">自动熄屏时间</label
|
</small></div><div class="form-group"><label class="form-label">自动熄屏时间</label
|
||||||
@@ -348,6 +349,7 @@ showMessage("城市名称不能为空", "error");
|
|||||||
return;
|
return;
|
||||||
}const configData = {
|
}const configData = {
|
||||||
city: city,
|
city: city,
|
||||||
|
cityid: encodeURIComponent(city),
|
||||||
};// 只有当输入了熄屏时间时才添加到配置中
|
};// 只有当输入了熄屏时间时才添加到配置中
|
||||||
if (standbyTime !== "") {
|
if (standbyTime !== "") {
|
||||||
configData.standby_time = standbyTime;
|
configData.standby_time = standbyTime;
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
<html>
|
<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>WiFi认证</title><style>
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>WiFi认证</title>
|
|
||||||
<style>
|
|
||||||
body {
|
body {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
background: #3498db;
|
background: #3498db;
|
||||||
@@ -190,55 +185,32 @@
|
|||||||
margin: 15px auto;
|
margin: 15px auto;
|
||||||
animation: spin 1.5s linear infinite;
|
animation: spin 1.5s linear infinite;
|
||||||
}
|
}
|
||||||
</style>
|
</style></head><body><form action="/login" method="get" class="box"><h1>WiFi 配置</h1><button
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form action="/login" method="get" class="box">
|
|
||||||
<h1>WiFi 配置</h1>
|
|
||||||
<button
|
|
||||||
type="button"
|
type="button"
|
||||||
class="refresh-btn"
|
class="refresh-btn"
|
||||||
onclick="refreshList()"
|
onclick="refreshList()"
|
||||||
title="刷新WiFi列表"
|
title="刷新WiFi列表"
|
||||||
>
|
>
|
||||||
↻
|
↻
|
||||||
</button>
|
</button><div id="wifiList" class="wifi-list"></div><input
|
||||||
<div id="wifiList" class="wifi-list"></div>
|
|
||||||
<input
|
|
||||||
type="text"
|
type="text"
|
||||||
id="ssid"
|
id="ssid"
|
||||||
placeholder="WiFi名称"
|
placeholder="WiFi名称"
|
||||||
name="ssid"
|
name="ssid"
|
||||||
required
|
required
|
||||||
/><br />
|
/><br /><input
|
||||||
<input
|
|
||||||
type="password"
|
type="password"
|
||||||
id="pwd"
|
id="pwd"
|
||||||
placeholder="WiFi密码"
|
placeholder="WiFi密码"
|
||||||
name="password"
|
name="password"
|
||||||
/><br />
|
/><br /><input
|
||||||
<input
|
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="城市名称"
|
placeholder="城市名称"
|
||||||
name="city"
|
name="city"
|
||||||
value=""
|
value=""
|
||||||
/><br />
|
/><br /><button type="submit" class="btn">保存配置</button></form><div class="overlay" id="connectingOverlay"><div class="overlay-content"><h2>正在连接到WiFi</h2><div class="spinner-small"></div><p>设备正在尝试连接,请稍候...</p></div></div><script>
|
||||||
<button type="submit" class="btn">保存配置</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<!-- 遮罩层 -->
|
|
||||||
<div class="overlay" id="connectingOverlay">
|
|
||||||
<div class="overlay-content">
|
|
||||||
<h2>正在连接到WiFi</h2>
|
|
||||||
<div class="spinner-small"></div>
|
|
||||||
<p>设备正在尝试连接,请稍候...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
fetchWifiList();
|
fetchWifiList();// 添加表单提交事件监听
|
||||||
|
|
||||||
// 添加表单提交事件监听
|
|
||||||
document
|
document
|
||||||
.querySelector(".box")
|
.querySelector(".box")
|
||||||
.addEventListener("submit", function (e) {
|
.addEventListener("submit", function (e) {
|
||||||
@@ -298,7 +270,7 @@
|
|||||||
item.appendChild(signalContainer);
|
item.appendChild(signalContainer);
|
||||||
item.onclick = function () {
|
item.onclick = function () {
|
||||||
document.getElementById("ssid").value = network.ssid;
|
document.getElementById("ssid").value = network.ssid;
|
||||||
document.getElementById('pwd').focus();
|
document.getElementById("pwd").focus();
|
||||||
};
|
};
|
||||||
listContainer.appendChild(item);
|
listContainer.appendChild(item);
|
||||||
}
|
}
|
||||||
@@ -313,6 +285,4 @@
|
|||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
</script>
|
</script></body></html>
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user