index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template xlang="wxml">
  2. <view class="container">
  3. <view class="qrimg">
  4. <view class="qrimg-i">
  5. <geek-qrcode v-if="ifShow" cid="qrcode1" ref="qrcode" :val="val" :size="size" :unit="unit"
  6. :background="background" :foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconsize"
  7. :lv="lv" :onval="onval" :loadMake="loadMake" :usingComponents="true" @result="qrR" />
  8. </view>
  9. <view class="qrimg-i">
  10. <geek-qrcode v-if="ifShow" cid="qrcode2" ref="qrcode2" val="第二个二维码" :size="size" :onval="onval"
  11. :loadMake="loadMake" :usingComponents="true" @result="qrR" />
  12. </view>
  13. </view>
  14. <view class="uni-padding-wrap">
  15. <view class="uni-title">请输入要生成的二维码内容</view>
  16. </view>
  17. <view class="uni-list">
  18. <input class="uni-input" placeholder="请输入要生成的二维码内容" v-model="val" />
  19. </view>
  20. <view class="uni-padding-wrap uni-common-mt">
  21. <view class="uni-title">设置二维码大小</view>
  22. </view>
  23. <view class="body-view">
  24. <slider :value="size" @change="sliderchange" min="50" max="500" show-value />
  25. </view>
  26. <view class="uni-padding-wrap">
  27. <view class="btns">
  28. <button type="primary" @tap="selectIcon">选择二维码图标</button>
  29. <button type="primary" @tap="creatQrcode">生成二维码</button>
  30. <button type="primary" @tap="saveQrcode">保存到图库</button>
  31. <button type="warn" @tap="clearQrcode">清除二维码</button>
  32. <button type="warn" @tap="ifQrcode">显示隐藏二维码</button>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. ifShow: true,
  42. val: '二维码', // 要生成的二维码值
  43. size: 200, // 二维码大小
  44. unit: 'upx', // 单位
  45. background: '#b4e9e2', // 背景色
  46. foreground: '#309286', // 前景色
  47. pdground: '#32dbc6', // 角标色
  48. icon: '', // 二维码图标
  49. iconsize: 40, // 二维码图标大小
  50. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  51. onval: false, // val值变化时自动重新生成二维码
  52. loadMake: true, // 组件加载完成后自动生成二维码
  53. src: '' // 二维码生成后的图片地址或base64
  54. }
  55. },
  56. methods: {
  57. sliderchange(e) {
  58. this.size = e.detail.value
  59. },
  60. creatQrcode() {
  61. this.$refs.qrcode._makeCode()
  62. },
  63. saveQrcode() {
  64. this.$refs.qrcode._saveCode()
  65. },
  66. qrR(res) {
  67. this.src = res
  68. },
  69. clearQrcode() {
  70. this.$refs.qrcode._clearCode()
  71. this.val = ''
  72. },
  73. ifQrcode() {
  74. this.ifShow = !this.ifShow
  75. },
  76. selectIcon() {
  77. let that = this
  78. uni.chooseImage({
  79. count: 1, //默认9
  80. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  81. sourceType: ['album'], //从相册选择
  82. success: function (res) {
  83. that.icon = res.tempFilePaths[0]
  84. setTimeout(() => {
  85. that.creatQrcode()
  86. }, 100);
  87. // console.log(res.tempFilePaths);
  88. }
  89. });
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. /* @import "../../../common/icon.css"; */
  96. .container {
  97. display: flex;
  98. flex-direction: column;
  99. width: 100%;
  100. }
  101. .qrimg {
  102. display: flex;
  103. justify-content: center;
  104. }
  105. .qrimg-i {
  106. margin-right: 10px;
  107. }
  108. slider {
  109. width: 100%;
  110. }
  111. input {
  112. width: 100%;
  113. margin-bottom: 20upx;
  114. }
  115. .btns {
  116. display: flex;
  117. flex-direction: column;
  118. width: 100%;
  119. }
  120. button {
  121. width: 100%;
  122. margin-top: 10upx;
  123. }</style>