微信小程序点击按钮弹窗生成二维码图片+长按识别

框架:uni-app

库:Painter 

ui框架:uView 1.X

<u-modal class="show-close" v-model="showClose" :title="title" :confirm-style="confirmStyle" confirm-text="确认" @confirm="confirmClose">
      <view class="slot-content">
        <view class="tit">温馨提示</view>
        <view class="con">请长按识别二维码跳转公众号或长按保存图片并通过微信扫码领取</view>
        <view class="img">
          <u-image width="280rpx" height="280rpx" :src="receiveSrc" :fade="true" duration="450" show-menu-by-longpress>
            <u-loading slot="error"></u-loading>
            <u-loading slot="loading"></u-loading>
          </u-image>
        </view>
      </view>
    </u-modal>


    <lPainter customStyle='position: absolute; left: -9999rpx;' :palette="base" @imgOK="onImgOK" />

 u-modal 为uView弹窗,弹窗内容显示生成的二维码图片

引入Painter组件(需事先下载库到components)

import lPainter from '@/packageA/components/ape-painter/painter.vue';

components: {
   lPainter
},
draw(obj) {
      this.base = {
        width: '280rpx',
        height: '280rpx',
        background: '#fff',//画布背景色
        views: [
          {
            type: 'qrcode',
            content: obj.body,
            css: {
              width: "280rpx",
              height: "280rpx",
              top: "0px",
              left: "0px",
              rotate: "0",
              borderRadius: ""
            }
          }
        ]
      }
    },

获取数据后,调用this.draw()方法,绘制canvas,这里使用的painter内置的生成二维码qrcode,

onImgOK(e){
      this.receiveSrc = e.detail.path
    },

绘制成功后,onImgOk回调中获取生成图片地址

u-image组件中绑定receiveSrc,并开启show-menu-by-longpress长按识别

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值