Skip to content

Commit 732c999

Browse files
committed
Merge branch 'v2-dev' of https://github.com/jdf2e/nutui into v2-dev
2 parents 11e2d59 + b41c627 commit 732c999

File tree

3 files changed

+136
-109
lines changed

3 files changed

+136
-109
lines changed

src/packages/luckycard/demo.vue

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
<template>
2-
<div class="demo-list">
3-
<h4>基本用法</h4>
4-
<nut-luckycard
5-
content="1000万"
6-
></nut-luckycard>
7-
<h4>内容异步</h4>
8-
<nut-luckycard
9-
:content="val"
10-
></nut-luckycard>
11-
<h4>刮开层和背景层都支持自定义颜色,奖品信息支持HTML</h4>
12-
<nut-luckycard
13-
coverColor="#F9CC9D"
14-
backgroundColor="#C3D08B"
15-
content="<em>1000<em><strong>元</strong>"
16-
></nut-luckycard>
17-
<h4>刮开层支持图片</h4>
18-
<nut-luckycard
19-
content="1000万"
20-
:coverImg="coverImage"
21-
></nut-luckycard>
22-
</div>
2+
<div class="demo-list">
3+
<h4>基本用法</h4>
4+
<nut-luckycard content="1000万"></nut-luckycard>
5+
<h4>内容异步</h4>
6+
<nut-luckycard :content="val"></nut-luckycard>
7+
<h4>刮开层和背景层都支持自定义颜色,奖品信息支持HTML</h4>
8+
<nut-luckycard coverColor="#F9CC9D" backgroundColor="#C3D08B" content="<em>1000<em><strong>元</strong>"></nut-luckycard>
9+
<h4>刮开层支持图片</h4>
10+
<nut-luckycard content="1000万" :coverImg="coverImage"></nut-luckycard>
11+
<h4>事件回调</h4>
12+
<nut-luckycard content="1000万" @open="opencard"></nut-luckycard>
13+
<h4>设置刮开比列</h4>
14+
<nut-luckycard content="1000万" @open="opencard" ratio="0.2"></nut-luckycard>
15+
<p></p>
16+
</div>
2317
</template>
2418
<script>
2519
export default {
26-
data() {
27-
return {
28-
val:"谢谢惠顾",
29-
coverImage:""
30-
};
31-
},
32-
mounted(){
33-
setTimeout(() => {
34-
this.val="数据修改"
35-
}, 500);
36-
},
37-
methods: {
20+
data() {
21+
return {
22+
val: '谢谢惠顾',
23+
coverImage: ''
24+
};
25+
},
26+
mounted() {
27+
setTimeout(() => {
28+
this.val = '数据修改';
29+
}, 500);
30+
},
31+
methods: {
32+
opencard() {
33+
alert('callback');
3834
}
39-
}
40-
</script>
35+
}
36+
};
37+
</script>

