OCRIdentify.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <div class="ocr-all">
  3. <div style="color: #606266;font-size: 15px;font-weight: 600;">PS:选择图片后,点击要需要识别类型!</div>
  4. <div class="ocr-box">
  5. <el-upload
  6. action="#"
  7. list-type="picture-card"
  8. :on-change="handleChangePicture"
  9. :auto-upload="false">
  10. <i slot="default" class="el-icon-plus"></i>
  11. <div slot="file" slot-scope="{file}">
  12. <img
  13. class="el-upload-list__item-thumbnail"
  14. :src="file.url" alt=""
  15. >
  16. <span class="el-upload-list__item-actions">
  17. <span
  18. class="el-upload-list__item-preview"
  19. @click="handlePictureCardPreview(file)"
  20. >
  21. <i class="el-icon-zoom-in"></i>
  22. </span>
  23. <!-- <span
  24. v-if="!disabled"
  25. class="el-upload-list__item-delete"
  26. @click="handleDownload(file)"
  27. >
  28. <i class="el-icon-download"></i>
  29. </span>
  30. <span
  31. v-if="!disabled"
  32. class="el-upload-list__item-delete"
  33. @click="handleRemove(file)"
  34. >
  35. <i class="el-icon-delete"></i>
  36. </span> -->
  37. </span>
  38. </div>
  39. </el-upload>
  40. <el-dialog :visible.sync="dialogVisible">
  41. <img width="100%" :src="dialogImageUrl" alt="">
  42. </el-dialog>
  43. </div>
  44. <div style="color: #606266;font-size: 15px;font-weight: 600;text-align: center;">上传图片只能是 JPG,PNG,BMP 格式!大小不能超过 7MB!</div>
  45. <el-row>
  46. <el-button type="primary" @click="license()">营业执照</el-button>
  47. <el-button type="primary" @click="IDcardR()">身份证-人像面</el-button>
  48. <el-button type="primary" @click="creditCode()">统一信用代码</el-button>
  49. <el-button type="primary" @click="IDcardG()">身份证-国徽面</el-button>
  50. <el-button type="primary" @click="driving()">行驶证</el-button>
  51. <el-button type="primary" @click="household()">户口本</el-button>
  52. <el-button type="primary" @click="deed()">房产证</el-button>
  53. <el-button type="primary" @click="Marriage()">结婚证</el-button>
  54. <el-button type="primary" @click="mainlandPassport()">大陆护照</el-button>
  55. <el-button type="primary" @click="universal()">通用印刷体</el-button>
  56. <el-button type="primary">营业执照(英文)</el-button>
  57. <el-button type="primary">统一信用代码(英文)</el-button>
  58. <el-button type="primary">身份证-人像面(英文)</el-button>
  59. <el-button type="primary">身份证-国徽面(英文)</el-button>
  60. <el-button type="primary">行驶证(英文)</el-button>
  61. <el-button type="primary">户口本(英文)</el-button>
  62. <!-- <el-button type="primary">户口本-成员页</el-button> -->
  63. <!-- <el-button type="primary">户口本-成员页(英文)</el-button> -->
  64. <el-button type="primary">房产证(英文)</el-button>
  65. <el-button type="primary">结婚证(英文)</el-button>
  66. <el-button type="primary">大陆护照(英文)</el-button>
  67. <el-button type="primary">通用印刷体(英文)</el-button>
  68. </el-row>
  69. </div>
  70. </template>
  71. <script>
  72. import { el } from '@fullcalendar/core/internal-common';
  73. export default {
  74. data() {
  75. return {
  76. token:'',
  77. userid:'',
  78. dialogImageUrl: '',
  79. dialogVisible: false,
  80. disabled: false,
  81. panduan:"",
  82. picBase64:''
  83. }
  84. },
  85. methods: {
  86. // handleRemove(file,) {
  87. // console.log(file);
  88. // file.status='cancel'
  89. // },
  90. handlePictureCardPreview(file) {
  91. this.dialogImageUrl = file.url;
  92. this.dialogVisible = true;
  93. },
  94. // handleDownload(file) {
  95. // console.log(file);
  96. // },
  97. handleChangePicture(file, fileList) {
  98. this.beforeAvatarUpload(file)
  99. if (fileList.length > 1) {
  100. fileList.splice(0, 1);
  101. }
  102. if(this.panduan){
  103. this.getBase64(file.raw).then(res => {
  104. this.picBase64=res
  105. console.log(res)
  106. });
  107. }
  108. },
  109. beforeAvatarUpload(file) {
  110. this.panduan=true;
  111. const isJPG = file.raw.type === 'image/jpeg';
  112. const isPNG = file.raw.type === 'image/png';
  113. const isWEBP = file.raw.type === 'image/webp';
  114. const isLt2M = file.size / 1024 / 1024 < 7;
  115. if (!isJPG&&!isPNG&&!isWEBP) {
  116. this.$message.error('上传图片只能是 JPG,PNG,BMP 格式!');
  117. this.panduan=false;
  118. }
  119. if (!isLt2M) {
  120. this.$message.error('上传图片大小不能超过 7MB!');
  121. this.panduan=false;
  122. }
  123. return isJPG && isLt2M;
  124. },
  125. getBase64(file) {
  126. return new Promise(function (resolve, reject) {
  127. const reader = new FileReader()
  128. let imgResult = ''
  129. reader.readAsDataURL(file)
  130. reader.onload = function () {
  131. imgResult = reader.result
  132. }
  133. reader.onerror = function (error) {
  134. reject(error)
  135. }
  136. reader.onloadend = function () {
  137. resolve(imgResult)
  138. }
  139. })
  140. },
  141. //身份证人像面
  142. IDcardR(){
  143. var url="/api/TencentOCR/GetIDCard"
  144. var that=this
  145. if(that.panduan){
  146. that.fullscreenLoading = true;
  147. this.$axios({
  148. method: 'post',
  149. url:url,
  150. headers:{
  151. Authorization:'Bearer '+this.token
  152. },
  153. data:{
  154. portType: 1,
  155. userId:that.userid,
  156. language:'en',
  157. picBase64:that.picBase64,
  158. cardSide:0
  159. }
  160. }).then(function(res){
  161. if(res.data.code==200){
  162. console.log(res)
  163. that.$message({
  164. message: res.data.msg,
  165. type: 'success'
  166. });
  167. // window.open(res.data.data.downUrl)
  168. }else{
  169. that.$message({
  170. message: res.data.msg,
  171. type: 'warning'
  172. });
  173. }
  174. })
  175. }else{
  176. this.$message.error('请检查图片是否为此类型!');
  177. }
  178. },
  179. //身份证国徽面
  180. IDcardG(){
  181. var url="/api/TencentOCR/GetIDCard"
  182. var that=this
  183. if(that.panduan){
  184. that.fullscreenLoading = true;
  185. this.$axios({
  186. method: 'post',
  187. url:url,
  188. headers:{
  189. Authorization:'Bearer '+this.token
  190. },
  191. data:{
  192. portType: 1,
  193. userId:that.userid,
  194. picBase64:that.picBase64,
  195. cardSide:1
  196. }
  197. }).then(function(res){
  198. if(res.data.code==200){
  199. console.log(res)
  200. that.$message({
  201. message: res.data.msg,
  202. type: 'success'
  203. });
  204. // window.open(res.data.data.downUrl)
  205. }else{
  206. that.$message({
  207. message: res.data.msg,
  208. type: 'warning'
  209. });
  210. }
  211. })
  212. }else{
  213. this.$message.error('请检查图片是否为此类型!');
  214. }
  215. },
  216. //营业执照
  217. license(){
  218. var url="/api/TencentOCR/GetBizLicenseOCR"
  219. var that=this
  220. if(that.panduan){
  221. that.fullscreenLoading = true;
  222. this.$axios({
  223. method: 'post',
  224. url:url,
  225. headers:{
  226. Authorization:'Bearer '+this.token
  227. },
  228. data:{
  229. picBase64:that.picBase64,
  230. }
  231. }).then(function(res){
  232. if(res.data.code==200){
  233. console.log(res)
  234. that.$message({
  235. message: res.data.msg,
  236. type: 'success'
  237. });
  238. // window.open(res.data.data.downUrl)
  239. }else{
  240. that.$message({
  241. message: res.data.msg,
  242. type: 'warning'
  243. });
  244. }
  245. })
  246. }else{
  247. this.$message.error('请检查图片是否为此类型!');
  248. }
  249. },
  250. //统一信用代码
  251. creditCode(){
  252. var url="/api/TencentOCR/GetOrgCodeCertOCR"
  253. var that=this
  254. if(that.panduan){
  255. that.fullscreenLoading = true;
  256. this.$axios({
  257. method: 'post',
  258. url:url,
  259. headers:{
  260. Authorization:'Bearer '+this.token
  261. },
  262. data:{
  263. picBase64:that.picBase64,
  264. }
  265. }).then(function(res){
  266. if(res.data.code==200){
  267. console.log(res)
  268. that.$message({
  269. message: res.data.msg,
  270. type: 'success'
  271. });
  272. window.open(res.data.data.downUrl)
  273. }else{
  274. that.$message({
  275. message: res.data.msg,
  276. type: 'warning'
  277. });
  278. }
  279. })
  280. }else{
  281. this.$message.error('请检查图片是否为此类型!');
  282. }
  283. },
  284. //行驶证
  285. driving(){
  286. var url="/api/TencentOCR/GetVehicleLicense"
  287. var that=this
  288. if(that.panduan){
  289. that.fullscreenLoading = true;
  290. this.$axios({
  291. method: 'post',
  292. url:url,
  293. headers:{
  294. Authorization:'Bearer '+this.token
  295. },
  296. data:{
  297. picBase64:that.picBase64,
  298. cardSide:0
  299. }
  300. }).then(function(res){
  301. if(res.data.code==200){
  302. console.log(res)
  303. that.$message({
  304. message: res.data.msg,
  305. type: 'success'
  306. });
  307. // window.open(res.data.data.downUrl)
  308. }else{
  309. that.$message({
  310. message: res.data.msg,
  311. type: 'warning'
  312. });
  313. }
  314. })
  315. }else{
  316. this.$message.error('请检查图片是否为此类型!');
  317. }
  318. },
  319. //户口本
  320. household(){
  321. var url="/api/TencentOCR/GetResidenceBookletOCR"
  322. var that=this
  323. if(that.panduan){
  324. that.fullscreenLoading = true;
  325. this.$axios({
  326. method: 'post',
  327. url:url,
  328. headers:{
  329. Authorization:'Bearer '+this.token
  330. },
  331. data:{
  332. picBase64:that.picBase64,
  333. }
  334. }).then(function(res){
  335. if(res.data.code==200){
  336. console.log(res)
  337. that.$message({
  338. message: res.data.msg,
  339. type: 'success'
  340. });
  341. // window.open(res.data.data.downUrl)
  342. }else{
  343. that.$message({
  344. message: res.data.msg,
  345. type: 'warning'
  346. });
  347. }
  348. })
  349. }else{
  350. this.$message.error('请检查图片是否为此类型!');
  351. }
  352. },
  353. //房产证
  354. deed(){
  355. var url="/api/TencentOCR/GetPropOwnerCert"
  356. var that=this
  357. if(that.panduan){
  358. that.fullscreenLoading = true;
  359. this.$axios({
  360. method: 'post',
  361. url:url,
  362. headers:{
  363. Authorization:'Bearer '+this.token
  364. },
  365. data:{
  366. picBase64:that.picBase64,
  367. }
  368. }).then(function(res){
  369. if(res.data.code==200){
  370. console.log(res)
  371. that.$message({
  372. message: res.data.msg,
  373. type: 'success'
  374. });
  375. // window.open(res.data.data.downUrl)
  376. }else{
  377. that.$message({
  378. message: res.data.msg,
  379. type: 'warning'
  380. });
  381. }
  382. })
  383. }else{
  384. this.$message.error('请检查图片是否为此类型!');
  385. }
  386. },
  387. //结婚证
  388. Marriage(){
  389. var url="/api/TencentOCR/GetMarriageLicense"
  390. var that=this
  391. if(that.panduan){
  392. that.fullscreenLoading = true;
  393. this.$axios({
  394. method: 'post',
  395. url:url,
  396. headers:{
  397. Authorization:'Bearer '+this.token
  398. },
  399. data:{
  400. picBase64:that.picBase64,
  401. }
  402. }).then(function(res){
  403. if(res.data.code==200){
  404. console.log(res)
  405. that.$message({
  406. message: res.data.msg,
  407. type: 'success'
  408. });
  409. // window.open(res.data.data.downUrl)
  410. }else{
  411. that.$message({
  412. message: res.data.msg,
  413. type: 'warning'
  414. });
  415. }
  416. })
  417. }else{
  418. this.$message.error('请检查图片是否为此类型!');
  419. }
  420. },
  421. //结婚证
  422. mainlandPassport(){
  423. var url="/api/TencentOCR/GetPassport"
  424. var that=this
  425. if(that.panduan){
  426. that.fullscreenLoading = true;
  427. this.$axios({
  428. method: 'post',
  429. url:url,
  430. headers:{
  431. Authorization:'Bearer '+this.token
  432. },
  433. data:{
  434. picBase64:that.picBase64,
  435. }
  436. }).then(function(res){
  437. if(res.data.code==200){
  438. console.log(res)
  439. that.$message({
  440. message: res.data.msg,
  441. type: 'success'
  442. });
  443. // window.open(res.data.data.downUrl)
  444. }else{
  445. that.$message({
  446. message: res.data.msg,
  447. type: 'warning'
  448. });
  449. }
  450. })
  451. }else{
  452. this.$message.error('请检查图片是否为此类型!');
  453. }
  454. },
  455. //通用印刷体
  456. universal(){
  457. var url="/api/TencentOCR/GetGeneralBasic"
  458. var that=this
  459. if(that.panduan){
  460. that.fullscreenLoading = true;
  461. this.$axios({
  462. method: 'post',
  463. url:url,
  464. headers:{
  465. Authorization:'Bearer '+this.token
  466. },
  467. data:{
  468. picBase64:that.picBase64,
  469. }
  470. }).then(function(res){
  471. if(res.data.code==200){
  472. console.log(res)
  473. that.$message({
  474. message: res.data.msg,
  475. type: 'success'
  476. });
  477. // window.open(res.data.data.downUrl)
  478. }else{
  479. that.$message({
  480. message: res.data.msg,
  481. type: 'warning'
  482. });
  483. }
  484. })
  485. }else{
  486. this.$message.error('请检查图片是否为此类型!');
  487. }
  488. },
  489. },
  490. mounted(){
  491. this.token=JSON.parse(localStorage.getItem('userinif')).token;
  492. this.userid=JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
  493. }
  494. }
  495. </script>
  496. <style>
  497. .ocr-all {
  498. background-color: #fff;
  499. padding: 10px;
  500. box-shadow: 0 0 5px #0005;
  501. border-radius: 10px;
  502. }
  503. .ocr-box .el-upload-list--picture-card .el-upload-list__item{
  504. display: inline-flex;
  505. }
  506. .ocr-box{
  507. display: flex;
  508. justify-content: center;
  509. margin-top: 180px;
  510. }
  511. .ocr-all .el-button--primary{
  512. width: 160px;
  513. margin: 10px 0px;
  514. }
  515. .ocr-all .el-button+.el-button{
  516. margin-left: 0px;
  517. }
  518. .ocr-all .el-row{
  519. width: 44%;
  520. margin: 0 auto;
  521. margin-top: 30px;
  522. margin-bottom: 180px;
  523. display: flex;
  524. flex-wrap: wrap;
  525. justify-content: space-between;
  526. }
  527. .ocr-all .el-row::after, .ocr-all .el-row::before{
  528. content: none;
  529. }
  530. </style>