diff --git a/xiaomusic/static/setting.js b/xiaomusic/static/setting.js index 87e6e57..9bf7dd7 100644 --- a/xiaomusic/static/setting.js +++ b/xiaomusic/static/setting.js @@ -5,33 +5,50 @@ $(function(){ $("#version").text(`(${data.version})`); }); + const updateSelectOptions = (selectId, optionsList, selectedOption) => { + const select = $(selectId); + select.empty(); + optionsList.forEach(option => { + select.append(new Option(option, option)); + }); + select.val(selectedOption); + }; + + let isChanging = false; + // 更新下拉菜单的函数 + const updateSelect = (selectId, value) => { + if (!isChanging) { + isChanging = true; + $(selectId).val(value); + isChanging = false; + } + }; + + // 联动逻辑 + const linkSelects = (sourceSelect, sourceList, targetSelect, targetList) => { + $(sourceSelect).change(function() { + if (!isChanging) { + const selectedValue = $(this).val(); + const selectedIndex = sourceList.indexOf(selectedValue); + console.log(selectedIndex, selectedValue,sourceList,targetList) + if (selectedIndex !== -1) { + updateSelect(targetSelect, targetList[selectedIndex]); + } + } + }); + }; + + // 拉取现有配置 $.get("/getsetting", function(data, status) { console.log(data, status); - var mi_did_div = $("#mi_did") - mi_did_div.empty(); - $.each(data.mi_did_list, function(index, option){ - mi_did_div.append($('