index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="content">
  3. 中间
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. windowWidth: 0,
  11. windowHeight: 0,
  12. showVideo: true
  13. }
  14. },
  15. onLoad() {
  16. uni.getSystemInfo({
  17. success: (res) => {
  18. //console.log(res)
  19. this.windowWidth = res.windowWidth
  20. this.windowHeight = res.windowHeight
  21. }
  22. });
  23. },
  24. methods: {
  25. clickDownLoad() {
  26. console.log('下载');
  27. // ***判断是否在微信内打开,如果是,提示用户在外部浏览器打开,否则运行下载代码***
  28. var ua = navigator.userAgent.toLowerCase();
  29. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  30. alert("请在右上角...点击【在浏览器打开】")
  31. } else {
  32. this.downLoad() //调用下载函数
  33. this.showVideo = false
  34. uni.showLoading({
  35. title: "正在下载"
  36. });
  37. }
  38. },
  39. downLoad() {
  40. //测试发现,在pc端正常下载; 在移动端 qq浏览器,safari浏览器不能下载
  41. let that = this;
  42. let url =
  43. ' https://zhengda.oss-cn-chengdu.aliyuncs.com/yishulian/2023-06-29/Qb8M1CqlIUBj.mp4';
  44. //**调用download.js下载,下载速度相对快一些**
  45. let downjs = require("@/utils/download.js"); //引用当前目录下的自定义函数
  46. let x = new XMLHttpRequest();
  47. x.open("GET", url, true);
  48. x.responseType = 'blob';
  49. let fileName = '学习资料' + Date.now() + ".mp4"
  50. x.onload = function(e) {
  51. downjs(x.response, fileName, "video/mp4")
  52. uni.hideLoading()
  53. that.showVideo = true
  54. };
  55. x.send();
  56. //**不调用download.js下载**
  57. // let xhr = new XMLHttpRequest();
  58. // xhr.open('GET', url, true);
  59. // xhr.responseType = 'blob'; // 返回类型blob
  60. // xhr.onload = function() {
  61. // if (xhr.readyState === 4 && xhr.status === 200) {
  62. // let blob = this.response;
  63. // // 转换一个blob链接
  64. // let u = window.URL.createObjectURL(new Blob([blob]));
  65. // let a = document.createElement('a');
  66. // a.download = 'test.mp4'; //下载后保存的名称
  67. // a.href = u;
  68. // a.style.display = 'none';
  69. // document.body.appendChild(a);
  70. // a.click();
  71. // a.remove();
  72. // uni.hideLoading();
  73. // that.showVideo = true;
  74. // }
  75. // };
  76. // xhr.send()
  77. }
  78. }
  79. }
  80. </script>
  81. <style>
  82. .bg-set {
  83. width: 100%;
  84. }
  85. .btn-set {
  86. height: 87rpx;
  87. width: 253rpx;
  88. position: absolute;
  89. z-index: 1000;
  90. top: 10%;
  91. left: 50%;
  92. transform: translateX(-50%) translateY(-50%);
  93. }
  94. .videoPoster {
  95. width: 79%;
  96. height: 71%;
  97. border-radius: 10rpx;
  98. overflow: hidden;
  99. background-color: #333333;
  100. position: absolute;
  101. z-index: 1000;
  102. top: 54%;
  103. left: 50%;
  104. transform: translateX(-50%) translateY(-50%);
  105. /* 水平垂直居中 要与上方的top,left配合使用*/
  106. }
  107. video {
  108. width: 100%;
  109. height: 100%;
  110. }
  111. </style>