qrcodeed.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div style="height: 150px">
  3. <div id="qrcode" ref="qrcodes" class="qrCode" />
  4. </div>
  5. </template>
  6. <script>
  7. import QRCode from 'qrcodejs2' // 引入qrcode
  8. import { BASE_URL } from '@/constant'
  9. export default {
  10. name: 'qrcode',
  11. props: {
  12. field: Object,
  13. formData: {
  14. type: Object,
  15. default() {
  16. return {}
  17. }
  18. },
  19. readonly: {
  20. type: Boolean,
  21. default: false
  22. }
  23. },
  24. data() {
  25. return {
  26. qrCode: ''
  27. }
  28. },
  29. watch: {
  30. 'formData.changJingId': {
  31. handler() {
  32. this.$nextTick(() => {
  33. this.qrcode()
  34. })
  35. },
  36. immediate: true
  37. }
  38. },
  39. mounted() {
  40. // setTimeout(() => {
  41. // this.qrcode()
  42. // }, 500)
  43. },
  44. destroyed() {
  45. if (window.qrTimer) {
  46. clearInterval(window.qrTimer)
  47. }
  48. },
  49. methods: {
  50. qrcode() {
  51. if (this.qrCode) {
  52. this.$refs.qrcodes.innerHTML = ''
  53. }
  54. this.qrCode = new QRCode('qrcode', {
  55. width: 132,
  56. height: 132,
  57. text: `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf0aecf99696061a3&redirect_uri=${encodeURIComponent(`${BASE_URL}#/ziliao`)}&response_type=code&scope=snsapi_base&state=${this.formData.changJingId}#wechat_redirect`,
  58. // text: `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxea2c214ca5d25739&redirect_uri=${encodeURIComponent(`${BASE_URL}#/ziliao`)}&response_type=code&scope=snsapi_base&state=${this.formData.changJingId}#wechat_redirect`,
  59. colorDark: '#000000', // 前景色
  60. colorLight: '#FFFFFF', // 背景色
  61. correctLevel: QRCode.CorrectLevel.L
  62. })
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. .qrCode {
  69. width: 100px;
  70. height: 100px;
  71. margin: 0 auto;
  72. }
  73. </style>