Skip to content

Commit

Permalink
hex输入支持空格&&修复输入框空时无法计算校验位
Browse files Browse the repository at this point in the history
  • Loading branch information
keysking committed May 5, 2023
1 parent 2cd1266 commit c7b00a6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/SendPanel/SendPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ const sendBuffer = computed(() => {
if (sendType.value == "hex") {
if (checkDigit.value) {
return Uint8Array.from([
...hexStringToBuffer(sendData.value),
...hexStringToBuffer(sendData.value.replace(" ", "")),
...checkDigit.value,
]);
}
return Uint8Array.from([...hexStringToBuffer(sendData.value)]);
return hexStringToBuffer(sendData.value.replaceAll(" ", ""));
} else {
return stringToBuffer(sendData.value + lineEnding.value);
}
});
const checkDigit = computed(() => {
if (!checkAlgorithm.value || sendType.value != "hex") return undefined;
if (sendData.value.length == 0) return [0x00];
return checkAlgorithm.value.algorithm(hexStringToBuffer(sendData.value));
});
Expand Down Expand Up @@ -81,7 +82,9 @@ watch(sendType, (value) => {
function onInput() {
if (sendType.value == "hex") {
sendData.value = sendData.value.replace(/([^0-9a-fA-F])/, "").toUpperCase();
sendData.value = sendData.value
.replace(/([^0-9a-fA-F ])/, "")
.toUpperCase();
}
}
Expand Down Expand Up @@ -132,7 +135,13 @@ function clear() {
</ul>
</div>
<AutoSendButton class="" @send="send" />
<button class="btn px-10" @click="send">发 送</button>
<button
class="btn px-10"
:class="sendData.length == 0 ? 'btn-disabled' : ''"
@click="send"
>
发 送
</button>
</div>
<button
class="absolute right-1 top-1 btn btn-ghost btn-circle btn-sm"
Expand Down

0 comments on commit c7b00a6

Please sign in to comment.