curriculum.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // compontents/curriculum/curriculum.js
  2. Component({
  3. options: {
  4. multipleSlots: true // 在组件定义时的选项中启用多slot支持
  5. },
  6. /**
  7. * 组件的属性列表
  8. * studyLog传过来的数据
  9. * height判断显不显示展开按钮
  10. */
  11. properties: {
  12. studyLog: {
  13. type: Array,
  14. value: []
  15. },
  16. height: {
  17. type: String,
  18. value: ''
  19. }
  20. },
  21. /**
  22. * 组件的初始数据
  23. * flag展开收起的判断
  24. * animationData动画封装对象
  25. * downUp和src传过去得值
  26. */
  27. data: {
  28. flag: false,
  29. animationData: {},
  30. downUp: '展开',
  31. src: '../../pages/image/toDown.png',
  32. },
  33. /**
  34. * 组件的方法列表
  35. */
  36. methods: {
  37. onTap (e) {
  38. let flage = e.target.dataset.flag;
  39. const height = this.properties.studyLog.length * 54;
  40. if(flage){
  41. this.util(flage, '680rpx');
  42. this.setData({
  43. 'flag': false,
  44. 'downUp': '展开',
  45. 'src':'../../pages/image/toDown.png'
  46. })
  47. } else {
  48. this.util(flage, height + 'rpx');
  49. this.setData({
  50. 'flag': true,
  51. 'downUp': '收起',
  52. 'src': '../../pages/image/toUp.png'
  53. })
  54. }
  55. },
  56. /* 创建动画并执行 */
  57. util (flag, height) {
  58. // 创建动画实例
  59. var animation = wx.createAnimation({
  60. duration: 200, //动画时长
  61. timingFunction: "linear", //线性
  62. delay: 0 //0则不延迟
  63. });
  64. this.animation = animation;
  65. animation.height(height).step();
  66. this.setData({
  67. animationData: animation.export()
  68. })
  69. }
  70. },
  71. ready: function () {
  72. //console.log(this.properties.studyLog)
  73. }
  74. })