@10yun/cv-mobile-ui 0.5.20 → 0.5.21
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 +1 -1
- package/ui-cv/components/cv-grid-item/cv-grid-item.vue +1 -1
- package/uni-ui/lib/uni-badge/uni-badge.vue +150 -1
- package/uni-ui/lib/uni-breadcrumb/uni-breadcrumb.vue +37 -1
- package/uni-ui/lib/uni-breadcrumb-item/uni-breadcrumb-item.vue +83 -1
- package/uni-ui/lib/uni-calendar/uni-calendar-item.vue +122 -1
- package/uni-ui/lib/uni-calendar/uni-calendar.vue +366 -1
- package/uni-ui/lib/uni-card/uni-card.vue +124 -1
- package/uni-ui/lib/uni-col/uni-col.vue +1 -1
- package/uni-ui/lib/uni-collapse/uni-collapse.vue +135 -1
- package/uni-ui/lib/uni-collapse-item/uni-collapse-item.vue +266 -1
- package/uni-ui/lib/uni-combox/uni-combox.vue +1 -1
- package/uni-ui/lib/uni-countdown/uni-countdown.vue +239 -1
- package/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue +487 -1
- package/uni-ui/lib/uni-data-picker/uni-data-picker.vue +530 -1
- package/uni-ui/lib/uni-data-pickerview/uni-data-picker.js +157 -150
- package/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.vue +166 -1
- package/uni-ui/lib/uni-data-select/uni-data-select.vue +289 -1
- package/uni-ui/lib/uni-datetime-picker/calendar-item.vue +70 -1
- package/uni-ui/lib/uni-datetime-picker/calendar.vue +629 -1
- package/uni-ui/lib/uni-datetime-picker/time-picker.vue +741 -1
- package/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue +847 -1
- package/uni-ui/lib/uni-drawer/uni-drawer.vue +115 -1
- package/uni-ui/lib/uni-easyinput/uni-easyinput.vue +515 -1
- package/uni-ui/lib/uni-fab/uni-fab.vue +257 -1
- package/uni-ui/lib/uni-fav/uni-fav.vue +123 -1
- package/uni-ui/lib/uni-file-picker/uni-file-picker.vue +642 -1
- package/uni-ui/lib/uni-file-picker/upload-file.vue +177 -1
- package/uni-ui/lib/uni-file-picker/upload-image.vue +176 -1
- package/uni-ui/lib/uni-forms/uni-forms.vue +375 -1
- package/uni-ui/lib/uni-forms-item/uni-forms-item.vue +429 -1
- package/uni-ui/lib/uni-goods-nav/uni-goods-nav.vue +129 -1
- package/uni-ui/lib/uni-grid/uni-grid.vue +115 -1
- package/uni-ui/lib/uni-grid-item/uni-grid-item.vue +78 -1
- package/uni-ui/lib/uni-group/uni-group.vue +85 -1
- package/uni-ui/lib/uni-icons/uni-icons.vue +85 -1
- package/uni-ui/lib/uni-indexed-list/uni-indexed-list-item.vue +68 -1
- package/uni-ui/lib/uni-indexed-list/uni-indexed-list.vue +294 -1
- package/uni-ui/lib/uni-list/uni-list.vue +81 -1
- package/uni-ui/lib/uni-list-ad/uni-list-ad.vue +77 -1
- package/uni-ui/lib/uni-list-chat/uni-list-chat.vue +294 -1
- package/uni-ui/lib/uni-list-item/uni-list-item.vue +346 -1
- package/uni-ui/lib/uni-load-more/uni-load-more.vue +172 -1
- package/uni-ui/lib/uni-nav-bar/uni-nav-bar.vue +205 -1
- package/uni-ui/lib/uni-nav-bar/uni-status-bar.vue +18 -1
- package/uni-ui/lib/uni-notice-bar/uni-notice-bar.vue +331 -1
- package/uni-ui/lib/uni-number-box/uni-number-box.vue +166 -1
- package/uni-ui/lib/uni-pagination/uni-pagination.vue +323 -1
- package/uni-ui/lib/uni-popup/uni-popup.vue +1 -1
- package/uni-ui/lib/uni-popup-dialog/uni-popup-dialog.vue +173 -1
- package/uni-ui/lib/uni-popup-message/uni-popup-message.vue +74 -1
- package/uni-ui/lib/uni-popup-share/uni-popup-share.vue +106 -1
- package/uni-ui/lib/uni-rate/uni-rate.vue +322 -1
- package/uni-ui/lib/uni-row/uni-row.vue +1 -1
- package/uni-ui/lib/uni-search-bar/uni-search-bar.vue +236 -1
- package/uni-ui/lib/uni-section/uni-section.vue +109 -1
- package/uni-ui/lib/uni-segmented-control/uni-segmented-control.vue +103 -1
- package/uni-ui/lib/uni-status-bar/uni-status-bar.vue +1 -1
- package/uni-ui/lib/uni-steps/uni-steps.vue +120 -1
- package/uni-ui/lib/uni-swipe-action-item/uni-swipe-action-item.vue +226 -3
- package/uni-ui/lib/uni-swiper-dot/uni-swiper-dot.vue +167 -1
- package/uni-ui/lib/uni-table/uni-table.vue +297 -1
- package/uni-ui/lib/uni-tag/uni-tag.vue +100 -1
- package/uni-ui/lib/uni-td/uni-td.vue +78 -1
- package/uni-ui/lib/uni-th/filter-dropdown.vue +1 -1
- package/uni-ui/lib/uni-th/uni-th.vue +224 -1
- package/uni-ui/lib/uni-thead/uni-thead.vue +77 -1
- package/uni-ui/lib/uni-tr/table-checkbox.vue +79 -1
- package/uni-ui/lib/uni-tr/uni-tr.vue +135 -1
|
@@ -1 +1,322 @@
|
|
|
1
|
-
<template>
|
|
2
1
|
<view>
|
|
3
2
|
<view ref="uni-rate" class="uni-rate">
|
|
4
3
|
<view
|
|
5
4
|
class="uni-rate__icon"
|
|
6
5
|
:class="{ 'uni-cursor-not-allowed': disabled }"
|
|
7
6
|
:style="{ 'margin-right': marginNumber + 'px' }"
|
|
8
7
|
v-for="(star, index) in stars"
|
|
9
8
|
:key="index"
|
|
10
9
|
@touchstart.stop="touchstart"
|
|
11
10
|
@touchmove.stop="touchmove"
|
|
12
11
|
@mousedown.stop="mousedown"
|
|
13
12
|
@mousemove.stop="mousemove"
|
|
14
13
|
@mouseleave="mouseleave"
|
|
15
14
|
>
|
|
16
15
|
<uni-icons :color="color" :size="size" :type="isFill ? 'star-filled' : 'star'" />
|
|
17
16
|
<!-- #ifdef APP-NVUE -->
|
|
18
17
|
<view :style="{ width: (star.activeWitch.replace('%', '') * size) / 100 + 'px' }" class="uni-rate__icon-on">
|
|
19
18
|
<uni-icons style="text-align: left" :color="disabled ? '#ccc' : activeColor" :size="size" type="star-filled" />
|
|
20
19
|
</view>
|
|
21
20
|
<!-- #endif -->
|
|
22
21
|
<!-- #ifndef APP-NVUE -->
|
|
23
22
|
<view :style="{ width: star.activeWitch }" class="uni-rate__icon-on">
|
|
24
23
|
<uni-icons :color="disabled ? disabledColor : activeColor" :size="size" type="star-filled" />
|
|
25
24
|
</view>
|
|
26
25
|
<!-- #endif -->
|
|
27
26
|
</view>
|
|
28
27
|
</view>
|
|
29
28
|
</view>
|
|
30
29
|
* Rate 评分
|
|
31
30
|
* @description 评分组件
|
|
32
31
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=33
|
|
33
32
|
* @property {Boolean} isFill = [true|false] 星星的类型,是否为实心类型, 默认为实心
|
|
34
33
|
* @property {String} color 未选中状态的星星颜色,默认为 "#ececec"
|
|
35
34
|
* @property {String} activeColor 选中状态的星星颜色,默认为 "#ffca3e"
|
|
36
35
|
* @property {String} disabledColor 禁用状态的星星颜色,默认为 "#c0c0c0"
|
|
37
36
|
* @property {Number} size 星星的大小
|
|
38
37
|
* @property {Number} value/v-model 当前评分
|
|
39
38
|
* @property {Number} max 最大评分评分数量,目前一分一颗星
|
|
40
39
|
* @property {Number} margin 星星的间距,单位 px
|
|
41
40
|
* @property {Boolean} disabled = [true|false] 是否为禁用状态,默认为 false
|
|
42
41
|
* @property {Boolean} readonly = [true|false] 是否为只读状态,默认为 false
|
|
43
42
|
* @property {Boolean} allowHalf = [true|false] 是否实现半星,默认为 false
|
|
44
43
|
* @property {Boolean} touchable = [true|false] 是否支持滑动手势,默认为 true
|
|
45
44
|
* @event {Function} change uniRate 的 value 改变时触发事件,e={value:Number}
|
|
46
45
|
*/
|
|
47
46
|
name: 'UniRate',
|
|
48
47
|
props: {
|
|
49
48
|
isFill: {
|
|
50
49
|
// 星星的类型,是否镂空
|
|
51
50
|
type: [Boolean, String],
|
|
52
51
|
default: true
|
|
53
52
|
},
|
|
54
53
|
color: {
|
|
55
54
|
// 星星未选中的颜色
|
|
56
55
|
type: String,
|
|
57
56
|
default: '#ececec'
|
|
58
57
|
},
|
|
59
58
|
activeColor: {
|
|
60
59
|
// 星星选中状态颜色
|
|
61
60
|
type: String,
|
|
62
61
|
default: '#ffca3e'
|
|
63
62
|
},
|
|
64
63
|
disabledColor: {
|
|
65
64
|
// 星星禁用状态颜色
|
|
66
65
|
type: String,
|
|
67
66
|
default: '#c0c0c0'
|
|
68
67
|
},
|
|
69
68
|
size: {
|
|
70
69
|
// 星星的大小
|
|
71
70
|
type: [Number, String],
|
|
72
71
|
default: 24
|
|
73
72
|
},
|
|
74
73
|
value: {
|
|
75
74
|
// 当前评分
|
|
76
75
|
type: [Number, String],
|
|
77
76
|
default: 0
|
|
78
77
|
},
|
|
79
78
|
modelValue: {
|
|
80
79
|
// 当前评分
|
|
81
80
|
type: [Number, String],
|
|
82
81
|
default: 0
|
|
83
82
|
},
|
|
84
83
|
max: {
|
|
85
84
|
// 最大评分
|
|
86
85
|
type: [Number, String],
|
|
87
86
|
default: 5
|
|
88
87
|
},
|
|
89
88
|
margin: {
|
|
90
89
|
// 星星的间距
|
|
91
90
|
type: [Number, String],
|
|
92
91
|
default: 0
|
|
93
92
|
},
|
|
94
93
|
disabled: {
|
|
95
94
|
// 是否可点击
|
|
96
95
|
type: [Boolean, String],
|
|
97
96
|
default: false
|
|
98
97
|
},
|
|
99
98
|
readonly: {
|
|
100
99
|
// 是否只读
|
|
101
100
|
type: [Boolean, String],
|
|
102
101
|
default: false
|
|
103
102
|
},
|
|
104
103
|
allowHalf: {
|
|
105
104
|
// 是否显示半星
|
|
106
105
|
type: [Boolean, String],
|
|
107
106
|
default: false
|
|
108
107
|
},
|
|
109
108
|
touchable: {
|
|
110
109
|
// 是否支持滑动手势
|
|
111
110
|
type: [Boolean, String],
|
|
112
111
|
default: true
|
|
113
112
|
}
|
|
114
113
|
},
|
|
115
114
|
data() {
|
|
116
115
|
return {
|
|
117
116
|
valueSync: '',
|
|
118
117
|
userMouseFristMove: true,
|
|
119
118
|
userRated: false,
|
|
120
119
|
userLastRate: 1
|
|
121
120
|
};
|
|
122
121
|
},
|
|
123
122
|
watch: {
|
|
124
123
|
value(newVal) {
|
|
125
124
|
this.valueSync = Number(newVal);
|
|
126
125
|
},
|
|
127
126
|
modelValue(newVal) {
|
|
128
127
|
this.valueSync = Number(newVal);
|
|
129
128
|
}
|
|
130
129
|
},
|
|
131
130
|
computed: {
|
|
132
131
|
stars() {
|
|
133
132
|
const value = this.valueSync ? this.valueSync : 0;
|
|
134
133
|
const starList = [];
|
|
135
134
|
const floorValue = Math.floor(value);
|
|
136
135
|
const ceilValue = Math.ceil(value);
|
|
137
136
|
for (let i = 0; i < this.max; i++) {
|
|
138
137
|
if (floorValue > i) {
|
|
139
138
|
starList.push({
|
|
140
139
|
activeWitch: '100%'
|
|
141
140
|
});
|
|
142
141
|
} else if (ceilValue - 1 === i) {
|
|
143
142
|
starList.push({
|
|
144
143
|
activeWitch: (value - floorValue) * 100 + '%'
|
|
145
144
|
});
|
|
146
145
|
} else {
|
|
147
146
|
starList.push({
|
|
148
147
|
activeWitch: '0'
|
|
149
148
|
});
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
151
|
return starList;
|
|
153
152
|
},
|
|
154
153
|
marginNumber() {
|
|
155
154
|
return Number(this.margin);
|
|
156
155
|
}
|
|
157
156
|
},
|
|
158
157
|
created() {
|
|
159
158
|
this.valueSync = Number(this.value || this.modelValue);
|
|
160
159
|
this._rateBoxLeft = 0;
|
|
161
160
|
this._oldValue = null;
|
|
162
161
|
},
|
|
163
162
|
mounted() {
|
|
164
163
|
setTimeout(() => {
|
|
165
164
|
this._getSize();
|
|
166
165
|
}, 100);
|
|
167
166
|
// #ifdef H5
|
|
168
167
|
this.PC = this.IsPC();
|
|
169
168
|
// #endif
|
|
170
169
|
},
|
|
171
170
|
methods: {
|
|
172
171
|
touchstart(e) {
|
|
173
172
|
// #ifdef H5
|
|
174
173
|
if (this.IsPC()) return;
|
|
175
174
|
// #endif
|
|
176
175
|
if (this.readonly || this.disabled) return;
|
|
177
176
|
const { clientX, screenX } = e.changedTouches[0];
|
|
178
177
|
// TODO 做一下兼容,只有 Nvue 下才有 screenX,其他平台式 clientX
|
|
179
178
|
this._getRateCount(clientX || screenX);
|
|
180
179
|
},
|
|
181
180
|
touchmove(e) {
|
|
182
181
|
// #ifdef H5
|
|
183
182
|
if (this.IsPC()) return;
|
|
184
183
|
// #endif
|
|
185
184
|
if (this.readonly || this.disabled || !this.touchable) return;
|
|
186
185
|
const { clientX, screenX } = e.changedTouches[0];
|
|
187
186
|
this._getRateCount(clientX || screenX);
|
|
188
187
|
},
|
|
189
188
|
/**
|
|
190
189
|
* 兼容 PC @tian
|
|
191
190
|
*/
|
|
192
191
|
mousedown(e) {
|
|
193
192
|
// #ifdef H5
|
|
194
193
|
if (!this.IsPC()) return;
|
|
195
194
|
if (this.readonly || this.disabled) return;
|
|
196
195
|
const { clientX } = e;
|
|
197
196
|
this.userLastRate = this.valueSync;
|
|
198
197
|
this._getRateCount(clientX);
|
|
199
198
|
this.userRated = true;
|
|
200
199
|
// #endif
|
|
201
200
|
},
|
|
202
201
|
mousemove(e) {
|
|
203
202
|
// #ifdef H5
|
|
204
203
|
if (!this.IsPC()) return;
|
|
205
204
|
if (this.userRated) return;
|
|
206
205
|
if (this.userMouseFristMove) {
|
|
207
206
|
console.log('---mousemove----', this.valueSync);
|
|
208
207
|
this.userLastRate = this.valueSync;
|
|
209
208
|
this.userMouseFristMove = false;
|
|
210
209
|
}
|
|
211
210
|
if (this.readonly || this.disabled || !this.touchable) return;
|
|
212
211
|
const { clientX } = e;
|
|
213
212
|
this._getRateCount(clientX);
|
|
214
213
|
// #endif
|
|
215
214
|
},
|
|
216
215
|
mouseleave(e) {
|
|
217
216
|
// #ifdef H5
|
|
218
217
|
if (!this.IsPC()) return;
|
|
219
218
|
if (this.readonly || this.disabled || !this.touchable) return;
|
|
220
219
|
if (this.userRated) {
|
|
221
220
|
this.userRated = false;
|
|
222
221
|
return;
|
|
223
222
|
}
|
|
224
223
|
this.valueSync = this.userLastRate;
|
|
225
224
|
// #endif
|
|
226
225
|
},
|
|
227
226
|
// #ifdef H5
|
|
228
227
|
IsPC() {
|
|
229
228
|
var userAgentInfo = navigator.userAgent;
|
|
230
229
|
var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
|
|
231
230
|
var flag = true;
|
|
232
231
|
for (let v = 0; v < Agents.length - 1; v++) {
|
|
233
232
|
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
|
234
233
|
flag = false;
|
|
235
234
|
break;
|
|
236
235
|
}
|
|
237
236
|
}
|
|
238
237
|
return flag;
|
|
239
238
|
},
|
|
240
239
|
// #endif
|
|
241
240
|
/**
|
|
242
241
|
* 获取星星个数
|
|
243
242
|
*/
|
|
244
243
|
_getRateCount(clientX) {
|
|
245
244
|
const _this = this;
|
|
246
245
|
this._getSize(function () {
|
|
247
246
|
const size = Number(_this.size);
|
|
248
247
|
if (isNaN(size)) {
|
|
249
248
|
return new Error('size 属性只能设置为数字');
|
|
250
249
|
}
|
|
251
250
|
const rateMoveRange = clientX - _this._rateBoxLeft;
|
|
252
251
|
let index = parseInt(rateMoveRange / (size + _this.marginNumber));
|
|
253
252
|
index = index < 0 ? 0 : index;
|
|
254
253
|
index = index > _this.max ? _this.max : index;
|
|
255
254
|
const range = parseInt(rateMoveRange - (size + _this.marginNumber) * index);
|
|
256
255
|
let value = 0;
|
|
257
256
|
if (_this._oldValue === index && !_this.PC) return;
|
|
258
257
|
_this._oldValue = index;
|
|
259
258
|
if (_this.allowHalf) {
|
|
260
259
|
if (range > size / 2) {
|
|
261
260
|
value = index + 1;
|
|
262
261
|
} else {
|
|
263
262
|
value = index + 0.5;
|
|
264
263
|
}
|
|
265
264
|
} else {
|
|
266
265
|
value = index + 1;
|
|
267
266
|
}
|
|
268
267
|
value = Math.max(0.5, Math.min(value, _this.max));
|
|
269
268
|
_this.valueSync = value;
|
|
270
269
|
_this._onChange();
|
|
271
270
|
});
|
|
272
271
|
},
|
|
273
272
|
/**
|
|
274
273
|
* 触发动态修改
|
|
275
274
|
*/
|
|
276
275
|
_onChange() {
|
|
277
276
|
this.$emit('input', this.valueSync);
|
|
278
277
|
this.$emit('update:modelValue', this.valueSync);
|
|
279
278
|
this.$emit('change', {
|
|
280
279
|
value: this.valueSync
|
|
281
280
|
});
|
|
282
281
|
},
|
|
283
282
|
/**
|
|
284
283
|
* 获取星星距离屏幕左侧距离
|
|
285
284
|
*/
|
|
286
285
|
_getSize(fn) {
|
|
287
286
|
// #ifndef APP-NVUE
|
|
288
287
|
uni
|
|
289
288
|
.createSelectorQuery()
|
|
290
289
|
.in(this)
|
|
291
290
|
.select('.uni-rate')
|
|
292
291
|
.boundingClientRect()
|
|
293
292
|
.exec((ret) => {
|
|
294
293
|
if (ret) {
|
|
295
294
|
this._rateBoxLeft = ret[0].left;
|
|
296
295
|
fn && fn();
|
|
297
296
|
}
|
|
298
297
|
});
|
|
299
298
|
// #endif
|
|
300
299
|
// #ifdef APP-NVUE
|
|
301
300
|
dom.getComponentRect(this.$refs['uni-rate'], (ret) => {
|
|
302
301
|
const size = ret.size;
|
|
303
302
|
if (size) {
|
|
304
303
|
this._rateBoxLeft = size.left;
|
|
305
304
|
fn && fn();
|
|
306
305
|
}
|
|
307
306
|
});
|
|
308
307
|
// #endif
|
|
309
308
|
}
|
|
310
309
|
}
|
|
310
|
+
<template>
|
|
311
|
+
<view>
|
|
312
|
+
<view ref="uni-rate" class="uni-rate">
|
|
313
|
+
<view
|
|
314
|
+
class="uni-rate__icon"
|
|
315
|
+
:class="{ 'uni-cursor-not-allowed': disabled }"
|
|
316
|
+
:style="{ 'margin-right': marginNumber + 'px' }"
|
|
317
|
+
v-for="(star, index) in stars"
|
|
318
|
+
:key="index"
|
|
319
|
+
@touchstart.stop="touchstart"
|
|
320
|
+
@touchmove.stop="touchmove"
|
|
321
|
+
@mousedown.stop="mousedown"
|
|
322
|
+
@mousemove.stop="mousemove"
|
|
323
|
+
@mouseleave="mouseleave"
|
|
324
|
+
>
|
|
325
|
+
<uni-icons :color="color" :size="size" :type="isFill ? 'star-filled' : 'star'" />
|
|
326
|
+
<!-- #ifdef APP-NVUE -->
|
|
327
|
+
<view :style="{ width: (star.activeWitch.replace('%', '') * size) / 100 + 'px' }" class="uni-rate__icon-on">
|
|
328
|
+
<uni-icons style="text-align: left" :color="disabled ? '#ccc' : activeColor" :size="size" type="star-filled" />
|
|
329
|
+
</view>
|
|
330
|
+
<!-- #endif -->
|
|
331
|
+
<!-- #ifndef APP-NVUE -->
|
|
332
|
+
<view :style="{ width: star.activeWitch }" class="uni-rate__icon-on">
|
|
333
|
+
<uni-icons :color="disabled ? disabledColor : activeColor" :size="size" type="star-filled" />
|
|
334
|
+
</view>
|
|
335
|
+
<!-- #endif -->
|
|
336
|
+
</view>
|
|
337
|
+
</view>
|
|
338
|
+
</view>
|
|
339
|
+
</template>
|
|
340
|
+
<script>
|
|
341
|
+
// #ifdef APP-NVUE
|
|
342
|
+
const dom = uni.requireNativePlugin('dom');
|
|
343
|
+
// #endif
|
|
344
|
+
/**
|
|
345
|
+
* Rate 评分
|
|
346
|
+
* @description 评分组件
|
|
347
|
+
* @tutorial https://ext.dcloud.net.cn/plugin?id=33
|
|
348
|
+
* @property {Boolean} isFill = [true|false] 星星的类型,是否为实心类型, 默认为实心
|
|
349
|
+
* @property {String} color 未选中状态的星星颜色,默认为 "#ececec"
|
|
350
|
+
* @property {String} activeColor 选中状态的星星颜色,默认为 "#ffca3e"
|
|
351
|
+
* @property {String} disabledColor 禁用状态的星星颜色,默认为 "#c0c0c0"
|
|
352
|
+
* @property {Number} size 星星的大小
|
|
353
|
+
* @property {Number} value/v-model 当前评分
|
|
354
|
+
* @property {Number} max 最大评分评分数量,目前一分一颗星
|
|
355
|
+
* @property {Number} margin 星星的间距,单位 px
|
|
356
|
+
* @property {Boolean} disabled = [true|false] 是否为禁用状态,默认为 false
|
|
357
|
+
* @property {Boolean} readonly = [true|false] 是否为只读状态,默认为 false
|
|
358
|
+
* @property {Boolean} allowHalf = [true|false] 是否实现半星,默认为 false
|
|
359
|
+
* @property {Boolean} touchable = [true|false] 是否支持滑动手势,默认为 true
|
|
360
|
+
* @event {Function} change uniRate 的 value 改变时触发事件,e={value:Number}
|
|
361
|
+
*/
|
|
362
|
+
export default {
|
|
363
|
+
name: 'UniRate',
|
|
364
|
+
props: {
|
|
365
|
+
isFill: {
|
|
366
|
+
// 星星的类型,是否镂空
|
|
367
|
+
type: [Boolean, String],
|
|
368
|
+
default: true
|
|
369
|
+
},
|
|
370
|
+
color: {
|
|
371
|
+
// 星星未选中的颜色
|
|
372
|
+
type: String,
|
|
373
|
+
default: '#ececec'
|
|
374
|
+
},
|
|
375
|
+
activeColor: {
|
|
376
|
+
// 星星选中状态颜色
|
|
377
|
+
type: String,
|
|
378
|
+
default: '#ffca3e'
|
|
379
|
+
},
|
|
380
|
+
disabledColor: {
|
|
381
|
+
// 星星禁用状态颜色
|
|
382
|
+
type: String,
|
|
383
|
+
default: '#c0c0c0'
|
|
384
|
+
},
|
|
385
|
+
size: {
|
|
386
|
+
// 星星的大小
|
|
387
|
+
type: [Number, String],
|
|
388
|
+
default: 24
|
|
389
|
+
},
|
|
390
|
+
value: {
|
|
391
|
+
// 当前评分
|
|
392
|
+
type: [Number, String],
|
|
393
|
+
default: 0
|
|
394
|
+
},
|
|
395
|
+
modelValue: {
|
|
396
|
+
// 当前评分
|
|
397
|
+
type: [Number, String],
|
|
398
|
+
default: 0
|
|
399
|
+
},
|
|
400
|
+
max: {
|
|
401
|
+
// 最大评分
|
|
402
|
+
type: [Number, String],
|
|
403
|
+
default: 5
|
|
404
|
+
},
|
|
405
|
+
margin: {
|
|
406
|
+
// 星星的间距
|
|
407
|
+
type: [Number, String],
|
|
408
|
+
default: 0
|
|
409
|
+
},
|
|
410
|
+
disabled: {
|
|
411
|
+
// 是否可点击
|
|
412
|
+
type: [Boolean, String],
|
|
413
|
+
default: false
|
|
414
|
+
},
|
|
415
|
+
readonly: {
|
|
416
|
+
// 是否只读
|
|
417
|
+
type: [Boolean, String],
|
|
418
|
+
default: false
|
|
419
|
+
},
|
|
420
|
+
allowHalf: {
|
|
421
|
+
// 是否显示半星
|
|
422
|
+
type: [Boolean, String],
|
|
423
|
+
default: false
|
|
424
|
+
},
|
|
425
|
+
touchable: {
|
|
426
|
+
// 是否支持滑动手势
|
|
427
|
+
type: [Boolean, String],
|
|
428
|
+
default: true
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
data() {
|
|
432
|
+
return {
|
|
433
|
+
valueSync: '',
|
|
434
|
+
userMouseFristMove: true,
|
|
435
|
+
userRated: false,
|
|
436
|
+
userLastRate: 1
|
|
437
|
+
};
|
|
438
|
+
},
|
|
439
|
+
watch: {
|
|
440
|
+
value(newVal) {
|
|
441
|
+
this.valueSync = Number(newVal);
|
|
442
|
+
},
|
|
443
|
+
modelValue(newVal) {
|
|
444
|
+
this.valueSync = Number(newVal);
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
computed: {
|
|
448
|
+
stars() {
|
|
449
|
+
const value = this.valueSync ? this.valueSync : 0;
|
|
450
|
+
const starList = [];
|
|
451
|
+
const floorValue = Math.floor(value);
|
|
452
|
+
const ceilValue = Math.ceil(value);
|
|
453
|
+
for (let i = 0; i < this.max; i++) {
|
|
454
|
+
if (floorValue > i) {
|
|
455
|
+
starList.push({
|
|
456
|
+
activeWitch: '100%'
|
|
457
|
+
});
|
|
458
|
+
} else if (ceilValue - 1 === i) {
|
|
459
|
+
starList.push({
|
|
460
|
+
activeWitch: (value - floorValue) * 100 + '%'
|
|
461
|
+
});
|
|
462
|
+
} else {
|
|
463
|
+
starList.push({
|
|
464
|
+
activeWitch: '0'
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return starList;
|
|
469
|
+
},
|
|
470
|
+
marginNumber() {
|
|
471
|
+
return Number(this.margin);
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
created() {
|
|
475
|
+
this.valueSync = Number(this.value || this.modelValue);
|
|
476
|
+
this._rateBoxLeft = 0;
|
|
477
|
+
this._oldValue = null;
|
|
478
|
+
},
|
|
479
|
+
mounted() {
|
|
480
|
+
setTimeout(() => {
|
|
481
|
+
this._getSize();
|
|
482
|
+
}, 100);
|
|
483
|
+
// #ifdef H5
|
|
484
|
+
this.PC = this.IsPC();
|
|
485
|
+
// #endif
|
|
486
|
+
},
|
|
487
|
+
methods: {
|
|
488
|
+
touchstart(e) {
|
|
489
|
+
// #ifdef H5
|
|
490
|
+
if (this.IsPC()) return;
|
|
491
|
+
// #endif
|
|
492
|
+
if (this.readonly || this.disabled) return;
|
|
493
|
+
const { clientX, screenX } = e.changedTouches[0];
|
|
494
|
+
// TODO 做一下兼容,只有 Nvue 下才有 screenX,其他平台式 clientX
|
|
495
|
+
this._getRateCount(clientX || screenX);
|
|
496
|
+
},
|
|
497
|
+
touchmove(e) {
|
|
498
|
+
// #ifdef H5
|
|
499
|
+
if (this.IsPC()) return;
|
|
500
|
+
// #endif
|
|
501
|
+
if (this.readonly || this.disabled || !this.touchable) return;
|
|
502
|
+
const { clientX, screenX } = e.changedTouches[0];
|
|
503
|
+
this._getRateCount(clientX || screenX);
|
|
504
|
+
},
|
|
505
|
+
/**
|
|
506
|
+
* 兼容 PC @tian
|
|
507
|
+
*/
|
|
508
|
+
mousedown(e) {
|
|
509
|
+
// #ifdef H5
|
|
510
|
+
if (!this.IsPC()) return;
|
|
511
|
+
if (this.readonly || this.disabled) return;
|
|
512
|
+
const { clientX } = e;
|
|
513
|
+
this.userLastRate = this.valueSync;
|
|
514
|
+
this._getRateCount(clientX);
|
|
515
|
+
this.userRated = true;
|
|
516
|
+
// #endif
|
|
517
|
+
},
|
|
518
|
+
mousemove(e) {
|
|
519
|
+
// #ifdef H5
|
|
520
|
+
if (!this.IsPC()) return;
|
|
521
|
+
if (this.userRated) return;
|
|
522
|
+
if (this.userMouseFristMove) {
|
|
523
|
+
console.log('---mousemove----', this.valueSync);
|
|
524
|
+
this.userLastRate = this.valueSync;
|
|
525
|
+
this.userMouseFristMove = false;
|
|
526
|
+
}
|
|
527
|
+
if (this.readonly || this.disabled || !this.touchable) return;
|
|
528
|
+
const { clientX } = e;
|
|
529
|
+
this._getRateCount(clientX);
|
|
530
|
+
// #endif
|
|
531
|
+
},
|
|
532
|
+
mouseleave(e) {
|
|
533
|
+
// #ifdef H5
|
|
534
|
+
if (!this.IsPC()) return;
|
|
535
|
+
if (this.readonly || this.disabled || !this.touchable) return;
|
|
536
|
+
if (this.userRated) {
|
|
537
|
+
this.userRated = false;
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
this.valueSync = this.userLastRate;
|
|
541
|
+
// #endif
|
|
542
|
+
},
|
|
543
|
+
// #ifdef H5
|
|
544
|
+
IsPC() {
|
|
545
|
+
var userAgentInfo = navigator.userAgent;
|
|
546
|
+
var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
|
|
547
|
+
var flag = true;
|
|
548
|
+
for (let v = 0; v < Agents.length - 1; v++) {
|
|
549
|
+
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
|
550
|
+
flag = false;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return flag;
|
|
555
|
+
},
|
|
556
|
+
// #endif
|
|
557
|
+
/**
|
|
558
|
+
* 获取星星个数
|
|
559
|
+
*/
|
|
560
|
+
_getRateCount(clientX) {
|
|
561
|
+
const _this = this;
|
|
562
|
+
this._getSize(function () {
|
|
563
|
+
const size = Number(_this.size);
|
|
564
|
+
if (isNaN(size)) {
|
|
565
|
+
return new Error('size 属性只能设置为数字');
|
|
566
|
+
}
|
|
567
|
+
const rateMoveRange = clientX - _this._rateBoxLeft;
|
|
568
|
+
let index = parseInt(rateMoveRange / (size + _this.marginNumber));
|
|
569
|
+
index = index < 0 ? 0 : index;
|
|
570
|
+
index = index > _this.max ? _this.max : index;
|
|
571
|
+
const range = parseInt(rateMoveRange - (size + _this.marginNumber) * index);
|
|
572
|
+
let value = 0;
|
|
573
|
+
if (_this._oldValue === index && !_this.PC) return;
|
|
574
|
+
_this._oldValue = index;
|
|
575
|
+
if (_this.allowHalf) {
|
|
576
|
+
if (range > size / 2) {
|
|
577
|
+
value = index + 1;
|
|
578
|
+
} else {
|
|
579
|
+
value = index + 0.5;
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
value = index + 1;
|
|
583
|
+
}
|
|
584
|
+
value = Math.max(0.5, Math.min(value, _this.max));
|
|
585
|
+
_this.valueSync = value;
|
|
586
|
+
_this._onChange();
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
/**
|
|
590
|
+
* 触发动态修改
|
|
591
|
+
*/
|
|
592
|
+
_onChange() {
|
|
593
|
+
this.$emit('input', this.valueSync);
|
|
594
|
+
this.$emit('update:modelValue', this.valueSync);
|
|
595
|
+
this.$emit('change', {
|
|
596
|
+
value: this.valueSync
|
|
597
|
+
});
|
|
598
|
+
},
|
|
599
|
+
/**
|
|
600
|
+
* 获取星星距离屏幕左侧距离
|
|
601
|
+
*/
|
|
602
|
+
_getSize(fn) {
|
|
603
|
+
// #ifndef APP-NVUE
|
|
604
|
+
uni
|
|
605
|
+
.createSelectorQuery()
|
|
606
|
+
.in(this)
|
|
607
|
+
.select('.uni-rate')
|
|
608
|
+
.boundingClientRect()
|
|
609
|
+
.exec((ret) => {
|
|
610
|
+
if (ret) {
|
|
611
|
+
this._rateBoxLeft = ret[0].left;
|
|
612
|
+
fn && fn();
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
// #endif
|
|
616
|
+
// #ifdef APP-NVUE
|
|
617
|
+
dom.getComponentRect(this.$refs['uni-rate'], (ret) => {
|
|
618
|
+
const size = ret.size;
|
|
619
|
+
if (size) {
|
|
620
|
+
this._rateBoxLeft = size.left;
|
|
621
|
+
fn && fn();
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
// #endif
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
</script>
|
|
629
|
+
<style>
|
|
630
|
+
@import 'style.css';
|
|
631
|
+
</style>
|