qrcode.uvue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('自定义')">
  5. <view class="flex flex-row justify-center py-3">
  6. <cl-qrcode
  7. ref="qrcodeRef"
  8. text="https://cool-js.com/"
  9. :logo="isLogo ? 'https://unix.cool-js.com/logo.png' : ''"
  10. :pd-radius="isPdRadius ? 50 : 0"
  11. :padding="isPadding ? 10 : 5"
  12. :foreground="isColor ? '#14b8a6' : '#000000'"
  13. :pd-color="isColor ? '#0d9488' : '#000000'"
  14. :mode="mode"
  15. ></cl-qrcode>
  16. </view>
  17. <cl-list border class="mt-3">
  18. <cl-list-item :label="t('添加LOGO')">
  19. <cl-switch v-model="isLogo"></cl-switch>
  20. </cl-list-item>
  21. <cl-list-item :label="t('圆角定位点')">
  22. <cl-switch v-model="isPdRadius"></cl-switch>
  23. </cl-list-item>
  24. <cl-list-item :label="t('内间距')">
  25. <cl-switch v-model="isPadding"></cl-switch>
  26. </cl-list-item>
  27. <cl-list-item :label="t('自定义颜色')">
  28. <cl-switch v-model="isColor"></cl-switch>
  29. </cl-list-item>
  30. <cl-list-item :label="t('导出图片')">
  31. <cl-button @tap="save">{{ t("预览") }}</cl-button>
  32. </cl-list-item>
  33. <view class="p-2">
  34. <cl-tabs
  35. v-model="mode"
  36. :height="66"
  37. :list="modeList"
  38. show-slider
  39. fill
  40. ></cl-tabs>
  41. </view>
  42. </cl-list>
  43. </demo-item>
  44. </view>
  45. </cl-page>
  46. </template>
  47. <script lang="ts" setup>
  48. import type { ClQrcodeMode, ClTabsItem } from "@/uni_modules/cool-ui";
  49. import DemoItem from "../components/item.uvue";
  50. import { ref } from "vue";
  51. import { t } from "@/locale";
  52. const isLogo = ref(true);
  53. const isPdRadius = ref(true);
  54. const isPadding = ref(false);
  55. const isColor = ref(false);
  56. const qrcodeRef = ref<ClQrcodeComponentPublicInstance | null>(null);
  57. const mode = ref<ClQrcodeMode>("circular");
  58. const modeList = [
  59. {
  60. label: t("矩形"),
  61. value: "rect"
  62. },
  63. {
  64. label: t("点"),
  65. value: "circular"
  66. },
  67. {
  68. label: t("线性"),
  69. value: "line"
  70. },
  71. {
  72. label: t("小方格"),
  73. value: "rectSmall"
  74. }
  75. ] as ClTabsItem[];
  76. function save() {
  77. qrcodeRef.value!.toPng().then((url) => {
  78. uni.previewImage({
  79. urls: [url]
  80. });
  81. });
  82. }
  83. </script>