• 微信小程序实现预约生成二维码


    业务需求:点击预约按钮即可生成二维码凭码入校参观~

    7c312412b3934664bb0f6e2d4e6e316e.png

    一.创建页面

    如下是博主自己写的wxml

    1. <swiper indicator-dots indicator-color="white" indicator-active-color="blue"
    2. autoplay interval="2000" circular
    3. >
    4. <swiper-item>
    5. <image src="/image/1606976870484.jpg">image>
    6. swiper-item>
    7. <swiper-item>
    8. <image src="/image/1606976921531.jpg">image>
    9. swiper-item>
    10. <swiper-item>
    11. <image src="/image/1606976936035.png">image>
    12. swiper-item>
    13. <swiper-item>
    14. <image src="/image/111.jpg">image>
    15. swiper-item>
    16. <swiper-item>
    17. <image src="/image/222.jpg">image>
    18. swiper-item>
    19. swiper>
    20. <button class="mybt" bindtap="yuyue">预约参观?button>
    21. <canvas type="2d"id="myQrcode">canvas>

    以及wxss

    1. /* pages/youke/youke.wxss */
    2. page{
    3. background-color:#f3ffff;
    4. }
    5. swiper{
    6. margin-top: 50rpx;
    7. width: 100%;
    8. height: 430rpx;
    9. border-radius: 30rpx;
    10. }
    11. swiper-item {
    12. width: 100%;
    13. height: 100%;
    14. border-radius: 50rpx;
    15. }
    16. .mybt{
    17. margin-top: 100rpx;
    18. width:300rpx;
    19. background-color: rgb(41, 113, 248);
    20. color: rgb(255, 255, 255);
    21. }
    22. view{
    23. font-size: 45rpx;
    24. text-align: center;
    25. margin-top: 100rpx;
    26. }
    27. canvas{
    28. width: 230rpx;
    29. height: 230rpx;
    30. margin-top: 100rpx;
    31. margin-left: 260rpx;
    32. }

    二.下载并配置第三方库

    去Gitee下载工具包:

    二维码工具包icon-default.png?t=N7T8http://​ https://gitee.com/WeiDoctor/weapp-qrcode-canvas-2d ​下载zip:

    a7c544ed67c6493e94585780013ffbd7.png 

    82665e09975645248e46029f03de4459.png 

    将dist文件夹中的js文件全部复制到utils目录下:

    d99d1bedf83242a980880f966f4a899f.png

    三.完成业务

    如下代码必须完整的导入再页面JS的最顶部:

    import drawQrcode from '../../utils/weapp.qrcode.esm.js'

     如下是完整的代码:

    1. // pages/youke/youke.js
    2. import drawQrcode from '../../utils/weapp.qrcode.esm.js'
    3. Page({
    4. data: {
    5. yynum:500,
    6. randomNum:"0"
    7. },
    8. onLoad() {
    9. },
    10. onReady() {
    11. },
    12. onShow() {
    13. },
    14. onHide() {
    15. },
    16. onUnload() {
    17. },
    18. onPullDownRefresh() {
    19. },
    20. onReachBottom() {
    21. },
    22. onShareAppMessage() {
    23. },
    24. yuyue(msg){
    25. // console.log("lll")
    26. if(this.data.yynum>0&&this.data.randomNum=="0")
    27. {
    28. wx.showToast({
    29. icon: 'success',
    30. title: '预约成功~',
    31. })
    32. let y=this.data.yynum;
    33. y--;
    34. this.setData({
    35. yynum:y
    36. })
    37. let r=(Math.random()*1).toFixed(4)*10000
    38. this.setData({
    39. randomNum:r
    40. }),
    41. console.log(r);
    42. const query = wx.createSelectorQuery()
    43. query.select('#myQrcode')
    44. .fields({
    45. node: true,
    46. size: true
    47. })
    48. .exec((res) => {
    49. var canvas = res[0].node
    50. drawQrcode({
    51. canvas: canvas,
    52. canvasId: 'myQrcode',
    53. width: 260,
    54. padding: 30,
    55. background: '#4169E1',
    56. foreground: '#ffffff',
    57. text: '个人二维码信息',
    58. })
    59. wx.canvasToTempFilePath({
    60. canvasId: 'myQrcode',
    61. canvas: canvas,
    62. x: 0,
    63. y: 0,
    64. width: 260,
    65. height: 260,
    66. destWidth: 260,
    67. destHeight: 260,
    68. })
    69. })
    70. }
    71. else if(this.data.randomNum!="0")
    72. {
    73. wx.showToast({
    74. icon: 'error',
    75. title: '禁止重复预约~',
    76. })
    77. }
    78. else{
    79. wx.showToast({
    80. icon: 'error',
    81. title: '很抱歉,已无预约名额~',
    82. })
    83. }
    84. }
    85. })

    点击预约即可成功生成二维码~ 

    b959150b5b054775829ea2f91283b386.png

     

  • 相关阅读:
    Linux—搭建Apache(httpd)服务
    ES系列十二、ES的scroll Api及分页实例
    刷题记录:牛客NC13947Contest
    亚马逊日本站养号测评需要哪些资源和注意点,如何确保账号的稳定性和纯净环境?
    linux安全加固
    (更新中)数据结构开发实战教程
    DAO 中常见的投票治理方式
    C语言——深入理解指针——函数指针
    【JavaEE基础与高级 第53章】Java中的IO流中的缓冲流详细介绍使用、字节缓冲流、字符缓冲流、案例使用与总结
    【C++ STL】-- list介绍与使用
  • 原文地址:https://blog.csdn.net/jsl123x/article/details/137757443