index.js
3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// pages/viewVideo/index.js
import { IMG_URL } from "~/utils/constantData.js";
import { senceData } from "~/pages/tab/index/constant/data";
// 导入方法
import { behavior as computedBehavior } from "~/utils/lib/miniprogram-computed";
import utils from '~/utils/util.js'
Page({
noPageAuth: true,
// 混入
behaviors: [computedBehavior],
/**
* 页面的初始数据
*/
data: {
IMG_URL,
isShare:false,//是否是被分享出去
videoSrc: "",
senceData,
tabActive: 0, //场景值
videoIndex: 0, //场景中的视频下表
},
// 使用
computed: {
videoitem(data) {
let { senceData, tabActive, videoIndex } = data;
return senceData[tabActive].videoList[videoIndex];
},
videoLeft(data) {
let { senceData, tabActive, videoIndex } = data;
// return senceData[tabActive].videoList.filter((item,index) => index != videoIndex)
return senceData[tabActive].videoList;
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let {isShare} = options;
this.setData({
isShare:isShare, //
})
this.shareDataFn(options)
},
//接受跳转的路由参数(小程序页面跳转)
onRoute(options) {
this.shareDataFn(options)
},
// 分享数据函数
shareDataFn(options){
if (!options || utils.isEmptyObj(options)) return
let {tabActive,videoIndex} = options
// console.log("options: ", options, !!options);
// console.log('tabActive,videoIndex: ', tabActive,videoIndex);
this.setData({
tabActive: tabActive,
videoIndex: videoIndex,
});
//
//分享的数据
this.changeShareData()
},
changeShareData(){
let {senceData,tabActive,videoIndex,videoitem} = this.data
// // 设置转发标题
// let userInfoObj = wx.$storage.get("userInfo");
// // #服务商账号#取该分享者商户的联系人字段,无则取商户简称,无则取商户全称
// let name = userInfoObj.merchantName;
this.shareTitle = `给您分享一个${videoitem.name } 视频`;
//分享的数据
let senceItem = senceData[tabActive]
this.shareQuery = `sceneCode=${senceItem?.sceneCode}&isShare=${true}&tabActive=${tabActive}&videoIndex=${videoIndex}`
},
changeVideo(e) {
let { index } = e.currentTarget.dataset;
this.setData({
videoIndex: index,
});
this.setpagesTitle()
this.changeShareData()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
this.setpagesTitle()
},
//设置标题
setpagesTitle(){
//设置标题
let {videoitem} = this.data
// wx.setNavigationBarTitle({
// title: videoitem.name,
// });
utils.setNavigationBarTitle(videoitem.name)
},
// 视频下载
downVideo() {
let {videoitem} = this.data
let url = videoitem.videoUrl
console.log(url)
wx.$api.showToast('正在下载视频...')
wx.downloadFile({
url: url,
success(res) {
// console.log(res,111)
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
setTimeout(() => {
wx.$api.showToast('下载成功!')
}, 2000)
}
})
}
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {},
});