dk-tabs-custom.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // components/dk-tabs-custom/dk-tabs-custom.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. list:{
  8. type:Array,
  9. value:[]
  10. },
  11. value:{
  12. type:String|Number,
  13. value:null
  14. },
  15. background:{
  16. type:String,
  17. value:'#ECF7FF'
  18. },
  19. sliderBackground:{
  20. type:String,
  21. value:'linear-gradient(180deg, #FFC47E 0%, #CE9965 68.5%)'
  22. },
  23. textColor:{
  24. type:String,
  25. value:'#002340'
  26. },
  27. sliderTextColor:{
  28. type:String,
  29. value:'#fff'
  30. }
  31. },
  32. /**
  33. * 组件的初始数据
  34. */
  35. data: {
  36. index:0
  37. },
  38. lifetimes:{
  39. attached(){
  40. if(this.properties.value){
  41. this.setData({
  42. index:this.properties.list.map(it=>it.id).indexOf(this.properties.value)
  43. })
  44. }
  45. }
  46. },
  47. /**
  48. * 组件的方法列表
  49. */
  50. methods: {
  51. changeIndex(e){
  52. this.setData({
  53. index:e.currentTarget.dataset.index,
  54. value:e.currentTarget.dataset.id
  55. })
  56. this.triggerEvent('change',this.data.list[e.currentTarget.dataset.index])
  57. }
  58. }
  59. })