down.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="web_box vflex acenter">
  3. <div class="table">
  4. <el-checkbox-group v-model="checkList" @change="handleCheckedCitiesChange">
  5. <div v-for="(item,index) in tableData" :key="index">
  6. <div class="cell hflex acenter jbetween">
  7. <div class="hflex acenter">
  8. <el-checkbox :label="item.file_url"></el-checkbox>
  9. <div class="hflex acenter left">
  10. <img src="@/assets/image/link.png" class="icon" alt="">
  11. <div class="name">{{ item.file_name }}</div>
  12. </div>
  13. </div>
  14. <div class="text">{{ item.file_size }}M</div>
  15. </div>
  16. </div>
  17. </el-checkbox-group>
  18. </div>
  19. <div class="bottom hflex jbetween">
  20. <div class="hflex">
  21. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange"></el-checkbox>
  22. <div class="text2">全选</div>
  23. </div>
  24. <div class="btn" @click="down">下载文件</div>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. const fileOptions = [];
  30. export default{
  31. name: 'down_wap',
  32. data() {
  33. return{
  34. img_title: require('@/assets/image/pc_title.png'),
  35. effective: 14,
  36. pageData: {
  37. title: '这是一些学习文件'
  38. },
  39. tableData: [],
  40. checkList: [],
  41. checkAll: false,
  42. isIndeterminate: true
  43. }
  44. },
  45. created() {
  46. this.id = window.localStorage.getItem('id')
  47. this.effective = this.$route.params.effective
  48. if(this.$route.params.code) {
  49. this.code = this.$route.params.code
  50. }
  51. this.getData()
  52. },
  53. methods: {
  54. getData() {
  55. let that = this
  56. let data = {
  57. id: that.id,
  58. password: that.code
  59. }
  60. that.$http.getFile(data).then((res) => {
  61. if(res.data.code == 0) {
  62. this.$message.error({
  63. message: res.data.msg,
  64. customClass: 'font10'
  65. })
  66. this.$router.go(-1)
  67. } else if(res.data.code == 1) {
  68. that.tableData = res.data.data
  69. for(var i=0;i<that.tableData.length;i++) {
  70. fileOptions.push(that.tableData[i].file_url)
  71. }
  72. }
  73. })
  74. },
  75. handleCheckAllChange(val) {
  76. this.checkList = val ? fileOptions : [];
  77. this.isIndeterminate = false;
  78. },
  79. handleCheckedCitiesChange(value) {
  80. let checkedCount = value.length;
  81. this.checkAll = checkedCount === fileOptions.length;
  82. this.isIndeterminate = checkedCount > 0 && checkedCount < fileOptions.length;
  83. },
  84. down() {
  85. if(this.checkList.length == 0) {
  86. this.$message.error({
  87. message: '请先选择要下载的文件',
  88. customClass: 'font20'
  89. })
  90. }
  91. for (let i = 0; i < this.checkList.length; i++) {
  92. if (this.checkList[i]) {
  93. this.downloadFile(this.checkList[i])
  94. }
  95. }
  96. },
  97. downloadFile(url) {
  98. const iframe = document.createElement("iframe");
  99. iframe.style.display = "none"; // 防止影响页面
  100. iframe.style.height = 0; // 防止影响页面
  101. iframe.src = url;
  102. document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
  103. // 5分钟之后删除(onload方法对于下载链接不起作用,就先抠脚一下吧)
  104. setTimeout(() => {
  105. iframe.remove();
  106. }, 5 * 60 * 1000);
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped>
  112. .web_box {
  113. width: 100%;
  114. min-height: 100vh;
  115. background: #F5F5F5;
  116. }
  117. .table {
  118. width: 100%;
  119. background: #FFFFFF;
  120. border-radius: 10px;
  121. box-sizing: border-box;
  122. padding: 0 20px;
  123. margin-bottom: 100px;
  124. }
  125. .cell {
  126. width: 100%;
  127. padding: 22px 0;
  128. border-top: 1px solid #F5F5F5;
  129. }
  130. .left {
  131. padding-left: 23px;
  132. }
  133. .text {
  134. font-size: 14px;
  135. font-family: PingFangSC-Medium, PingFang SC;
  136. font-weight: 500;
  137. color: #666666;
  138. line-height: 20px;
  139. }
  140. .name {
  141. font-size: 14px;
  142. font-family: PingFangSC-Regular, PingFang SC;
  143. font-weight: 400;
  144. color: rgba(0,0,0,0.88);
  145. line-height: 22px;
  146. }
  147. .icon {
  148. width: 16px;
  149. height: 16px;
  150. margin-right: 4px;
  151. }
  152. .bottom {
  153. width: 100%;
  154. height: 80px;
  155. background: #FFFFFF;
  156. padding: 10px 14px;
  157. box-sizing: border-box;
  158. position: fixed;
  159. left: 0;
  160. bottom: 0;
  161. z-index: 99;
  162. }
  163. .btn {
  164. width: 107px;
  165. height: 40px;
  166. background: #1677B3;
  167. border-radius: 20px;
  168. font-size: 14px;
  169. font-family: PingFangSC-Medium, PingFang SC;
  170. font-weight: 500;
  171. color: #FFFFFF;
  172. line-height: 40px;
  173. text-align: center;
  174. }
  175. .text2 {
  176. font-size: 14px;
  177. font-family: PingFangSC-Medium, PingFang SC;
  178. font-weight: 500;
  179. color: #666666;
  180. line-height: 20px;
  181. padding-left: 10px;
  182. }
  183. /deep/ .el-checkbox__label {
  184. display: none;
  185. }
  186. /deep/.el-checkbox__inner {
  187. border-radius: 50%;
  188. }
  189. </style>
  190. <style>
  191. .font10 {
  192. font-size: 15px !important;
  193. }
  194. </style>