Skip to content

Commit a623ef8

Browse files
committed
build: Travis CI automatic compilation
1 parent dabce63 commit a623ef8

File tree

4 files changed

+57
-80
lines changed

4 files changed

+57
-80
lines changed

dist/counter/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/counter/index.wxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<view class="l-class container-count">
2-
<view class="symbol {{result<=min|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}" catchtap="{{result<=min|| disabled?'doNothing':'reduceTap'}}" data-type="overflow_min" hover-class="{{isHover?'count-hover':''}}">
2+
<view class="symbol {{count<=min|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}" catchtap="{{count<=min|| disabled?'doNothing':'onTapChange'}}" data-type="overflow_min" data-change-type="reduce" hover-class="{{isHover?'count-hover':''}}">
33
<view class="l-icon l-icon-reduce" style="font-size:{{iconSize}};color:{{iconColor}}"></view>
44
</view>
5-
<input wx:if="{{focus}}" class="l-count-class count" disabled="{{disabled}}" type="number" focus="{{focus}}" value="{{result}}" bind:input="onInput" bindblur="onBlur"/>
6-
<view wx:else class="l-count-class count" mut-bind:tap="onCount">{{result}}</view>
7-
<view class="l-symbol-class symbol {{result>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}" catchtap="{{result>=max|| disabled?'doNothing':'addTap'}}" data-type="overflow_max" hover-class="{{isHover?'count-hover':''}}">
5+
<input hidden="{{!focus}}" class="l-count-class count" disabled="{{disabled}}" type="number" focus="{{focus}}" value="{{count}}" bind:input="onInput" bindblur="onBlur"/>
6+
<view hidden="{{focus}}" class="l-count-class count" mut-bind:tap="onCount">{{count}}</view>
7+
<view class="l-symbol-class symbol {{count>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}" catchtap="{{count>=max|| disabled?'doNothing':'onTapChange'}}" data-type="overflow_max" data-change-type="add" hover-class="{{isHover?'count-hover':''}}">
88
<view class="l-icon l-icon-add" style="font-size:{{iconSize}};color:{{iconColor}}"></view>
99
</view>
1010
</view>

examples/dist/counter/index.js

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import hover from '../behaviors/hover';
21
import eventUtil from '../core/utils/event-util';
32

