index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  2. import { VantComponent } from '../common/component';
  3. VantComponent({
  4. field: true,
  5. classes: ['icon-class'],
  6. props: {
  7. readonly: Boolean,
  8. disabled: Boolean,
  9. size: {
  10. type: Number,
  11. value: 20
  12. },
  13. icon: {
  14. type: String,
  15. value: 'star'
  16. },
  17. voidIcon: {
  18. type: String,
  19. value: 'star-o'
  20. },
  21. color: {
  22. type: String,
  23. value: '#ffd21e'
  24. },
  25. voidColor: {
  26. type: String,
  27. value: '#c7c7c7'
  28. },
  29. disabledColor: {
  30. type: String,
  31. value: '#bdbdbd'
  32. },
  33. count: {
  34. type: Number,
  35. value: 5
  36. },
  37. value: {
  38. type: Number,
  39. value: 0
  40. }
  41. },
  42. data: {
  43. innerValue: 0
  44. },
  45. watch: {
  46. value: function value(_value) {
  47. if (_value !== this.data.innerValue) {
  48. this.set({
  49. innerValue: _value
  50. });
  51. }
  52. }
  53. },
  54. computed: {
  55. list: function list() {
  56. var _this$data = this.data,
  57. count = _this$data.count,
  58. innerValue = _this$data.innerValue;
  59. return Array.from({
  60. length: count
  61. }, function (_, index) {
  62. return index < innerValue;
  63. });
  64. }
  65. },
  66. methods: {
  67. onSelect: function onSelect(event) {
  68. var data = this.data;
  69. var index = event.currentTarget.dataset.index;
  70. if (!data.disabled && !data.readonly) {
  71. this.set({
  72. innerValue: index + 1
  73. });
  74. this.$emit('input', index + 1);
  75. this.$emit('change', index + 1);
  76. }
  77. },
  78. onTouchMove: function onTouchMove(event) {
  79. var _this = this;
  80. var _event$touches$ = event.touches[0],
  81. clientX = _event$touches$.clientX,
  82. clientY = _event$touches$.clientY;
  83. this.getRect('.van-rate__item', true).then(function (list) {
  84. var target = list.find(function (item) {
  85. return clientX >= item.left && clientX <= item.right && clientY >= item.top && clientY <= item.bottom;
  86. });
  87. if (target != null) {
  88. _this.onSelect(_extends({}, event, {
  89. currentTarget: target
  90. }));
  91. }
  92. });
  93. }
  94. }
  95. });