handoutsTree.vue 3.1 KB

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