• url上传图标转base64


    methods:{

     // 发票验证-OCR发票查验 由于跨域,只能传网上预览
        getInvoiceOcr() {
          this.InvoiceLoading = true
          const base1 = this.baseurl + ':9527/mystatic/ce/capitalexpend/' + this.detailDialog.fileList[0].url
          this.strimagebase64 = ''
          var that = this
          var image = new Image()
          image.src = base1 + '?v=' + Math.random() // 处理缓存
          image.crossOrigin = '*' // 支持跨域图片
          image.onload = function() {
            var base64 = that.drawBase64Image(image)
            that.strimagebase64 = base64.split(',')[1]
            // 转完base64才能走接口
            if (that.strimagebase64) {
              invoiceOCR({
                'lngproductid': 315,
                'lngreceipttypeid': 2,
                'strqrcode': '',
                'strfilepath': '/mystatic/ce/capitalexpend/' + that.detailDialog.fileList[0].url, // 后台返回图片路径拼接 1234.png
                'strfilerealname': that.detailDialog.fileList[0].name, // 上传图片的名称 通行费.png
                'imgurl': that.strimagebase64 // 'BASE64'
              }).then(res => {
                that.InvoiceLoading = false
                if (res.code === 20000) {
                  that.$message.success(res.message)
                  that.detailDialog.fileList[0].intinvoicestatus = 0
                  that.detailDialog.fileList[0].strinvoicemsg = res.message
                } else {
                  that.detailDialog.fileList[0].intinvoicestatus = 1
                  that.detailDialog.fileList[0].strinvoicemsg = res.message
                }
              })
            }
          }
        },
        // this.getBase64Image('http://wwww.test/test.png')
        // 参数是图片的URL地址
        // getBase64Image(url) {
        //   this.strimagebase64 = ''
        //   var that = this
        //   var image = new Image()
        //   image.src = url + '?v=' + Math.random() // 处理缓存
        //   image.crossOrigin = '*' // 支持跨域图片
        //   image.onload = function() {
        //     var base64 = that.drawBase64Image(image)
        //     that.strimagebase64 = base64.split(',')[1]
        //   }
        // },
        drawBase64Image(img) {
          var canvas = document.createElement('canvas')
          canvas.width = img.width
          canvas.height = img.height
          var ctx = canvas.getContext('2d')
          ctx.drawImage(img, 0, 0, img.width, img.height)
          var dataURL = canvas.toDataURL('image/png')
          return dataURL
        }
    }
  • 相关阅读:
    luogu P4342 [IOI1998]Polygon
    luogu P2051 [AHOI2009]中国象棋
    luogu P3304 [SDOI2013]直径
    luogu P1776 宝物筛选_NOI导刊2010提高(02)
    luogu P2900 [USACO08MAR]土地征用Land Acquisition
    CF1009E [Intercity Travelling]
    luogu P4360 [CEOI2004]锯木厂选址
    luogu P1268 树的重量
    centos7扩展根分区
    tcpdump抓包工具的使用
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/13396863.html
Copyright © 2020-2023  润新知