preview.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 * 72;
  33. if(flage){
  34. this.util(flage, `${this.data.height}rpx`);
  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. })