import QtQuick 2.15 import QtQuick.Window 2.15 import QtGraphicalEffects 1.15 import QtQuick.Shapes 1.15 import QtQuick.Layouts 1.15 import HuskarUI.Basic 1.0 import "../MyGlobals" 1.0 import QmlTool 1.0 import "../Component" 1.0 import SSHManager 1.0 Item { anchors.fill: parent anchors.leftMargin: 1 //用户名称 property string user_name: "未定名用户XNJASDND" //用户会员等级 property string user_level: "普通会员" //用户积分 property int user_points: 0 //用户所有服务器列表 property var user_server_list : [] //当前测试连通性服务器ip property int testip : -1 //新增服务器窗口 property var addServerWindow: null Component.onCompleted: { GlobalVars.tab_personal = this; SSHManager.connectionSuccess.connect(connectionSuccess) SSHManager.connectionFailed.connect(connectionFailed) initAccInfo(); initAccServerList(); } // 窗口关闭时自动触发清理 Component.onDestruction: { SSHManager.connectionSuccess.disconnect(connectionSuccess); SSHManager.connectionFailed.disconnect(connectionFailed); } //构造账号信息 function initAccInfo(){ if(GlobalVars.accInfo){ user_name = GlobalVars.accInfo.username user_level = GlobalVars.accInfo.uservip user_points = GlobalVars.accInfo.userpoints } } //构造账号服务器列表 function initAccServerList(){ if(GlobalVars.accServerList){ user_server_list = []; var arrbuf = []; for(var i = 0; i < GlobalVars.accServerList.length;i++){ var obj = GlobalVars.accServerList[i]; var buf = { action:i, state:0, ip : obj.serverIp, port : obj.port, username : obj.userName, password : obj.password } arrbuf.push(buf); } user_server_list = arrbuf; } } //监听全局变量的变化 这里需要监听 因为在本页会产生刷新数据 Connections { target: GlobalVars //账号基础信息 function onAccInfoChanged(){initAccInfo();} //账号服务器列表 function onAccServerListChanged(){initAccServerList();} } //尝试连接服务器 function testConnect(index){ if(testip === -1){ testip = index; changeServerValue(index,"state",-1); var data = user_server_list[index]; SSHManager.connectAndStartShell(data.ip,data.port,data.username,data.password) } else{ GlobalVars.msg_control.warning('当前正在测试' + user_server_list[testip].ip + "的连通性,请不要重复操作!"); } } //连接成功信号 function connectionSuccess(){ if (addServerWindow)return; changeServerValue(testip,"state",1); testip = -1 } //连接失败信号 function connectionFailed(error){ if (addServerWindow)return; changeServerValue(testip,"state",2); testip = -1 } //更改服务器列表的数据模型 function changeServerValue(index,key,value){ var buf = user_server_list; buf[index][key] = value; user_server_list = buf; } //打开新增服务器窗口 function openAddServerWindow(index = null){ if (!addServerWindow) { // 创建新窗口 var component = Qt.createComponent("Window_AddServer.qml"); addServerWindow = component.createObject(parent); // 绑定关闭时自动销毁 addServerWindow.closing.connect(function() { addServerWindow.destroy() addServerWindow = null // 关键:释放引用 }) } //如果有传入数据 if(index !== null){ var data = user_server_list[index]; addServerWindow.serverIP = data.ip addServerWindow.serverPort = data.port addServerWindow.serverUsername = data.username addServerWindow.serverPassword = data.password addServerWindow.mode = 1 } addServerWindow.y = GlobalVars.main_Window.y + 130 addServerWindow.show() addServerWindow.raise() // 把窗口提到最前面 } Rectangle{ id: top_rect anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.topMargin: 15 anchors.leftMargin: 10 anchors.rightMargin: 15 height: 50 radius: 8 border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7" border.width: 3 color:"transparent" // 头像部分 HusAvatar { id: avatarImg size:parent.height * 0.65 anchors.left: top_rect.left anchors.leftMargin: 20 anchors.verticalCenter: parent.verticalCenter iconSource: HusIcon.UserOutlined } //用户名 Text { id:username anchors.left: avatarImg.right anchors.leftMargin: 10 anchors.verticalCenter: parent.verticalCenter text: user_name font { pixelSize: 14 family: HusTheme.Primary.fontPrimaryFamily } color: HusTheme.Primary.colorTextBase elide: Text.ElideRight } HusButton { anchors.right: lxkf.left anchors.rightMargin: 2 anchors.verticalCenter: parent.verticalCenter type: HusButton.Type_Link text: qsTr(`关于贡献点`) HusToolTip { visible: parent.hovered arrowVisible: true text: qsTr("扫描赞助码赞助时备注DPS管理工具账号即可(如果长时间未增加贡献点可联系客服)") position: HusToolTip.Position_Left } } HusButton { id:lxkf anchors.right: change_zl.left anchors.rightMargin: 2 anchors.verticalCenter: parent.verticalCenter type: HusButton.Type_Link text: qsTr(`联系客服`) onClicked: { Qt.openUrlExternally("tencent://message/?uin=1713381454") } HusToolTip { visible: parent.hovered arrowVisible: true text: qsTr("如无法跳转QQ链接,可手动添加客服QQ:1713381454") position: HusToolTip.Position_Top } } HusButton { id:change_zl anchors.right: top_rect.right anchors.rightMargin: 10 anchors.verticalCenter: parent.verticalCenter type: HusButton.Type_Link text: qsTr(`修改资料`) onClicked: { GlobalVars.msg_control.warning('暂未开放此功能'); } } } Rectangle{ id:middle_rect anchors.left: parent.left anchors.leftMargin: 10 anchors.right: parent.right anchors.rightMargin: 15 anchors.bottomMargin: 10 anchors.bottom:bottom_rect.top anchors.topMargin: 10 anchors.top:top_rect.bottom border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7" border.width: 3 color:"transparent" radius: 8 Row{ anchors.fill: parent spacing: 20 anchors.leftMargin: 20 anchors.rightMargin: 20 Card { id:points_card width:(parent.width) / 3 - 14 height: parent.height*0.8 anchors.verticalCenter: parent.verticalCenter isDarkMode: HusTheme.isDark content: Item { anchors.fill:parent HusIconButton { id:points_icon type: HusButton.Type_Primary iconSource: HusIcon.CreditCardOutlined iconSize: 54 anchors.top:parent.top anchors.topMargin: 20 anchors.horizontalCenter : parent.horizontalCenter } Text { id:points_text text: "贡献点: " + user_points font { pixelSize: 14 family: HusTheme.Primary.fontPrimaryFamily } color: HusTheme.Primary.colorTextBase elide: Text.ElideRight anchors.top:points_icon.bottom anchors.topMargin: 20 anchors.horizontalCenter : parent.horizontalCenter } } } Card { id:vip_card width:(parent.width) / 3 - 14 height: parent.height*0.8 anchors.verticalCenter: parent.verticalCenter isDarkMode: HusTheme.isDark content: Item { anchors.fill:parent HusIconButton { id:vip_icon type: HusButton.Type_Primary iconSource: HusIcon.SketchOutlined iconSize: 54 anchors.top:parent.top anchors.topMargin: 20 anchors.horizontalCenter : parent.horizontalCenter } Text { id:vip_text text: "VIP等级: " + user_level font { pixelSize: 14 family: HusTheme.Primary.fontPrimaryFamily } color: HusTheme.Primary.colorTextBase elide: Text.ElideRight anchors.top:vip_icon.bottom anchors.topMargin: 20 anchors.horizontalCenter : parent.horizontalCenter } } } Card { id:cash_card width:(parent.width) / 3 - 14 height: parent.height*0.8 anchors.verticalCenter: parent.verticalCenter isDarkMode: HusTheme.isDark content: Item { anchors.fill:parent HusIconButton { id:cash_icon type: HusButton.Type_Primary iconSource:HusIcon.WalletOutlined iconSize: 54 anchors.top:parent.top anchors.topMargin: 20 anchors.horizontalCenter : parent.horizontalCenter } Text { id:cash_text text: "暂无代金券" font { pixelSize: 14 family: HusTheme.Primary.fontPrimaryFamily } color: HusTheme.Primary.colorTextBase elide: Text.ElideRight anchors.top:cash_icon.bottom anchors.topMargin: 20 anchors.horizontalCenter : parent.horizontalCenter } } } } } Rectangle{ id:bottom_rect height: 400 anchors.left: parent.left anchors.right: parent.right anchors.leftMargin: 10 anchors.rightMargin: 15 anchors.bottomMargin: 15 anchors.bottom:parent.bottom border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7" border.width: 3 color:"transparent" radius: 8 Column { anchors.fill: parent anchors.margins: 8 spacing: 8 Rectangle{ id:serverlist_header anchors.left: parent.left anchors.leftMargin: 6 width:parent.width height: 20 color:"transparent" Text { id:label_serverlist_text text: "我的服务器" font { pixelSize: 14 family: HusTheme.Primary.fontPrimaryFamily } color: HusTheme.Primary.colorTextBase elide: Text.ElideRight } HusButton { type: HusButton.Type_Link text: qsTr(`新增服务器`) anchors.right: parent.right anchors.rightMargin: 6 anchors.verticalCenter: parent.verticalCenter onClicked: { if (!addServerWindow) openAddServerWindow(); } } } HusTableView { width: parent.width height: parent.height - serverlist_header.height - 1 rowHeaderVisible: false columns: [ { title: '服务器IP', dataIndex: "ip", key: "ip", delegate: textDelegate, width: 150 }, { title: 'SSH端口', dataIndex: "port", key: "port", delegate: textDelegate, width: 80 }, { title: '服务器账号', dataIndex: 'username', key: 'username', delegate: textDelegate, width: 100 }, { title: '服务器密码', key: 'password', dataIndex: 'password', delegate: textDelegate, width: 160 }, { title: '状态', key: 'state', dataIndex: 'state', delegate: tagsDelegate, width: 80 }, { title: '操作', key: 'action', dataIndex: 'action', delegate: actionDelegate, width: 250 } ] initModel: user_server_list } } } Component { id: textDelegate Text { id: displayText leftPadding: 8 rightPadding: 8 font { family: HusTheme.Primary.fontPrimaryFamily pixelSize: HusTheme.Primary.fontPrimarySize } text: cellData color: HusTheme.Primary.colorTextBase horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter TextMetrics { id: displayWidth font: displayText.font text: displayText.text } TextMetrics { id: startWidth font: displayText.font text: { let index = displayText.text.indexOf(filterInput); if (index !== -1) return displayText.text.substring(0, index); else return ''; } } TextMetrics { id: filterWidth font: displayText.font text: filterInput } Rectangle { color: "red" opacity: 0.1 x: startWidth.advanceWidth + (displayText.width - displayWidth.advanceWidth) * 0.5 width: filterWidth.advanceWidth height: parent.height } } } Component { id: tagsDelegate Item { Row { id: row anchors.left: parent.left anchors.leftMargin: 20 anchors.verticalCenter: parent.verticalCenter spacing: 6 HusTag { visible: cellData != -1 text: { switch(cellData) { case 0 : return "未知"; case 1 : return "成功"; case 2 : return "失败"; default: return "连接中" } } presetColor: { switch(cellData) { case 0 : return "purple"; case 1 : return "green"; case 2 : return "red"; default: return "transparent" } } } BusyIndicator { visible: cellData === -1 anchors.verticalCenter: parent.verticalCenter color: "#FF5722" // 橙色 size: 18 duration: 12000 } } } } Component { id: actionDelegate Item { Row { anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter spacing: 4 HusButton { type: HusButton.Type_Link text: qsTr(`测试`) onClicked: { if (!addServerWindow) testConnect(cellData) } } HusButton { type: HusButton.Type_Link text: qsTr(`修改`) onClicked: { if (!addServerWindow) openAddServerWindow(cellData) } } HusButton { type: HusButton.Type_Link text: qsTr(`删除`) onClicked: { if (!addServerWindow) { var ip = user_server_list[cellData]["ip"]; GlobalVars.removeServer(ip); } } } } } } }