123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <template>
- <view class="zmm-watermark">
-
- <view class="zmm-watermark-mold" ref="mold" id="mold">
- <rich-text :style="moldStyle" :nodes="watermark"></rich-text>
- </view>
-
- <view class="zmm-watermark-content" :style="{opacity:opacity}">
- <rich-text :nodes="watermark" :style="itemStyle" v-for="(item,index) in forLength" :key="index"></rich-text>
- </view>
- </view>
- </template>
- <script>
-
- const dom = weex.requireModule("dom");
-
- export default {
- data() {
- return {
- forLength: 0,
- watermarkArea: 0
- };
- },
- props: {
- watermark: {
- type: String,
- default: '水印文字'
- },
- color: {
- type: String,
- default: '#666'
- },
- fontSize: {
- type: Number,
- default: 16
- },
- opacity: {
- type: Number,
- default: 0.15
- },
- margin: {
- type: Number,
- default: 40
- },
- rotate: {
- type: Number,
- default: -21
- },
- column: {
- type: Number,
- default: 2
- }
- },
- computed: {
-
- moldStyle() {
- return `width:${this.itemWidth}px;text-align: center;font-size:${this.fontSize}px;`
- },
-
- itemStyle() {
- return `color:${this.color};font-size:${this.fontSize}px;margin:${this.margin}px;width:${this.itemWidth}px;transform:rotate(${this.rotate}deg);text-align: center;`
- },
-
- screenArea() {
- let height = uni.getSystemInfoSync().windowHeight + uni.getSystemInfoSync().windowTop
- let width = uni.getSystemInfoSync().windowWidth
- return Math.floor(height * width * 1.2)
- },
-
- itemWidth() {
- let windowWidth = uni.getSystemInfoSync().windowWidth
- return Math.floor(windowWidth / this.column - this.margin * 2)
- }
- },
- watch: {
- watermark: {
- handler(v) {
- if (v) {
- this.countForLength();
- }
- },
- deep: true
- }
- },
- mounted() {
- if (this.watermark) {
- this.countForLength();
- }
- },
- methods: {
- countForLength() {
-
- const query = uni.createSelectorQuery().in(this);
- query.select('#mold').boundingClientRect(data => {
- let width = data.width ? data.width : this.itemWidth
- let height = data.height ? data.height : 30
- let itemWidth = width + this.margin * 2
- let itemHeight = height + this.margin * 2
- this.watermarkArea = Math.floor(itemWidth * itemHeight)
- this.forLength = Math.floor(this.screenArea / this.watermarkArea)
- }).exec();
-
-
- setTimeout(() => {
- const result = dom.getComponentRect(this.$refs.mold, (option) => {
- let size = option.size;
- let itemWidth = size.width + this.margin * 2
- let itemHeight = size.height + this.margin * 2
- this.watermarkArea = Math.floor(itemWidth * itemHeight)
- this.forLength = Math.floor(this.screenArea / this.watermarkArea)
- });
- }, 50);
-
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .zmm-watermark {
- position: fixed;
- overflow: hidden;
- z-index: 999;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
-
- pointer-events: none;
-
- }
- .zmm-watermark-content {
- position: fixed;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- overflow: hidden;
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- justify-content: space-around;
- }
- .zmm-watermark-mold {
- position: fixed;
- left: 0;
- top: 0;
- opacity: 0;
- }
- </style>
|