刘光辉
8 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<script lang="ts" setup>
import { reactive, toRefs, unref, watch } from 'vue';
 
import { LoadingOutlined } from '@ant-design/icons-vue';
 
import { getOcrData } from '#/api/onlineDev/visualDev';
 
import { ocrProps } from './props';
 
interface State {
  imageUrl: any;
  loading: boolean;
}
 
defineOptions({ inheritAttrs: false, name: 'JnpfOcr' });
const props = defineProps(ocrProps);
const emit = defineEmits(['update:value', 'change']);
const state = reactive<State>({
  imageUrl: '',
  loading: false,
});
const { imageUrl, loading } = toRefs(state);
 
watch(
  () => unref(props.value),
  (val) => {
    state.imageUrl = val;
  },
  { immediate: true },
);
 
function onChange(url) {
  if (!url) {
    emit('update:value', '');
    emit('change', '');
    return;
  }
  state.loading = true;
  const data = { url, type: props.ocrType };
  getOcrData(data)
    .then((res) => {
      emit('update:value', url);
      emit('change', url, res.data);
      state.loading = false;
    })
    .catch(() => {
      state.loading = false;
    });
}
</script>
 
<template>
  <div class="jnpf-ocr">
    <div class="loading" v-show="loading">
      <LoadingOutlined />
    </div>
    <JnpfUploadImgSingle v-model:value="imageUrl" :disabled="disabled" tip-text="点击上传" @change="onChange" />
  </div>
</template>
<style lang="scss" scoped>
.jnpf-ocr {
  position: relative;
  width: 100%;
 
  .loading {
    position: absolute;
    top: 1px;
    left: 1px;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 98px;
    height: 98px;
 
    .anticon {
      font-size: 26px;
      color: #8c939d;
    }
  }
}
</style>