feat: 优化首页加载慢的问题
This commit is contained in:
parent
e3d60d3f2e
commit
0189a00155
@ -127,11 +127,13 @@ async def do_cmd():
|
|||||||
@app.route("/getsetting", methods=["GET"])
|
@app.route("/getsetting", methods=["GET"])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
async def getsetting():
|
async def getsetting():
|
||||||
|
need_device_list = request.args.get("need_device_list")
|
||||||
config = xiaomusic.getconfig()
|
config = xiaomusic.getconfig()
|
||||||
data = asdict(config)
|
data = asdict(config)
|
||||||
device_list = await xiaomusic.call_main_thread_function(xiaomusic.getalldevices)
|
if need_device_list == "true":
|
||||||
log.info(f"getsetting device_list: {device_list}")
|
device_list = await xiaomusic.call_main_thread_function(xiaomusic.getalldevices)
|
||||||
data["device_list"] = device_list
|
log.info(f"getsetting device_list: {device_list}")
|
||||||
|
data["device_list"] = device_list
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,14 +35,11 @@ $(function(){
|
|||||||
$("#did").empty();
|
$("#did").empty();
|
||||||
var dids = data.mi_did.split(',');
|
var dids = data.mi_did.split(',');
|
||||||
$.each(dids, function(index, value) {
|
$.each(dids, function(index, value) {
|
||||||
var device = data.device_list.find(function(device) {
|
var cur_device = Object.values(data.devices).find(device => device.did === value);
|
||||||
return device.miotDID == value;
|
if (cur_device) {
|
||||||
});
|
|
||||||
|
|
||||||
if (device) {
|
|
||||||
var option = $('<option></option>')
|
var option = $('<option></option>')
|
||||||
.val(value)
|
.val(value)
|
||||||
.text(device.name)
|
.text(cur_device.name)
|
||||||
.prop('selected', value === did);
|
.prop('selected', value === did);
|
||||||
$("#did").append(option);
|
$("#did").append(option);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ $(function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拉取现有配置
|
// 拉取现有配置
|
||||||
$.get("/getsetting", function(data, status) {
|
$.get("/getsetting?need_device_list=true", function(data, status) {
|
||||||
console.log(data, status);
|
console.log(data, status);
|
||||||
updateCheckbox("#mi_did", data.mi_did, data.device_list);
|
updateCheckbox("#mi_did", data.mi_did, data.device_list);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user