
<template>
  <div>
    <el-button type="primary" @click="scanCode" style="margin-left:4px">{{labeltext}}</el-button>
  </div>
</template>

<script>
export default {
  props: {
    labeltext: {
      type: String,
      default: "扫码",
    }
  },
  data() {
    return {
      scannedResult: null, // 存储扫描到的二维码数据
    };
  },
  mounted() {
    window.onScanResult = this.onScanResult;
  },
  methods: {
    scanCode(){
			if (window.Android) {
				window.Android.openScanner();
			} else {
				alert("当前环境不支持扫码");
			}
		},
		onScanResult(data) {
			this.scannedResult = data;
      this.$emit('scanResult', data);
      return data;
		}, 
  },
};
</script>
<style></style>
