Optimize code.

This commit is contained in:
rainerosion 2022-03-09 22:55:25 +08:00
parent 2a0c3a126b
commit 12bbf41693

View File

@ -171,8 +171,8 @@ function startSky() {
// let len = Object.keys(menu_map).length;
console.log("len => " + len + " menuLen => " + Object.keys(getMenu()).length);
if (len - 1 > Object.keys(getMenu()).length) {
sort_options = [];
storage_map = global_option;//初始化
let sort_options = [];
let storage_map = global_option;//初始化
Object.keys(menu_map).map(function (key, index) {
console.log("key => " + key, "index => " + index);
if (!isOptions(key, menu_map)) {
@ -181,13 +181,17 @@ function startSky() {
});
let befor_index = dialogs.select("请选择需要变更位置的徽章", sort_options);
let after_index = dialogs.select("请选择变更后的位置", sort_options);
if(befor_index==after_index){toast("两次选项一样。");return;}
for(var x=0;x<len;x++){//map重排序
if(x==befor_index){
if (befor_index === after_index) {
toast("两次选项一样。");
return;
}
// map重排序
for (let x = 0; x < len; x++) {
if (x === befor_index) {
storage_map[sort_options[after_index]] = menu_map[sort_options[after_index]];
}else if(x==after_index){
} else if (x === after_index) {
storage_map[sort_options[befor_index]] = menu_map[sort_options[befor_index]];
}else{
} else {
storage_map[sort_options[x]] = menu_map[sort_options[x]];
}
}