single_file_page.hbs
2.35 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
<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="form">
<div class="form-group">
<label for=""></label>
<div class="input-group">
<span class="input-group-addon">{{domain}}/</span>
<input type="text" class="form-control" id="actPath" aria-describedby="basic-addon3" placeholder="请输入文件路径,例:20171030/v2.4.8">
</div>
</div>
<div class="form-group">
<label for="file">选择文件</label>
<input type="file" class="form-control" name="file" id="fileInput">
</div>
<input type="hidden" id="cover" name="cover" value="29m34gs6f5">
<div class="form-group">
<button class="btn btn-default" id="upLoadBtn">上传</button>
<span id="resultMsg"></span>
</div>
</div>
</div>
<script>
$('#upLoadBtn').on('click', function(){
$('#upLoadBtn').attr('disabled', 'disabled');
var file = $('#fileInput').prop('files')[0];
var actPath = $('#actPath').val();
var formData = new FormData();
var cover = $('#cover').val();
formData.append('file', file);
formData.append('actPath', actPath);
formData.append('cover', cover);
$.ajax({
type: 'POST',
url: '/files/single-file-upload',
cache: false,
data: formData,
dataType: 'json',
processData: false,
contentType: false,
complete: function() {
$('#upLoadBtn').removeAttr('disabled');
},
success: function(result) {
if (result.code === 200) {
$('#resultMsg').html(`<a target="_blank" href="${result.data.url}">${result.data.url}</a>`);
} else {
$('#resultMsg').html(result.message);
}
}
});
});
</script>