index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Component({
  2. externalClasses: ['l-class', 'l-class-self', 'l-self-class'],
  3. properties: {
  4. // 红点模式
  5. dot: {
  6. type: Boolean,
  7. value: false
  8. },
  9. shape: {
  10. type: String,
  11. value: 'horn'
  12. },
  13. value: {
  14. type: String,
  15. value: '0'
  16. },
  17. mode: {
  18. type: String,
  19. value: 'number'
  20. },
  21. // 数字最大值
  22. maxCount: {
  23. type: Number,
  24. value: 99
  25. },
  26. // 数字形式
  27. numberType: {
  28. type: String,
  29. value: 'overflow'
  30. },
  31. show: {
  32. type: Boolean,
  33. value: true
  34. }
  35. },
  36. data: {
  37. finalCount: 0
  38. },
  39. observers: {
  40. 'value': function () {
  41. this.finalCount();
  42. }
  43. },
  44. methods: {
  45. // 最终数字
  46. finalCount() {
  47. if (isNaN(Number(this.data.value)) || (this.data.mode === 'text')) {
  48. this.setData({
  49. finalCount: this.data.value
  50. });
  51. } else {
  52. this.switchType();
  53. }
  54. },
  55. switchType() {
  56. switch (this.data.numberType) {
  57. case 'overflow':
  58. this.setData({
  59. finalCount: Number(this.data.value) > Number(this.data.maxCount) ? `${this.data.maxCount}+` : this.data.value
  60. });
  61. break;
  62. case 'ellipsis':
  63. this.setData({
  64. finalCount: Number(this.data.value) > Number(this.data.maxCount) ? `...` : this.data.value
  65. });
  66. break;
  67. case 'limit':
  68. this.setData({
  69. finalCount: Number(this.data.value) > 999 ? `${ Number.isInteger(this.data.value / 1000)? (this.data.value/1000) : (this.data.value/1000).toFixed(1) }k` : this.data.value
  70. });
  71. break;
  72. default:
  73. this.setData({
  74. finalCount: Number(this.data.value)
  75. });
  76. break;
  77. }
  78. },
  79. // 点击事件
  80. handleTap() {
  81. this.triggerEvent('lintap', {}, {
  82. bubbles: true,
  83. composed: true
  84. });
  85. },
  86. }
  87. });