watermark.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <script setup lang="ts">
  2. import { ref, onMounted, nextTick, onBeforeUnmount } from "vue";
  3. import { useWatermark } from "@pureadmin/utils";
  4. defineOptions({
  5. name: "WaterMark"
  6. });
  7. const local = ref();
  8. const preventLocal = ref();
  9. const color = ref("#409EFF");
  10. const value = ref("vue-pure-admin");
  11. const { setWatermark, clear } = useWatermark();
  12. const { setWatermark: setLocalWatermark, clear: clearLocal } =
  13. useWatermark(local);
  14. const { setWatermark: setPreventLocalWatermark } = useWatermark(preventLocal);
  15. onMounted(() => {
  16. nextTick(() => {
  17. setPreventLocalWatermark("无法删除的水印", {
  18. forever: true,
  19. width: 180,
  20. height: 70
  21. });
  22. });
  23. });
  24. onBeforeUnmount(() => {
  25. // 在离开该页面时清除整页水印
  26. clear();
  27. });
  28. </script>
  29. <template>
  30. <el-card shadow="never">
  31. <template #header>
  32. <div class="card-header">
  33. <span class="font-medium">
  34. <el-link
  35. href="https://pure-admin-utils.netlify.app/hooks/useWatermark/useWatermark"
  36. target="_blank"
  37. style="margin: 0 5px 4px 0; font-size: 16px"
  38. >
  39. 页面水印
  40. </el-link>
  41. </span>
  42. </div>
  43. <el-link
  44. class="mt-2"
  45. href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/able/watermark.vue"
  46. target="_blank"
  47. >
  48. 代码位置 src/views/able/watermark.vue
  49. </el-link>
  50. </template>
  51. <el-space wrap class="mb-2!">
  52. <span> 请输入要创建水印的值:</span>
  53. <el-input v-model="value" class="mr-4" style="width: 200px" clearable />
  54. <span>请选择要创建水印的颜色:</span>
  55. <el-color-picker v-model="color" show-alpha />
  56. </el-space>
  57. <el-space wrap>
  58. <el-button plain @click="setWatermark(value, { color })">
  59. 创建整页水印
  60. </el-button>
  61. <el-button
  62. plain
  63. @click="
  64. setWatermark(value, {
  65. gradient: [
  66. { value: 0, color: 'magenta' },
  67. { value: 0.5, color: 'blue' },
  68. { value: 1.0, color: 'red' }
  69. ]
  70. })
  71. "
  72. >
  73. 创建整页渐变水印
  74. </el-button>
  75. <el-button
  76. plain
  77. @click="
  78. setWatermark(value, {
  79. rotate: 0,
  80. gradient: [
  81. { value: 0, color: 'magenta' },
  82. { value: 0.5, color: 'blue' },
  83. { value: 1.0, color: 'red' }
  84. ]
  85. })
  86. "
  87. >
  88. 创建整页渐变且水平90度的水印
  89. </el-button>
  90. <el-button
  91. plain
  92. @click="
  93. setWatermark(value, {
  94. gradient: [
  95. { value: 0, color: 'magenta' },
  96. { value: 0.5, color: 'blue' },
  97. { value: 1.0, color: 'red' }
  98. ],
  99. shadowConfig: [20]
  100. })
  101. "
  102. >
  103. 创建整页渐变且有阴影的水印
  104. </el-button>
  105. <el-button
  106. plain
  107. @click="
  108. setWatermark(value, {
  109. globalAlpha: 0.15, // 值越低越透明
  110. gradient: [
  111. { value: 0, color: 'magenta' },
  112. { value: 0.5, color: 'blue' },
  113. { value: 1.0, color: 'red' }
  114. ]
  115. })
  116. "
  117. >
  118. 创建整页高透明渐变水印
  119. </el-button>
  120. <el-button plain @click="clear">清除整页水印</el-button>
  121. </el-space>
  122. <div ref="local" class="w-1/2 h-[200px] border border-sky-500 mt-4" />
  123. <el-space wrap class="mt-6">
  124. <el-button
  125. plain
  126. @click="
  127. setLocalWatermark('局部水印', {
  128. color,
  129. width: 140,
  130. height: 65
  131. })
  132. "
  133. >
  134. 创建局部水印
  135. </el-button>
  136. <el-button
  137. plain
  138. @click="
  139. setLocalWatermark('局部水印', {
  140. width: 140,
  141. height: 65,
  142. gradient: [
  143. { value: 0, color: 'magenta' },
  144. { value: 0.5, color: 'blue' },
  145. { value: 1.0, color: 'red' }
  146. ]
  147. })
  148. "
  149. >
  150. 创建局部渐变水印
  151. </el-button>
  152. <el-button
  153. plain
  154. @click="
  155. setLocalWatermark('局部水印', {
  156. width: 140,
  157. height: 65,
  158. rotate: 0,
  159. gradient: [
  160. { value: 0, color: 'magenta' },
  161. { value: 0.5, color: 'blue' },
  162. { value: 1.0, color: 'red' }
  163. ]
  164. })
  165. "
  166. >
  167. 创建局部渐变且水平90度的水印
  168. </el-button>
  169. <el-button
  170. plain
  171. @click="
  172. setLocalWatermark('局部水印', {
  173. width: 140,
  174. height: 65,
  175. gradient: [
  176. { value: 0, color: 'magenta' },
  177. { value: 0.5, color: 'blue' },
  178. { value: 1.0, color: 'red' }
  179. ],
  180. shadowConfig: [20]
  181. })
  182. "
  183. >
  184. 创建局部渐变且有阴影的水印
  185. </el-button>
  186. <el-button plain @click="clearLocal">清除局部水印</el-button>
  187. </el-space>
  188. <div
  189. ref="preventLocal"
  190. class="w-1/2 h-[200px] border border-indigo-500 mt-4"
  191. />
  192. </el-card>
  193. </template>