file_page.hbs
9.78 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li>静态资源</li>
</ul>
<h4>活动上传</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel">
<div class="row">
<div class="col-sm-12">
<div class="form-horizontal">
<div class="form-group col-sm-12">
<label class="control-label col-sm-1">上传地址:</label>
<div class="col-sm-6">
<div class="input-group">
<span class="input-group-addon">https://huodong.yoho.cn/</span>
<input id="actPath" type="text" class="form-control col-sm-10" placeholder="请输入上传地址">
<span class="input-group-addon">/index.html</span>
</div>
</div>
</div>
<div class="form-group col-sm-12">
<label class="control-label col-sm-1">上传文件:</label>
<div class="col-sm-3">
<input type="file" accept="application/x-zip-compressed" name="file" id="fileInput" class="btn btn-default btn-block">
<p class="form-control-static">注:仅支持zip格式</p>
<button id="upload" class="btn btn-primary btn-block">上传</button>
</div>
</div>
<div class="form-group col-sm-12">
<label class="control-label col-sm-1">上传日志:</label>
<div class="col-sm-8">
<div class="logs panel-body yoho-log-dark" style="height: 150px; overflow-y: scroll; color: #fff;"></div>
</div>
</div>
<div class="form-group col-sm-12">
<label class="control-label col-sm-1">上传记录:</label>
<div class="col-sm-11">
<table id="upload-list" style="word-break: break-all;" class="table table-bordered table-hover">
<tr class="title">
<th style="text-align:center;">活动地址</th>
<th style="text-align:center;">文件名称</th>
<th style="text-align:center;">上传时间</th>
<th style="text-align:center;">上传用户</th>
<th style="text-align:center;">操作</th>
</tr>
</table>
</div>
</div>
<div class="form-group col-sm-12">
<div class="col-sm-11 col-sm-offset-1" style="text-align: center;">
<a class="btn btn-primary more-list">加载更多记录</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
let $uploadList = $('#upload-list tbody');
let marker = '';
let page = 1;
$('#upload').on('click', function() {
var formData = new FormData();
var file = $('#fileInput').prop('files')[0];
var actPath = $('#actPath').val();
if (!$('#actPath').val()) {
$('.logs').prepend('<p>state: 请输入上传地址!</p>');
return false;
}
actPath = `/${actPath}`;
formData.append('file', file);
formData.append('actPath', actPath);
$.ajax({
type: 'POST',
url: '/files/upload',
cache: false,
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(result) {
if (result) {
if (result.code === 200) {
$('.logs').prepend('<p>state: 上传完成!</p>');
$('#upload-list tr[class!=title]').remove();
page = 1;
getList();
} else if (result.code === 400) {
$('.logs').prepend('<p>state: 请选择上传文件!</p>');
}
} else {
$('.logs').prepend('<p>state: 请稍后再试!</p>');
}
}
});
});
// 上传记录列表
function getList(){
$.ajax({
type: 'GET',
url: '/files/listlogs',
cache: false,
dataType: 'json',
data: {
page: page++
},
success: function(result) {
if (result && result.data && result.data.length > 0) {
let $uploadList = $('#upload-list > tbody');
result.data.forEach(function(item){
$uploadList.append(`
<tr>
<td><a href="${item.actPath}">${item.actPath}</a></td>
<td style="text-align:center;">${item.fileName}</td>
<td style="text-align:center;">${item.date}</td>
<td style="text-align:center;">${item.username}</td>
<td style="text-align: center;">
<a class="detail-btn btn btn-warning btn-block" data-path="${item.actPath}">展开详情</a>
<a class="get-more btn btn-success btn-block hide" data-path="${item.actPath}">加载更多</a>
</td>
</tr>
<tr class="detail-c hide">
<td colspan=5>
<table class="table table-bordered detail-table">
<tr>
<th style="text-align: center">文件路径</th>
<th style="text-align: center">文件大小</th>
<th style="text-align: center">文件格式</th>
<th style="text-align: center">上传时间</th>
</tr>
</table>
</td>
</tr>
`);
});
} else {
$('.more-list').hide();
}
}
});
};
// 上传记录详情
function getDetail(e, marker) {
let $this = $(e.currentTarget);
let path = $this.data('path');
let $uploadDetail = $this.parents('tr');
let detail = '';
$.ajax({
type: 'GET',
url: '/files/listfiles',
cache: false,
dataType: 'json',
data: {
actPath: `${path}`,
marker: marker
},
success: (result) => {
if (result && result.data &&result.data.items) {
if ($this.parents('td').find('.get-more').attr('data-marker') === result.data.marker) {
$this.parents('td').find('.get-more').remove();
return false;
}
$this.parents('td').find('.get-more').attr('data-marker', result.data.marker);
result.data.items.forEach(function(item){
detail += `<tr class="detail-list">
<td><a href="${item.link}">${item.key}</a></td>
<td style="text-align:center;">${item.fsizekb}</td>
<td style="text-align:center;">${item.mimeType}</td>
<td style="text-align:center;">${item.putTimeFormat}</td>
</tr>`;
});
$uploadDetail.next('.detail-c').find('.detail-table tbody').append(detail);
$this.parents('td').find('.get-more').removeClass('hide');
}
}
});
}
// 加载更多列表
$('.more-list').on('click', function() {
getList();
})
// 上传记录详情,插入tr
$uploadList.on('click', '.detail-btn', function(e) {
let $this = $(e.currentTarget);
let $detailC = $this.parents('tr').next('.detail-c');
let $detailList = $this.parents('tr').next('.detail-c').find('.detail-list');
if ($detailC.is(':hidden')) {
$('.detail-c').addClass('hide');
$detailC.removeClass('hide');
$('.detail-btn').text('展开详情');
$this.text('关闭详情');
if ($detailList.length <= 0) {
getDetail(e, marker);
} else if ($detailC.find('.detail-list').length > 0) {
$this.siblings('.get-more').removeClass('hide');
}
} else {
$detailC.addClass('hide');
$this.text('展开详情');
$this.siblings('.get-more').addClass('hide');
}
});
// 加载更多
$uploadList.on('click', '.get-more', function(e) {
let $this = $(e.currentTarget);
let marker = $this.data('marker');
getDetail(e, marker);
})
// 打印日志
$(() => {
var ws = io();
ws.on('connect', function() {
ws.on('/upload', function(data) {
$('.logs').prepend(`<p>state: ${data.state}</p>`);
});
});
getList();
});
</script>