实现nfc配对
This commit is contained in:
parent
2a58e93f96
commit
2fcaa764c8
|
|
@ -120,7 +120,7 @@ export function getDeceasedList(params) {
|
|||
* @returns {Promise}
|
||||
*/
|
||||
export function bindNfcCard(data) {
|
||||
return post("/bst/nfc", data, {
|
||||
return post("/bst/nfc/add", data, {
|
||||
showLoading: false,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,23 +27,26 @@
|
|||
<view v-if="cardNo" class="text-btn" @click="resetCard"
|
||||
>清空卡号
|
||||
</view>
|
||||
<view v-if="connectionError" class="text-btn" @click="testServerConnection"
|
||||
<view
|
||||
v-if="connectionError"
|
||||
class="text-btn"
|
||||
@click="testServerConnection"
|
||||
>测试服务器
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="form-card">
|
||||
<view class="field">
|
||||
<text class="label">设备 MAC 地址</text>
|
||||
<input
|
||||
v-model.trim="deviceMac"
|
||||
class="input"
|
||||
maxlength="32"
|
||||
placeholder="请输入设备 MAC"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
<!-- <view class="field">-->
|
||||
<!-- <text class="label">设备 MAC 地址</text>-->
|
||||
<!-- <input-->
|
||||
<!-- v-model.trim="deviceMac"-->
|
||||
<!-- class="input"-->
|
||||
<!-- maxlength="32"-->
|
||||
<!-- placeholder="请输入设备 MAC"-->
|
||||
<!-- placeholder-class="placeholder"-->
|
||||
<!-- />-->
|
||||
<!-- </view>-->
|
||||
<view class="field">
|
||||
<text class="label">NFC 卡号</text>
|
||||
<input
|
||||
|
|
@ -102,7 +105,7 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
canSubmit() {
|
||||
return !!this.deviceMac && !!this.cardNo;
|
||||
return !!this.cardNo;
|
||||
},
|
||||
connectionText() {
|
||||
if (this.connectionError) {
|
||||
|
|
@ -197,7 +200,7 @@ export default {
|
|||
clearTimeout(this.connectTimeout);
|
||||
this.connectionError = `连接失败: ${err.errMsg || "未知错误"}`;
|
||||
this.socketConnected = false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (!this.socketTask) {
|
||||
|
|
@ -282,13 +285,17 @@ export default {
|
|||
let userFriendlyMsg = "连接失败";
|
||||
|
||||
// 处理 Invalid HTTP status 错误
|
||||
if (errorMsg.includes("Invalid HTTP status") || error.errCode === 1004) {
|
||||
userFriendlyMsg = "服务器不支持WebSocket或路径不存在\n请检查:\n1. 服务器是否正常运行\n2. WebSocket路径是否正确\n3. 服务器是否支持WebSocket协议";
|
||||
if (
|
||||
errorMsg.includes("Invalid HTTP status") ||
|
||||
error.errCode === 1004
|
||||
) {
|
||||
userFriendlyMsg =
|
||||
"服务器不支持WebSocket或路径不存在\n请检查:\n1. 服务器是否正常运行\n2. WebSocket路径是否正确\n3. 服务器是否支持WebSocket协议";
|
||||
console.error("WebSocket握手失败,可能原因:", {
|
||||
url: this.buildSocketUrl(),
|
||||
errorCode: error.errCode,
|
||||
errorMsg: errorMsg,
|
||||
suggestion: "服务器可能返回了404或500错误,请检查服务器日志"
|
||||
suggestion: "服务器可能返回了404或500错误,请检查服务器日志",
|
||||
});
|
||||
} else if (errorMsg.includes("timeout")) {
|
||||
userFriendlyMsg = "连接超时,请检查网络连接";
|
||||
|
|
@ -301,6 +308,8 @@ export default {
|
|||
});
|
||||
this.socketTask.onMessage((event) => {
|
||||
this.handleSocketMessage(event);
|
||||
|
||||
console.log("WebSocket <UNK>接收到事件", event);
|
||||
});
|
||||
},
|
||||
bindGlobalSocketEvents() {
|
||||
|
|
@ -340,13 +349,17 @@ export default {
|
|||
let userFriendlyMsg = "连接失败";
|
||||
|
||||
// 处理 Invalid HTTP status 错误
|
||||
if (errorMsg.includes("Invalid HTTP status") || error.errCode === 1004) {
|
||||
userFriendlyMsg = "服务器不支持WebSocket或路径不存在\n请检查:\n1. 服务器是否正常运行\n2. WebSocket路径是否正确\n3. 服务器是否支持WebSocket协议";
|
||||
if (
|
||||
errorMsg.includes("Invalid HTTP status") ||
|
||||
error.errCode === 1004
|
||||
) {
|
||||
userFriendlyMsg =
|
||||
"服务器不支持WebSocket或路径不存在\n请检查:\n1. 服务器是否正常运行\n2. WebSocket路径是否正确\n3. 服务器是否支持WebSocket协议";
|
||||
console.error("WebSocket握手失败,可能原因:", {
|
||||
url: this.buildSocketUrl(),
|
||||
errorCode: error.errCode,
|
||||
errorMsg: errorMsg,
|
||||
suggestion: "服务器可能返回了404或500错误,请检查服务器日志"
|
||||
suggestion: "服务器可能返回了404或500错误,请检查服务器日志",
|
||||
});
|
||||
} else if (errorMsg.includes("timeout")) {
|
||||
userFriendlyMsg = "连接超时,请检查网络连接";
|
||||
|
|
@ -394,7 +407,8 @@ export default {
|
|||
this.lastMessage = parsed.msg || trimmed;
|
||||
return;
|
||||
} else {
|
||||
this.cardNo = trimmed;
|
||||
this.cardNo = trimmed.replace(/^['"]|['"]$/g, "");
|
||||
console.log("接收到的卡号", this.cardNo);
|
||||
this.lastMessage = "已接收卡号";
|
||||
uni.showToast({ title: "收到卡号", icon: "success" });
|
||||
return;
|
||||
|
|
@ -510,11 +524,11 @@ export default {
|
|||
uni.showLoading({ title: "提交中...", mask: true });
|
||||
try {
|
||||
const payload = {
|
||||
memorialMac: this.deviceMac,
|
||||
// memorialMac: this.deviceMac,
|
||||
nfcMac: this.cardNo,
|
||||
};
|
||||
if (this.unitId) {
|
||||
payload.unitId = this.unitId;
|
||||
payload.memorialId = this.unitId;
|
||||
}
|
||||
const res = await bindNfcCard(payload);
|
||||
if (res && (res.code === 200 || res.status === 200)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user