tki_qrcode.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <tki-qrcode v-if="ifShow" cid="qrcode1" ref="qrcode" :val="qrval" :size="size" :unit="unit" :background="background" :foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconsize" :lv="lv" :onval="onval" :loadMake="loadMake" :usingComponents="true" @result="qrR" />
  3. </template>
  4. <script>
  5. import tkiQrcode from './tki-qrcode/tki-qrcode.vue'
  6. export default {
  7. data() {
  8. return {
  9. ifShow: false,
  10. val: '二维码', // 要生成的二维码值
  11. size: 200, // 二维码大小
  12. unit: 'upx', // 单位
  13. background: '#fff', // 背景色
  14. foreground: '#000', // 前景色
  15. pdground: '#000', // 角标色
  16. icon: '', // 二维码图标
  17. iconsize: 40, // 二维码图标大小
  18. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  19. onval: true, // val值变化时自动重新生成二维码
  20. loadMake: true, // 组件加载完成后自动生成二维码
  21. src: '' // 二维码生成后的图片地址或base64
  22. }
  23. },
  24. props:{
  25. qrval:{
  26. type:String,
  27. default:'二维码'
  28. }
  29. },
  30. methods: {
  31. sliderchange(e) {
  32. this.size = e.detail.value
  33. },
  34. creatQrcode(val) {
  35. this.val = val
  36. // this.$refs.qrcode._makeCode()
  37. },
  38. saveQrcode() {
  39. this.$refs.qrcode._saveCode()
  40. },
  41. qrR(res) {
  42. this.src = res
  43. this.$emit("onQrPath",res);
  44. },
  45. clearQrcode() {
  46. this.$refs.qrcode._clearCode()
  47. this.val = ''
  48. },
  49. ifQrcode() {
  50. this.ifShow = !this.ifShow
  51. },
  52. selectIcon() {
  53. let that = this
  54. uni.chooseImage({
  55. count: 1, //默认9
  56. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  57. sourceType: ['album'], //从相册选择
  58. success: function (res) {
  59. that.icon = res.tempFilePaths[0]
  60. setTimeout(() => {
  61. that.creatQrcode()
  62. }, 100);
  63. // console.log(res.tempFilePaths);
  64. }
  65. });
  66. }
  67. },
  68. components: {
  69. tkiQrcode
  70. },
  71. onLoad: function () { },
  72. }
  73. </script>
  74. <style lang="scss" scoped>
  75. /* @import "../../../common/icon.css"; */
  76. .container {
  77. display: flex;
  78. flex-direction: column;
  79. width: 100%;
  80. }
  81. .qrimg {
  82. display: flex;
  83. justify-content: center;
  84. }
  85. .qrimg-i{
  86. margin-right: 10px;
  87. }
  88. slider {
  89. width: 100%;
  90. }
  91. input {
  92. width: 100%;
  93. margin-bottom: 20upx;
  94. }
  95. .btns {
  96. display: flex;
  97. flex-direction: column;
  98. width: 100%;
  99. }
  100. button {
  101. width: 100%;
  102. margin-top: 10upx;
  103. }
  104. </style>