微信小程序?qū)崿F(xiàn)預(yù)約生成二維碼功能
業(yè)務(wù)需求:點(diǎn)擊預(yù)約按鈕即可生成二維碼憑碼入校參觀~

一.創(chuàng)建頁面
如下是博主自己寫的wxml:
<swiper indicator-dots indicator-color="white" indicator-active-color="blue" autoplay interval="2000" circular > <!-- 這部分是實(shí)現(xiàn)輪播圖下面的小圓點(diǎn),可以根據(jù)兩個(gè)不同的屬性來分別更改樣式 --> <swiper-item> <image src="/image/1606976870484.jpg"></image> </swiper-item> <swiper-item> <image src="/image/1606976921531.jpg"></image> </swiper-item> <swiper-item> <image src="/image/1606976936035.png"></image> </swiper-item> <swiper-item> <image src="/image/111.jpg"></image> </swiper-item> <swiper-item> <image src="/image/222.jpg"></image> </swiper-item> </swiper> <button class="mybt" bindtap="yuyue">預(yù)約參觀?</button> <canvas type="2d"id="myQrcode"></canvas>
以及wxss:
/* pages/youke/youke.wxss */
page{
background-color:#f3ffff;
}
swiper{
margin-top: 50rpx;
width: 100%;
height: 430rpx;
border-radius: 30rpx;
}
swiper-item {
width: 100%;
height: 100%;
border-radius: 50rpx;
}
.mybt{
margin-top: 100rpx;
width:300rpx;
background-color: rgb(41, 113, 248);
color: rgb(255, 255, 255);
}
view{
font-size: 45rpx;
text-align: center;
margin-top: 100rpx;
}
canvas{
width: 230rpx;
height: 230rpx;
margin-top: 100rpx;
margin-left: 260rpx;
}二.下載并配置第三方庫
去Gitee下載工具包:
二維碼工具包
http://? https://gitee.com/WeiDoctor/weapp-qrcode-canvas-2d
?下載zip:


將dist文件夾中的js文件全部復(fù)制到utils目錄下:

三.完成業(yè)務(wù)
如下代碼必須完整的導(dǎo)入再頁面JS的最頂部:
import drawQrcode from '../../utils/weapp.qrcode.esm.js'
如下是完整的代碼:
// pages/youke/youke.js
import drawQrcode from '../../utils/weapp.qrcode.esm.js'
Page({
data: {
yynum:500,
randomNum:"0"
},
onLoad() {
},
onReady() {
},
onShow() {
},
onHide() {
},
onUnload() {
},
onPullDownRefresh() {
},
onReachBottom() {
},
onShareAppMessage() {
},
yuyue(msg){
// console.log("lll")
if(this.data.yynum>0&&this.data.randomNum=="0")
{
wx.showToast({
icon: 'success',
title: '預(yù)約成功~',
})
let y=this.data.yynum;
y--;
this.setData({
yynum:y
})
let r=(Math.random()*1).toFixed(4)*10000
this.setData({
randomNum:r
}),
console.log(r);
const query = wx.createSelectorQuery()
query.select('#myQrcode')
.fields({
node: true,
size: true
})
.exec((res) => {
var canvas = res[0].node
drawQrcode({
canvas: canvas,
canvasId: 'myQrcode',
width: 260,
padding: 30,
background: '#4169E1',
foreground: '#ffffff',
text: '個(gè)人二維碼信息',
})
wx.canvasToTempFilePath({
canvasId: 'myQrcode',
canvas: canvas,
x: 0,
y: 0,
width: 260,
height: 260,
destWidth: 260,
destHeight: 260,
})
})
}
else if(this.data.randomNum!="0")
{
wx.showToast({
icon: 'error',
title: '禁止重復(fù)預(yù)約~',
})
}
else{
wx.showToast({
icon: 'error',
title: '很抱歉,已無預(yù)約名額~',
})
}
}
})點(diǎn)擊預(yù)約即可成功生成二維碼~

到此這篇關(guān)于微信小程序?qū)崿F(xiàn)預(yù)約生成二維碼的文章就介紹到這了,更多相關(guān)小程序預(yù)約生成二維碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解XMLHttpRequest(一)同步請(qǐng)求和異步請(qǐng)求
這篇文章主要為大家詳細(xì)介紹了XMLHttpRequest 同步請(qǐng)求和異步請(qǐng)求,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
JS運(yùn)動(dòng)特效之鏈?zhǔn)竭\(yùn)動(dòng)分析
這篇文章主要介紹了JS運(yùn)動(dòng)特效之鏈?zhǔn)竭\(yùn)動(dòng),結(jié)合實(shí)例形式分析了javascript鏈?zhǔn)竭\(yùn)動(dòng)的原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-01-01
一文學(xué)會(huì)JavaScript如何手寫防抖節(jié)流
其實(shí)防抖和節(jié)流不僅僅在面試中會(huì)讓大家手寫,在實(shí)際項(xiàng)目中也可以起到性能優(yōu)化的作用,所以還是很有必要掌握的。這篇文章就帶大家徹底學(xué)會(huì)JavaScript手寫防抖節(jié)流,希望對(duì)大家有所幫助2022-11-11
javascript+css實(shí)現(xiàn)單擊顏色褪去效果
javascript+css實(shí)現(xiàn)單擊顏色褪去效果...2007-08-08
axios/fetch實(shí)現(xiàn)stream流式請(qǐng)求示例詳解
這篇文章主要為大家介紹了axios/fetch實(shí)現(xiàn)stream流式請(qǐng)求示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09
JavaScript實(shí)現(xiàn)單擊下拉框選擇直接跳轉(zhuǎn)頁面的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)單擊下拉框選擇直接跳轉(zhuǎn)頁面的方法,涉及javascript控制頁面跳轉(zhuǎn)的相關(guān)技巧,需要的朋友可以參考下2015-07-07
js時(shí)間戳轉(zhuǎn)yyyy-MM-dd HH-mm-ss工具類詳解
這篇文章主要介紹了js時(shí)間戳轉(zhuǎn)yyyy-MM-dd HH-mm-ss工具類,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
JavaScript實(shí)現(xiàn)select添加option
這篇文章主要介紹了JavaScript為select添加option的方法和示例,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2015-07-07

