Skip to content

Commit c1a8abe

Browse files
committed
v2.2.1: 新增列表排序,+1优化
version 2.2.1 2018-05-12 [新增] 列表排序,可以根据名称、修改时间、大小来升降序排列 [优化] 数据格式化逻辑
1 parent da63f49 commit c1a8abe

File tree

7 files changed

+87
-90
lines changed

7 files changed

+87
-90
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# hfs4OSS
22

33
## 更新日志/ChangeLog
4-
4+
### version 2.2.1 2018-05-12
5+
```
6+
[新增] 列表排序,可以根据名称、修改时间、大小来升降序排列
7+
[优化] 数据格式化逻辑
8+
```
59
### version 2.2.0 2018-05-04
610
```
711
[新增] 简单的访问验证功能

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SDK:aliyun-oss-php-[sdk](https://promotion.aliyun.com/ntms/act/ossdoclist.html
88

99
## 预览/Demo
1010
* oovoo.site:[http://file.oovoo.site/](http://file.oovoo.site/)
11-
* ![image](https://yxuuan.github.io/hfs4oss-demo/demo.png)
11+
* ![image](https://yxuuan.github.io/hfs4oss-demo/v2.2.0.png)
1212

1313
## 部署/Build
1414
* 环境:
@@ -39,7 +39,7 @@ Releases:[https://github.com/YXuuan/hfs4OSS/releases/](https://github.com/YXuu
3939
ROOT_DIR :根目录路径,类似于FTP服务器的虚拟目录显示(例如此项为"photo/"则会将photo文件夹下的内容当作根目录显示)。缺省值为空
4040
注意:必须以"/"结尾且开头无需用"/"表示根目录
4141
SIGNEDURL_TIMEOUT :(int)每次下载文件时请求的签名URL有效期时长(秒)。缺省值:3600
42-
INDEX_PASSWORD :访问密码,程序将在每次请求时验证,为空则为不设置。缺省值为空
42+
INDEX_PASSWORD :访问密码,程序将在首次访问站点时要求输入,为空则为不设置。缺省值为空
4343
4444
4545
/config/static.config.json: --前端配置文件
@@ -65,10 +65,9 @@ Releases:[https://github.com/YXuuan/hfs4OSS/releases/](https://github.com/YXuu
6565
```
6666
## 更新日志/ChangeLog
6767
```
68-
version 2.2.0 2018-05-04
69-
[新增] 简单的访问验证功能
70-
[优化] 减小程序体积,去除无用文件
71-
ATTENTION: app.config.php有更新
68+
version 2.2.1 2018-05-12
69+
[新增] 列表排序,可以根据名称、修改时间、大小来升降序排列
70+
[优化] 数据格式化逻辑
7271
```
7372
更多:[CHANGELOG.md](https://github.com/YXuuan/hfs4OSS/blob/master/CHANGELOG.md)
7473

@@ -83,7 +82,7 @@ version 2.2.0 2018-05-04
8382
(划掉)输出item的大小
8483
批量下载(非压缩闭包)
8584
简单的object管理功能(上传,重命名等)
86-
列表排序
85+
(划掉)列表排序
8786
```
8887

8988
## 开源协议/License

app/action/listObjects.action.php

+22-7
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,39 @@
2525
$prefixList = $listObjectResult->getPrefixList();
2626
if (!empty($objectList)) {
2727
foreach ($objectList as $objectInfo) {
28-
$resultToReturn["fileList"][] = array( //取出每一个
28+
$resultToReturn["fileList"][] = array(
29+
//取出每一个
2930
substr($objectInfo->getKey(), strlen($options['prefix'])), //并去掉父级路径
30-
date("Y-m-d H:i", strtotime($objectInfo->getLastModified())),
31-
format_bytes($objectInfo->getSize()),
31+
//$objectInfo->getLastModified(),
32+
strtotime($objectInfo->getLastModified()),
33+
$objectInfo->getSize()
34+
//format_bytes($objectInfo->getSize()),
3235
);
3336
}
3437
if($options['prefix'] !== ''){
35-
@array_shift($resultToReturn['fileList']); //$fileList第一个object为当前目录,忽略
36-
}
38+
@array_shift($resultToReturn['fileList']); //$fileList第一个object为当前目录,忽略
39+
}
3740
}
41+
//取出每一个并去掉父级路径放入数组
3842
if (!empty($prefixList)) {
3943
foreach ($prefixList as $prefixInfo) {
40-
$resultToReturn["folderList"][] = substr($prefixInfo->getPrefix(), strlen($options['prefix'])); //取出每一个并去掉父级路径放入数组
44+
$resultToReturn["folderList"][] = substr($prefixInfo->getPrefix(), strlen($options['prefix']));
4145
}
4246
}
47+
//排序相关
48+
if((isset($_POST['sortBy'])) && (!empty($_POST['sortBy'])) && (isset($_POST['descending'])) && (!empty($_POST['descending']))){
49+
$descending = ($_POST['descending'] == "true") ? SORT_ASC : SORT_DESC ;
50+
if($_POST['sortBy'] == "date"){
51+
@array_multisort(array_column($resultToReturn['fileList'], 1), $descending, $resultToReturn['fileList']);
52+
}elseif($_POST['sortBy'] == "size"){
53+
@array_multisort(array_column($resultToReturn['fileList'], 2), $descending, $resultToReturn['fileList']);
54+
}else{
55+
@array_multisort(array_column($resultToReturn['fileList'], 0), $descending, $resultToReturn['fileList']);
56+
@array_multisort($resultToReturn['folderList'], $descending, $resultToReturn['folderList']);
4357

58+
}
59+
}
4460
$t2 = microtime(true);
45-
4661
@$resultToReturn['fileCount'] = count($resultToReturn["fileList"]);
4762
@$resultToReturn['folderCount'] = count($resultToReturn["folderList"]);
4863
$resultToReturn['takes'] = floor(($t2-$t1)*1000) . 'ms';

app/init.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
require_once __DIR__ . '/../config/app.config.php';
33
require_once __DIR__ . '/function/app.function.php';
44

5-
date_default_timezone_set("PRC");
6-
75
if(APPConfig::INDEX_PASSWORD !== ""){
86
if(!isset($_COOKIE['hfs4OSS_indexPassword']) || (empty($_COOKIE['hfs4OSS_indexPassword']))){
97
die('Exception201');

index.html

+7-39
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@
3939
<div id="view" class="view-details view-size-20">
4040
<ul id="items" class="clearfix">
4141
<li class="header">
42-
<a class="label">
43-
<span class="l10n-name">Name</span>
42+
<a class="label descending">
43+
<span>Name</span>
44+
<img src="/_h5ai/public/images/ui/sort.svg" class="sort" alt="sort order">
4445
</a>
4546
<a class="date">
46-
<span class="l10n-lastModified">Last modified</span>
47+
<span>Last modified</span>
48+
<img src="/_h5ai/public/images/ui/sort.svg" class="sort" alt="sort order">
4749
</a>
4850
<a class="size">
49-
<span class="l10n-size">Size</span>
51+
<span>Size</span>
52+
<img src="/_h5ai/public/images/ui/sort.svg" class="sort" alt="sort order">
5053
</a>
5154
</li>
5255
<div id="back"></div>
@@ -59,41 +62,6 @@
5962
</div>
6063
</div>
6164
</div>
62-
<!--<div id="pv-overlay" class="hidden">
63-
<div id="pv-container" style="width: 955px; height: 875px; left: 20px; top: 20px;"></div>
64-
<div id="pv-spinner" class="hidden" style="left: 497.5px; top: 481.5px;">
65-
<img class="back">
66-
<img class="spinner" src="static/h5ai/public/images/ui/spinner.svg">
67-
</div>
68-
<div id="pv-prev-area" class="hof">
69-
<img src="static/h5ai/public/images/ui/preview-prev.svg">
70-
</div>
71-
<div id="pv-next-area" class="hof">
72-
<img src="static/h5ai/public/images/ui/preview-next.svg">
73-
</div>
74-
<div id="pv-bottombar" class="clearfix hof">
75-
<ul id="pv-buttons">
76-
<li id="pv-bar-close" class="bar-right bar-button">
77-
<img src="static/h5ai/public/images/ui/preview-close.svg">
78-
</li>
79-
<li id="pv-bar-raw" class="bar-right">
80-
<a class="bar-button" target="_blank">
81-
<img src="static/h5ai/public/images/ui/preview-raw.svg">
82-
</a>
83-
</li>
84-
<li id="pv-bar-fullscreen" class="bar-right bar-button">
85-
<img src="static/h5ai/public/images/ui/preview-fullscreen.svg">
86-
</li>
87-
<li id="pv-bar-next" class="bar-right bar-button">
88-
<img src="static/h5ai/public/images/ui/preview-next.svg">
89-
</li>
90-
<li id="pv-bar-idx" class="bar-right bar-label"></li>
91-
<li id="pv-bar-prev" class="bar-right bar-button">
92-
<img src="static/h5ai/public/images/ui/preview-prev.svg">
93-
</li>
94-
</ul>
95-
</div>
96-
</div>-->
9765
</body>
9866

9967
</html>

static/h5ai/public/css/styles.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ html.no-browser .noBrowserMsg {
18581858
/*font-weight: bold*/ /*Changed*/
18591859
}
18601860
@media only screen and (max-width:785px) { /*Changed*/
1861-
.date, .l10n-lastModified{ /*Changed*/
1861+
.date, .lastModified{ /*Changed*/
18621862
display: none
18631863
}
18641864
#view.view-details .label{
@@ -1877,7 +1877,7 @@ html.no-browser .noBrowserMsg {
18771877
}
18781878
}
18791879
@media only screen and (max-width:500px) {
1880-
.size, .l10n-size{ /*Changed*/
1880+
.size{ /*Changed*/
18811881
display: none
18821882
}
18831883
#view.view-details .label{

static/script/main.js

+45-32
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ $.ajax({
3434
console.log(textStatus);
3535
}
3636
});
37-
if(window.location.hash){
38-
listObjects(window.location.hash.substring(1)); //截掉“#”
39-
}else{
40-
listObjects();
41-
}
37+
listObjects(window.location.hash.substring(1));
4238
$(document).ready(function(){
4339
//Event Loop
40+
$(".header").on("click", "a", function(event){ //定义的#back是为了每次覆盖
41+
sortSwitch($(this)); //listObjects(当前元素的data值)
42+
});
4443
//对Ajax返回数据后新生成的元素进行绑定
4544
$("#back").on("click", "li.item.folder.folder-parent", function(event){ //定义的#back是为了每次覆盖
4645
listObjects($(this).attr("data")); //listObjects(当前元素的data值)
@@ -62,14 +61,16 @@ $(document).ready(function(){
6261
});
6362
});
6463

65-
function listObjects(path = ''){
64+
function listObjects(path, sortBy = "label", descending = "true"){
6665
$("#items").attr("style", "opacity: 0.5;-moz-opacit: 0.5;");
67-
console.log('-----listObjects("' + decodeURI(path) + path + ' = ' + '")-----');
66+
console.log('-----listObjects("' + decodeURI(path) + ', ' + sortBy + ', ' + descending + ')-----');
6867
$.ajax({
6968
type: 'POST',
7069
url: 'app/action/listObjects.action.php',
7170
data: {
7271
prefix: decodeURI(path),
72+
sortBy: sortBy,
73+
descending: descending
7374
},
7475
dataType: 'text',
7576
success: function(data){
@@ -144,11 +145,11 @@ function listObjects(path = ''){
144145
'<span class="label" title="' + decodeURI(path) + fileInfo[0] +'">' +
145146
fileInfo[0] +
146147
'</span>' +
147-
'<span class="date" title="' + fileInfo[1] +'">' +
148-
fileInfo[1] +
148+
'<span class="date" title="' + getTime(fileInfo[1]) +'">' +
149+
getTime(fileInfo[1]) +
149150
'</span>' +
150-
'<span class="size" title="' + fileInfo[2] +'">' +
151-
fileInfo[2] +
151+
'<span class="size" title="' + bytesToSize(fileInfo[2]) +'">' +
152+
bytesToSize(fileInfo[2]) +
152153
'</span>' +
153154
'</a>' +
154155
'</li>'
@@ -247,6 +248,21 @@ function listObjects(path = ''){
247248
}
248249
});
249250
}
251+
function sortSwitch(who){
252+
if($(who).hasClass("ascending")){
253+
$(who).removeClass("ascending");
254+
listObjects(window.location.hash.substring(1), $(who).attr("class"), "true");
255+
$(who).addClass("descending");
256+
}else if($(who).hasClass("descending")){
257+
$(who).removeClass("descending");
258+
listObjects(window.location.hash.substring(1), $(who).attr("class"), "false");
259+
$(who).addClass("ascending");
260+
}else{
261+
$(".header a").removeClass("ascending").removeClass("descending"); //清空排序方法
262+
listObjects(window.location.hash.substring(1), $(who).attr("class"), "true"); //默认新一次排序为倒序
263+
$(who).addClass("descending");
264+
}
265+
}
250266
function downloadObject(target, who){
251267
console.log('-----getObject("' + decodeURI(target) + '")-----');
252268
$(who).attr('style', 'opacity: 0.5;-moz-opacit: 0.5;');
@@ -282,25 +298,22 @@ function downloadObject(target, who){
282298
});
283299
$(who).attr("style", "opacity: 1.0;-moz-opacit: 1.0;");
284300
}
285-
function exceptionHandler(msg){
286-
var handlerFlag = null;
287-
switch(msg){
288-
case 'Exception201':
289-
var inputedPassword = prompt(appConfig.INDEX_PASSWORD_MESSAGE + "\nPassword needed: ");
290-
if(inputedPassword !== null){
291-
$.cookie('hfs4OSS_indexPassword', inputedPassword);
292-
listObjects();
293-
}
294-
handlerFlag = true;
295-
break;
296-
case 'Exception202':
297-
var inputedPassword = prompt("Invalid password, try again: ");
298-
if(inputedPassword !== null){
299-
$.cookie('hfs4OSS_indexPassword', inputedPassword)
300-
listObjects();
301-
}
302-
handlerFlag = true;
303-
break;
304-
}
305-
return handlerFlag;
301+
function getTime() {
302+
var ts = arguments[0] || 0;
303+
var t,y,m,d,h,i,s;
304+
t = ts ? new Date(ts*1000) : new Date();
305+
y = t.getFullYear();
306+
m = t.getMonth()+1;
307+
d = t.getDate();
308+
h = t.getHours();
309+
i = t.getMinutes();
310+
s = t.getSeconds();
311+
return y+'-'+(m<10?'0'+m:m)+'-'+(d<10?'0'+d:d)+' '+(h<10?'0'+h:h)+':'+(i<10?'0'+i:i)+':'+(s<10?'0'+s:s);
312+
}
313+
function bytesToSize(bytes) {
314+
if (bytes === 0) return '0 B';
315+
var k = 1024;
316+
sizes = ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
317+
i = Math.floor(Math.log(bytes) / Math.log(k))
318+
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
306319
}

0 commit comments

Comments
 (0)