sign.uvue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <cl-page>
  3. <cl-sign ref="signRef" :height="height" :width="width" :enable-brush="isBrush"></cl-sign>
  4. <view class="p-3">
  5. <cl-list>
  6. <cl-list-item :label="t('操作')">
  7. <cl-button type="info" @click="clear">{{ t("清空") }}</cl-button>
  8. <cl-button @click="preview">{{ t("预览") }}</cl-button>
  9. </cl-list-item>
  10. <cl-list-item :label="t('设置高度')">
  11. <cl-switch v-model="isFullscreen" @change="onFullscreenChange"></cl-switch>
  12. </cl-list-item>
  13. <cl-list-item :label="t('毛笔效果')">
  14. <cl-switch v-model="isBrush"></cl-switch>
  15. </cl-list-item>
  16. </cl-list>
  17. </view>
  18. </cl-page>
  19. </template>
  20. <script setup lang="ts">
  21. import { t } from "@/locale";
  22. import { ref } from "vue";
  23. const height = ref(200);
  24. const width = ref(0);
  25. const isFullscreen = ref(false);
  26. const isBrush = ref(true);
  27. const signRef = ref<ClSignComponentPublicInstance | null>(null);
  28. function clear() {
  29. signRef.value!.clear();
  30. }
  31. function preview() {
  32. signRef.value!.toPng().then((url) => {
  33. uni.previewImage({
  34. urls: [url]
  35. });
  36. });
  37. }
  38. function onFullscreenChange() {
  39. height.value = isFullscreen.value ? uni.getWindowInfo().windowHeight - 200 : 200;
  40. }
  41. onReady(() => {
  42. width.value = uni.getWindowInfo().windowWidth;
  43. });
  44. </script>