43
Component({
5-
behaviors: [hover],
64
externalClasses: [
75
'l-class',
86
'l-symbol-class',
@@ -35,12 +33,11 @@ Component({
3533
* 组件的初始数据
3634
*/
3735
data: {
38-
focus: false,
39-
result: 1
36+
focus: false
4037
},
4138

4239
observers: {
43-
'result': function (count) {
40+
'count': function (count) {
4441
eventUtil.emit(this, 'linchange', { count });
4542
},
4643
'count,min,max': function () {
@@ -58,97 +55,75 @@ Component({
5855
},
5956

6057
onCount() {
61-
this.setData({
62-
focus: true
63-
});
58+
this.setData({ focus: true });
6459
},
6560

6661
onBlur(e) {
67-
this.setData({
68-
focus: false
69-
});
7062
let {
7163
value
7264
} = e.detail;
7365
setTimeout(() => {
7466
this.blurCount(Number(value), () => {
75-
this.data.count = this.data.result;
76-
eventUtil.emit(this, 'lintap', { count: this.data.result, type: 'blur' });
67+
eventUtil.emit(this, 'lintap', { count: this.data.count, type: 'blur' });
7768
});
7869
}, 50);
7970
},
8071

8172
blurCount(value, callback) {
8273
if (value) {
8374
this.valueRange(value);
84-
} else {
85-
this.setData({
86-
result: this.properties.count
87-
});
8875
}
8976
callback && callback();
9077
},
9178

9279
valueRange(value, way = 'input') {
93-
if (value > this.properties.max) {
94-
this.setData({
95-
result: this.properties.max
96-
}, () => {
97-
eventUtil.emit(this, 'linout', { type: 'overflow_max', way });
98-
});
99-
} else if (value < this.properties.min) {
100-
this.setData({
101-
result: this.properties.min
102-
}, () => {
103-
eventUtil.emit(this, 'linout', { type: 'overflow_min', way });
104-
});
105-
} else {
106-
this.setData({
107-
result: value
108-
});
109-
}
110-
},
80+
const { count, min, max } = this.data;
11181

112-
reduceTap() {
113-
let distance = this.data.count - this.properties.step;
114-
if (distance <= this.properties.min) {
115-
this.data.count = this.properties.min;
116-
} else {
117-
this.data.count -= this.properties.step;
118-
}
119-
this.setData({
120-
result: this.data.count
121-
});
122-
this.triggerEvent('lintap', {
123-
count: this.data.result,
124-
type: 'reduce'
125-
}, {
126-
bubbles: true,
127-
composed: true
82+
// 数据错误,显示警告
83+
way === 'parameter' && value > max && console.error(`Counter 组件:初始值 ${count} 大于了最大值 ${max},请注意修正`);
84+
way === 'parameter' && value < min && console.error(`Counter 组件:初始值 ${count} 小于了最小值 ${min},请注意修正`);
85+
86+
// 触发相应事件
87+
value > max && eventUtil.emit(this, 'linout', { type: 'overflow_max', way });
88+
value < min && eventUtil.emit(this, 'linout', { type: 'overflow_min', way });
89+
90+
// 如果 value 越界,则修正其值
91+
value = value > max ? max : value;
92+
value = value < min ? min : value;
93+
94+
// 更新页面显示数值
95+
value === this.data.count && this.setData({ focus: false });
96+
value !== this.data.count && this.setData({ count: value }, () => {
97+
this.setData({ focus: false });
12898
});
12999
},
130100

131-
addTap() {
132-
let distance = this.data.count + this.properties.step;
133-
if (distance >= this.properties.max) {
134-
this.data.count = this.properties.max;
135-
} else {
136-
this.data.count += this.properties.step;
101+
/**
102+
* 点击 +/- 改变数值的监听函数
103+
*
104+
* @param {Object} e 事件对象
105+
*/
106+
onTapChange(e) {
107+
const type = e.currentTarget.dataset.changeType;
108+
const { count, step, min, max } = this.data;
109+
let result;
110+
111+
// 根据 +/- 做不同运算
112+
if (type === 'add') {
113+
result = count + step > max ? max : count + step;
114+
} else if (type === 'reduce') {
115+
result = count - step < min ? min : count - step;
137116
}
138-
this.setData({
139-
result: this.data.count
140-
});
141-
this.triggerEvent('lintap', {
142-
count: this.data.result,
143-
type: 'add'
144-
}, {
145-
bubbles: true,
146-
composed: true
117+
118+
this.setData({ count: result });
119+
eventUtil.emit(this, 'lintap', {
120+
count: this.data.count,
121+
type
147122
});
148123
},
149124

150-
onInput(e){
151-
eventUtil.emit(this,'lininput',e.detail);
125+
onInput(e) {
126+
eventUtil.emit(this, 'lininput', e.detail);
152127
}
153128
}
154129
});

examples/dist/counter/index.wxml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<view class="l-class container-count">
2-
<view class="symbol {{result<=min|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
3-
catchtap="{{result<=min|| disabled?'doNothing':'reduceTap'}}"
2+
<view class="symbol {{count<=min|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
3+
catchtap="{{count<=min|| disabled?'doNothing':'onTapChange'}}"
44
data-type="overflow_min"
5+
data-change-type="reduce"
56
hover-class="{{isHover?'count-hover':''}}">
67
<view class="l-icon l-icon-reduce" style="font-size:{{iconSize}};color:{{iconColor}}"></view>
78
</view>
8-
<input wx:if="{{focus}}"
9+
<input hidden="{{!focus}}"
910
class="l-count-class count"
1011
disabled="{{disabled}}"
1112
type="number"
1213
focus="{{focus}}"
13-
value="{{result}}"
14+
value="{{count}}"
1415
bind:input="onInput"
1516
bindblur="onBlur"/>
16-
<view wx:else class="l-count-class count" mut-bind:tap="onCount">{{result}}</view>
17-
<view class="l-symbol-class symbol {{result>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
18-
catchtap="{{result>=max|| disabled?'doNothing':'addTap'}}"
17+
<view hidden="{{focus}}" class="l-count-class count" mut-bind:tap="onCount">{{count}}</view>
18+
<view class="l-symbol-class symbol {{count>=max|| disabled?'disabled l-disabled-class':'abled l-symbol-class'}}"
19+
catchtap="{{count>=max|| disabled?'doNothing':'onTapChange'}}"
1920
data-type="overflow_max"
21+
data-change-type="add"
2022
hover-class="{{isHover?'count-hover':''}}">
2123
<view class="l-icon l-icon-add" style="font-size:{{iconSize}};color:{{iconColor}}"></view>
2224
</view>

0 commit comments

Comments
 (0)