kxj-watermark.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="watermarks"
  3. :style="{'opacity': opacity,'height':height,'position': position, 'bottom': bottom, 'z-index': zindex }">
  4. <view class="watermarksshell">
  5. <block v-for="(t, i) in count" :key="'watermark' + i">
  6. <view :style="{ transform: 'rotate(' + rotate + 'deg)' }">
  7. <image v-if="logo != '' || logo != 'none'" :src="logo"
  8. :style="{ width: size * texts.length + 'em', height: size * texts.length + 'em', float: 'left' }">
  9. </image>
  10. <view
  11. :style="{ 'padding-left': logo != '' || logo != 'none' ? size * texts.length + 0.2 + 'em' : 0 + 'em' }">
  12. <view v-for="(text, c) in texts" :key="'wmtext' + c"
  13. :style="{ color: color, 'font-size': size + 'em', 'line-height': size + 'em' }">{{ text }}
  14. </view>
  15. </view>
  16. </view>
  17. </block>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'kxj-watermark',
  24. props: {
  25. //水印类型:fixation固定,follow随动
  26. type: {
  27. type: String,
  28. default: 'follow'
  29. },
  30. //高度,只有当type=follow时才需要设置
  31. height: {
  32. type: String,
  33. default: '90%'
  34. },
  35. //水印内容
  36. texts: {
  37. type: Array,
  38. //required:true, //必填参数
  39. default: () => ['']
  40. },
  41. //图标,自带三种颜色的图标
  42. logo: {
  43. type: String,
  44. default: ''
  45. },
  46. //设置水印数量(密集度),最好设置为偶数,数字越大水印越密集
  47. count: {
  48. type: Number,
  49. default: 12
  50. },
  51. //透明度,0到1之间。
  52. opacity: {
  53. type: Number,
  54. default: 0.2
  55. },
  56. //文字大小,单位是em
  57. size: {
  58. type: Number,
  59. default: 1
  60. },
  61. //文字颜色
  62. color: {
  63. type: String,
  64. default: '#d9d9d9'
  65. },
  66. //旋转角度
  67. rotate: {
  68. type: Number,
  69. default: -30
  70. },
  71. //层级
  72. zindex: {
  73. type: String,
  74. default: '500'
  75. }
  76. },
  77. data() {
  78. return {
  79. position: 'fixed',
  80. width: '150%',
  81. bottom: 0
  82. };
  83. },
  84. beforeMount() {
  85. if (this.type === 'follow') {
  86. this.position = 'absolute';
  87. (this.width = '150%'), (this.bottom = 'auto');
  88. }
  89. }
  90. };
  91. </script>
  92. <style lang="css">
  93. .watermarks {
  94. top: 0;
  95. left: 0;
  96. right: 0;
  97. width: 100%;
  98. height: 100%;
  99. overflow: hidden;
  100. }
  101. .watermarksshell {
  102. display: flex;
  103. flex-wrap: wrap;
  104. pointer-events: none;
  105. top: 0;
  106. left: 0;
  107. right: 0;
  108. width: 150%;
  109. height: 130%;
  110. }
  111. </style>