@ericbyliang/miniprogram 0.0.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ericbyliang/miniprogram",
3
- "version": "0.0.2",
3
+ "version": "1.1.3",
4
4
  "description": "Wechat miniprogram global watermark component",
5
5
  "main": "index.js",
6
6
  "miniprogram": "src",
@@ -0,0 +1,6 @@
1
+ const TEXT_KEY = '$&watermark_text$*&'
2
+ const TEXT_CHANGE_KEY = '$&watermark-change$*&'
3
+ module.exports = {
4
+ TEXT_KEY,
5
+ TEXT_CHANGE_KEY
6
+ }
@@ -0,0 +1,22 @@
1
+ const events = {}
2
+
3
+ function on(name, fn) {
4
+ if (!events[name]) events[name] = []
5
+ events[name].push(fn)
6
+ }
7
+
8
+ function off(name, fn) {
9
+ if (!events[name]) return
10
+ events[name] = events[name].filter(f => f !== fn)
11
+ }
12
+
13
+ function emit(name, data) {
14
+ if (!events[name]) return
15
+ events[name].forEach(fn => fn(data))
16
+ }
17
+
18
+ module.exports = {
19
+ on,
20
+ off,
21
+ emit
22
+ }
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ const eventBus = require('./event-bus')
2
+ const {TEXT_KEY, TEXT_CHANGE_KEY} = require('./constants')
3
+ const setWatermarkText = (text)=>{
4
+ wx.setStorageSync(TEXT_KEY, text)
5
+ eventBus.emit(TEXT_CHANGE_KEY, text)
6
+ }
7
+ module.exports = {
8
+ setWatermarkText
9
+ }
@@ -1,6 +1,17 @@
1
+ const eventBus = require('../event-bus')
2
+ const {TEXT_KEY, TEXT_CHANGE_KEY} = require('../constants')
1
3
  Component({
2
4
  lifetimes: {
3
- ready: function () {
5
+ attached: function () {
6
+ this._onChange = (text) => {
7
+ this.setData({
8
+ text
9
+ })
10
+ }
11
+ eventBus.on(TEXT_CHANGE_KEY, this._onChange)
12
+ },
13
+ detached: function() {
14
+ eventBus.off(TEXT_CHANGE_KEY, this._onChange)
4
15
  }
5
16
  },
6
17
  /**
@@ -9,7 +20,7 @@ Component({
9
20
  properties: {
10
21
  text: {
11
22
  type: String,
12
- value: wx.getStorageSync('$&watermark_text$*&') || '',
23
+ value: wx.getStorageSync(TEXT_KEY) || '',
13
24
  observer: function (newVal, oldVal) {
14
25
  this.setData({
15
26
  text: newVal,
@@ -1,6 +1,6 @@
1
1
  <view class="watermark" style="transform: rotate({{rotate}}deg);color: {{textColor}};font-size: {{textSize}}rpx;">
2
2
  <block wx:for="{{60}}" wx:key="row">
3
- <view class="watermark-row" style="margin-left: {{index % 2 === 0 ? 0 : gapX / 2}}rpx;margin-bottom: {{gapY}}rpx;">
3
+ <view class="watermark-row" style="margin-left: {{index % 2 === 0 ? 0 : textSize*text.length/2}}rpx;margin-bottom: {{gapY}}rpx;">
4
4
  <block wx:for="{{15}}" wx:key="col">
5
5
  <text class="watermark-col" style="margin-right: {{gapX}}rpx;">{{text}}</text>
6
6
  </block>
package/index.js DELETED
@@ -1,6 +0,0 @@
1
- const setWatermarkText = (text)=>{
2
- wx.setStorageSync('$&watermark_text$*&', text)
3
- }
4
- module.exports = {
5
- setWatermarkText
6
- }