handoutsTree.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. // uni.navigateTo({
  72. // url: `/pages/webview/sdlink?url=` + url,
  73. // });
  74. // #endif
  75. // #ifdef MP-WEIXIN
  76. this.downLoading = true;
  77. uni.downloadFile({
  78. url: url,
  79. success: (res) => {
  80. var filePath = res.tempFilePath;
  81. // h5不支持
  82. uni.openDocument({
  83. filePath: filePath,
  84. showMenu: this.canDownload == 1 ? true : false,
  85. success: (res) => {
  86. this.downLoading = false;
  87. uni.setStorageSync("nofresh", 1);
  88. },
  89. fail: (err) => {
  90. this.downLoading = false;
  91. uni.showToast({
  92. icon: "none",
  93. title: "文档地址错误",
  94. });
  95. },
  96. });
  97. },
  98. fail: (err) => {
  99. this.downLoading = false;
  100. uni.showModal({
  101. title: "提示",
  102. content: "文档错误," + err.errMsg,
  103. showCancel: false,
  104. });
  105. },
  106. });
  107. // #endif
  108. },
  109. },
  110. components: {
  111. handoutsTree,
  112. },
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .menu_name {
  117. font-size: 26rpx;
  118. font-weight: bold;
  119. color: #333;
  120. margin-left: 14rpx;
  121. }
  122. .level1 {
  123. height: 78rpx;
  124. padding-right: 20rpx;
  125. .title {
  126. flex: 1;
  127. font-size: 26rpx;
  128. }
  129. .loading_down {
  130. transform: rotate(360deg);
  131. animation: rotation 3s linear infinite;
  132. }
  133. image {
  134. width: 40rpx;
  135. height: 40rpx;
  136. }
  137. }
  138. @keyframes rotation {
  139. from {
  140. -webkit-transform: rotate(0deg);
  141. }
  142. to {
  143. -webkit-transform: rotate(360deg);
  144. }
  145. }
  146. </style>