index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 utils_1 = require('../common/utils');
  19. var component_1 = require('../common/component');
  20. var version_1 = require('../common/version');
  21. component_1.VantComponent({
  22. field: true,
  23. classes: ['icon-class'],
  24. props: {
  25. value: {
  26. type: Number,
  27. observer: function (value) {
  28. if (value !== this.data.innerValue) {
  29. this.setData({ innerValue: value });
  30. }
  31. },
  32. },
  33. readonly: Boolean,
  34. disabled: Boolean,
  35. allowHalf: Boolean,
  36. size: null,
  37. icon: {
  38. type: String,
  39. value: 'star',
  40. },
  41. voidIcon: {
  42. type: String,
  43. value: 'star-o',
  44. },
  45. color: String,
  46. voidColor: String,
  47. disabledColor: String,
  48. count: {
  49. type: Number,
  50. value: 5,
  51. observer: function (value) {
  52. this.setData({ innerCountArray: Array.from({ length: value }) });
  53. },
  54. },
  55. gutter: null,
  56. touchable: {
  57. type: Boolean,
  58. value: true,
  59. },
  60. },
  61. data: {
  62. innerValue: 0,
  63. innerCountArray: Array.from({ length: 5 }),
  64. },
  65. methods: {
  66. onSelect: function (event) {
  67. var _this = this;
  68. var data = this.data;
  69. var score = event.currentTarget.dataset.score;
  70. if (!data.disabled && !data.readonly) {
  71. this.setData({ innerValue: score + 1 });
  72. if (version_1.canIUseModel()) {
  73. this.setData({ value: score + 1 });
  74. }
  75. wx.nextTick(function () {
  76. _this.$emit('input', score + 1);
  77. _this.$emit('change', score + 1);
  78. });
  79. }
  80. },
  81. onTouchMove: function (event) {
  82. var _this = this;
  83. var touchable = this.data.touchable;
  84. if (!touchable) return;
  85. var clientX = event.touches[0].clientX;
  86. utils_1.getAllRect(this, '.van-rate__icon').then(function (list) {
  87. var target = list
  88. .sort(function (cur, next) {
  89. return cur.dataset.score - next.dataset.score;
  90. })
  91. .find(function (item) {
  92. return clientX >= item.left && clientX <= item.right;
  93. });
  94. if (target != null) {
  95. _this.onSelect(
  96. __assign(__assign({}, event), { currentTarget: target })
  97. );
  98. }
  99. });
  100. },
  101. },
  102. });