63 lines
1.5 KiB
Vue
Raw Normal View History

2025-04-14 10:57:27 +08:00
<template>
2025-07-10 14:43:10 +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-10 14:43:10 +08:00
import { ref, onMounted } from "vue";
import { showModelMessage, getUrlParams } from "@/utils/tools.js";
2025-04-14 10:57:27 +08:00
2025-07-10 14:43:10 +08:00
const inputCodeValue = ref("");
const { codeValue } = defineProps(["codeValue"]);
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"]);
2025-07-10 14:43:10 +08:00
const onScan = () => {
uni.scanCode({
onlyFromCamera: true, //只能扫码
scanType: ["qrCode"],
success: function (res) {
const { result } = res;
2025-07-30 17:29:08 +08:00
console.log("扫码结果", result);
2025-07-10 14:43:10 +08:00
if (!result || result.indexOf("number") == -1) {
showModelMessage("无效的车辆二维码");
inputCodeValue.value = "";
emit("scan-change", "");
} else {
const params = getUrlParams(result);
inputCodeValue.value = params["number"];
emit("scan-change", params["number"]);
}
},
});
};
const onInput = (value) => {
2025-07-21 14:47:22 +08:00
if (value.detail.value == "") return emit("scan-empty");
2025-07-10 14:43:10 +08:00
inputCodeValue.value = value.detail.value;
emit("scan-change", value.detail.value);
};
2025-04-14 10:57:27 +08:00
2025-07-10 14:43:10 +08:00
const onSetValue = (value) => {
inputCodeValue.value = value;
};
2025-07-21 14:47:22 +08:00
const clearValue = () => {
inputCodeValue.value = "";
};
2025-07-10 14:43:10 +08:00
defineExpose({
onSetValue,
2025-07-21 14:47:22 +08:00
clearValue,
2025-07-10 14:43:10 +08:00
});
2025-04-14 10:57:27 +08:00
</script>
2025-07-10 14:43:10 +08:00
<style></style>