index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <script lang="ts" setup>
  2. import { Page } from '@vben/common-ui';
  3. import { useWatermark } from '@vben/hooks';
  4. import { Button, Card } from 'ant-design-vue';
  5. const { destroyWatermark, updateWatermark, watermark } = useWatermark();
  6. async function recreateWaterMark() {
  7. destroyWatermark();
  8. await updateWatermark({});
  9. }
  10. async function createWaterMark() {
  11. await updateWatermark({
  12. advancedStyle: {
  13. colorStops: [
  14. {
  15. color: 'red',
  16. offset: 0,
  17. },
  18. {
  19. color: 'blue',
  20. offset: 1,
  21. },
  22. ],
  23. type: 'linear',
  24. },
  25. content: `hello my watermark\n${new Date().toLocaleString()}`,
  26. globalAlpha: 0.5,
  27. gridLayoutOptions: {
  28. cols: 2,
  29. gap: [20, 20],
  30. matrix: [
  31. [1, 0],
  32. [0, 1],
  33. ],
  34. rows: 2,
  35. },
  36. height: 200,
  37. layout: 'grid',
  38. rotate: 22,
  39. width: 200,
  40. });
  41. }
  42. </script>
  43. <template>
  44. <Page title="水印">
  45. <template #description>
  46. <div class="text-foreground/80 mt-2">
  47. 水印使用了
  48. <a
  49. class="text-primary"
  50. href="https://zhensherlock.github.io/watermark-js-plus/"
  51. target="_blank"
  52. >
  53. watermark-js-plus
  54. </a>
  55. 开源插件,详细配置可见插件配置。
  56. </div>
  57. </template>
  58. <Card title="使用">
  59. <Button
  60. :disabled="!!watermark"
  61. class="mr-2"
  62. type="primary"
  63. @click="recreateWaterMark"
  64. >
  65. 创建水印
  66. </Button>
  67. <Button
  68. :disabled="!watermark"
  69. class="mr-2"
  70. type="primary"
  71. @click="createWaterMark"
  72. >
  73. 更新水印
  74. </Button>
  75. <Button :disabled="!watermark" danger @click="destroyWatermark">
  76. 移除水印
  77. </Button>
  78. </Card>
  79. </Page>
  80. </template>