WebApp【公共组件库】@前端(For Git Submodule)
‘chensiAb’
2025-03-25 3b03f87a02458f719e2eb4bf112a13441b427d14
forms/input/CInputScanCode.vue
@@ -4,7 +4,10 @@
 */
<template>
    <view class="c-input-scan-code">
    <view
        class="c-input-scan-code"
        :class="[readOnly?'read-only':'']"
    >
        <AtInput
            :name="itemRes.name"
            :title="itemRes.label"
@@ -13,16 +16,16 @@
            :required="itemRes.required"
            :error="itemRes.error"
            :value="itemRes.formData[itemRes.name]"
            :onChange="evt=>itemRes.onChange(evt)"
            :onChange="evt => itemRes.onChange(evt)"
            :onBlur="evt => onBlur(evt)"
        >
            <view
                class="c-input-scan-btn"
                @tap="evt => handleScan()"
            ></view>
            <view class="c-input-scan-space"></view>
            <AtButton
                class="c-input-scan-show"
                class="c-input-scan-btn"
                size="small"
                type="primary"
                :disabled="readOnly"
                :onClick="evt => handleScan()"
            >
                <text v-show="!scaning">扫描</text>
                <AtIcon
@@ -52,8 +55,18 @@
        itemRes: Object,
        // 占位提示
        placeholder: String,
        // 只读模式
        readOnly: {
            type: Boolean,
            default: false,
        },
        // 由业务层调用app
        onScaning: Function,
        // 失去焦点回调
        onBlur: {
            type: Function,
            default: () => () => null,
        },
    },
    data() {
        return {
@@ -82,7 +95,7 @@
            this.scaning = true;
            if (type === 'taro') {
                Taro.scanCode({
                    onlyFromCamera: true,
                    onlyFromCamera: false,
                    scanType: 'barCode',
                    success: res => {
                        this.scaning = false;
@@ -99,10 +112,10 @@
                });
            } else if (type === 'app') {
                if (this.onScaning) {
                    this.onScaning(res => {
                    this.onScaning(result => {
                        this.scaning = false;
                        if (res.result) {
                            this.itemRes.onChange(res.result);
                        if (result) {
                            this.itemRes.onChange(result);
                        }
                    });
                }