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
| Page({
| data: {
| type: 'image',
| url: '',
| showPreview: false,
| },
| onShareAppMessage: function (res) {
| var typeMap = {
| image: '图片',
| video: '视频',
| };
| var data = {
| title: 'COS 上传示例 - 预览' + (typeMap[this.data.type] || '文件'),
| path: this.route + '?type=' + this.data.type + '&url=' + encodeURIComponent(this.data.url),
| };
| if (this.data.type === 'image') {
| data.imageUrl = this.data.url;
| }
| return data;
| },
| onShow() {
| this.setData({showPreview: false});
| this.setData({
| type: this.options.type || 'image',
| url: decodeURIComponent(this.options.url) || '',
| });
| },
| showPreviewBox() {
| this.setData({showPreview: true});
| },
| copyLink() {
| wx.setClipboardData({
| data: this.data.url || '',
| success: function () {
| wx.showToast({title: '复制成功', icon: 'success', duration: 2000});
| },
| fail: function () {
| wx.showToast({title: '复制失败', icon: 'error', duration: 2000});
| },
| });
| },
| saveImage() {
| wx.downloadFile({
| url: this.data.url,
| success: function(res) {
| // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
| if (res.statusCode === 200) {
| wx.saveImageToPhotosAlbum({
| filePath: res.tempFilePath,
| });
| }
| }
| });
| },
| });
|
|