index.js 2.8 KB

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