first
This commit is contained in:
1
node_modules/vant/es/rate/index.css
generated
vendored
Normal file
1
node_modules/vant/es/rate/index.css
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
.van-rate{display:-webkit-inline-box;display:-webkit-inline-flex;display:inline-flex;-webkit-flex-wrap:wrap;flex-wrap:wrap;cursor:pointer;-webkit-user-select:none;user-select:none}.van-rate__item{position:relative}.van-rate__item:not(:last-child){padding-right:4px}.van-rate__icon{display:block;width:1em;color:#c8c9cc;font-size:20px}.van-rate__icon--half{position:absolute;top:0;left:0;width:.5em;overflow:hidden}.van-rate__icon--full{color:#ee0a24}.van-rate__icon--disabled{color:#c8c9cc}.van-rate--disabled{cursor:not-allowed}.van-rate--readonly{cursor:default}
|
227
node_modules/vant/es/rate/index.js
generated
vendored
Normal file
227
node_modules/vant/es/rate/index.js
generated
vendored
Normal file
@ -0,0 +1,227 @@
|
||||
// Utils
|
||||
import { createNamespace, addUnit } from '../utils';
|
||||
import { preventDefault } from '../utils/dom/event'; // Mixins
|
||||
|
||||
import { TouchMixin } from '../mixins/touch';
|
||||
import { FieldMixin } from '../mixins/field'; // Components
|
||||
|
||||
import Icon from '../icon';
|
||||
|
||||
var _createNamespace = createNamespace('rate'),
|
||||
createComponent = _createNamespace[0],
|
||||
bem = _createNamespace[1];
|
||||
|
||||
function getRateStatus(value, index, allowHalf) {
|
||||
if (value >= index) {
|
||||
return 'full';
|
||||
}
|
||||
|
||||
if (value + 0.5 >= index && allowHalf) {
|
||||
return 'half';
|
||||
}
|
||||
|
||||
return 'void';
|
||||
}
|
||||
|
||||
export default createComponent({
|
||||
mixins: [TouchMixin, FieldMixin],
|
||||
props: {
|
||||
size: [Number, String],
|
||||
color: String,
|
||||
gutter: [Number, String],
|
||||
readonly: Boolean,
|
||||
disabled: Boolean,
|
||||
allowHalf: Boolean,
|
||||
voidColor: String,
|
||||
iconPrefix: String,
|
||||
disabledColor: String,
|
||||
value: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
default: 'star'
|
||||
},
|
||||
voidIcon: {
|
||||
type: String,
|
||||
default: 'star-o'
|
||||
},
|
||||
count: {
|
||||
type: [Number, String],
|
||||
default: 5
|
||||
},
|
||||
touchable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
list: function list() {
|
||||
var list = [];
|
||||
|
||||
for (var i = 1; i <= this.count; i++) {
|
||||
list.push(getRateStatus(this.value, i, this.allowHalf));
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
sizeWithUnit: function sizeWithUnit() {
|
||||
return addUnit(this.size);
|
||||
},
|
||||
gutterWithUnit: function gutterWithUnit() {
|
||||
return addUnit(this.gutter);
|
||||
}
|
||||
},
|
||||
mounted: function mounted() {
|
||||
this.bindTouchEvent(this.$el);
|
||||
},
|
||||
methods: {
|
||||
select: function select(index) {
|
||||
if (!this.disabled && !this.readonly && index !== this.value) {
|
||||
this.$emit('input', index);
|
||||
this.$emit('change', index);
|
||||
}
|
||||
},
|
||||
onTouchStart: function onTouchStart(event) {
|
||||
var _this = this;
|
||||
|
||||
if (this.readonly || this.disabled || !this.touchable) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.touchStart(event);
|
||||
var rects = this.$refs.items.map(function (item) {
|
||||
return item.getBoundingClientRect();
|
||||
});
|
||||
var ranges = [];
|
||||
rects.forEach(function (rect, index) {
|
||||
if (_this.allowHalf) {
|
||||
ranges.push({
|
||||
score: index + 0.5,
|
||||
left: rect.left
|
||||
}, {
|
||||
score: index + 1,
|
||||
left: rect.left + rect.width / 2
|
||||
});
|
||||
} else {
|
||||
ranges.push({
|
||||
score: index + 1,
|
||||
left: rect.left
|
||||
});
|
||||
}
|
||||
});
|
||||
this.ranges = ranges;
|
||||
},
|
||||
onTouchMove: function onTouchMove(event) {
|
||||
if (this.readonly || this.disabled || !this.touchable) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.touchMove(event);
|
||||
|
||||
if (this.direction === 'horizontal') {
|
||||
preventDefault(event);
|
||||
var clientX = event.touches[0].clientX;
|
||||
this.select(this.getScoreByPosition(clientX));
|
||||
}
|
||||
},
|
||||
getScoreByPosition: function getScoreByPosition(x) {
|
||||
for (var i = this.ranges.length - 1; i > 0; i--) {
|
||||
if (x > this.ranges[i].left) {
|
||||
return this.ranges[i].score;
|
||||
}
|
||||
}
|
||||
|
||||
return this.allowHalf ? 0.5 : 1;
|
||||
},
|
||||
genStar: function genStar(status, index) {
|
||||
var _this2 = this;
|
||||
|
||||
var h = this.$createElement;
|
||||
var icon = this.icon,
|
||||
color = this.color,
|
||||
count = this.count,
|
||||
voidIcon = this.voidIcon,
|
||||
disabled = this.disabled,
|
||||
voidColor = this.voidColor,
|
||||
disabledColor = this.disabledColor;
|
||||
var score = index + 1;
|
||||
var isFull = status === 'full';
|
||||
var isVoid = status === 'void';
|
||||
var style;
|
||||
|
||||
if (this.gutterWithUnit && score !== +count) {
|
||||
style = {
|
||||
paddingRight: this.gutterWithUnit
|
||||
};
|
||||
}
|
||||
|
||||
return h("div", {
|
||||
"ref": "items",
|
||||
"refInFor": true,
|
||||
"key": index,
|
||||
"attrs": {
|
||||
"role": "radio",
|
||||
"tabindex": "0",
|
||||
"aria-setsize": count,
|
||||
"aria-posinset": score,
|
||||
"aria-checked": String(!isVoid)
|
||||
},
|
||||
"style": style,
|
||||
"class": bem('item')
|
||||
}, [h(Icon, {
|
||||
"attrs": {
|
||||
"size": this.sizeWithUnit,
|
||||
"name": isFull ? icon : voidIcon,
|
||||
"color": disabled ? disabledColor : isFull ? color : voidColor,
|
||||
"classPrefix": this.iconPrefix,
|
||||
"data-score": score
|
||||
},
|
||||
"class": bem('icon', {
|
||||
disabled: disabled,
|
||||
full: isFull
|
||||
}),
|
||||
"on": {
|
||||
"click": function click() {
|
||||
_this2.select(score);
|
||||
}
|
||||
}
|
||||
}), this.allowHalf && h(Icon, {
|
||||
"attrs": {
|
||||
"size": this.sizeWithUnit,
|
||||
"name": isVoid ? voidIcon : icon,
|
||||
"color": disabled ? disabledColor : isVoid ? voidColor : color,
|
||||
"classPrefix": this.iconPrefix,
|
||||
"data-score": score - 0.5
|
||||
},
|
||||
"class": bem('icon', ['half', {
|
||||
disabled: disabled,
|
||||
full: !isVoid
|
||||
}]),
|
||||
"on": {
|
||||
"click": function click() {
|
||||
_this2.select(score - 0.5);
|
||||
}
|
||||
}
|
||||
})]);
|
||||
}
|
||||
},
|
||||
render: function render() {
|
||||
var _this3 = this;
|
||||
|
||||
var h = arguments[0];
|
||||
return h("div", {
|
||||
"class": bem({
|
||||
readonly: this.readonly,
|
||||
disabled: this.disabled
|
||||
}),
|
||||
"attrs": {
|
||||
"tabindex": "0",
|
||||
"role": "radiogroup"
|
||||
}
|
||||
}, [this.list.map(function (status, index) {
|
||||
return _this3.genStar(status, index);
|
||||
})]);
|
||||
}
|
||||
});
|
47
node_modules/vant/es/rate/index.less
generated
vendored
Normal file
47
node_modules/vant/es/rate/index.less
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
@import '../style/var';
|
||||
|
||||
.van-rate {
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
|
||||
&__item {
|
||||
position: relative;
|
||||
|
||||
&:not(:last-child) {
|
||||
padding-right: @rate-icon-gutter;
|
||||
}
|
||||
}
|
||||
|
||||
&__icon {
|
||||
display: block;
|
||||
width: 1em;
|
||||
color: @rate-icon-void-color;
|
||||
font-size: @rate-icon-size;
|
||||
|
||||
&--half {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 0.5em;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
&--full {
|
||||
color: @rate-icon-full-color;
|
||||
}
|
||||
|
||||
&--disabled {
|
||||
color: @rate-icon-disabled-color;
|
||||
}
|
||||
}
|
||||
|
||||
&--disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&--readonly {
|
||||
cursor: default;
|
||||
}
|
||||
}
|
4
node_modules/vant/es/rate/style/index.js
generated
vendored
Normal file
4
node_modules/vant/es/rate/style/index.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import '../../style/base.css';
|
||||
import '../../info/index.css';
|
||||
import '../../icon/index.css';
|
||||
import '../index.css';
|
4
node_modules/vant/es/rate/style/less.js
generated
vendored
Normal file
4
node_modules/vant/es/rate/style/less.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import '../../style/base.less';
|
||||
import '../../info/index.less';
|
||||
import '../../icon/index.less';
|
||||
import '../index.less';
|
Reference in New Issue
Block a user