Browse Source

修复找不到下载图片的bug

另修改了样式,添加了查看文件夹的功能
master
Naomi 1 year ago
parent
commit
4a2358da49
11 changed files with 148 additions and 82 deletions
  1. +1
    -1
      app.json
  2. +2
    -1
      config.js
  3. BIN
      images/background.jpg
  4. BIN
      images/wave.png
  5. +44
    -11
      pages/album/album.js
  6. +7
    -1
      pages/album/album.wxml
  7. +1
    -1
      pages/index/index.js
  8. +3
    -2
      pages/index/index.wxml
  9. +88
    -63
      pages/index/index.wxss
  10. +1
    -1
      pages/preview/preview.js
  11. +1
    -1
      project.config.json

+ 1
- 1
app.json View File

@ -5,7 +5,7 @@
"pages/album/album"
],
"window": {
"navigationBarTitleText": "Naomi 图床",
"navigationBarTitleText": "Naomi 相册",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#373b3e"
},


+ 2
- 1
config.js View File

@ -2,5 +2,6 @@ module.exports = {
stsUrl: 'https://pic.naomi.pub/authorization/sts.php',
Bucket: 'naomi-1257008753',
Region: 'ap-guangzhou',
albumDir: '',
Delimiter: '',
Prefix: '',
};

BIN
images/background.jpg View File

Before After
Width: 500  |  Height: 500  |  Size: 16 KiB

BIN
images/wave.png View File

Before After
Width: 750  |  Height: 286  |  Size: 217 KiB Width: 750  |  Height: 286  |  Size: 221 KiB

+ 44
- 11
pages/album/album.js View File

@ -30,6 +30,10 @@ Page({
// 相册列表数据
albumList: [],
//文件夹选择器
folder: ['/'],
index: 0,
// 图片布局列表(二维数组,由`albumList`计算而得)
layoutList: [],
@ -128,17 +132,25 @@ Page({
// 获取相册列表
getAlbumList(callback) {
let that = this;
this.showLoading('加载列表中…');
setTimeout(() => this.hideLoading(), 1000);
setTimeout(() => this.hideLoading(), 300);
var prefix = that.data.folder[that.data.index];
if (prefix == '/')
prefix = config.Prefix
cos.getBucket({
Bucket: config.Bucket,
Region: config.Region,
Prefix: config.albumDir
Prefix: prefix,
Delimiter: config.Delimiter,
}, function(err, data) {
if (data) {
console.log(data)
var list = (data && data.Contents || [])
.map(item => 'https://' + config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + util.camSafeUrlEncode(item.Key).replace(/%2F/g, '/')).filter(item => /\.(jpg|png|gif)$/.test(item));
.map(item => 'https://' + config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + util.camSafeUrlEncode(item.Key).replace(/%2F/g, '/')).filter(item => /\.(jpg|png|gif|jpeg|pjp|pjpeg|jfif)$/.test(item));
if (that.data.folder.length == 1)
that.data.folder.push((data && data.Contents || []).map(item => item.Key).filter(item => /^((?!\.).)*$/.test(item)));
callback(list);
} else {
callback([]);
@ -156,7 +168,8 @@ Page({
});
layoutList = listToMatrix(imageList, layoutColumnSize);
this.setData({
layoutList
layoutList,
folder: this.data.folder
});
},
@ -237,14 +250,13 @@ Page({
// 下载图片
downloadImage() {
this.showLoading('正在保存图片…');
let tmp = this.data.imageInAction;
console.log('download_image_url', tmp);
console.log('download_image_url', this.data.imageInAction);
wx.downloadFile({
url: tmp,
url: this.data.imageInAction,
type: 'image',
success: (resp) => {
wx.saveFile({
tempFilePath: resp.tempFilePath,
wx.saveImageToPhotosAlbum({
filePath: resp.tempFilePath,
success: (resp) => {
this.showToast('图片保存成功');
},
@ -317,16 +329,37 @@ Page({
wx.showToast({
title: '复制成功',
icon: 'success',
duration: 2000
duration: 1000
});
},
fail: function() {
wx.showToast({
title: '复制失败',
icon: 'error',
duration: 2000
duration: 1000
});
},
});
},
bindPickerChange: function(e) {
console.log('picker发送选择改变,当前文件夹为', this.data.folder[e.detail.value])
this.setData({
index: e.detail.value,
layoutList: [],
albumList: [],
})
var self = this;
this.renderAlbumList();
this.getAlbumList(function(list) {
list = self.data.albumList.concat(list || {});
if (!list.length) {
list = [];
}
list = list.reverse();
self.setData({
'albumList': list
});
self.renderAlbumList();
});
},
});

+ 7
- 1
pages/album/album.wxml View File

@ -1,5 +1,11 @@
<scroll-view class="container" scroll-y="true" style="display: {{!preview ? 'block' : 'none'}};">
<view class="upload-tips">上传图片到Naomi图床共享,长按图片可删除</view>
<view class="upload-tips" style="position:absolute;right:22rpx;">长按图片可下载删除</view>
<picker bindchange="bindPickerChange" value="{{index}}" range="{{folder}}">
<view class="upload-tips" style="margin-left:32rpx;">
当前文件夹: {{folder[index]}}
</view>
</picker>
<view class="album-container">
<view class="item-group" wx:for="{{layoutList}}" wx:for-item="group" wx:for-index="rowIndex" wx:key="group">
<block wx:for="{{group}}" wx:for-item="item" wx:for-index="cellIndex" wx:key="item">


+ 1
- 1
pages/index/index.js View File

@ -6,7 +6,7 @@ Page({
onLoad: function() {},
onShareAppMessage: function(res) {
return {
title: 'Naomi 图床',
title: 'Naomi 相册',
path: this.route,
}
},


+ 3
- 2
pages/index/index.wxml View File

@ -1,4 +1,5 @@
<view class="wave"></view>
<view class="top"></view>
<view class="bottom"></view>
<view class="main">
<view class="page-title">文件上传</view>
<view class="page-tips1">CDN流量仅有10G</view>
@ -11,5 +12,5 @@
<view class="page-btn-wrap">
<button class="page-btn" bindtap="gotoAlbum">云相册</button>
</view>
<view class="page-tips2">● 请不要当网盘用(T ^ T)</view>
<view class="page-tips2" style="margin-bottom:50rpx;">● 请不要当网盘用(T ^ T)</view>
</view>

+ 88
- 63
pages/index/index.wxss
File diff suppressed because it is too large
View File


+ 1
- 1
pages/preview/preview.js View File

@ -12,7 +12,7 @@ Page({
video: '视频',
};
var data = {
title: 'Naomi 图床' + (typeMap[this.data.type] || '文件'),
title: 'Naomi 相册' + (typeMap[this.data.type] || '文件'),
path: this.route + '?type=' + this.data.type + '&url=' + encodeURIComponent(this.data.url),
};
if (this.data.type === 'image') {


+ 1
- 1
project.config.json View File

@ -21,7 +21,7 @@
},
"compileType": "miniprogram",
"libVersion": "2.10.1",
"appid": "wxc20315852e05233c",
"appid": "wxfbc5db33bd702838",
"projectname": "naomi-album",
"isGameTourist": false,
"simulatorType": "wechat",


Loading…
Cancel
Save