src/packages/luckycard/doc.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
></nut-luckycard>
3333
```
3434

35+
## 事件回调
36+
37+
```html
38+
<nut-luckycard
39+
content="1000万"
40+
@open="opencard"
41+
></nut-luckycard>
42+
```
43+
## 设置刮开比例
44+
45+
```html
46+
<nut-luckycard
47+
content="1000万"
48+
@open="opencard"
49+
ratio="0.2"
50+
></nut-luckycard>
51+
```
52+
3553
## Prop
3654

3755
| 字段 | 说明 | 类型 | 默认值
@@ -43,7 +61,13 @@
4361
| coverImg | 刮开层是图片(不支持跨域。设置此项后coverColor失效) | String | ''
4462
| fontSize | 中奖信息字号 | String | 20px
4563
| backgroundColor | 内容层背景颜色 | String | '#FFFFFF'
46-
| ratio | 触发事件的刮开比 | Number |0.5(介于0-1之间)
64+
| ratio | 触发事件的刮开比 | Number |0.8(介于0-1之间)
65+
66+
## 事件
67+
68+
| 字段 | 说明 | 类型 | 默认值
69+
|----- | ----- | ----- | -----
70+
| open | 刮开后回调函数 | function | ''
4771

4872

4973

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,92 @@
11
<template>
2-
<div class="nut-luckycard" :style="{height:height+'px',width:width+'px'}">
3-
<div class="nut-content" v-html="content" :style="{backgroundColor:backgroundColor,fontSize:fontSize+'px'}"></div>
4-
</div>
2+
<div class="nut-luckycard" :style="{ height: height + 'px', width: width + 'px' }">
3+
<div class="nut-content" v-html="content" :style="{ backgroundColor: backgroundColor, fontSize: fontSize + 'px' }"></div>
4+
</div>
55
</template>
66

77
<script>
88
import LuckyCard from './luckycard.js';
99
export default {
10-
name:'nut-luckycard',
11-
props: {
12-
content:{
13-
type:String,
14-
default:''
15-
},
16-
height: {
17-
type: [String, Number],
18-
default: 50
19-
},
20-
width: {
21-
type: [String, Number],
22-
default: 300
23-
},
24-
coverColor:{
25-
type:String,
26-
default:'#C5C5C5'
27-
},
28-
coverImg:{
29-
type:String,
30-
default:''
31-
},
32-
fontSize:{
33-
type:[String, Number],
34-
default:20
35-
},
36-
backgroundColor:{
37-
type:String,
38-
default:'#FFFFFF'
39-
},
40-
ratio:{
41-
type: [String, Number],
42-
default:0.5
43-
}
10+
name: 'nut-luckycard',
11+
props: {
12+
content: {
13+
type: String,
14+
default: ''
15+
},
16+
height: {
17+
type: [String, Number],
18+
default: 50
19+
},
20+
width: {
21+
type: [String, Number],
22+
default: 300
23+
},
24+
coverColor: {
25+
type: String,
26+
default: '#C5C5C5'
27+
},
28+
coverImg: {
29+
type: String,
30+
default: ''
4431
},
45-
data() {
46-
return {};
32+
fontSize: {
33+
type: [String, Number],
34+
default: 20
4735
},
48-
methods: {
36+
backgroundColor: {
37+
type: String,
38+
default: '#FFFFFF'
4939
},
50-
mounted(){
51-
this.$nextTick(()=>{
52-
const _vm = this;
53-
LuckyCard({
54-
scratchDiv:this.$el,
55-
coverColor:this.coverColor,
56-
coverImg:this.coverImg,
57-
ratio:Number(this.ratio),
58-
callback:function(){
59-
//console.log(this);
60-
//this.clearCover();
61-
_vm.$emit('open',this);
62-
}
63-
})
64-
})
40+
ratio: {
41+
type: [String, Number],
42+
default: 0.5
6543
}
66-
}
44+
},
45+
data() {
46+
return {
47+
luckcard: null
48+
};
49+
},
50+
methods: {
51+
clearCover() {
52+
console.log(this.luckcard);
53+
this.luckcard.clearCover();
54+
}
55+
},
56+
mounted() {
57+
this.$nextTick(() => {
58+
const _vm = this;
59+
this.luckcard = LuckyCard({
60+
scratchDiv: this.$el,
61+
coverColor: this.coverColor,
62+
coverImg: this.coverImg,
63+
ratio: Number(this.ratio),
64+
callback: function() {
65+
//console.log(this);
66+
this.clearCover();
67+
_vm.$emit('open', this);
68+
}
69+
});
70+
});
71+
}
72+
};
6773
</script>
6874
<style lang="scss">
69-
.nut-luckycard{
70-
position: relative;
71-
.nut-cover{
72-
position:absolute;
73-
top:0;
74-
left:0;
75-
}
76-
.nut-content{
77-
display:flex;
78-
align-items: center;
79-
justify-content: center;
80-
height:100%;
81-
width:100%;
82-
line-height: 100%;
83-
user-select:none;
84-
}
75+
.nut-luckycard {
76+
position: relative;
77+
.nut-cover {
78+
position: absolute;
79+
top: 0;
80+
left: 0;
81+
}
82+
.nut-content {
83+
display: flex;
84+
align-items: center;
85+
justify-content: center;
86+
height: 100%;
87+
width: 100%;
88+
line-height: 100%;
89+
user-select: none;
90+
}
8591
}
86-
</style>
92+
</style>

0 commit comments

Comments
 (0)