index.js 2.9KB

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