preview.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // compontents/lesson_list/lessonList.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. * 跟curriculum一样
  6. */
  7. properties: {
  8. materialData: {
  9. type: Array,
  10. value: []
  11. },
  12. height: {
  13. type: String,
  14. value: ''
  15. }
  16. },
  17. /**
  18. * 组件的初始数据
  19. */
  20. data: {
  21. flag: false,
  22. animationData: {},
  23. downUp: '展开',
  24. src: '../../pages/image/toDown.png'
  25. },
  26. /**
  27. * 组件的方法列表
  28. */
  29. methods: {
  30. onTap (e) {
  31. let flage = e.target.dataset.flag;
  32. const height = this.properties.materialData.length * 70;
  33. if(flage){
  34. this.util(flage, '280rpx');
  35. this.setData({
  36. 'flag': false,
  37. 'downUp': '展开',
  38. 'src': '../../pages/image/toDown.png'
  39. })
  40. } else {
  41. this.util(flage, height + 'rpx');
  42. this.setData({
  43. 'flag': true,
  44. 'downUp': '收起',
  45. 'src': '../../pages/image/toUp.png'
  46. })
  47. }
  48. },
  49. /* 创建动画并执行 */
  50. util (flag, height) {
  51. // 创建动画实例
  52. var animation = wx.createAnimation({
  53. duration: 200, //动画时长
  54. timingFunction: "linear", //线性
  55. delay: 0 //0则不延迟
  56. });
  57. this.animation = animation;
  58. animation.height(height).step();
  59. this.setData({
  60. animationData: animation.export()
  61. })
  62. },
  63. //点击预览图片
  64. preview (e) {
  65. const warePath = e.currentTarget.dataset.warepath;
  66. wx.downloadFile({
  67. url: warePath,
  68. success: function (res) {
  69. var filePath = res.tempFilePath
  70. wx.openDocument({
  71. filePath: filePath,
  72. success: function (res) {
  73. console.log('打开文档成功')
  74. }
  75. })
  76. }
  77. })
  78. }
  79. }
  80. })