rate.wxs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. module.exports = {
  2. getText: function (texts, val, defaultTexts) {
  3. if (!texts.length) {
  4. texts = defaultTexts;
  5. }
  6. var curVal = Math.floor(val - 1);
  7. return texts[curVal];
  8. },
  9. getIconName: function (defaultValue, value, index, variant) {
  10. var curVal = value ? value : defaultValue;
  11. var name = 'star-filled';
  12. if (curVal - index >= 1) {
  13. return name;
  14. } else {
  15. return variant === 'outline' ? 'star' : 'star-filled';
  16. }
  17. },
  18. getIconClass: function (classPrefix, defaultValue, value, index, allowHalf, disabled) {
  19. var curVal = value ? value : defaultValue;
  20. var className = [];
  21. if (curVal - index >= 1) {
  22. className.push(classPrefix + '-selected');
  23. if (disabled) {
  24. className.push(classPrefix + '-disabled');
  25. }
  26. } else if (allowHalf && curVal - index > 0) {
  27. className.push(classPrefix + '-selected-half');
  28. if (disabled) {
  29. className.push(classPrefix + '-disabled-half');
  30. }
  31. } else {
  32. className.push(classPrefix + '-unselected');
  33. }
  34. return className.join(' ');
  35. },
  36. };