98 lines
3.2 KiB
C++
98 lines
3.2 KiB
C++
#include "desktop_service.h"
|
||
|
||
namespace vdi {
|
||
|
||
void DesktopService::login(const QString& username, const QString& password, AuthCallback callback) {
|
||
// 本地演示认证:账号与密码非空即通过。
|
||
// 正式版本替换为 /api/v1/terminal/session/login(SN+用户身份校验)。
|
||
AuthResult result;
|
||
if (username.trimmed().isEmpty() || password.isEmpty()) {
|
||
result.ok = false;
|
||
result.message = QStringLiteral("请输入用户名和密码");
|
||
} else {
|
||
result.ok = true;
|
||
result.displayName = username.trimmed();
|
||
currentUser_ = username.trimmed();
|
||
}
|
||
if (callback) {
|
||
callback(result);
|
||
}
|
||
}
|
||
|
||
void DesktopService::listDesktops(DesktopListCallback callback) {
|
||
// 本地演示数据:Windows 可用(Moonlight),Ubuntu/麒麟尚未分配连接信息。
|
||
// 正式版本替换为 /api/v1/terminal/session/desktops(按用户绑定返回)。
|
||
std::vector<DesktopInfo> desktops;
|
||
|
||
DesktopInfo windows;
|
||
windows.id = QStringLiteral("desk-win10-01");
|
||
windows.name = QStringLiteral("Windows 10");
|
||
windows.os = QStringLiteral("Windows 10 22H2 专业版");
|
||
windows.protocol = Protocol::kMoonlight;
|
||
windows.state = DesktopState::kAvailable;
|
||
windows.endpoint = QStringLiteral("192.168.1.70");
|
||
windows.app = QStringLiteral("Desktop");
|
||
desktops.push_back(windows);
|
||
|
||
DesktopInfo ubuntu;
|
||
ubuntu.id = QStringLiteral("desk-ubuntu-01");
|
||
ubuntu.name = QStringLiteral("Ubuntu");
|
||
ubuntu.os = QStringLiteral("Ubuntu 桌面");
|
||
ubuntu.protocol = Protocol::kRdp;
|
||
ubuntu.state = DesktopState::kUnassigned;
|
||
desktops.push_back(ubuntu);
|
||
|
||
DesktopInfo kylin;
|
||
kylin.id = QStringLiteral("desk-kylin-01");
|
||
kylin.name = QStringLiteral("麒麟");
|
||
kylin.os = QStringLiteral("银河麒麟桌面");
|
||
kylin.protocol = Protocol::kRdp;
|
||
kylin.state = DesktopState::kUnassigned;
|
||
desktops.push_back(kylin);
|
||
|
||
if (callback) {
|
||
callback(std::move(desktops), QString());
|
||
}
|
||
}
|
||
|
||
void DesktopService::createTicket(const QString& desktopId, TicketCallback callback) {
|
||
// 本地演示票据:直接由桌面列表数据构造。
|
||
// 正式版本替换为 /api/v1/terminal/session/connect-ticket(短期一次性票据)。
|
||
ConnectionTicket ticket;
|
||
ticket.desktopId = desktopId;
|
||
|
||
std::vector<DesktopInfo> desktops;
|
||
QString error;
|
||
listDesktops([&desktops, &error](std::vector<DesktopInfo> list, const QString& err) {
|
||
desktops = std::move(list);
|
||
error = err;
|
||
});
|
||
|
||
for (const DesktopInfo& d : desktops) {
|
||
if (d.id == desktopId) {
|
||
if (d.state != DesktopState::kAvailable) {
|
||
error = QStringLiteral("桌面 %1 尚未分配连接信息").arg(d.name);
|
||
break;
|
||
}
|
||
ticket.protocol = d.protocol;
|
||
ticket.endpoint = d.endpoint;
|
||
ticket.app = d.app;
|
||
ticket.width = d.width;
|
||
ticket.height = d.height;
|
||
ticket.fps = d.fps;
|
||
error.clear();
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (callback) {
|
||
callback(ticket, error);
|
||
}
|
||
}
|
||
|
||
void DesktopService::logout() {
|
||
currentUser_.clear();
|
||
}
|
||
|
||
} // namespace vdi
|