Basf_FCL/FCL/FineUIPro.Web/AttachFile/webuploader2.aspx

163 lines
6.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="webuploader2.aspx.cs" Inherits="FineUIPro.Web.AttachFile.webuploader2" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
<meta name="sourcefiles" content="~/AttachFile/fileupload.ashx" />
<style>
.webuploader-element-invisible {
position: absolute !important;
clip: rect(1px,1px,1px,1px);
}
.webuploader-pick-disable {
opacity: 0.6;
pointer-events: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" runat="server" />
<f:Grid ID="Grid1" runat="server" ShowHeader="false" ShowBorder="true" Title="File upload"
Width="650px" Height="360px"
EnableCollapse="false" EnableCheckBoxSelect="false" EmptyText="File not uploaded"
DataIDField="id" OnRowCommand="Grid1_RowCommand">
<Toolbars>
<f:Toolbar ID="Toolbar1" runat="server">
<Items>
<f:Button ID="btnSelectFiles" Text="Select file upload" IconFont="Plus" runat="server" EnablePostBack="false">
</f:Button>
<f:ToolbarSeparator runat="server"></f:ToolbarSeparator>
<f:Button ID="btnDelete" Text="Delete selected file" IconFont="Remove" runat="server" OnClick="btnDelete_Click">
</f:Button>
<f:Button ID="btnSave" Text="Save" Icon="Add" runat="server" OnClick="btnSave_Click">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Columns>
<f:LinkButtonField ColumnID="FileName" DataTextField="name" DataToolTipField="name" HeaderText="File Name" ExpandUnusedSpace="True" CommandName="Attach"/>
<f:BoundField ColumnID="FileType" DataField="type" HeaderText="Type" Width="80px" />
<f:RenderField ColumnID="FileSize" DataField="size" HeaderText="FileSize" Renderer="FileSize" Width="90px" />
<f:BoundField ColumnID='FileStatus' DataField="status" NullDisplayText="Completed" HeaderText="State" Width="90px" />
<f:LinkButtonField Width="70px" ConfirmText="Are you sure you want to delete this file" ConfirmTarget="Top" ToolTip="删除"
HeaderText="Delete" CommandName="Delete" IconUrl="~/res/icon/delete.png" />
</Columns>
</f:Grid>
<br />
本多附件上传支持的浏览器版本为Chrome、Firefox、Safari、IE10+ 。
</form>
<script src="res/webuploader/webuploader.nolog.js" type="text/javascript"></script>
<script type="text/javascript">
var btnDeleteClientID = '<%= btnDelete.ClientID %>';
var btnSelectFilesClientID = '<%= btnSelectFiles.ClientID %>';
var gridClientID = '<%= Grid1.ClientID %>';
var BASE_URL = '<%= ResolveUrl("~/") %>';
var SERVER_URL = BASE_URL + 'AttachFile/fileupload.ashx';
F.ready(function () {
var grid = F(gridClientID);
var uploader = WebUploader.create({
// swf文件路径
swf: BASE_URL + 'AttachFile/res/webuploader/Uploader.swf',
// 文件接收服务端。
server: SERVER_URL,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建可能是input元素也可能是flash.
pick: '#' + btnSelectFilesClientID,
// 不压缩image, 默认如果是jpeg文件上传前会压缩一把再上传
resize: false,
// 自动上传
auto: true,
// 文件上传参数表用来标记文件的所有者如果是一篇文章的附件就是文章的ID
formData: {
owner: '<%= ParamStr%>'
},
// 单个文件大小限制单位byte这里限制为 20M
fileSingleSizeLimit: 20 * 1024 * 1024
});
// 添加到上传队列
uploader.on('fileQueued', function (file) {
grid.addNewRecord(file.id, {
'FileName': file.name,
'FileType': file.ext,
'FileSize': file.size,
'FileStatus': 'Waiting for upload'
}, true);
});
uploader.on('uploadProgress', function (file, percentage) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
var barEl = cellEl.find('.ui-progressbar-value');
// 避免重复创建
if (!barEl.length) {
cellEl.html('<div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" style="height:12px;">' +
'<div class="ui-progressbar-value ui-widget-header ui-corner-left" style="width:0%">' +
'</div></div>');
barEl = cellEl.find('.ui-progressbar-value');
}
barEl.css('width', percentage * 100 + '%');
});
uploader.on('uploadSuccess', function (file) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
cellEl.text('Upload successful');
});
uploader.on('uploadError', function (file) {
var cellEl = grid.getCellEl(file.id, 'FileStatus').find('.f-grid-cell-inner');
cellEl.text('Upload error');
});
// 不管上传成功还是失败,都会触发 uploadComplete 事件
uploader.on('uploadComplete', function (file) {
uploader.removeFile(file, true);
});
// 当开始上传流程时触发
uploader.on('startUpload', function () {
// 禁用删除按钮
F(btnDeleteClientID).disable();
});
// 当所有文件上传结束时触发
uploader.on('uploadFinished', function () {
// 启用删除按钮
F(btnDeleteClientID).enable();
// 回发页面,重新绑定表格数据
__doPostBack('', 'RebindGrid');
});
uploader.on('error', function (type, arg, file) {
if (type === 'F_EXCEED_SIZE') {
F.alert('Flie[' + file.name + '] Size Limit exceeded' + F.format.fileSize(arg) + '');
}
});
});
</script>
</body>
</html>