|
@@ -11,15 +11,21 @@
|
|
<el-row style="color: gray; font-size: small;">
|
|
<el-row style="color: gray; font-size: small;">
|
|
<h4>支持jpg, png, bmp, pdf等文件格式</h4>
|
|
<h4>支持jpg, png, bmp, pdf等文件格式</h4>
|
|
</el-row>
|
|
</el-row>
|
|
- <el-row>
|
|
|
|
- <div class="common-layout">
|
|
|
|
- <el-container>
|
|
|
|
- <el-input type="file" v-model="fileName" @change="uploadImg"></el-input>
|
|
|
|
- <OcrLangList />
|
|
|
|
- <el-button type="primary" @click="predict" :loading="loading">Predict</el-button>
|
|
|
|
- </el-container>
|
|
|
|
- </div>
|
|
|
|
- </el-row>
|
|
|
|
|
|
+ <div class="common-layout">
|
|
|
|
+ <el-upload class="upload-demo" drag :before-upload="beforeUpload" multiple>
|
|
|
|
+ <el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
|
|
|
+ <div class="el-upload__text">
|
|
|
|
+ Drop file here or <em>click to upload</em>
|
|
|
|
+ </div>
|
|
|
|
+ <template #tip>
|
|
|
|
+ <div class="el-upload__tip">
|
|
|
|
+ {{ fileName }}
|
|
|
|
+ </div>
|
|
|
|
+ </template>
|
|
|
|
+ </el-upload>
|
|
|
|
+ <OcrLangList />
|
|
|
|
+ <el-button type="primary" @click="predict" :loading="loading">Predict</el-button>
|
|
|
|
+ </div>
|
|
<div v-show="is_pdf">
|
|
<div v-show="is_pdf">
|
|
<el-row>
|
|
<el-row>
|
|
<el-button-group>
|
|
<el-button-group>
|
|
@@ -94,6 +100,7 @@ import { createLoadingTask } from "vue3-pdfjs/esm"; // 获得总页数
|
|
import {
|
|
import {
|
|
ArrowLeft,
|
|
ArrowLeft,
|
|
ArrowRight,
|
|
ArrowRight,
|
|
|
|
+ UploadFilled
|
|
} from '@element-plus/icons-vue'
|
|
} from '@element-plus/icons-vue'
|
|
import { useServerIpStore } from '../../../../store/ServerIp';
|
|
import { useServerIpStore } from '../../../../store/ServerIp';
|
|
import { useServerPortStore } from '../../../../store/ServerPort';
|
|
import { useServerPortStore } from '../../../../store/ServerPort';
|
|
@@ -234,7 +241,7 @@ const { ocr_lang } = storeToRefs(ol);
|
|
let loading = ref(false)
|
|
let loading = ref(false)
|
|
let show_predict = ref(false)
|
|
let show_predict = ref(false)
|
|
let predictTime = ref(0)
|
|
let predictTime = ref(0)
|
|
-const fileName = ref(null);
|
|
|
|
|
|
+const fileName = ref(null as unknown as string);
|
|
const canvas = ref(null as unknown as HTMLCanvasElement);
|
|
const canvas = ref(null as unknown as HTMLCanvasElement);
|
|
const img_canvas = ref(null as unknown as HTMLCanvasElement);
|
|
const img_canvas = ref(null as unknown as HTMLCanvasElement);
|
|
|
|
|
|
@@ -251,6 +258,8 @@ const json_result = ref("");
|
|
|
|
|
|
const { toClipboard } = useClipboard()
|
|
const { toClipboard } = useClipboard()
|
|
|
|
|
|
|
|
+const input_file = ref(null as unknown as File)
|
|
|
|
+
|
|
interface iRect {
|
|
interface iRect {
|
|
left: number,
|
|
left: number,
|
|
top: number,
|
|
top: number,
|
|
@@ -265,55 +274,42 @@ onMounted(async () => {
|
|
img_canvas.value = document.getElementById("img_canvas") as HTMLCanvasElement;
|
|
img_canvas.value = document.getElementById("img_canvas") as HTMLCanvasElement;
|
|
});
|
|
});
|
|
|
|
|
|
-const uploadImg = () => {
|
|
|
|
- /**
|
|
|
|
- * 这里由于操作是绑定在 el-input 上;因此需要在内部重新获取 input 再拿到 file
|
|
|
|
- */
|
|
|
|
- const reader = new FileReader();
|
|
|
|
- // 用于展示
|
|
|
|
|
|
+const beforeUpload = (file: File): boolean | Promise<boolean> => {
|
|
|
|
+ if (fa_canvas != null) {
|
|
|
|
+ fa_canvas.dispose();
|
|
|
|
+ fa_canvas = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
const showImg = document.getElementById("show-img") as HTMLImageElement;
|
|
const showImg = document.getElementById("show-img") as HTMLImageElement;
|
|
- const inputElement = document
|
|
|
|
- .getElementsByClassName("el-input")[0]
|
|
|
|
- .getElementsByTagName("input")[0];
|
|
|
|
|
|
|
|
- try {
|
|
|
|
- const file = inputElement.files![0];
|
|
|
|
- reader.onload = () => {
|
|
|
|
- const post_ = file.name.substring(file.name.lastIndexOf("."), file.name.length).toLowerCase();
|
|
|
|
- if (fa_canvas && typeof fa_canvas.dispose === 'function') {
|
|
|
|
- fa_canvas.dispose();
|
|
|
|
- fa_canvas = null;
|
|
|
|
|
|
+ const post_ = file.name.substring(file.name.lastIndexOf("."), file.name.length).toLowerCase();
|
|
|
|
+ if (post_ == ".pdf") {
|
|
|
|
+ state.pageNum = 1;
|
|
|
|
+ state.source = URL.createObjectURL(file);
|
|
|
|
+ is_pdf.value = true
|
|
|
|
+ loadingTask = createLoadingTask(state.source);
|
|
|
|
+ getPdfImage(state.pageNum);
|
|
|
|
+ } else
|
|
|
|
+ if (post_ == ".jpg" || post_ == ".png" || post_ == ".bmp" || post_ == ".jpeg") {
|
|
|
|
+ showImg.src = URL.createObjectURL(file);
|
|
|
|
+ input_file.value = file;
|
|
|
|
+ showImg.onload = () => {
|
|
|
|
+ canvas.value.width = showImg.width;
|
|
|
|
+ canvas.value.height = showImg.height;
|
|
|
|
+ fa_canvas = new fabric.Canvas(canvas.value);
|
|
|
|
+ rects.splice(0)
|
|
|
|
+ selectedItem.value = -1;
|
|
}
|
|
}
|
|
- if (post_ == ".pdf") {
|
|
|
|
- state.pageNum = 1;
|
|
|
|
- // state.scale = 4;
|
|
|
|
- state.source = URL.createObjectURL(file);
|
|
|
|
- is_pdf.value = true
|
|
|
|
- loadingTask = createLoadingTask(state.source);
|
|
|
|
- getPdfImage(state.pageNum);
|
|
|
|
- } else
|
|
|
|
- if (post_ == ".jpg" || post_ == ".png" || post_ == ".bmp" || post_ == ".jpeg") {
|
|
|
|
- showImg.src = URL.createObjectURL(file);
|
|
|
|
- showImg.onload = () => {
|
|
|
|
- canvas.value.width = showImg.width;
|
|
|
|
- canvas.value.height = showImg.height;
|
|
|
|
- fa_canvas = new fabric.Canvas(canvas.value);
|
|
|
|
- rects.splice(0)
|
|
|
|
- selectedItem.value = -1;
|
|
|
|
- }
|
|
|
|
- is_pdf.value = false
|
|
|
|
- } else {
|
|
|
|
- alert('不支持的文件格式!')
|
|
|
|
- fileName.value = null
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- reader.readAsDataURL(file);
|
|
|
|
- } catch (err) {
|
|
|
|
- console.error(err);
|
|
|
|
- }
|
|
|
|
|
|
+ is_pdf.value = false
|
|
|
|
+ } else {
|
|
|
|
+ alert('不支持的文件格式!')
|
|
|
|
+ fileName.value = ''
|
|
|
|
+ }
|
|
|
|
+ fileName.value = file.name
|
|
if (show_predict.value === true)
|
|
if (show_predict.value === true)
|
|
show_predict.value = !show_predict.value;
|
|
show_predict.value = !show_predict.value;
|
|
-};
|
|
|
|
|
|
+ return true
|
|
|
|
+}
|
|
|
|
|
|
type RectWithId = fabric.Rect & { id: number };
|
|
type RectWithId = fabric.Rect & { id: number };
|
|
|
|
|
|
@@ -348,7 +344,7 @@ function CreateRect(canvas: any, i: number, left: number, top: number, width: nu
|
|
}
|
|
}
|
|
|
|
|
|
const predict = async () => {
|
|
const predict = async () => {
|
|
- if (fileName.value == undefined) {
|
|
|
|
|
|
+ if (fileName.value == undefined || fileName.value == '') {
|
|
alert('请上传图片!')
|
|
alert('请上传图片!')
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -359,10 +355,6 @@ const predict = async () => {
|
|
rects.splice(0)
|
|
rects.splice(0)
|
|
|
|
|
|
const img = document.getElementById("show-img") as HTMLImageElement;
|
|
const img = document.getElementById("show-img") as HTMLImageElement;
|
|
- const inputElement = document
|
|
|
|
- .getElementsByClassName("el-input")[0]
|
|
|
|
- .getElementsByTagName("input")[0];
|
|
|
|
- const file = inputElement.files![0];
|
|
|
|
|
|
|
|
loading.value = !loading.value
|
|
loading.value = !loading.value
|
|
var data = new FormData();
|
|
var data = new FormData();
|
|
@@ -408,7 +400,7 @@ const predict = async () => {
|
|
});
|
|
});
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
- data.append('image', file);
|
|
|
|
|
|
+ data.append('image', input_file.value);
|
|
|
|
|
|
OcrRec(api, data).then(res => {
|
|
OcrRec(api, data).then(res => {
|
|
console.log(res.code)
|
|
console.log(res.code)
|