taskDetail.js
5 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// packageActivity/pages/taskDetail/taskDetail.js
import index_const from "../../../pages/tab/index/index_const"
Page({
/**
* 页面的初始数据
*/
data: {
taskTypeImgList: index_const.data.taskTypeImgList,
activityTypList: index_const.data.activityTypList,
detailInfo: {
title: '今日完成首次分享',
content: '指定分享内容在今日完成首次分享',
integralAccount: 20,
activityName: '360全景活动',
merchantName: '广汽丰田鹏峰4S店360全景活动360全景活动',
userName: '余皖平123',
activityType: 1,
taskType: 1,
textContent: '💫广汽丰田鹏峰4S店💫\n#360全景影像系统大酬宾\n任意角度查看 行车无忧\n多角度高清采集,拒绝盲区\n活动时间:9月20日-26日\n联系我获取专属报名通道!',
imgUrlList: [
{url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/order_person_default.png', type: 'image'},
{url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/order_person_default.png', type: 'image'},
{url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/order_person_default.png', type: 'image'},
{url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/order_person_default.png', type: 'image'},
// {url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/share_task_icon.png', type: 'image'},
{url: 'http://scrm.test.glsx.com.cn/group1/M00/00/59/wKgD3mGvIc2AHq2FAAtkYkTMHOI111.mp4', type: 'video', poster: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/order_person_default.png'}
]
},
isloading: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
// 预览图片/视频
previewMedia(e) {
let { imgUrlList } = this.data.detailInfo
let { current } = e.currentTarget.dataset
wx.previewMedia({
sources: imgUrlList,
current: current
})
},
// 复制文案
copyText(e) {
let { textContent } = this.data.detailInfo
wx.setClipboardData({
data: textContent,
success (res) {
wx.showToast({
title: '内容已复制',
icon: "none"
})
}
})
},
// 一键保存
saveWith() {
var that = this
if (that.data.isloading) return
that.setData({
isloading: true
})
// 获取保存到相册权限
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success () {
// 调用保存图片promise队列
that.queue(that.data.detailInfo.imgUrlList)
.then(res => {
that.setData({
isloading: false
})
wx.showToast({
title: '下载完成'
})
})
.catch(err => {
that.setData({
isloading: false
})
})
},
fail() {
that.setData({
isloading: false
})
wx.showToast({
title: '您拒绝了保存到相册'
})
}
})
} else {
that.queue(that.data.detailInfo.imgUrlList)
.then(res => {
that.setData({
isloading: false
})
})
.catch(err => {
that.setData({
isloading: false
})
})
}
}
})
},
// 队列
queue(urls) {
let promise = Promise.resolve()
urls.forEach(item => {
promise = promise.then(() => {
return this.download(item.url, item.type)
})
})
return promise
},
// 下载
download(url, type) {
return new Promise((resolve, reject) => {
wx.downloadFile({
url: url,
success: function (res) {
var temp = res.tempFilePath
let fn = type == 'image' ? wx.saveImageToPhotosAlbum : wx.saveVideoToPhotosAlbum
fn({
filePath: temp,
success: function (res) {
resolve(res)
},
fail: function (err) {
reject(res)
}
})
},
fail: function (err) {
reject(err)
}
})
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})