index.vue 3.4 KB

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