rate.wxs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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, allowHalf, icon, halfIcon, variant) {
  10. var curVal = value ? value : defaultValue;
  11. if (curVal - index >= 1) {
  12. return icon;
  13. } else if (allowHalf && curVal - index > 0) {
  14. return halfIcon;
  15. } else {
  16. return variant === 'outline' ? 'star' : 'star-filled';
  17. }
  18. },
  19. getIconColor: function (defaultValue, value, index, allowHalf, disabled, color, disabledColor) {
  20. var curVal = value ? value : defaultValue;
  21. var colorList = color.split(',');
  22. var primaryColor = colorList[0] || color;
  23. var defaultColor = colorList[1] || '#E3E6EB';
  24. if (curVal - index >= 1) {
  25. return disabled ? disabledColor : primaryColor;
  26. } else if (allowHalf && curVal - index > 0) {
  27. return 'transparent';
  28. } else {
  29. return defaultColor;
  30. }
  31. },
  32. getBackgroundColor: function (disabled, color, disabledColor) {
  33. var colorList = color.split(',');
  34. var primaryColor = colorList[0] || color;
  35. var defaultColor = colorList[1] || '#E3E6EB';
  36. var linearColor = disabled ? disabledColor : primaryColor;
  37. return (
  38. 'background:linear-gradient(to right, ' +
  39. linearColor +
  40. ' 0%,' +
  41. linearColor +
  42. ' 50%, ' +
  43. defaultColor +
  44. ' 51%, ' +
  45. defaultColor +
  46. ' 100%);-webkit-background-clip:text;background-clip:text;'
  47. );
  48. },
  49. };