index.js 2.7 KB

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