index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. Component({
  2. properties: {
  3. position: {
  4. type: String,
  5. value: 'bottom'
  6. },
  7. show: {
  8. type: Boolean,
  9. value: true
  10. },
  11. selected: {
  12. type: Number,
  13. value: 0
  14. },
  15. color: {
  16. type: String,
  17. value: '#707070'
  18. },
  19. selectedColor: {
  20. type: String,
  21. value: '3963BC'
  22. },
  23. borderStyle: {
  24. type: String,
  25. value: '#f6f6f6'
  26. },
  27. backgroundColor: {
  28. type: String,
  29. value: '#fff'
  30. },
  31. backgroundImg: {
  32. type: String,
  33. value: ''
  34. },
  35. fontSize: {
  36. type: Number,
  37. value: 24
  38. },
  39. isRedirectToTab: {
  40. type: Boolean,
  41. value: true
  42. },
  43. // 是否跳转
  44. isNav: {
  45. type: Boolean,
  46. value: true
  47. },
  48. list: {
  49. type: Array,
  50. value: []
  51. }
  52. },
  53. data: {},
  54. attached() {},
  55. methods: {
  56. switchTab(e) {
  57. const data = e.currentTarget.dataset;
  58. const url = data.path;
  59. if (this.data.isNav) {
  60. if (this.data.isRedirectToTab) {
  61. wx.switchTab({
  62. url
  63. });
  64. } else {
  65. wx.switchTab({
  66. url
  67. });
  68. }
  69. }
  70. this.showItem(data.index);
  71. },
  72. show() {
  73. this.setData({
  74. show: true
  75. });
  76. },
  77. hide() {
  78. this.setData({
  79. show: false
  80. });
  81. },
  82. showItem(idx) {
  83. this.setData({
  84. selected: idx
  85. });
  86. let detail = {
  87. idx,
  88. path:this.route
  89. };
  90. let option = { bubbles: true, composed: true };
  91. this.triggerEvent('lintap', detail, option);
  92. },
  93. showRedDot(idx) {
  94. const redDot = `list[${idx}].redDot`;
  95. this.setData({
  96. [redDot]: true
  97. });
  98. },
  99. hideRedDot(idx) {
  100. const redDot = `list[${idx}].redDot`;
  101. this.setData({
  102. [redDot]: false
  103. });
  104. },
  105. setTabBarBadge(idx, text) {
  106. const badge = `list[${idx}].badge`;
  107. this.setData({
  108. [badge]: text
  109. });
  110. },
  111. removeTabBarBadge(idx) {
  112. const badge = `list[${idx}].badge`;
  113. this.setData({
  114. [badge]: ''
  115. });
  116. }
  117. }
  118. });