feat(shell): 设备列表显示在线状态 + 手动选择解绑(不选不动手)+ 文案下线改解绑 + 手机端双输入框界面
This commit is contained in:
@@ -42,9 +42,10 @@ static char g_lastResp[8192] = ""; // 上一次 /login 原始响应(设备
|
||||
static int g_overlay = 0; // 0=正常 1=公告 2=更新 3=设备
|
||||
static int g_devManage = 0; // 1 = 设备面板处于「我的设备」自助模式
|
||||
|
||||
struct DevItem { char id[64]; char name[64]; char created[32]; };
|
||||
struct DevItem { char id[64]; char name[64]; char created[32]; int online; };
|
||||
static DevItem g_devs[16];
|
||||
static int g_devCount = 0, g_devMax = 0;
|
||||
static int g_selIdx = 0; // 设备页手动选中的那台(1 起;0=未选)
|
||||
|
||||
struct Notice { int id; char title[128]; char body[1024]; };
|
||||
static Notice g_notices[8];
|
||||
@@ -268,7 +269,7 @@ static int api_login(const char *user, const char *pass, char *msg, int cap) {
|
||||
snprintf(g_lastResp, sizeof(g_lastResp), "%s", resp);
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台下线一台设备");
|
||||
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台解绑一台设备");
|
||||
else if (strstr(resp, "IP_LIMIT")) snprintf(msg, cap, "IP 绑定已达上限,请解绑后再试");
|
||||
else if (ok) snprintf(msg, cap, "登录成功");
|
||||
else snprintf(msg, cap, "账号或密码错误");
|
||||
@@ -1366,6 +1367,7 @@ public:
|
||||
// 把 g_lastResp 里的设备数组解析到 g_devs/后面统一渲染
|
||||
void ParseDevicesInto() {
|
||||
g_devCount = 0;
|
||||
g_selIdx = 0;
|
||||
g_devMax = json_int(g_lastResp, "max_devices", g_maxDevices);
|
||||
const char *p = g_lastResp;
|
||||
while ((p = strstr(p, "\"device_id\":\"")) && g_devCount < 16) {
|
||||
@@ -1379,13 +1381,29 @@ public:
|
||||
}
|
||||
snprintf(g_devs[g_devCount].id, sizeof(g_devs[0].id), "%s", id);
|
||||
snprintf(g_devs[g_devCount].name, sizeof(g_devs[0].name), "%s", name[0] ? name : "未命名设备");
|
||||
g_devs[g_devCount].online = 0;
|
||||
if (const char *oc = strstr(p, "\"online_count\":")) g_devs[g_devCount].online = atoi(oc + 15);
|
||||
g_devCount++;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
// 设备列表渲染:写进 devBody 这个多行 Label(与原资产一致的单标签写法)
|
||||
void RenderDeviceList() {
|
||||
std::wstring body;
|
||||
for (int i = 0; i < g_devCount; i++) {
|
||||
wchar_t line[320];
|
||||
swprintf(line, 320, L"%d. %ls %ls %ls\r\n", i + 1,
|
||||
U8(g_devs[i].name).c_str(), U8(g_devs[i].id).c_str(),
|
||||
g_devs[i].online > 0 ? L"\u25cf \u5728\u7ebf" : L"\u25cb \u79bb\u7ebf");
|
||||
body += line;
|
||||
}
|
||||
if (CLabelUI *b = static_cast<CLabelUI *>(m_pm.FindControl(_T("devBody")))) b->SetText(body.c_str());
|
||||
}
|
||||
|
||||
void ShowDevicePanel() {
|
||||
ParseDevicesInto();
|
||||
g_selIdx = 0;
|
||||
std::wstring body;
|
||||
for (int i = 0; i < g_devCount; i++) {
|
||||
wchar_t line[256];
|
||||
@@ -1393,6 +1411,7 @@ public:
|
||||
body += line;
|
||||
}
|
||||
if (body.empty()) body = L"(服务器没有返回设备明细,可直接重试登录)";
|
||||
else body = L"点选下面要解绑的那台设备,再按「解绑该设备」";
|
||||
#ifdef VFY_DEBUG
|
||||
{ HANDLE f = ::CreateFileW(L"C:\\vfy_dev.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
||||
if (f != INVALID_HANDLE_VALUE) { std::string dump; char tmp[2048];
|
||||
@@ -1400,11 +1419,14 @@ public:
|
||||
dump = tmp; for (int i2 = 0; i2 < g_devCount; i2++) { snprintf(tmp, sizeof(tmp), "ITEM[%d] name=<%s> id=<%s>\n", i2, g_devs[i2].name, g_devs[i2].id); dump += tmp; }
|
||||
DWORD wr = 0; ::WriteFile(f, dump.c_str(), (DWORD)dump.size(), &wr, NULL); ::CloseHandle(f); } }
|
||||
#endif
|
||||
if (CLabelUI *b = static_cast<CLabelUI *>(m_pm.FindControl(_T("devBody")))) b->SetText(body.c_str());
|
||||
RenderDeviceList(); // 列表正文由它写进 devBody
|
||||
wchar_t title[160];
|
||||
swprintf(title, 160, L"已绑定 %d / %d 台,解绑一台后即可登录", g_devCount, g_devMax > 0 ? g_devMax : g_maxDevices);
|
||||
if (CLabelUI *t = static_cast<CLabelUI *>(m_pm.FindControl(_T("devTitle")))) t->SetText(title);
|
||||
ShowOverlay("panelDevice");
|
||||
if (CLabelUI *tp = static_cast<CLabelUI *>(m_pm.FindControl(_T("devTip"))))
|
||||
tp->SetText(L"点选上面要解绑的那台设备,再按「解绑该设备」");
|
||||
if (CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("devIdx")))) e->SetText(L"");
|
||||
}
|
||||
|
||||
// 一键解绑最早绑定的一台(服务器按 created_at DESC 返回,最后一台最老)
|
||||
@@ -1465,7 +1487,7 @@ public:
|
||||
text += line;
|
||||
}
|
||||
if (text.empty()) text = L"当前没有已绑定设备";
|
||||
if (CLabelUI *b = static_cast<CLabelUI *>(m_pm.FindControl(_T("devBody")))) b->SetText(text.c_str());
|
||||
RenderDeviceList(); // 列表正文由它写进 devBody
|
||||
wchar_t title[160];
|
||||
swprintf(title, 160, L"已绑定 %d / %d 台,解绑一台即可换设备登录", g_devCount, g_devMax > 0 ? g_devMax : g_maxDevices);
|
||||
if (CLabelUI *t = static_cast<CLabelUI *>(m_pm.FindControl(_T("devTitle")))) t->SetText(title);
|
||||
@@ -1476,7 +1498,14 @@ public:
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("devTip")));
|
||||
if (!e || !tip) return;
|
||||
int idx = _wtoi(e->GetText().GetData());
|
||||
if (idx < 1 || idx > g_devCount) { tip->SetText(L"请输入列表里的序号,例如 1"); return; }
|
||||
if (idx < 1) idx = g_selIdx; // 没填序号时用列表里点选的那台
|
||||
if (idx < 1 || idx > g_devCount) { tip->SetText(L"请先在「输入要解绑的设备序号」里填上列表中的序号(例如 1),再按「解绑该设备」"); return; }
|
||||
{
|
||||
wchar_t conf[256];
|
||||
swprintf(conf, 256, L"正在解绑第 %d 台:%ls(%ls)", idx,
|
||||
U8(g_devs[idx - 1].name).c_str(), g_devs[idx - 1].online > 0 ? L"在线" : L"离线");
|
||||
tip->SetText(conf);
|
||||
}
|
||||
UnbindDeviceIdx(idx);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user