<input type="file" data-ng-model="file">
<uib-progress data-ng-show="progress">
<uib-bar value="progress" type="{{type}}" data-ng-bind="progress + '%'"/>
</uib-progress>
<span class="err" data-ng-show="isShowMsg" data-ng-bind="Msg"></span>
<button class="btn btn-primary" type="button" data-ng-click="upload()">确认</button>
Upload.upload(
{
url: "",
data: {
file: file
},
method: 'post'
}).then(function (res) {
//这里是success方法
$scope.isShowMsg = true;
$scope.Msg = res.data.msg;
if($scope.Msg == "导入数据不符合格式要求!")
$scope.type = "progress-bar progress-bar-danger progress-bar-striped";//设置进度条样式
else {
$scope.type = "progress-bar progress-bar-success progress-bar-striped";
$scope.progress = 100;//上传成功之后,将进度条设置为100
}
}, function (){
//这里是error方法
}, function (){
//这里是progress方法
$scope.type = "progress-bar progress-bar-info progress-bar-striped";
$http({
url:"",
method: "get"
}).success(function (res) {
$scope.progress = res;//绑定进度条的值
})
});
public Map<String, Object> batchModify(InputStream inputStream,HttpSession session) {
Map<String, Object> res = new HashMap<>();
Workbook workbook = null;
try {
workbook = Util.createWorkbook(inputStream);
} catch (InvalidFormatException | IOException e) {
e.printStackTrace();
}
session.setAttribute("progress", 5);//解析成功后我将进度设置为5
Sheet sheet = workbook.getSheetAt(0);
Map<String, Object> roleWithPages = new HashMap<>();
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row r = sheet.getRow(i);
if (r == null || r.getCell(0) == null || r.getCell(1) == null)
continue;
Set<Page> pages = null;
if (roleWithPages.get(r.getCell(0).toString()) == null) {
pages = new HashSet<>();
} else {
pages = (Set<Page>) roleWithPages.get(r.getCell(0).toString());
}
Page p = new Page();
p.setId(Math.round(r.getCell(1).getNumericCellValue()));
pages.add(p);
roleWithPages.put(r.getCell(0).toString(), pages);
session.setAttribute("progress", 5 + i*90/sheet.getLastRowNum());
//我将处理文件主体进度总量设置为90(5是加上解析部分的进度)
}
List<Role> roles = new ArrayList<>();
for (String rolename : roleWithPages.keySet()) {
Role role = repo.findByName(rolename);
role.setPages((Set<Page>) roleWithPages.get(rolename));
roles.add(role);
}
repo.save(roles);
session.setAttribute("progress", 100);//保存之后将进度设置为100
res.put("msg", "数据导入成功!");
return res;
}
public int getProgress(HttpServletRequest request){
return (int) request.getSession().getAttribute("progress");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有