batch update server tag

This commit is contained in:
naiba
2022-09-17 00:08:27 +08:00
parent 41b84163b9
commit 9352d3d0e0
5 changed files with 128 additions and 3 deletions

View File

@@ -181,6 +181,12 @@ other = "启用"
[AddServer]
other = "添加服务器"
[BatchEditServerGroup]
other = "批量修改分组"
[InputServerGroupName]
other = "输入分组名称"
[ServerGroup]
other = "服务器分组"

View File

@@ -5,6 +5,9 @@
<div class="ui container">
<div class="ui grid">
<div class="right floated right aligned twelve wide column">
<button class="ui right labeled nezha-primary-btn icon button" onclick="batchEditServerGroup()"><i
class="edit icon"></i> {{tr "BatchEditServerGroup"}}
</button>
<button class="ui right labeled nezha-primary-btn icon button" onclick="addOrEditServer()"><i
class="add icon"></i> {{tr "AddServer"}}
</button>
@@ -128,5 +131,56 @@
});
})
}
function batchEditServerGroup() {
let groupName = prompt('{{tr "InputServerGroupName"}}')
if (!groupName) {
return;
}
const servers = []
checkBoxList.forEach(cb => {
if (cb.checked) {
servers.push(parseInt(cb.value))
}
})
if (servers.length == 0) {
$.suiAlert({
title: '{{tr "NoServerSelected"}}',
description: '',
type: 'warning',
time: '2',
position: 'top-center',
});
return
}
$.post('/api/batch-update-server-group', JSON.stringify({ servers: servers, group: groupName }))
.then((resp) => {
if (resp.code == 200) {
$.suiAlert({
title: '{{tr "ExecutionResults"}}',
description: resp.message,
type: 'success',
time: '3',
position: 'top-center',
});
window.location.reload()
} else {
$.suiAlert({
title: '',
description: resp.message,
type: 'error',
time: '3',
position: 'top-center',
});
}
}).catch(err => {
$.suiAlert({
title: '',
description: err,
type: 'error',
time: '3',
position: 'top-center',
});
})
}
</script>
{{end}}