Skip to content

Commit 802b22d

Browse files
author
xutao15
committed
modify rate
1 parent 203965a commit 802b22d

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
</a>
55
</p>
66

7-
# iView Weapp
7+
# iView mpvue
88

9-
### 一套高质量的微信小程序 UI 组件库
9+
### 一套高质量的小程序 UI 组件库
1010

1111
## 文档
1212
[https://weapp.iviewui.com](https://weapp.iviewui.com)

dist/components/rate/rate.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
:key="index"
77
:data-index="index"
88
:class="[index < value ? 'i-rate-current' : '']"
9-
class="i-rate-star">
9+
class="i-rate-star"
10+
@click="handleClick">
1011
<i-icon type="collection_fill" :size="size"></i-icon>
1112
</div>
12-
<div class="i-rate-text" v-if="value"><slot></slot></div>
13+
<div class="i-rate-text" v-if="value && showText">{{value}}{{showText}}</div>
1314
</div>
1415
</template>
1516
<script>
@@ -41,7 +42,11 @@ export default {
4142
},
4243
iClass: {
4344
type: String,
44-
default: 'dfsgdfg'
45+
default: ''
46+
},
47+
showText: {
48+
type: String,
49+
default: ''
4550
}
4651
},
4752
data() {
@@ -72,8 +77,15 @@ export default {
7277
})
7378
},
7479
handleTouchMove(evt) {
75-
if (this.disabled || evt.mp.ch) return
76-
80+
if (this.disabled || !evt.mp.changedTouches[0]) return
81+
const movePageX = evt.mp.changedTouches[0].pageX
82+
const space = movePageX - this.touchesStart.pageX
83+
if (space <= 0) {
84+
return
85+
}
86+
let setIndex = Math.ceil(space / this.size)
87+
setIndex = setIndex > this.count ? this.count : setIndex
88+
this.$emit('change', {index: setIndex})
7789
}
7890
}
7991
}

examples/src/app.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"pages/radio/main",
3737
"pages/checkbox/main",
3838
"pages/switch/main",
39-
"pages/rate/main",
40-
"pages/input-number/main"],
39+
"pages/rate/main"],
4140
"window": {
4241
"backgroundTextStyle": "light",
4342
"navigationBarBackgroundColor": "#fff",

examples/src/components/rate/rate.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
:key="index"
77
:data-index="index"
88
:class="[index < value ? 'i-rate-current' : '']"
9-
class="i-rate-star">
9+
class="i-rate-star"
10+
@click="handleClick">
1011
<i-icon type="collection_fill" :size="size"></i-icon>
1112
</div>
12-
<div class="i-rate-text" v-if="value"><slot></slot></div>
13+
<div class="i-rate-text" v-if="value && showText">{{value}}{{showText}}</div>
1314
</div>
1415
</template>
1516
<script>
@@ -41,7 +42,11 @@ export default {
4142
},
4243
iClass: {
4344
type: String,
44-
default: 'dfsgdfg'
45+
default: ''
46+
},
47+
showText: {
48+
type: String,
49+
default: ''
4550
}
4651
},
4752
data() {
@@ -72,8 +77,15 @@ export default {
7277
})
7378
},
7479
handleTouchMove(evt) {
75-
if (this.disabled || evt.mp.ch) return
76-
80+
if (this.disabled || !evt.mp.changedTouches[0]) return
81+
const movePageX = evt.mp.changedTouches[0].pageX
82+
const space = movePageX - this.touchesStart.pageX
83+
if (space <= 0) {
84+
return
85+
}
86+
let setIndex = Math.ceil(space / this.size)
87+
setIndex = setIndex > this.count ? this.count : setIndex
88+
this.$emit('change', {index: setIndex})
7789
}
7890
}
7991
}

examples/src/pages/rate/index.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
<i-cell title="自定义文字说明">
2525
<i-rate
2626
@change="onChange2"
27-
:value="starIndex2">
28-
{{starIndex2}}星
27+
:value="starIndex2"
28+
show-text="">
2929
</i-rate>
3030
</i-cell>
3131
<i-cell title="手势touch选择星">
3232
<i-rate
3333
@change="onChange3"
34-
:value="starIndex3">
35-
{{starIndex3}}星
34+
:value="starIndex3"
35+
show-text="">
3636
</i-rate>
3737
</i-cell>
3838
<i-cell title="禁用点击和手势选择星">
3939
<i-rate
4040
:disabled="true"
41-
:value="starIndex4">
42-
{{starIndex4}}星
41+
:value="starIndex4"
42+
show-text="">
4343
</i-rate>
4444
</i-cell>
4545
</i-cell-group>
@@ -66,16 +66,16 @@ export default {
6666
},
6767
methods: {
6868
onChange1(e) {
69-
69+
this.starIndex1 = e.index
7070
},
7171
onChange2(e) {
72-
72+
this.starIndex2 = e.index
7373
},
7474
onChange3(e) {
75-
75+
this.starIndex3 = e.index
7676
},
7777
onChange5(e) {
78-
78+
this.starIndex5 = e.index
7979
}
8080
}
8181
}

src/components/rate/rate.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
:key="index"
77
:data-index="index"
88
:class="[index < value ? 'i-rate-current' : '']"
9-
class="i-rate-star">
9+
class="i-rate-star"
10+
@click="handleClick">
1011
<i-icon type="collection_fill" :size="size"></i-icon>
1112
</div>
12-
<div class="i-rate-text" v-if="value"><slot></slot></div>
13+
<div class="i-rate-text" v-if="value && showText">{{value}}{{showText}}</div>
1314
</div>
1415
</template>
1516
<script>
@@ -41,7 +42,11 @@ export default {
4142
},
4243
iClass: {
4344
type: String,
44-
default: 'dfsgdfg'
45+
default: ''
46+
},
47+
showText: {
48+
type: String,
49+
default: ''
4550
}
4651
},
4752
data() {
@@ -72,8 +77,15 @@ export default {
7277
})
7378
},
7479
handleTouchMove(evt) {
75-
if (this.disabled || evt.mp.ch) return
76-
80+
if (this.disabled || !evt.mp.changedTouches[0]) return
81+
const movePageX = evt.mp.changedTouches[0].pageX
82+
const space = movePageX - this.touchesStart.pageX
83+
if (space <= 0) {
84+
return
85+
}
86+
let setIndex = Math.ceil(space / this.size)
87+
setIndex = setIndex > this.count ? this.count : setIndex
88+
this.$emit('change', {index: setIndex})
7789
}
7890
}
7991
}

0 commit comments

Comments
 (0)