增加同步服务器数据按钮

This commit is contained in:
jingrow 2025-08-09 22:03:40 +08:00
parent ba43a9954c
commit c7d55d99d8
2 changed files with 39 additions and 1 deletions

View File

@ -1567,11 +1567,13 @@ def update_server_record(instance_ids):
server.plan_price = float(plan['origin_price']) server.plan_price = float(plan['origin_price'])
break break
sync_firewall_rules(instance_id)
# 保存更新 # 保存更新
server.save(ignore_permissions=True) server.save(ignore_permissions=True)
jingrow.db.commit() jingrow.db.commit()
# 同步防火墙规则(在保存服务器信息之后)
sync_firewall_rules(instance_id)
return { return {
"success": True, "success": True,
"message": "服务器信息更新成功", "message": "服务器信息更新成功",

View File

@ -117,6 +117,16 @@ jingrow.ui.form.on("Jsite Server", {
} }
); );
}); });
frm.add_custom_button(__('同步服务器数据'), function() {
// 弹出确认对话框
jingrow.confirm(
__('确定要同步服务器数据吗这将从阿里云同步最新的服务器信息包括状态、IP地址、系统信息、规格和防火墙规则等。'),
function() {
sync_server_data(frm);
}
);
});
} }
// 为password字段添加眼睛图标 // 为password字段添加眼睛图标
@ -258,3 +268,29 @@ function sync_firewall_rules(frm) {
} }
}); });
} }
function sync_server_data(frm) {
jingrow.call({
method: 'jcloud.api.aliyun_server_light.update_server_record',
args: {
instance_ids: JSON.stringify([frm.pg.instance_id])
},
callback: function(r) {
if (r.message && r.message.success) {
jingrow.msgprint({
title: __('成功'),
message: r.message.message || __('服务器数据同步成功'),
indicator: 'green'
});
// 刷新表单以显示最新的服务器数据
frm.reload_pg();
} else {
jingrow.msgprint({
title: __('错误'),
message: r.message ? r.message.message : __('同步服务器数据失败'),
indicator: 'red'
});
}
}
});
}