index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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: Number,
  20. readonly: Boolean,
  21. disabled: Boolean,
  22. allowHalf: Boolean,
  23. size: {
  24. type: Number,
  25. value: 20
  26. },
  27. icon: {
  28. type: String,
  29. value: 'star'
  30. },
  31. voidIcon: {
  32. type: String,
  33. value: 'star-o'
  34. },
  35. color: {
  36. type: String,
  37. value: '#ffd21e'
  38. },
  39. voidColor: {
  40. type: String,
  41. value: '#c7c7c7'
  42. },
  43. disabledColor: {
  44. type: String,
  45. value: '#bdbdbd'
  46. },
  47. count: {
  48. type: Number,
  49. value: 5
  50. }
  51. },
  52. data: {
  53. innerValue: 0
  54. },
  55. watch: {
  56. value: function (value) {
  57. if (value !== this.data.innerValue) {
  58. this.set({ innerValue: value });
  59. }
  60. }
  61. },
  62. methods: {
  63. onSelect: function (event) {
  64. var data = this.data;
  65. var score = event.currentTarget.dataset.score;
  66. if (!data.disabled && !data.readonly) {
  67. this.set({ innerValue: score + 1 });
  68. this.$emit('input', score + 1);
  69. this.$emit('change', score + 1);
  70. }
  71. },
  72. onTouchMove: function (event) {
  73. var _this = this;
  74. var _a = event.touches[0], clientX = _a.clientX, clientY = _a.clientY;
  75. this.getRect('.van-rate__icon', true).then(function (list) {
  76. var target = list
  77. .sort(function (item) { return item.right - item.left; })
  78. .find(function (item) {
  79. return clientX >= item.left &&
  80. clientX <= item.right &&
  81. clientY >= item.top &&
  82. clientY <= item.bottom;
  83. });
  84. if (target != null) {
  85. _this.onSelect(__assign({}, event, { currentTarget: target }));
  86. }
  87. });
  88. }
  89. }
  90. });