// components/watermark/watermark.js Component({ /** * 组件的属性列表 */ properties: { // 父组件高度 height: { type: Number, observer(data) { // 当传值进来时 触发方法 this.watermark(data) } } }, /** * 组件的初始数据 */ data: { watermark: [] //水印位置集合方法 }, ready() { // 当组件准备好时触发 先行触发 然后覆盖减少突然出现水印的概率 this.watermark() }, /** * 组件的方法列表 */ methods: { // 生成水印位置集合方法 watermark(height) { // 获取当前系统信息 const system = wx.getSystemInfoSync(); const _height = system.windowHeight > height ? system.windowHeight : height; // 计算水印行数 const row = Math.floor(_height * (750 / system.windowWidth) / 201); const json = []; for (let i = 0; i < row; i++) { json.push([]) let _tmp = i % 2; // 奇数行三个 偶数行两个 if (_tmp) { for (let j = 0; j < 2; j++) { json[i].push({ top: 30 + 201 * i, left: 160 + 245 * j }) } } else { for (let j = 0; j < 3; j++) { json[i].push({ top: 30 + 201 * i, left: 30 + 260 * j }) } } } this.setData({ watermark: json }) } } })