index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <PageWrapper title="二维码组件使用示例">
  3. <div class="flex flex-wrap">
  4. <CollapseContainer title="基础示例" :canExpand="true" class="text-center mb-6 w-1/5 mr-6">
  5. <QrCode :value="qrCodeUrl" />
  6. </CollapseContainer>
  7. <CollapseContainer title="渲染成img标签示例" class="text-center mb-6 w-1/5 mr-6">
  8. <QrCode :value="qrCodeUrl" tag="img" />
  9. </CollapseContainer>
  10. <CollapseContainer title="配置样式示例" class="text-center mb-6 w-1/5 mr-6">
  11. <QrCode
  12. :value="qrCodeUrl"
  13. :options="{
  14. color: { dark: '#55D187' },
  15. }"
  16. />
  17. </CollapseContainer>
  18. <CollapseContainer title="本地logo示例" class="text-center mb-6 w-1/5 mr-6">
  19. <QrCode :value="qrCodeUrl" :logo="LogoImg" />
  20. </CollapseContainer>
  21. <CollapseContainer title="在线logo示例" class="text-center mb-6 w-1/5 mr-6">
  22. <QrCode
  23. :value="qrCodeUrl"
  24. logo="https://vebn.oss-cn-beijing.aliyuncs.com/vben/logo.png"
  25. :options="{
  26. color: { dark: '#55D187' },
  27. }"
  28. />
  29. </CollapseContainer>
  30. <CollapseContainer title="logo配置示例" class="text-center mb-6 w-1/5 mr-6">
  31. <QrCode
  32. :value="qrCodeUrl"
  33. :logo="{
  34. src: 'https://vebn.oss-cn-beijing.aliyuncs.com/vben/logo.png',
  35. logoSize: 0.2,
  36. borderSize: 0.05,
  37. borderRadius: 50,
  38. bgColor: 'blue',
  39. }"
  40. />
  41. </CollapseContainer>
  42. <CollapseContainer title="下载示例" class="text-center mb-6 w-1/5 mr-6">
  43. <QrCode :value="qrCodeUrl" ref="qrRef" :logo="LogoImg" />
  44. <a-button class="mb-2" type="primary" @click="download"> 下载 </a-button>
  45. <div class="msg">(在线logo会导致图片跨域,需要下载图片需要自行解决跨域问题)</div>
  46. </CollapseContainer>
  47. <CollapseContainer title="配置大小示例" class="text-center w-1/5 mr-6">
  48. <QrCode :value="qrCodeUrl" :width="300" />
  49. </CollapseContainer>
  50. <CollapseContainer title="扩展绘制示例" class="text-center w-1/5 mr-6">
  51. <QrCode
  52. :value="qrCodeUrl"
  53. :width="200"
  54. :options="{ margin: 5 }"
  55. ref="qrDiyRef"
  56. :logo="LogoImg"
  57. @done="onQrcodeDone"
  58. />
  59. <a-button class="mb-2" type="primary" @click="downloadDiy"> 下载 </a-button>
  60. <div class="msg">要进行扩展绘制则不能将tag设为img</div>
  61. </CollapseContainer>
  62. <CollapseContainer title="Antdv QRCode" class="text-center w-1/5 mr-6">
  63. <QRCode :value="qrCodeUrl" :size="200" />
  64. </CollapseContainer>
  65. <CollapseContainer title="Antdv QRCode 带icon" class="text-center w-1/5 mr-6">
  66. <QRCode :value="qrCodeUrl" :size="200" :icon="LogoImg" />
  67. </CollapseContainer>
  68. </div>
  69. </PageWrapper>
  70. </template>
  71. <script lang="ts" setup>
  72. import LogoImg from '@/assets/images/logo.png';
  73. import { CollapseContainer } from '@/components/Container';
  74. import { PageWrapper } from '@/components/Page';
  75. import { QrCode, QrCodeActionType } from '@/components/Qrcode';
  76. import { type Nullable } from '@vben/types';
  77. import { QRCode } from 'ant-design-vue';
  78. import { ref, unref } from 'vue';
  79. const qrCodeUrl = 'https://www.vvbin.cn';
  80. const qrRef = ref<Nullable<QrCodeActionType>>(null);
  81. const qrDiyRef = ref<Nullable<QrCodeActionType>>(null);
  82. function download() {
  83. const qrEl = unref(qrRef);
  84. if (!qrEl) return;
  85. qrEl.download('文件名');
  86. }
  87. function downloadDiy() {
  88. const qrEl = unref(qrDiyRef);
  89. if (!qrEl) return;
  90. qrEl.download('Qrcode');
  91. }
  92. function onQrcodeDone({ ctx }: any) {
  93. if (ctx instanceof CanvasRenderingContext2D) {
  94. // 额外绘制
  95. ctx.fillStyle = 'black';
  96. ctx.font = '16px "微软雅黑"';
  97. ctx.textBaseline = 'bottom';
  98. ctx.textAlign = 'center';
  99. ctx.fillText('你帅你先扫', 100, 195, 200);
  100. }
  101. }
  102. </script>