handoutsTree.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view style="padding-left: 20rpx">
  3. <view v-if="fileInfo.type == 2">
  4. <view
  5. @click="handelClick"
  6. class="fl u-border-bottom"
  7. style="height: 78rpx; padding-right: 30rpx"
  8. >
  9. <u-icon name="arrow-down" color="#999" size="24" v-if="!down"></u-icon>
  10. <u-icon name="arrow-right" color="#999" size="24" v-if="down"></u-icon>
  11. <text class="menu_name u-line-1">{{ fileInfo.urlName }}</text>
  12. </view>
  13. <view v-show="!down">
  14. <view v-for="item in fileInfo.children" :key="item.fileId">
  15. <handouts-tree
  16. :canDownload="canDownload"
  17. :fileInfo="item"
  18. ></handouts-tree>
  19. </view>
  20. </view>
  21. </view>
  22. <view v-if="fileInfo.type == 1">
  23. <view class="fl_c u-border-bottom level1">
  24. <view class="title u-line-1">
  25. {{ fileInfo.urlName }}
  26. </view>
  27. <view @click="openDocument">
  28. <image
  29. v-if="!downLoading"
  30. src="/pages3/static/imgs/downLoad.png"
  31. ></image>
  32. <image
  33. v-else
  34. src="/pages3/static/imgs/downLoading.png"
  35. class="loading_down"
  36. ></image>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import handoutsTree from "@/components/course/handoutsTree.vue";
  44. export default {
  45. name: "handoutsTree",
  46. props: {
  47. fileInfo: {
  48. type: Object,
  49. default: () => {
  50. return {};
  51. },
  52. },
  53. canDownload: {
  54. type: Number,
  55. },
  56. },
  57. data() {
  58. return {
  59. down: true,
  60. downLoading: false,
  61. };
  62. },
  63. methods: {
  64. handelClick() {
  65. this.down = !this.down;
  66. },
  67. openDocument() {
  68. let url = this.$method.splitImgHost(this.fileInfo.url);
  69. // #ifdef H5
  70. window.location.href = url;
  71. // #endif
  72. // #ifdef MP-WEIXIN
  73. this.downLoading = true;
  74. uni.downloadFile({
  75. url: url,
  76. success: (res) => {
  77. var filePath = res.tempFilePath;
  78. // h5不支持
  79. uni.openDocument({
  80. filePath: filePath,
  81. fileType: "pdf",
  82. showMenu: this.canDownload == 1 ? true : false,
  83. success: (res) => {
  84. this.downLoading = false;
  85. uni.setStorageSync("nofresh", 1);
  86. },
  87. fail: (err) => {
  88. this.downLoading = false;
  89. uni.showToast({
  90. icon: "none",
  91. title: "文档地址错误",
  92. });
  93. },
  94. });
  95. },
  96. fail: (err) => {
  97. this.downLoading = false;
  98. uni.showModal({
  99. title: "提示",
  100. content: "文档错误," + err.errMsg,
  101. showCancel: false,
  102. });
  103. },
  104. });
  105. // #endif
  106. },
  107. },
  108. components: {
  109. handoutsTree,
  110. },
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. .menu_name {
  115. font-size: 26rpx;
  116. font-weight: bold;
  117. color: #333;
  118. margin-left: 14rpx;
  119. }
  120. .level1 {
  121. height: 78rpx;
  122. padding-right: 20rpx;
  123. .title {
  124. flex: 1;
  125. font-size: 26rpx;
  126. }
  127. .loading_down {
  128. transform: rotate(360deg);
  129. animation: rotation 3s linear infinite;
  130. }
  131. image {
  132. width: 40rpx;
  133. height: 40rpx;
  134. }
  135. }
  136. @keyframes rotation {
  137. from {
  138. -webkit-transform: rotate(0deg);
  139. }
  140. to {
  141. -webkit-transform: rotate(360deg);
  142. }
  143. }
  144. </style>