2025-04-14 10:57:27 +08:00
|
|
|
<template>
|
2025-07-21 14:47:22 +08:00
|
|
|
<view>
|
|
|
|
|
<uni-easyinput
|
|
|
|
|
class="uni-mt-5"
|
|
|
|
|
@blur="onInput"
|
|
|
|
|
v-model="inputCodeValue"
|
|
|
|
|
placeholder="请扫描或输入中控编号"
|
|
|
|
|
suffixIcon="scan"
|
|
|
|
|
@iconClick="onScan"
|
|
|
|
|
>
|
|
|
|
|
</uni-easyinput>
|
|
|
|
|
</view>
|
2025-04-14 10:57:27 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-07-21 14:47:22 +08:00
|
|
|
import { ref } from "vue";
|
|
|
|
|
import { showModelMessage, getUrlParams } from "@/utils/tools.js";
|
2025-04-14 10:57:27 +08:00
|
|
|
|
2025-07-21 14:47:22 +08:00
|
|
|
const inputCodeValue = ref("");
|
|
|
|
|
const { codeValue, scanValue } = defineProps(["codeValue", "scanValue"]);
|
|
|
|
|
inputCodeValue.value = codeValue;
|
2025-04-14 10:57:27 +08:00
|
|
|
|
2025-07-21 14:47:22 +08:00
|
|
|
const emit = defineEmits(["scan-change", "scan-empty"]);
|
|
|
|
|
const onScan = () => {
|
|
|
|
|
uni.scanCode({
|
|
|
|
|
onlyFromCamera: true, //只能扫码
|
|
|
|
|
scanType: ["qrCode"],
|
|
|
|
|
success: function (res) {
|
|
|
|
|
const { result } = res;
|
|
|
|
|
if (!result || result.toLowerCase().indexOf("imei") == -1) {
|
|
|
|
|
showModelMessage("无效的中控二维码");
|
|
|
|
|
inputCodeValue.value = "";
|
|
|
|
|
emit("scan-change", {
|
|
|
|
|
imei: "",
|
|
|
|
|
sn: "",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const arr = result.split(" ");
|
|
|
|
|
const imei = arr[0].replace("IMEI:", "");
|
|
|
|
|
const sn = arr[1].replace("SN:", "");
|
|
|
|
|
const params = {
|
|
|
|
|
imei,
|
|
|
|
|
sn,
|
|
|
|
|
};
|
2025-05-22 17:16:26 +08:00
|
|
|
|
2025-07-21 14:47:22 +08:00
|
|
|
if (scanValue == "sn") {
|
|
|
|
|
inputCodeValue.value = sn;
|
|
|
|
|
} else {
|
|
|
|
|
inputCodeValue.value = imei;
|
|
|
|
|
}
|
|
|
|
|
emit("scan-change", params);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
2025-04-14 10:57:27 +08:00
|
|
|
|
2025-07-21 14:47:22 +08:00
|
|
|
const onInput = (value) => {
|
|
|
|
|
if (value.detail.value == "") return emit("scan-empty");
|
|
|
|
|
inputCodeValue.value = value.detail.value;
|
|
|
|
|
if (scanValue == "sn") {
|
|
|
|
|
emit("scan-change", {
|
|
|
|
|
imei: "",
|
|
|
|
|
sn: value.detail.value,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
emit("scan-change", {
|
|
|
|
|
imei: value.detail.value,
|
|
|
|
|
sn: "",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-04-14 10:57:27 +08:00
|
|
|
|
2025-07-21 14:47:22 +08:00
|
|
|
const onSetValue = (value) => {
|
|
|
|
|
inputCodeValue.value = value;
|
|
|
|
|
};
|
|
|
|
|
defineExpose({
|
|
|
|
|
onSetValue,
|
|
|
|
|
});
|
2025-04-14 10:57:27 +08:00
|
|
|
</script>
|
2025-07-21 14:47:22 +08:00
|
|
|
<style></style>
|