OCRIdentify.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. 3
  134. reader.onerror = function (error) {
  135. reject(error)
  136. }
  137. reader.onloadend = function () {
  138. resolve(imgResult)
  139. }
  140. })
  141. },
  142. //身份证人像面
  143. IDcardR(){
  144. var url="/api/TencentOCR/GetIDCard"
  145. var that=this
  146. if(that.panduan){
  147. that.fullscreenLoading = true;
  148. this.$axios({
  149. method: 'post',
  150. url:url,
  151. headers:{
  152. Authorization:'Bearer '+this.token
  153. },
  154. data:{
  155. portType: 1,
  156. userId:that.userid,
  157. language:'en',
  158. picBase64:that.picBase64,
  159. cardSide:0
  160. }
  161. }).then(function(res){
  162. if(res.data.code==200){
  163. console.log(res)
  164. that.$message({
  165. message: res.data.msg,
  166. type: 'success'
  167. });
  168. // window.open(res.data.data.downUrl)
  169. }else{
  170. that.$message({
  171. message: res.data.msg,
  172. type: 'warning'
  173. });
  174. }
  175. })
  176. }else{
  177. this.$message.error('请检查图片是否为此类型!');
  178. }
  179. },
  180. //身份证国徽面
  181. IDcardG(){
  182. var url="/api/TencentOCR/GetIDCard"
  183. var that=this
  184. if(that.panduan){
  185. that.fullscreenLoading = true;
  186. this.$axios({
  187. method: 'post',
  188. url:url,
  189. headers:{
  190. Authorization:'Bearer '+this.token
  191. },
  192. data:{
  193. portType: 1,
  194. userId:that.userid,
  195. picBase64:that.picBase64,
  196. cardSide:1
  197. }
  198. }).then(function(res){
  199. if(res.data.code==200){
  200. console.log(res)
  201. that.$message({
  202. message: res.data.msg,
  203. type: 'success'
  204. });
  205. // window.open(res.data.data.downUrl)
  206. }else{
  207. that.$message({
  208. message: res.data.msg,
  209. type: 'warning'
  210. });
  211. }
  212. })
  213. }else{
  214. this.$message.error('请检查图片是否为此类型!');
  215. }
  216. },
  217. //营业执照
  218. license(){
  219. var url="/api/TencentOCR/GetBizLicenseOCR"
  220. var that=this
  221. if(that.panduan){
  222. that.fullscreenLoading = true;
  223. this.$axios({
  224. method: 'post',
  225. url:url,
  226. headers:{
  227. Authorization:'Bearer '+this.token
  228. },
  229. data:{
  230. picBase64:that.picBase64,
  231. }
  232. }).then(function(res){
  233. if(res.data.code==200){
  234. console.log(res)
  235. that.$message({
  236. message: res.data.msg,
  237. type: 'success'
  238. });
  239. // window.open(res.data.data.downUrl)
  240. }else{
  241. that.$message({
  242. message: res.data.msg,
  243. type: 'warning'
  244. });
  245. }
  246. })
  247. }else{
  248. this.$message.error('请检查图片是否为此类型!');
  249. }
  250. },
  251. //统一信用代码
  252. creditCode(){
  253. var url="/api/TencentOCR/GetOrgCodeCertOCR"
  254. var that=this
  255. if(that.panduan){
  256. that.fullscreenLoading = true;
  257. this.$axios({
  258. method: 'post',
  259. url:url,
  260. headers:{
  261. Authorization:'Bearer '+this.token
  262. },
  263. data:{
  264. picBase64:that.picBase64,
  265. }
  266. }).then(function(res){
  267. if(res.data.code==200){
  268. console.log(res)
  269. that.$message({
  270. message: res.data.msg,
  271. type: 'success'
  272. });
  273. window.open(res.data.data.downUrl)
  274. }else{
  275. that.$message({
  276. message: res.data.msg,
  277. type: 'warning'
  278. });
  279. }
  280. })
  281. }else{
  282. this.$message.error('请检查图片是否为此类型!');
  283. }
  284. },
  285. //行驶证
  286. driving(){
  287. var url="/api/TencentOCR/GetVehicleLicense"
  288. var that=this
  289. if(that.panduan){
  290. that.fullscreenLoading = true;
  291. this.$axios({
  292. method: 'post',
  293. url:url,
  294. headers:{
  295. Authorization:'Bearer '+this.token
  296. },
  297. data:{
  298. picBase64:that.picBase64,
  299. cardSide:0
  300. }
  301. }).then(function(res){
  302. if(res.data.code==200){
  303. console.log(res)
  304. that.$message({
  305. message: res.data.msg,
  306. type: 'success'
  307. });
  308. // window.open(res.data.data.downUrl)
  309. }else{
  310. that.$message({
  311. message: res.data.msg,
  312. type: 'warning'
  313. });
  314. }
  315. })
  316. }else{
  317. this.$message.error('请检查图片是否为此类型!');
  318. }
  319. },
  320. //户口本
  321. household(){
  322. var url="/api/TencentOCR/GetResidenceBookletOCR"
  323. var that=this
  324. if(that.panduan){
  325. that.fullscreenLoading = true;
  326. this.$axios({
  327. method: 'post',
  328. url:url,
  329. headers:{
  330. Authorization:'Bearer '+this.token
  331. },
  332. data:{
  333. picBase64:that.picBase64,
  334. }
  335. }).then(function(res){
  336. if(res.data.code==200){
  337. console.log(res)
  338. that.$message({
  339. message: res.data.msg,
  340. type: 'success'
  341. });
  342. // window.open(res.data.data.downUrl)
  343. }else{
  344. that.$message({
  345. message: res.data.msg,
  346. type: 'warning'
  347. });
  348. }
  349. })
  350. }else{
  351. this.$message.error('请检查图片是否为此类型!');
  352. }
  353. },
  354. //房产证
  355. deed(){
  356. var url="/api/TencentOCR/GetPropOwnerCert"
  357. var that=this
  358. if(that.panduan){
  359. that.fullscreenLoading = true;
  360. this.$axios({
  361. method: 'post',
  362. url:url,
  363. headers:{
  364. Authorization:'Bearer '+this.token
  365. },
  366. data:{
  367. picBase64:that.picBase64,
  368. }
  369. }).then(function(res){
  370. if(res.data.code==200){
  371. console.log(res)
  372. that.$message({
  373. message: res.data.msg,
  374. type: 'success'
  375. });
  376. // window.open(res.data.data.downUrl)
  377. }else{
  378. that.$message({
  379. message: res.data.msg,
  380. type: 'warning'
  381. });
  382. }
  383. })
  384. }else{
  385. this.$message.error('请检查图片是否为此类型!');
  386. }
  387. },
  388. //结婚证
  389. Marriage(){
  390. var url="/api/TencentOCR/GetMarriageLicense"
  391. var that=this
  392. if(that.panduan){
  393. that.fullscreenLoading = true;
  394. this.$axios({
  395. method: 'post',
  396. url:url,
  397. headers:{
  398. Authorization:'Bearer '+this.token
  399. },
  400. data:{
  401. picBase64:that.picBase64,
  402. }
  403. }).then(function(res){
  404. if(res.data.code==200){
  405. console.log(res)
  406. that.$message({
  407. message: res.data.msg,
  408. type: 'success'
  409. });
  410. // window.open(res.data.data.downUrl)
  411. }else{
  412. that.$message({
  413. message: res.data.msg,
  414. type: 'warning'
  415. });
  416. }
  417. })
  418. }else{
  419. this.$message.error('请检查图片是否为此类型!');
  420. }
  421. },
  422. //结婚证
  423. mainlandPassport(){
  424. var url="/api/TencentOCR/GetPassport"
  425. var that=this
  426. if(that.panduan){
  427. that.fullscreenLoading = true;
  428. this.$axios({
  429. method: 'post',
  430. url:url,
  431. headers:{
  432. Authorization:'Bearer '+this.token
  433. },
  434. data:{
  435. picBase64:that.picBase64,
  436. }
  437. }).then(function(res){
  438. if(res.data.code==200){
  439. console.log(res)
  440. that.$message({
  441. message: res.data.msg,
  442. type: 'success'
  443. });
  444. // window.open(res.data.data.downUrl)
  445. }else{
  446. that.$message({
  447. message: res.data.msg,
  448. type: 'warning'
  449. });
  450. }
  451. })
  452. }else{
  453. this.$message.error('请检查图片是否为此类型!');
  454. }
  455. },
  456. //通用印刷体
  457. universal(){
  458. var url="/api/TencentOCR/GetGeneralBasic"
  459. var that=this
  460. if(that.panduan){
  461. that.fullscreenLoading = true;
  462. this.$axios({
  463. method: 'post',
  464. url:url,
  465. headers:{
  466. Authorization:'Bearer '+this.token
  467. },
  468. data:{
  469. picBase64:that.picBase64,
  470. }
  471. }).then(function(res){
  472. if(res.data.code==200){
  473. console.log(res)
  474. that.$message({
  475. message: res.data.msg,
  476. type: 'success'
  477. });
  478. // window.open(res.data.data.downUrl)
  479. }else{
  480. that.$message({
  481. message: res.data.msg,
  482. type: 'warning'
  483. });
  484. }
  485. })
  486. }else{
  487. this.$message.error('请检查图片是否为此类型!');
  488. }
  489. },
  490. },
  491. mounted(){
  492. this.token=JSON.parse(localStorage.getItem('userinif')).token;
  493. this.userid=JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
  494. }
  495. }
  496. </script>
  497. <style>
  498. .ocr-all {
  499. background-color: #fff;
  500. padding: 10px;
  501. box-shadow: 0 0 5px #0005;
  502. border-radius: 10px;
  503. }
  504. .ocr-box .el-upload-list--picture-card .el-upload-list__item{
  505. display: inline-flex;
  506. }
  507. .ocr-box{
  508. display: flex;
  509. justify-content: center;
  510. margin-top: 180px;
  511. }
  512. .ocr-all .el-button--primary{
  513. width: 160px;
  514. margin: 10px 0px;
  515. }
  516. .ocr-all .el-button+.el-button{
  517. margin-left: 0px;
  518. }
  519. .ocr-all .el-row{
  520. width: 44%;
  521. margin: 0 auto;
  522. margin-top: 30px;
  523. margin-bottom: 180px;
  524. display: flex;
  525. flex-wrap: wrap;
  526. justify-content: space-between;
  527. }
  528. .ocr-all .el-row::after, .ocr-all .el-row::before{
  529. content: none;
  530. }
  531. </style>