Browse Source

新增视频下载功能

Limengbo 4 years ago
parent
commit
cc5c6e812d

+ 42 - 0
component/video-swiper/index.js

@@ -343,6 +343,48 @@ Component({
                 });
             }
         },
+        // 下载视频
+        download: function (e) {
+            // console.log(e.currentTarget.dataset)
+            wx.showLoading({
+                title: '保存到本地',
+                mask: true
+            })
+            const { url } = e.currentTarget.dataset;
+            wx.downloadFile({
+                url,
+                success (res) {
+                    // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
+                    if (res.statusCode === 200) {
+                        console.log(res.tempFilePath)
+                        wx.saveVideoToPhotosAlbum({
+                            filePath: res.tempFilePath,
+                            success (res) {
+                              wx.hideLoading()
+                              wx.showToast({
+                                title: '保存成功',
+                                icon: 'success',
+                                duration: 2000,
+                                mask: true
+                              })                              
+                            },
+                            fail (error) {
+                                console.log(error)
+                            }
+                        })
+                    }
+                },
+                fail () {
+                    wx.hideLoading()
+                    wx.showToast({
+                      title: '网络不给力',
+                      icon: 'error',
+                      duration: 2000,
+                      mask: true
+                    })                              
+                }
+            })
+        },
         delete: function (e) {
             console.log('删除', e)
             wx.showModal({

+ 4 - 0
component/video-swiper/index.wxml

@@ -119,6 +119,10 @@
             <text>发布时间:{{item.time}}</text>
           </view>
           <view wx:if="{{item.showMyBtn && !item.ifCheck}}" class="my_btn">
+            <view class="delete" catchtap="download" data-url="{{item.markPath ? item.markPath : '' }}" data-id="{{item.id}}">
+              <image class="download_image" src="../../static/index/down.png" />
+              <text class="delete_text" >下载</text>
+            </view>
             <view class="delete" catchtap="delete" data-id="{{item.id}}">
               <image class="delete_image" src="../../static/index/delete.png" />
               <text class="delete_text" >删除</text>

+ 5 - 0
component/video-swiper/index.wxss

@@ -82,6 +82,11 @@
   display: flex;
   align-items: center;
 }
+.swiper_container .swiper_item .head_box .my_btn .delete .download_image {
+  width: 29rpx;
+  height: 33rpx;
+  margin-bottom: 2rpx;
+}
 .swiper_container .swiper_item .head_box .my_btn .delete {
   display: flex;
   flex-direction: column;

+ 2 - 0
pages/index/index.js

@@ -406,6 +406,7 @@ Page({
       temp.avatar = item.user.avatar;
       temp.profession = item.user.profession;
       temp.uid = item.user.uid;
+      temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
       temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
       temp.id = item.userRead.id;
       temp.type = item.userRead.type;
@@ -651,6 +652,7 @@ Page({
         temp.avatar = item.user.avatar;
         temp.profession = item.user.profession;
         temp.uid = item.user.uid;
+        temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
         temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
         temp.id = item.userRead.id;
         temp.type = item.userRead.type;

+ 115 - 114
project.config.json

@@ -1,116 +1,117 @@
 {
-  "description": "项目配置文件",
-  "packOptions": {
-    "ignore": []
-  },
-  "setting": {
-    "urlCheck": true,
-    "es6": true,
-    "postcss": true,
-    "minified": true,
-    "newFeature": true,
-    "coverView": true,
-    "autoAudits": true,
-    "showShadowRootInWxmlPanel": true,
-    "scopeDataCheck": false,
-    "checkInvalidKey": true,
-    "checkSiteMap": true,
-    "uploadWithSourceMap": true,
-    "useMultiFrameRuntime": false,
-    "useApiHook": true,
-    "babelSetting": {
-      "ignore": [],
-      "disablePlugins": [],
-      "outputPath": ""
-    },
-    "useIsolateContext": true,
-    "useCompilerModule": true,
-    "userConfirmedUseCompilerModuleSwitch": false,
-    "userConfirmedBundleSwitch": false,
-    "packNpmManually": false,
-    "packNpmRelationList": [],
-    "minifyWXSS": true,
-    "bundle": false
-  },
-  "compileType": "miniprogram",
-  "libVersion": "2.14.0",
-  "appid": "wx8961a3e5512f307c",
-  "projectname": "%E5%B0%8F%E5%AD%A6%E8%AF%BE%E6%96%87%E6%9C%97%E8%AF%BB%E9%85%8D%E9%9F%B3",
-  "debugOptions": {
-    "hidedInDevtools": []
-  },
-  "isGameTourist": false,
-  "simulatorType": "wechat",
-  "simulatorPluginLibVersion": {},
-  "condition": {
-    "plugin": {
-      "list": []
-    },
-    "game": {
-      "list": []
-    },
-    "gamePlugin": {
-      "list": []
-    },
-    "miniprogram": {
-      "list": [
-        {
-          "id": 0,
-          "name": "pages/vipPage/wechat/wechat",
-          "pathName": "pages/vipPage/wechat/wechat",
-          "query": "",
-          "scene": null
-        },
-        {
-          "id": 1,
-          "name": "作品",
-          "pathName": "pages/social/works/works",
-          "query": "id=1548160250807513&title=【识字1】春夏秋冬",
-          "scene": "1012"
-        },
-        {
-          "id": 2,
-          "name": "分享团",
-          "pathName": "pages/groupPage/group-details/group-details",
-          "query": "productId=1550459447432909",
-          "scene": 1012
-        },
-        {
-          "id": -1,
-          "name": "公众号进入",
-          "pathName": "pages/index/index",
-          "query": "",
-          "scene": 1020,
-          "referrerInfo": {}
-        },
-        {
-          "id": -1,
-          "name": "公众号文章进入",
-          "pathName": "pages/index/index",
-          "query": "",
-          "scene": 1058
-        },
-        {
-          "id": -1,
-          "name": "小红花兑换页面",
-          "pathName": "pages/social/prize/prize",
-          "query": "",
-          "scene": null
-        },
-        {
-          "id": -1,
-          "name": "有问题朗读页面",
-          "pathName": "pages/social/works/works",
-          "query": "id=1553402613620097&title=【课文7】怎么都快乐",
-          "scene": null
-        },
-        {
-          "name": "pages/index/index",
-          "pathName": "pages/index/index",
-          "query": "readId=1606387447807610",
-          "scene": 1007
-        }
-      ]
-    }
-  }
+	"description": "项目配置文件",
+	"packOptions": {
+		"ignore": []
+	},
+	"setting": {
+		"urlCheck": true,
+		"es6": true,
+		"postcss": true,
+		"preloadBackgroundData": false,
+		"minified": true,
+		"newFeature": true,
+		"coverView": true,
+		"autoAudits": false,
+		"showShadowRootInWxmlPanel": true,
+		"scopeDataCheck": false,
+		"checkInvalidKey": true,
+		"checkSiteMap": true,
+		"uploadWithSourceMap": true,
+		"babelSetting": {
+			"ignore": [],
+			"disablePlugins": [],
+			"outputPath": ""
+		},
+		"bundle": false,
+		"useCompilerModule": false,
+		"userConfirmedUseCompilerModuleSwitch": false,
+		"useMultiFrameRuntime": false,
+		"useApiHook": true,
+		"useIsolateContext": true,
+		"userConfirmedBundleSwitch": false,
+		"packNpmManually": false,
+		"packNpmRelationList": [],
+		"minifyWXSS": true
+	},
+	"compileType": "miniprogram",
+	"libVersion": "2.14.0",
+	"appid": "wx8961a3e5512f307c",
+	"projectname": "%E5%B0%8F%E5%AD%A6%E8%AF%AD%E6%96%87%E6%9C%97%E8%AF%BB",
+	"debugOptions": {
+		"hidedInDevtools": []
+	},
+	"isGameTourist": false,
+	"simulatorType": "wechat",
+	"simulatorPluginLibVersion": {},
+	"condition": {
+		"plugin": {
+			"list": []
+		},
+		"game": {
+			"list": []
+		},
+		"gamePlugin": {
+			"list": []
+		},
+		"miniprogram": {
+			"list": [
+				{
+					"id": 0,
+					"name": "pages/vipPage/wechat/wechat",
+					"pathName": "pages/vipPage/wechat/wechat",
+					"query": "",
+					"scene": null
+				},
+				{
+					"id": 1,
+					"name": "作品",
+					"pathName": "pages/social/works/works",
+					"query": "id=1548160250807513&title=【识字1】春夏秋冬",
+					"scene": "1012"
+				},
+				{
+					"id": 2,
+					"name": "分享团",
+					"pathName": "pages/groupPage/group-details/group-details",
+					"query": "productId=1550459447432909",
+					"scene": 1012
+				},
+				{
+					"id": -1,
+					"name": "公众号进入",
+					"pathName": "pages/index/index",
+					"query": "",
+					"scene": 1020,
+					"referrerInfo": {}
+				},
+				{
+					"id": -1,
+					"name": "公众号文章进入",
+					"pathName": "pages/index/index",
+					"query": "",
+					"scene": 1058
+				},
+				{
+					"id": -1,
+					"name": "小红花兑换页面",
+					"pathName": "pages/social/prize/prize",
+					"query": "",
+					"scene": null
+				},
+				{
+					"id": -1,
+					"name": "有问题朗读页面",
+					"pathName": "pages/social/works/works",
+					"query": "id=1553402613620097&title=【课文7】怎么都快乐",
+					"scene": null
+				},
+				{
+					"name": "pages/index/index",
+					"pathName": "pages/index/index",
+					"query": "readId=1606387447807610",
+					"scene": 1007
+				}
+			]
+		}
+	}
 }

BIN
static/index/down.png