gaoluyang
9 天以前 86966ec9a83b93decbd93fc8ce2be1882d4c9775
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script lang="ts" setup>
import type { BarcodeFormat } from '@vben/common-ui';
 
import { computed, ref } from 'vue';
 
import { BarcodeFormatEnum, Barcode as CommonBarcode } from '@vben/common-ui';
 
defineOptions({ name: 'MesWmBarcode' });
 
const props = withDefaults(
  defineProps<{
    content?: string;
    displayValue?: boolean;
    format?: number;
    height?: number;
    width?: number;
  }>(),
  {
    content: '',
    displayValue: true,
    format: BarcodeFormatEnum.QR_CODE,
    height: 100,
    width: 200,
  },
);
 
const emit = defineEmits<{ done: [value: string] }>();
 
const barcodeRef = ref<InstanceType<typeof CommonBarcode>>();
const commonFormat = computed<BarcodeFormat>(
  () => (props.format || BarcodeFormatEnum.QR_CODE) as BarcodeFormat,
);
 
function getImageBase64() {
  return barcodeRef.value?.getImageBase64() || '';
}
 
defineExpose({ getImageBase64 });
</script>
 
<template>
  <CommonBarcode
    ref="barcodeRef"
    :content="content"
    :display-value="displayValue"
    :format="commonFormat"
    :height="height"
    :width="width"
    @done="emit('done', $event)"
  />
</template>