DPS_Manage/Page/Tab_server.qml

625 lines
24 KiB
QML
Raw Permalink Normal View History

2025-05-29 14:04:05 +08:00
import QtQuick 2.15
import QtQuick.Window 2.15
import QtGraphicalEffects 1.15
import QtQuick.Shapes 1.15
import QtQuick.Layouts 1.15
import QtQuick.Dialogs 1.3
2025-09-15 09:46:04 +08:00
import HuskarUI.Basic 1.0
2025-05-29 14:04:05 +08:00
import QmlTool 1.0
import SSHManager 1.0
import FileTransfer 1.0
import "../MyGlobals" 1.0
import "../Component" 1.0
Item {
anchors.fill: parent
anchors.leftMargin: 1
property string server_ip: "192.168.1.100" // 示例 IP
property string server_port: "22" // 示例 IP
property string server_user: "root" // 示例 IP
property string server_passwd: "123456" // 示例 IP
property int page_state: 0 // 页面状态
property string dps_version_ready: "undefine" // dps版本
property string java_p_version_ready: "undefine" // java插件版本
property string java_version_ready: "undefine" // java版本
//安装dps的flag 0需要安装 1需要更新 2不显示
property int dpsInstallationFlag : 2;
//安装javap的flag 0需要安装 1需要更新 2不显示
property int javapInstallationFlag : 2;
//安装java的flag 0需要安装 1需要更新 2不显示
property int javaInstallationFlag : 2;
//我的服务器插件窗口
property var myPluginsWidow: null
Component.onCompleted: {
GlobalVars.tab_server = this;
SSHManager.connectionSuccess.connect(connectionSuccess)
SSHManager.connectionFailed.connect(connectionFailed)
SSHManager.shellOutput.connect(consoleOutput)
FileTransfer.downloadCompleted.connect(downloadCompleted)
FileTransfer.downloadProgressChanged.connect(downloadProgressChanged)
FileTransfer.uploadCompleted.connect(uploadCompleted)
FileTransfer.uploadProgressChanged.connect(uploadProgressChanged)
}
Component.onDestruction: {
// 断开所有信号连接
SSHManager.connectionSuccess.disconnect(connectionSuccess);
SSHManager.connectionFailed.disconnect(connectionFailed);
SSHManager.shellOutput.disconnect(consoleOutput)
FileTransfer.downloadCompleted.disconnect(downloadCompleted)
FileTransfer.downloadProgressChanged.disconnect(downloadProgressChanged)
FileTransfer.uploadCompleted.disconnect(uploadCompleted)
FileTransfer.uploadProgressChanged.disconnect(uploadProgressChanged)
}
function init(ip, port, user, passwd){
server_ip = ip;
server_port = port;
server_user = user;
server_passwd = passwd;
//尝试连接ssh服务器
SSHManager.connectAndStartShell(server_ip, server_port, server_user, server_passwd)
}
//ssh链接成功的信号
function connectionSuccess(){
GlobalVars.sshConnectServer = server_ip
getServerPluginsState();
}
//ssh链接失败的信号
function connectionFailed(error){
page_state = 2
}
//ssh控制台输出的信号
function consoleOutput(msg){
//如果解压命令执行成功重新拉取版本信息
if(msg.indexOf("DP-S插件解压成功") !== -1 || msg.indexOf("JAVA插件解压成功") !== -1 || msg.indexOf("JAVA安装成功") !== -1){
getServerPluginsState();
}
//删除插件成功
else if(msg.indexOf("删除插件成功!")!== -1){
GlobalVars.getServerPlugins(server_ip)
GlobalVars.msg_control.success("删除插件成功!");
}
}
//下载完成的信号
function downloadCompleted(success, message) {
if (success) {
//如果下载了dps 就上传dps
if(message === "dps"){
FileTransfer.postUpload("http://" + server_ip + ":65170/api/uploadfiles","download/dp_s.tar","/rindro/download/","dps")
GlobalVars.msg_control.success("DP-S插件本体下载成功!现在准备上传!")
}
//如果下载javap
else if(message === "javap"){
FileTransfer.postUpload("http://" + server_ip + ":65170/api/uploadfiles","download/RT.tar.gz","/rindro/download/","javap")
GlobalVars.msg_control.success("JAVA插件本体下载成功!现在准备上传!")
}
} else {
GlobalVars.msg_control.error("错误:" + message)
progressobj.visible = false
}
}
//下载进度的信号
function downloadProgressChanged(rate,add){
if(rate)progressobj.currentValue = rate * 100.0;
}
//上传完成的信号
function uploadCompleted(success, message) {
if (success) {
//上传完dp_s解压
if(message === "dps"){
GlobalVars.sendPostRequestByIp("http://" + server_ip + ":65170","/api/addrun",{},function(error, response) {})
SSHManager.sendInput("echo '开始解压DP-S插件'")
SSHManager.sendInput("sudo tar -xvf /rindro/download/dp_s.tar -C /")
SSHManager.sendInput("chmod 777 /dp_s")
SSHManager.sendInput("echo -e \"\\033[32mDP-S插件解压成功\\033[0m\"")
GlobalVars.msg_control.success("DP-S插件本体上传成功现在将执行解压操作!在右侧控制台页面出现'DP-S插件解压成功'字样则为安装成功!")
progressobj.visible = false
dps_version_ready = "undefine"
}
else if(message === "javap"){
SSHManager.sendInput("echo '开始解压JAVA插件'")
SSHManager.sendInput("sudo rm -rf /java_plugin")
SSHManager.sendInput("sudo mkdir /java_plugin")
SSHManager.sendInput("sudo tar -zxvf /rindro/download/RT.tar.gz -C /java_plugin/")
SSHManager.sendInput("grep -q \"cd /java_plugin \n./Restart\" \"/root/run\" || echo \"cd /java_plugin \n./Restart\" >> \"/root/run\" && chmod +x /root/run")
SSHManager.sendInput("echo -e \"\\033[32mJAVA插件解压成功\\033[0m\"")
GlobalVars.msg_control.success("JAVA插件本体上传成功现在将执行解压操作!在右侧控制台页面出现'JAVA插件解压成功'字样则为安装成功!")
progressobj.visible = false
java_p_version_ready = "undefine"
}
} else {
GlobalVars.msg_control.error("错误:" + message)
progressobj.visible = false
}
}
//上传进度的信号
function uploadProgressChanged(rate,add){
if(rate)progressobj.currentValue = rate * 100.0;
}
//获取服务器插件版本
function getServerPluginsState(){
//向网关发送http请求 获取版本
GlobalVars.getServerInfo("http://" + server_ip + ":65170",function(flag,type,info){
//dps插件
if(type === 0){
//如果安装了
if(flag){
dps_version_ready = info.ProjectVersion
//需要更新
if(parseFloat(GlobalVars.all_Version.dpsVer) > parseFloat(info.ProjectVersion)){
dpsInstallationFlag = 1
dps_install.visible = true
}
else dpsInstallationFlag = 2
}
//如果没有安装
else {
dps_version_ready = "noinstall"
dpsInstallationFlag = 0
}
}
//java插件
else if(type === 1){
//如果安装了
if(flag){
java_p_version_ready = info.ProjectVersion
//需要更新
if(parseFloat(GlobalVars.all_Version.jarVer) > parseFloat(info.ProjectVersion)){
javapInstallationFlag = 1
javap_install.visible = true
}
else javapInstallationFlag = 2
}
//如果没有安装
else {
java_p_version_ready = "noinstall"
javapInstallationFlag = 0
}
}
//java版本
else if(type === 2){
//如果安装了
if(flag){
java_version_ready = info.ProjectVersion
javaInstallationFlag = 2
}
//如果没有安装
else {
java_version_ready = "noinstall"
javaInstallationFlag = 0
}
}
//连通测试函数
else if(type === 3){
//如果回复了信息才算连接成功
page_state = 1
}
});
}
FileDialog {
id: fileDialog
title: "请选择保存路径"
selectFolder: true // 选择文件而非文件夹
selectMultiple: false // 不允许多选
property int dtype: 0
onAccepted: {
var filePath = fileDialog.fileUrl.toString()
var cleanPath = filePath.replace(/^(file:\/{2,3})/, "");
var filename = "客户端插件包.zip";
var filekey = "dps";
if(dtype === 1){
filename = "Yosin.key";
filekey = "dps";
}
GlobalVars.downlad_quest_window.addQuest(filename,[
function(quest){
//下载
quest.status = 1;
FileTransfer.postDownload(GlobalVars.server_url + "/rindro/download", cleanPath + "/" + filename,{projectName:"通用"},"quest");
},
function(quest){
GlobalVars.msg_control.success(cleanPath + filename + "已下载完成!");
quest.instruction = true
}]);
}
onRejected: {
}
}
property string selectedFilePath: ""
//进度条对象
property var progressobj : null
//进度
property double progressRate: 0.0
//没加载出来的页面
BusyIndicator {
id:loadingpage
visible: page_state === 0
anchors.centerIn: parent
color: "#FF5722" // 橙色
size: 32
duration: 12000
}
//连接错误的页面
Text {
visible: page_state === 2
id:errorpage
text: "连接服务器失败,请前往个人中心,修改账号密码以测试您的服务器连接!"
anchors.centerIn: parent
font {
pixelSize: 24
2025-09-15 09:46:04 +08:00
family: HusTheme.Primary.fontPrimaryFamily
2025-05-29 14:04:05 +08:00
bold: true
}
2025-09-15 09:46:04 +08:00
color: HusTheme.Primary.colorTextBase
2025-05-29 14:04:05 +08:00
}
// 新增:服务器信息区域
Rectangle {
visible: page_state === 1
id:supage
anchors.fill: parent
color:"transparent"
2025-09-15 09:46:04 +08:00
HusRectangle{
2025-05-29 14:04:05 +08:00
id: top_rect
anchors {
top: parent.top
left: parent.left
right: parent.right
bottomMargin: 0
topMargin: 4
margins:10
}
height: 50
topLeftRadius: 8
topRightRadius: 8
2025-09-15 09:46:04 +08:00
border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7"
2025-05-29 14:04:05 +08:00
border.width: 3
color:"transparent"
Text {
id:server_ip_label
anchors.left: parent.left
anchors.leftMargin: 20
anchors.verticalCenter: parent.verticalCenter
text: "服务器IP:"
font {
pixelSize: 22
2025-09-15 09:46:04 +08:00
family: HusTheme.Primary.fontPrimaryFamily
2025-05-29 14:04:05 +08:00
bold: true
}
2025-09-15 09:46:04 +08:00
color: HusTheme.Primary.colorTextBase
2025-05-29 14:04:05 +08:00
}
//用户名
Text {
id:username
anchors.left: server_ip_label.right
anchors.leftMargin: 10
anchors.verticalCenter: parent.verticalCenter
text: server_ip
font {
pixelSize: 14
2025-09-15 09:46:04 +08:00
family: HusTheme.Primary.fontPrimaryFamily
2025-05-29 14:04:05 +08:00
}
2025-09-15 09:46:04 +08:00
color: HusTheme.Primary.colorTextBase
2025-05-29 14:04:05 +08:00
elide: Text.ElideRight
}
2025-09-15 09:46:04 +08:00
HusButton {
2025-05-29 14:04:05 +08:00
text: qsTr("查看我的服务器插件")
2025-09-15 09:46:04 +08:00
type: HusButton.Type_Text
2025-05-29 14:04:05 +08:00
anchors.right: parent.right
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
onClicked: {
if (!myPluginsWidow) {
// 创建新窗口
var component = Qt.createComponent("Window_ServerPlugins.qml");
myPluginsWidow = component.createObject(parent);
// 绑定关闭时自动销毁
myPluginsWidow.closing.connect(function() {
myPluginsWidow.destroy()
myPluginsWidow = null // 关键:释放引用
})
}
myPluginsWidow.y = GlobalVars.main_Window.y + 90
myPluginsWidow.show()
myPluginsWidow.init(server_ip);
myPluginsWidow.raise() // 把窗口提到最前面
}
}
}
// 服务器信息卡片
2025-09-15 09:46:04 +08:00
HusRectangle {
2025-05-29 14:04:05 +08:00
id:server_info
anchors {
top: top_rect.bottom
left: parent.left
right: parent.right
topMargin: -2
margins:10
}
height: 94
color: "transparent"
bottomLeftRadius: 8
bottomRightRadius: 8
2025-09-15 09:46:04 +08:00
border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7"
2025-05-29 14:04:05 +08:00
border.width: 3
antialiasing: true
2025-09-15 09:46:04 +08:00
HusButton {
2025-05-29 14:04:05 +08:00
id:download_clientplugins
text: qsTr("下载双端插件包")
2025-09-15 09:46:04 +08:00
type: HusButton.Type_Text
2025-05-29 14:04:05 +08:00
anchors.right: parent.right
anchors.rightMargin: 10
anchors.bottom:parent.bottom
anchors.bottomMargin: 10
onClicked: {
fileDialog.dtype = 0
fileDialog.open()
}
2025-09-15 09:46:04 +08:00
HusToolTip {
2025-05-29 14:04:05 +08:00
x: 0
visible: parent.hovered
arrowVisible: true
text: qsTr("使用双端插件才需要安装,仅使用dps服务端插件不需要安装!")
2025-09-15 09:46:04 +08:00
position: HusToolTip.Position_Top
2025-05-29 14:04:05 +08:00
}
}
// DelButton {
// id:build_clientplugins_keys
// text: qsTr("生成客户端授权Key")
// type: DelButton.Type_Text
// anchors.right: parent.right
// anchors.rightMargin: 10
// anchors.top:download_clientplugins.bottom
// anchors.topMargin: 10
// onClicked: {
// fileDialog.dtype = 1
// fileDialog.open()
// }
// }
Rectangle{
id:plugins_group
anchors.left: parent.left
anchors.leftMargin: 10
width:200
height:parent.height
color: "transparent"
Text {
id:state_label_dps
anchors.top: parent.top
anchors.topMargin: 10
anchors.left: parent.left
anchors.leftMargin: 10
text: "DP-S插件状态: "
font {
pixelSize: 16
2025-09-15 09:46:04 +08:00
family: HusTheme.Primary.fontPrimaryFamily
2025-05-29 14:04:05 +08:00
}
2025-09-15 09:46:04 +08:00
color: HusTheme.Primary.colorTextSecondary
2025-05-29 14:04:05 +08:00
}
Text {
id:state_label_javap
anchors.top: state_label_dps.top
anchors.topMargin: 27
anchors.left: parent.left
anchors.leftMargin: 10
text: "JAVA插件状态: "
font {
pixelSize: 16
2025-09-15 09:46:04 +08:00
family: HusTheme.Primary.fontPrimaryFamily
2025-05-29 14:04:05 +08:00
}
2025-09-15 09:46:04 +08:00
color: HusTheme.Primary.colorTextSecondary
2025-05-29 14:04:05 +08:00
}
Text {
id:state_label_java
anchors.top: state_label_javap.top
anchors.topMargin: 27
anchors.left: parent.left
anchors.leftMargin: 10
text: "JAVA版本状态: "
font {
pixelSize: 16
2025-09-15 09:46:04 +08:00
family: HusTheme.Primary.fontPrimaryFamily
2025-05-29 14:04:05 +08:00
}
2025-09-15 09:46:04 +08:00
color: HusTheme.Primary.colorTextSecondary
2025-05-29 14:04:05 +08:00
}
BusyIndicator {
anchors.left: state_label_dps.right
anchors.leftMargin: 8
anchors.top: state_label_dps.top
anchors.topMargin: 2
visible: dps_version_ready === "undefine" ? true : false
color: "#FF5722" // 橙色
size: 18
duration: 12000
}
BusyIndicator {
anchors.left: state_label_javap.right
anchors.leftMargin: 8
anchors.top: state_label_javap.top
anchors.topMargin: 2
visible: java_p_version_ready === "undefine" ? true : false
color: "#FF5722" // 橙色
size: 18
duration: 12000
}
BusyIndicator {
anchors.left: state_label_java.right
anchors.leftMargin: 8
anchors.top: state_label_java.top
anchors.topMargin: 2
visible: java_version_ready === "undefine" ? true : false
color: "#FF5722" // 橙色
size: 18
duration: 12000
}
2025-09-15 09:46:04 +08:00
HusTag {
2025-05-29 14:04:05 +08:00
id:dps_tag
anchors.left: state_label_dps.right
anchors.leftMargin: 6
anchors.top: state_label_dps.top
anchors.topMargin: -2
visible: dps_version_ready != "undefine" ? true : false
text: dps_version_ready === "noinstall" ? "未安装" : dps_version_ready
presetColor: dps_version_ready === "noinstall" ? "red" : "green"
}
2025-09-15 09:46:04 +08:00
HusTag {
2025-05-29 14:04:05 +08:00
anchors.left: state_label_javap.right
anchors.leftMargin: 6
anchors.top: state_label_javap.top
anchors.topMargin: -2
visible: java_p_version_ready != "undefine" ? true : false
text: java_p_version_ready === "noinstall" ? "未安装" : java_p_version_ready
presetColor: java_p_version_ready === "noinstall" ? "red" : "green"
}
2025-09-15 09:46:04 +08:00
HusTag {
2025-05-29 14:04:05 +08:00
anchors.left: state_label_java.right
anchors.leftMargin: 6
anchors.top: state_label_java.top
anchors.topMargin: -2
visible: java_version_ready != "undefine" ? true : false
text: java_version_ready === "noinstall" ? "未安装" : java_version_ready
presetColor: java_version_ready === "noinstall" ? "red" : "green"
}
2025-09-15 09:46:04 +08:00
HusIconButton {
2025-05-29 14:04:05 +08:00
id:dps_install
anchors.left: plugins_group.left
anchors.leftMargin: 200
anchors.top: plugins_group.top
anchors.topMargin: 5
visible: dpsInstallationFlag === 2 ? false : true
text: dpsInstallationFlag === 1 ? "更新DP-S插件" : "安装DP-S插件"
2025-09-15 09:46:04 +08:00
type: HusButton.Type_Text
2025-05-29 14:04:05 +08:00
onClicked: {
FileTransfer.postDownload(GlobalVars.server_url + "/rindro/download/all", "download/dp_s.tar",{key : "dps"},"dps")
visible = false;
dps_progress.visible = true;
progressobj = dps_progress;
}
}
CustomProgressBar {
id:dps_progress
anchors.left: dps_install.left
anchors.top: dps_install.top
anchors.topMargin: 8
visible: false
}
2025-09-15 09:46:04 +08:00
HusIconButton {
2025-05-29 14:04:05 +08:00
id:javap_install
anchors.left: plugins_group.left
anchors.leftMargin: 200
anchors.top: plugins_group.top
anchors.topMargin: 32
visible: javapInstallationFlag === 2 ? false : true
text: javapInstallationFlag === 1 ? "更新JAVA插件" : "安装JAVA插件"
2025-09-15 09:46:04 +08:00
type: HusButton.Type_Text
2025-05-29 14:04:05 +08:00
onClicked: {
FileTransfer.postDownload(GlobalVars.server_url + "/rindro/download/all", "download/RT.tar.gz",{key : "javap"},"javap")
visible = false;
javap_progress.visible = true;
progressobj = javap_progress;
}
}
CustomProgressBar {
id:javap_progress
anchors.left: javap_install.left
anchors.top: javap_install.top
anchors.topMargin: 8
visible: false
}
2025-09-15 09:46:04 +08:00
HusIconButton {
2025-05-29 14:04:05 +08:00
id:java_install
anchors.left: plugins_group.left
anchors.leftMargin: 200
anchors.top: plugins_group.top
anchors.topMargin: 59
visible: javaInstallationFlag === 0 ? true : false
text: "安装JAVA"
2025-09-15 09:46:04 +08:00
type: HusButton.Type_Text
2025-05-29 14:04:05 +08:00
onClicked: {
SSHManager.sendInput("yum install -y java")
SSHManager.sendInput("echo -e \"\\033[32mJAVA安装成功\\033[0m\"")
}
}
CustomProgressBar {
id:java_progress
anchors.left: java_install.left
anchors.top: java_install.top
anchors.topMargin: 8
visible: false
}
}
}
Rectangle{
id:ssh_console
// height: parent.height * 0.7
// anchors.fill: parent
anchors.top: server_info.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 10
radius: 8
2025-09-15 09:46:04 +08:00
border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7"
2025-05-29 14:04:05 +08:00
border.width: 3
color:"transparent"
ServerConsole{
anchors.fill:parent
}
}
}
}