|
@@ -0,0 +1,211 @@
|
|
|
|
+<template>
|
|
|
|
+ <el-dialog
|
|
|
|
+ class="page-dialog"
|
|
|
|
+ custom-class="ocr-test-dialog"
|
|
|
|
+ :visible.sync="modalIsShow"
|
|
|
|
+ :close-on-click-modal="false"
|
|
|
|
+ :close-on-press-escape="false"
|
|
|
|
+ append-to-body
|
|
|
|
+ fullscreen
|
|
|
|
+ @closed="visibleChange()"
|
|
|
|
+ >
|
|
|
|
+ <div slot="title">OCR测试</div>
|
|
|
|
+ <div class="body">
|
|
|
|
+ <div class="left">
|
|
|
|
+ <el-upload
|
|
|
|
+ ref="upload"
|
|
|
|
+ action=""
|
|
|
|
+ class="avatar-uploader"
|
|
|
|
+ :show-file-list="false"
|
|
|
|
+ :on-success="handleSuccess"
|
|
|
|
+ :before-upload="beforeUpload"
|
|
|
|
+ accept="image/*"
|
|
|
|
+ :auto-upload="false"
|
|
|
|
+ :multiple="false"
|
|
|
|
+ :on-change="onChange"
|
|
|
|
+ :http-request="customSubmit"
|
|
|
|
+ drag
|
|
|
|
+ >
|
|
|
|
+ <img
|
|
|
|
+ v-if="imageUrl"
|
|
|
|
+ :src="imageUrl"
|
|
|
|
+ class="avatar animate__animated animate__backInLeft"
|
|
|
|
+ />
|
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
|
+ </el-upload>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="right">
|
|
|
|
+ <div>
|
|
|
|
+ <el-select v-model="type">
|
|
|
|
+ <el-option value="GENERAL" label="通用"></el-option>
|
|
|
|
+ <el-option value="HANDWRITING" label="手写"></el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ <el-button
|
|
|
|
+ type="primary"
|
|
|
|
+ style="margin-left: 10px"
|
|
|
|
+ :disabled="!file"
|
|
|
|
+ @click="submit"
|
|
|
|
+ >开始识别</el-button
|
|
|
|
+ >
|
|
|
|
+ </div>
|
|
|
|
+ <div style="height: calc(100% - 32px)">
|
|
|
|
+ <el-link
|
|
|
|
+ :underline="false"
|
|
|
|
+ type="success"
|
|
|
|
+ style="margin-top: 20px; margin-bottom: 5px"
|
|
|
|
+ >识别结果:</el-link
|
|
|
|
+ >
|
|
|
|
+ <div v-html="resultText" class="result-text"></div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </el-dialog>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import { orgTestApi } from "../api";
|
|
|
|
+export default {
|
|
|
|
+ name: "ocr-test",
|
|
|
|
+ props: {
|
|
|
|
+ curRow: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default() {
|
|
|
|
+ return {};
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ modalIsShow: false,
|
|
|
|
+ file: null,
|
|
|
|
+ imageUrl: "",
|
|
|
|
+ type: "GENERAL",
|
|
|
|
+ resultText: "",
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ title() {
|
|
|
|
+ return `应用nginx配置-${this.app.name}`;
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ async visibleChange(visible) {
|
|
|
|
+ this.file = null;
|
|
|
|
+ this.imageUrl = "";
|
|
|
|
+ this.type = "GENERAL";
|
|
|
|
+ },
|
|
|
|
+ cancel() {
|
|
|
|
+ this.modalIsShow = false;
|
|
|
|
+ },
|
|
|
|
+ open() {
|
|
|
|
+ this.modalIsShow = true;
|
|
|
|
+ },
|
|
|
|
+ handleSuccess(res, file) {
|
|
|
|
+ console.log("handleSuccess", file);
|
|
|
|
+ },
|
|
|
|
+ beforeUpload(file) {
|
|
|
|
+ const isLt20M = file.size / 1024 / 1024 < 20;
|
|
|
|
+ if (!isLt20M) {
|
|
|
|
+ this.$message.error("上传头像图片大小不能超过 20MB!");
|
|
|
|
+ }
|
|
|
|
+ return isLt20M;
|
|
|
|
+ },
|
|
|
|
+ submit() {
|
|
|
|
+ this.$refs.upload.submit();
|
|
|
|
+ },
|
|
|
|
+ customSubmit(option) {
|
|
|
|
+ this.resultText = "";
|
|
|
|
+ orgTestApi({
|
|
|
|
+ id: this.curRow.id,
|
|
|
|
+ type: this.type,
|
|
|
|
+ image: option.file,
|
|
|
|
+ }).then((res) => {
|
|
|
|
+ if (res && res.text) {
|
|
|
|
+ let initText = (res.text || "").replaceAll(/\n/g, "<br />");
|
|
|
|
+ this.writing(0, initText);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ onChange(file, fileList) {
|
|
|
|
+ this.imageUrl = "";
|
|
|
|
+ console.log("file", file);
|
|
|
|
+ this.file = file.raw;
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.imageUrl = URL.createObjectURL(file.raw);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ writing(index, data) {
|
|
|
|
+ if (index < data.length) {
|
|
|
|
+ this.resultText = this.resultText + data[index];
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ this.writing(++index, data);
|
|
|
|
+ }, 20);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+<style lang="scss">
|
|
|
|
+.ocr-test-dialog {
|
|
|
|
+ .el-dialog__body {
|
|
|
|
+ height: calc(100vh - 2px);
|
|
|
|
+ .body {
|
|
|
|
+ height: 100%;
|
|
|
|
+ display: flex;
|
|
|
|
+ .left,
|
|
|
|
+ .right {
|
|
|
|
+ width: calc(50% - 10px);
|
|
|
|
+ background-color: #fff;
|
|
|
|
+ border-radius: 8px;
|
|
|
|
+ }
|
|
|
|
+ .right {
|
|
|
|
+ margin-left: 20px;
|
|
|
|
+ padding: 20px;
|
|
|
|
+ .result-text {
|
|
|
|
+ height: calc(100% - 44px);
|
|
|
|
+ overflow: auto;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ .left {
|
|
|
|
+ padding: 20px;
|
|
|
|
+ .avatar-uploader {
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 100%;
|
|
|
|
+ }
|
|
|
|
+ .avatar-uploader .el-upload {
|
|
|
|
+ // border: 1px dashed #d9d9d9;
|
|
|
|
+ border-radius: 6px;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+ position: relative;
|
|
|
|
+ overflow: hidden;
|
|
|
|
+ height: 100%;
|
|
|
|
+
|
|
|
|
+ .el-upload-dragger {
|
|
|
|
+ height: 100%;
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ align-items: center;
|
|
|
|
+ }
|
|
|
|
+ & .avatar {
|
|
|
|
+ max-width: 100%;
|
|
|
|
+ max-height: 100%;
|
|
|
|
+ display: block;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ .avatar-uploader .el-upload:hover {
|
|
|
|
+ border-color: #409eff;
|
|
|
|
+ }
|
|
|
|
+ .avatar-uploader-icon {
|
|
|
|
+ font-size: 50px;
|
|
|
|
+ color: #8c939d;
|
|
|
|
+ width: 178px;
|
|
|
|
+ height: 178px;
|
|
|
|
+ line-height: 178px;
|
|
|
|
+ text-align: center;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+</style>
|
|
|
|
+<style scoped lang="scss"></style>
|