index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: {
  46. type: String,
  47. value: '#ffd21e',
  48. },
  49. voidColor: {
  50. type: String,
  51. value: '#c7c7c7',
  52. },
  53. disabledColor: {
  54. type: String,
  55. value: '#bdbdbd',
  56. },
  57. count: {
  58. type: Number,
  59. value: 5,
  60. observer: function (value) {
  61. this.setData({ innerCountArray: Array.from({ length: value }) });
  62. },
  63. },
  64. gutter: null,
  65. touchable: {
  66. type: Boolean,
  67. value: true,
  68. },
  69. },
  70. data: {
  71. innerValue: 0,
  72. innerCountArray: Array.from({ length: 5 }),
  73. },
  74. methods: {
  75. onSelect: function (event) {
  76. var _this = this;
  77. var data = this.data;
  78. var score = event.currentTarget.dataset.score;
  79. if (!data.disabled && !data.readonly) {
  80. this.setData({ innerValue: score + 1 });
  81. if (version_1.canIUseModel()) {
  82. this.setData({ value: score + 1 });
  83. }
  84. wx.nextTick(function () {
  85. _this.$emit('input', score + 1);
  86. _this.$emit('change', score + 1);
  87. });
  88. }
  89. },
  90. onTouchMove: function (event) {
  91. var _this = this;
  92. var touchable = this.data.touchable;
  93. if (!touchable) return;
  94. var clientX = event.touches[0].clientX;
  95. utils_1.getAllRect(this, '.van-rate__icon').then(function (list) {
  96. var target = list
  97. .sort(function (item) {
  98. return item.right - item.left;
  99. })
  100. .find(function (item) {
  101. return clientX >= item.left && clientX <= item.right;
  102. });
  103. if (target != null) {
  104. _this.onSelect(
  105. __assign(__assign({}, event), { currentTarget: target })
  106. );
  107. }
  108. });
  109. },
  110. },
  111. });