watermark.uvue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('自定义样式')">
  5. <view class="flex">
  6. <cl-watermark
  7. :text="customText"
  8. :font-size="fontSize"
  9. :color="color"
  10. :dark-color="darkColor"
  11. :opacity="opacity"
  12. :rotate="rotate"
  13. :width="width"
  14. :height="height"
  15. :gap-x="gapX"
  16. :gap-y="gapY"
  17. :font-weight="fontWeight"
  18. >
  19. <view
  20. class="flex flex-col p-4 rounded-xl bg-surface-50 dark:bg-surface-800 h-[400rpx]"
  21. >
  22. <cl-text>
  23. 明月几时有?把酒问青天。 不知天上宫阙,今夕是何年。
  24. 我欲乘风归去,又恐琼楼玉宇,高处不胜寒。 起舞弄清影,何似在人间。
  25. </cl-text>
  26. </view>
  27. </cl-watermark>
  28. </view>
  29. <cl-list border class="mt-3">
  30. <cl-list-item :label="t('水印文本')">
  31. <cl-input
  32. v-model="customText"
  33. placeholder="请输入水印文本"
  34. :pt="{ className: 'w-[300rpx]' }"
  35. />
  36. </cl-list-item>
  37. <cl-list-item :label="t('字体大小')">
  38. <view class="w-[300rpx]">
  39. <cl-slider v-model="fontSize" :min="12" :max="32" :step="1"></cl-slider>
  40. </view>
  41. </cl-list-item>
  42. <!-- #ifndef APP -->
  43. <cl-list-item :label="t('透明度')">
  44. <view class="w-[300rpx]">
  45. <cl-slider
  46. v-model="opacity"
  47. :min="0.1"
  48. :max="1"
  49. :step="0.05"
  50. ></cl-slider>
  51. </view>
  52. </cl-list-item>
  53. <!-- #endif -->
  54. <cl-list-item :label="t('旋转角度')">
  55. <view class="w-[300rpx]">
  56. <cl-slider
  57. v-model="rotate"
  58. :min="-180"
  59. :max="180"
  60. :step="5"
  61. ></cl-slider>
  62. </view>
  63. </cl-list-item>
  64. <cl-list-item :label="t('水印宽度')">
  65. <view class="w-[300rpx]">
  66. <cl-slider v-model="width" :min="80" :max="300" :step="10"></cl-slider>
  67. </view>
  68. </cl-list-item>
  69. <cl-list-item :label="t('水印高度')">
  70. <view class="w-[300rpx]">
  71. <cl-slider v-model="height" :min="40" :max="200" :step="10"></cl-slider>
  72. </view>
  73. </cl-list-item>
  74. <cl-list-item :label="t('水平间距')">
  75. <view class="w-[300rpx]">
  76. <cl-slider v-model="gapX" :min="20" :max="200" :step="10"></cl-slider>
  77. </view>
  78. </cl-list-item>
  79. <cl-list-item :label="t('垂直间距')">
  80. <view class="w-[300rpx]">
  81. <cl-slider v-model="gapY" :min="20" :max="200" :step="10"></cl-slider>
  82. </view>
  83. </cl-list-item>
  84. <cl-list-item :label="t('字体粗细')">
  85. <cl-tabs
  86. v-model="fontWeight"
  87. :list="fontWeightList"
  88. :height="60"
  89. show-slider
  90. ></cl-tabs>
  91. </cl-list-item>
  92. </cl-list>
  93. </demo-item>
  94. <demo-item :label="t('图片保护')">
  95. <view class="flex">
  96. <cl-watermark text="© Cool UI" :width="200" :height="80" :opacity="0.9">
  97. <image
  98. src="https://unix.cool-js.com/images/demo/avatar.jpg"
  99. mode="aspectFit"
  100. class="w-full"
  101. ></image>
  102. </cl-watermark>
  103. </view>
  104. </demo-item>
  105. </view>
  106. </cl-page>
  107. </template>
  108. <script lang="ts" setup>
  109. import DemoItem from "../components/item.uvue";
  110. import { ref } from "vue";
  111. import { t } from "@/locale";
  112. import type { ClTabsItem } from "@/uni_modules/cool-ui";
  113. const customText = ref("Cool UI");
  114. const fontSize = ref(16);
  115. const color = ref("rgba(0, 0, 0, 0.15)");
  116. const darkColor = ref("rgba(255, 255, 255, 0.15)");
  117. const opacity = ref(1);
  118. const rotate = ref(-22);
  119. const width = ref(120);
  120. const height = ref(64);
  121. const gapX = ref(100);
  122. const gapY = ref(100);
  123. const fontWeight = ref("normal");
  124. const fontWeightList = [
  125. {
  126. label: t("正常"),
  127. value: "normal"
  128. },
  129. {
  130. label: t("加粗"),
  131. value: "bold"
  132. }
  133. ] as ClTabsItem[];
  134. </script>