关于接口
This commit is contained in:
parent
2adcdaf91f
commit
4e3bab9474
|
|
@ -11,8 +11,8 @@ android {
|
|||
applicationId = "com.stand.standapp"
|
||||
minSdk = 24
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0.0"
|
||||
versionCode = 2
|
||||
versionName = "1.0.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,19 @@
|
|||
.log-item { margin-bottom: 4px; border-bottom: 1px solid #334155; padding-bottom: 2px; }
|
||||
.log-time { color: #94a3b8; margin-right: 5px; }
|
||||
.log-msg { word-break: break-all; }
|
||||
|
||||
/* Custom Modal Styles */
|
||||
.modal-overlay {
|
||||
display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
||||
background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;
|
||||
}
|
||||
.modal-content {
|
||||
background: white; padding: 20px; border-radius: 12px; width: 85%; max-width: 400px;
|
||||
box-shadow: 0 10px 25px rgba(0,0,0,0.2);
|
||||
}
|
||||
.modal-header { font-weight: bold; font-size: 18px; margin-bottom: 15px; color: #004A8F; border-bottom: 1px solid #eee; padding-bottom: 10px; }
|
||||
.modal-body { font-size: 14px; line-height: 1.8; color: #444; word-break: break-all; }
|
||||
.modal-footer { margin-top: 20px; text-align: right; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -66,7 +79,8 @@
|
|||
<p style="font-size: 12px; color: #666;">(适用于蓝牙/USB 小票机,传输原始 JSON)</p>
|
||||
|
||||
<button class="btn btn-orange" onclick="callUpdate()">3. 检查系统更新</button>
|
||||
<button class="btn btn-red" onclick="callExit()">4. 退出应用</button>
|
||||
<button class="btn" style="background: #64748b;" onclick="callAbout()">4. 关于应用</button>
|
||||
<button class="btn btn-red" onclick="callExit()">5. 退出应用</button>
|
||||
|
||||
<!-- WebSocket 控制区 -->
|
||||
<div class="ws-card">
|
||||
|
|
@ -177,6 +191,19 @@
|
|||
Telewave SDK Connectivity v1.0
|
||||
</div>
|
||||
|
||||
<!-- 自定义“关于”弹窗 -->
|
||||
<div id="aboutModal" class="modal-overlay" onclick="closeAbout()">
|
||||
<div class="modal-content" onclick="event.stopPropagation()">
|
||||
<div class="modal-header">关于应用信息</div>
|
||||
<div id="aboutBody" class="modal-body">
|
||||
正在获取信息...
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" style="padding: 10px 20px; background: #64748b; margin: 0;" onclick="closeAbout()">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 初始化界面
|
||||
document.getElementById('current-time').innerText = new Date().toLocaleString();
|
||||
|
|
@ -239,6 +266,32 @@
|
|||
}
|
||||
}
|
||||
|
||||
function callAbout() {
|
||||
if (window.android && window.android.getAboutInfo) {
|
||||
const infoStr = window.android.getAboutInfo();
|
||||
try {
|
||||
const info = JSON.parse(infoStr);
|
||||
const html = `
|
||||
<strong>应用名称:</strong> ${info.appName}<br>
|
||||
<strong>版本号:</strong> <span style="color: #3b82f6;">${info.versionName}</span><br>
|
||||
<strong>设备型号:</strong> ${info.model}<br>
|
||||
<strong>系统版本:</strong> Android ${info.osVersion}
|
||||
`;
|
||||
document.getElementById('aboutBody').innerHTML = html;
|
||||
document.getElementById('aboutModal').style.display = 'flex';
|
||||
} catch (e) {
|
||||
document.getElementById('aboutBody').innerText = "获取信息解析失败: " + infoStr;
|
||||
document.getElementById('aboutModal').style.display = 'flex';
|
||||
}
|
||||
} else {
|
||||
alert("关于接口未就绪");
|
||||
}
|
||||
}
|
||||
|
||||
function closeAbout() {
|
||||
document.getElementById('aboutModal').style.display = 'none';
|
||||
}
|
||||
|
||||
// 安卓回调函数:退出确认时执行
|
||||
function addExitText() {
|
||||
const tag = document.getElementById('inject-status');
|
||||
|
|
@ -258,6 +311,7 @@
|
|||
let clientId = "WEB_" + Math.random().toString(36).substr(2, 9);
|
||||
let heartbeatTimer = null;
|
||||
let reconnectTimer = null;
|
||||
let isManualClose = false; // 新增:手动断开标记
|
||||
const logList = document.getElementById('log-list');
|
||||
|
||||
document.getElementById('ws-client-id').innerText = clientId;
|
||||
|
|
@ -301,6 +355,7 @@
|
|||
const finalUrl = rawUrl.replace("{clientId}", clientId);
|
||||
|
||||
addLog("正在尝试连接: " + finalUrl, false);
|
||||
isManualClose = false; // 启动连接时重置标记
|
||||
|
||||
try {
|
||||
ws = new WebSocket(finalUrl);
|
||||
|
|
@ -324,8 +379,12 @@
|
|||
updateWSStatus(false);
|
||||
addLog("连接关闭", false);
|
||||
stopHeartbeat();
|
||||
// 5秒后自动重连
|
||||
reconnectTimer = setTimeout(connectWS, 5000);
|
||||
|
||||
// 只有非手动断开(如网络异常)时才自动重连
|
||||
if (!isManualClose) {
|
||||
addLog("异常断开,5秒后自动重连...", false);
|
||||
reconnectTimer = setTimeout(connectWS, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = (err) => {
|
||||
|
|
@ -339,6 +398,7 @@
|
|||
|
||||
function toggleWS() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
isManualClose = true; // 标记为手动断开
|
||||
clearTimeout(reconnectTimer);
|
||||
reconnectTimer = null;
|
||||
ws.close();
|
||||
|
|
|
|||
|
|
@ -103,6 +103,24 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JS 调用:获取“关于”信息
|
||||
*/
|
||||
@JavascriptInterface
|
||||
fun getAboutInfo(): String {
|
||||
return try {
|
||||
val packageInfo = activity.packageManager.getPackageInfo(activity.packageName, 0)
|
||||
val json = org.json.JSONObject()
|
||||
json.put("appName", activity.getString(R.string.app_name))
|
||||
json.put("versionName", packageInfo.versionName)
|
||||
json.put("model", android.os.Build.MODEL)
|
||||
json.put("osVersion", android.os.Build.VERSION.RELEASE)
|
||||
json.toString()
|
||||
} catch (e: Exception) {
|
||||
"{ \"appName\": \"StandApp\", \"versionName\": \"1.0.0\" }"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JS 调用:保存消息记录
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue