微信小程序條碼、二維碼生成模塊


代碼地址如下:
http://www.demodashi.com/demo/13994.html

一、前期准備工作

軟件環境:微信開發者工具
官方下載地址:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

1、基本需求。
  • 實現一維條碼,二維碼的快速生成
2、案例目錄結構

二、程序實現具體步驟

1.條碼index.wxml代碼
<!--index.wxml-->
<view class="container page">
  <view class="panel">
    <view class="header">
    </view>
    <view class="barcode">
      <view class="barnum">{{code}}</view>
      <canvas canvas-id="barcode" />
    </view>
    <view class="qrcode">
      <canvas canvas-id="qrcode" />
    </view>
  </view>
</view>

2.條碼index.wxss代碼
/**index.wxss**/
page {
    background-color: #439057;
}

.page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.container {
	padding-bottom: 10rpx;
}

.panel {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    box-sizing: border-box;
    width: 710rpx;
    margin-top: 40rpx;
    border-radius: 10rpx;
    background-color: #fff;
}

.header {
    height: 140rpx;
    background-color: #f0f0f0;
    border-radius: 10rpx 10rpx 0 0;
}

.barcode {
    display: flex;
    height: 320rpx;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.barnum {
    width: 670rpx;
    height: 100rpx;
    line-height: 100rpx;
    font-size: 38rpx;
    font-weight: bold;
    text-align: center;
    letter-spacing: 10rpx;
    white-space: nowrap;
}

.barcode > canvas {
    width: 680rpx;
    height: 200rpx;  
}

.qrcode {
    height: 420rpx;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.qrcode > canvas {
    width: 420rpx;
    height: 420rpx;
}

3.條碼index.js邏輯代碼
//index.js
var wxbarcode = require('../../utils/index.js');

Page({

    data: {
        code: 'http://blog.geekxz.com'
    },

    onLoad: function() {
        wxbarcode.barcode('barcode', 'http://blog.geekxz.com', 680, 200);
        wxbarcode.qrcode('qrcode', 'http://blog.geekxz.com', 420, 420);
    }
})

三、案例運行效果圖

四、總結與備注

暫無
微信小程序條碼、二維碼生成模塊

代碼地址如下:
http://www.demodashi.com/demo/13994.html

注:本文著作權歸作者,由demo大師代發,拒絕轉載,轉載需要作者授權


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM