qrcode.uvue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 v-model="mode" :height="66" :list="modeList" show-slider></cl-tabs>
  35. </view>
  36. </cl-list>
  37. </demo-item>
  38. </view>
  39. </cl-page>
  40. </template>
  41. <script lang="ts" setup>
  42. import type { ClQrcodeMode, ClTabsItem } from "@/uni_modules/cool-ui";
  43. import DemoItem from "../components/item.uvue";
  44. import { ref } from "vue";
  45. import { t } from "@/locale";
  46. const isLogo = ref(true);
  47. const isPdRadius = ref(true);
  48. const isPadding = ref(false);
  49. const isColor = ref(false);
  50. const qrcodeRef = ref<ClQrcodeComponentPublicInstance | null>(null);
  51. const mode = ref<ClQrcodeMode>("circular");
  52. const modeList = [
  53. {
  54. label: t("矩形"),
  55. value: "rect"
  56. },
  57. {
  58. label: t("点"),
  59. value: "circular"
  60. },
  61. {
  62. label: t("线性"),
  63. value: "line"
  64. },
  65. {
  66. label: t("小方格"),
  67. value: "rectSmall"
  68. }
  69. ] as ClTabsItem[];
  70. function save() {
  71. qrcodeRef.value!.toPng().then((url) => {
  72. uni.previewImage({
  73. urls: [url]
  74. });
  75. });
  76. }
  77. </script>