瀏覽代碼

1.文件下载方法
2.文件下载保存到相册方法
3.下载方法组件相互调用

FailedToRead 2 年之前
父節點
當前提交
995a14d0fa

+ 52 - 3
miniprogram/component/documentItem/documentItem.ts

@@ -4,7 +4,11 @@ Component({
      * 组件的属性列表
      */
     properties: {
-        itemData: null
+        itemData: null,
+        itemIndex: {
+            type: String,
+            value: ''
+        },
     },
 
     /**
@@ -12,7 +16,8 @@ Component({
      */
     data: {
         type: 1,
-        hasDownLoad: true
+        hasDownLoad: false,
+        downLoadProgress: ''
     },
     lifetimes: {
         attached: function () {
@@ -21,6 +26,7 @@ Component({
             this.setData({
                 type: this.properties.itemData.type
             })
+            console.log("itemIndex:", this.properties.itemIndex)
 
         },
         detached: function () {
@@ -34,7 +40,50 @@ Component({
      */
     methods: {
         showActionWindow: function () {
-            this.triggerEvent("showActionWindow", { item: this.properties.itemData })
+            this.triggerEvent("showActionWindow", { item: this.properties.itemData, itemIndex: this.properties.itemIndex })
+        },
+        setDownLoadProgress: function (data: any) {
+            console.log("设置下载百分比:", data.detail.progress)
+            this.setData({
+                downLoadProgress: '下载:' + data.detail.progress + '%',
+                hasDownLoad: true
+            })
+        },
+        downLoadComplete: function (data: any) {
+            // console.log("下载成功:", data)
+            // console.log("data.detail.data.tempFilePath:", data.detail.data.tempFilePath)
+            if (this.data.type == 0) {
+                //0是图片,图片保存到相册
+                wx.saveImageToPhotosAlbum({
+                    filePath: data.detail.data.tempFilePath,
+                    success(res) {
+                        wx.showModal({
+                            content: '保存相册成功'
+                        })
+                    }
+                })
+            } else if (this.data.type == 1) {
+                //1是视频,视频保存到相册
+                wx.saveVideoToPhotosAlbum({
+                    filePath: data.detail.data.tempFilePath,
+                    success(res) {
+                        // console.log(res.errMsg)
+                        wx.showModal({
+                            content: '保存相册成功'
+                        })
+                    }
+                })
+            }
+
+            this.setData({
+                downLoadProgress: '下载完成'
+            })
+        },
+        downLoadError: function (data: any) {
+            console.log("下载失败:", data)
+            this.setData({
+                downLoadProgress: '下载失败'
+            })
         }
     }
 })

+ 3 - 3
miniprogram/component/documentItem/documentItem.wxml

@@ -12,10 +12,10 @@
     </view>
     <view class="timeLayout">
         <text class="timeLayout_time">起止时间:{{itemData.created}}</text>
-        <text wx:if="{{hasDownLoad}}" class="timeLayout_download_text">下载:80%</text>
+        <text wx:if="{{hasDownLoad}}" class="timeLayout_download_text">{{downLoadProgress}}</text>
     </view>
     <view class="playerLayout">
-        <video wx:if="{{type==0}}" class="player" src="{{itemData.url}}"> </video>
-        <image wx:elif=" {{type==1}}" class="player" style="background-color: sienna;" src="{{itemData.url}}"></image>
+        <video wx:if="{{type==1}}" class="player" src="{{itemData.url}}" autoplay="{{false}}"> </video>
+        <image wx:elif=" {{type==0}}" class="player" style="background-color: sienna;" src="{{itemData.url}}"></image>
     </view>
 </view>

+ 21 - 7
miniprogram/component/fileBottomPop/fileBottomPop.ts

@@ -6,7 +6,10 @@ Component({
      * 组件的属性列表
      */
     properties: {
-
+        itemIndex: {
+            type: Number,
+            value: 0
+        }
     },
 
     /**
@@ -21,7 +24,9 @@ Component({
         fileName: '',
         uploadTime: '',
         expireTime: '',
-        iconUrl: ''
+        iconUrl: '',
+
+
     },
 
     lifetimes: {
@@ -32,6 +37,7 @@ Component({
                 pageHeight: wx.getSystemInfoSync().windowHeight,
                 pageWidth: wx.getSystemInfoSync().windowWidth
             })
+            console.log("itemIndex:", this.properties.itemIndex)
 
         },
         detached: function () {
@@ -108,7 +114,7 @@ Component({
                             lessId: that.data.itemData.lessId,
                             title: rename
                         }
-                        httpUtil.wxPut(puturl, params).then((res:any) => {
+                        httpUtil.wxPut(puturl, params).then((res: any) => {
                             that.setData({
                                 fileName: res.data.data.title
                             })
@@ -127,12 +133,20 @@ Component({
 
         downloadFile: function () {
             console.log("下载方法")
-            if (this.data.windowType == 0) {
+            let that = this;
+            if (that.data.windowType == 0) {
                 //文件夹下载
-            } else if (this.data.windowType == 1) {
+            } else if (that.data.windowType == 1) {
                 //文件下载
-                httpUtil.wxDownLoadFile(this.data.itemData.url, function (res: any) {
-                    console.log("下载没??===", res.progress)
+                httpUtil.wxDownLoadFile(that.data.itemData.url, function (res: any) {
+                    // console.log("下载没===", res)
+                    that.triggerEvent("downLoading", { progress: res.progress })
+                }).then((res) => {
+                    // console.log("下载成功:", res)
+                    that.triggerEvent("downLoadComplete", { data: res })
+                }).catch((res) => {
+                    // console.log("下载失败")
+                    that.triggerEvent("downLoadError", { data: res })
                 })
             }
         },

+ 1 - 0
miniprogram/component/teacher/teacherFault/teacherFault.ts

@@ -233,6 +233,7 @@ Component({
                             classIndex: index,
                             classId: res.data.data[index].id
                         })
+                        this.getDeviceByRSC()
                         console.log("this.data.classIndex:", this.data.classIndex)
                     }
                     this.data.classArray.push(element.title)

+ 1 - 0
miniprogram/component/teacher/teacherMonitor/monitor.ts

@@ -225,6 +225,7 @@ Component({
                             classIndex: index,
                             classId: res.data.data[index].id
                         })
+                        this.getDeviceByRSC()
                         console.log("this.data.classIndex:", this.data.classIndex)
                     }
                     this.data.classArray.push(element.title)

+ 15 - 1
miniprogram/pages/document/document.ts

@@ -7,7 +7,8 @@ Page({
      */
     data: {
         lessId: '',
-        itemList: null
+        itemList: null,
+        showItemIndex: 0
     },
 
     /**
@@ -23,6 +24,9 @@ Page({
 
     showActionWindow: function (evnet: any) {
         console.log("event:", evnet.detail.item)
+        this.setData({
+            showItemIndex: evnet.detail.itemIndex
+        })
         this.selectComponent("#popupwindow").showModal(evnet.detail.item, 1)
 
     },
@@ -49,5 +53,15 @@ Page({
         }).catch((res) => {
             console.log("获取所有文件失败:", res)
         })
+    },
+
+    downLoading: function (progress: any) {
+        this.selectComponent("#documentItem" + this.data.showItemIndex).setDownLoadProgress(progress)
+    },
+    downLoadComplete: function (data: any) {
+        this.selectComponent("#documentItem" + this.data.showItemIndex).downLoadComplete(data)
+    },
+    downLoadError: function (data: any) {
+        this.selectComponent("#documentItem" + this.data.showItemIndex).downLoadError(data)
     }
 })

+ 4 - 3
miniprogram/pages/document/document.wxml

@@ -2,11 +2,12 @@
 <view class="container">
 
     <scroll-view style="height: 100%; width: 100%;background-color: #ffffff; " scroll-y>
-        <view wx:for="{{itemList}}" style="margin-top: 28rpx;" wx:key="index">
-            <documentitem itemData="{{item}}" bind:showActionWindow="showActionWindow"></documentitem>
+        <view wx:for="{{itemList}}" style="margin-top: 28rpx;" wx:key="itemIndex" wx:for-item="item">
+            <documentitem id="documentItem{{index}}" itemData="{{item}}" bind:showActionWindow="showActionWindow" itemIndex="{{index}}">
+            </documentitem>
         </view>
     </scroll-view>
 </view>
 
 
-<fileBottomPop id="popupwindow" style="position: absolute; left: 0;" bind:fileDel="fileDel"></fileBottomPop>
+<fileBottomPop id="popupwindow" style="position: absolute; left: 0;" bind:fileDel="fileDel" bind:downLoading="downLoading" bind:downLoadComplete="downLoadComplete" bind:downLoadError="downLoadError"></fileBottomPop>

+ 0 - 3
miniprogram/utils/restful.ts

@@ -150,9 +150,6 @@ function downLoadFile(url: string, onProgress: any) {
         })
         download.onProgressUpdate((res) => {
             onProgress(res)
-            console.log('下载进度', res.progress)
-            console.log('已经下载的数据长度', res.totalBytesWritten)
-            console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
         })
     })