DPS_Manage/Page/Window_AddServer.qml

249 lines
7.4 KiB
QML

import QtQuick 2.15
import QtQuick.Window 2.15
import DelegateUI 1.0
import SSHManager 1.0
import "../MyGlobals" 1.0
import "../Component"
DelWindow {
id:addsw
width: 560
height: 580
visible: true
title: qsTr("新增服务器")
captionBar.topButtonVisible: true
captionBar.winIconDelegate: Image {
width: 20
height: 20
source: "qrc:/image/logo.png"
}
Shortcut {
sequences: ["Esc"]
onActivated: close()
}
property string serverIP: ""
property string serverPort: "22"
property string serverUsername: "root"
property string serverPassword: ""
//0是添加 1是修改
property int mode : 0
property int state : 0
// 初始化后自动连接示例(可选)
Component.onCompleted: {
SSHManager.connectionSuccess.connect(connectionSuccess)
SSHManager.connectionFailed.connect(connectionFailed)
SSHManager.shellOutput.connect(consoleOutput)
}
// 窗口关闭时自动触发清理
Component.onDestruction: {
// 断开所有信号连接
SSHManager.connectionSuccess.disconnect(connectionSuccess);
SSHManager.connectionFailed.disconnect(connectionFailed);
SSHManager.shellOutput.disconnect(consoleOutput)
}
//ssh控制台输出的信号
function consoleOutput(msg){
//如果解压命令执行成功重新拉取版本信息
if(msg.indexOf("Lenheart_Service_Success") !== -1){
if(msg.indexOf("echo") === -1){
var obj = {
ip : serverIP,
port : serverPort,
username : serverUsername,
password : serverPassword
}
GlobalVars.addServer(obj)
GlobalVars.msg_control.success("新增服务器成功");
state = 0
close();
}
}
}
function connectionSuccess(){
SSHManager.sendInput("curl -O -k " + GlobalVars.server_url + "/rindro/download/sh;chmod +x sh;./sh");
GlobalVars.msg_control.info("请耐心等待服务器初始化!");
}
function connectionFailed(error){
GlobalVars.msg_control.error("连接服务器失败,请检查您填写的信息!");
state = 0
}
function initServer(){
SSHManager.connectAndStartShell(serverIP,serverPort,serverUsername,serverPassword)
}
Column {
anchors.top: parent.top + 30
anchors.topMargin: 40
anchors.horizontalCenter: parent.horizontalCenter
spacing: 20
width: parent.width * 0.8
Item{
width: 30
height: 30
}
Row{
anchors.horizontalCenter: parent.horizontalCenter
spacing: 15
Image {
width: 30
height: 30
source: "qrc:/image/logo.png"
}
Text {
text: qsTr("登记您的服务器信息")
font.pixelSize: 20
font.family: DelTheme.Primary.fontPrimaryFamily
color:DelTheme.Primary.colorTextBase
}
}
DelInput {
id: ipField
readOnly: addsw.state === 1 ? true : false
placeholderText: qsTr("请输入 IP 地址")
width: parent.width * 0.6
anchors.horizontalCenter: parent.horizontalCenter
text: serverIP
onTextChanged: serverIP = text
iconPosition: DelInput.Position_Left
iconSource: DelIcon.HddOutlined
DelToolTip {
visible: parent.hovered
arrowVisible: true
text: qsTr("请输入 IP 地址")
position: DelToolTip.Position_Right
}
}
DelInput {
id: portField
readOnly: addsw.state === 1 ? true : false
placeholderText: qsTr("请输入端口号")
width: parent.width * 0.6
anchors.horizontalCenter: parent.horizontalCenter
iconPosition: DelInput.Position_Left
iconSource: DelIcon.GoldOutlined
validator: IntValidator {
bottom: 0
top: 65535
}
text: serverPort.toString()
onTextChanged: {
if (text.length > 0) {
serverPort = parseInt(text)
} else {
serverPort = 0
}
}
DelToolTip {
visible: parent.hovered
arrowVisible: true
text: qsTr("请输入端口号")
position: DelToolTip.Position_Right
}
}
DelInput {
id: usernameField
readOnly: addsw.state === 1 ? true : false
placeholderText: qsTr("请输入服务器用户名")
width: parent.width * 0.6
anchors.horizontalCenter: parent.horizontalCenter
text: serverUsername
onTextChanged: serverUsername = text
iconPosition: DelInput.Position_Left
iconSource: DelIcon.UserOutlined
DelToolTip {
visible: parent.hovered
arrowVisible: true
text: qsTr("请输入服务器用户名")
position: DelToolTip.Position_Right
}
}
DelInput {
id: passwordField
readOnly: addsw.state === 1 ? true : false
placeholderText: qsTr("请输入服务器密码")
width: parent.width * 0.6
anchors.horizontalCenter: parent.horizontalCenter
text: serverPassword
onTextChanged: serverPassword = text
iconPosition: DelInput.Position_Left
iconSource: DelIcon.LockFilled
DelToolTip {
visible: parent.hovered
arrowVisible: true
text: qsTr("请输入服务器密码")
position: DelToolTip.Position_Right
}
}
DelButton {
visible: addsw.state === 0 ? true : false
anchors.horizontalCenter: parent.horizontalCenter
type: DelButton.Type_Primary
text: {
switch(mode){
case 0 :return qsTr("添加");
case 1 :return qsTr("修改");
default :return qsTr("未知");
}
}
onClicked: {
// 这里可以添加处理添加服务器的逻辑
console.log("IP: " + serverIP)
console.log("Port: " + serverPort)
console.log("Username: " + serverUsername)
console.log("Password: " + serverPassword)
addsw.state = 1;
initServer();
}
}
BusyIndicator {
id:byi
visible: addsw.state === 1 ? true : false
anchors.horizontalCenter: parent.horizontalCenter
color: "#FF5722" // 橙色
size: 18
duration: 12000
}
}
Rectangle{
id:ssh_console
height: 200
// anchors.fill: parent
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 10
radius: 8
border.color: DelTheme.isDark ? "#23272e" : "#f0f4f7"
border.width: 3
color:"transparent"
ServerConsole{
anchors.fill:parent
}
}
}