src/main/java/com/zy/crm/system/controller/AppVersionController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/crm/system/entity/AppVersion.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/AppVersionMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/webapp/static/js/appVersion/appVersion.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/webapp/views/appVersion/appVersion.html | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/crm/system/controller/AppVersionController.java
@@ -9,8 +9,14 @@ import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.R; import com.zy.crm.common.utils.FileSaveExampleUtil; import com.zy.crm.common.web.BaseController; import com.zy.crm.manager.entity.Plan; import com.zy.crm.manager.entity.PlanType; import com.zy.crm.manager.entity.PlanUrl; import com.zy.crm.manager.entity.PriQuote; import com.zy.crm.system.entity.AppVersion; import com.zy.crm.system.entity.User; import com.zy.crm.system.service.AppVersionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; @@ -213,4 +219,47 @@ response.setStatus(404); } } @RequestMapping(value = "/appVersion/downloadApp/url/view/file/auth") @ManagerAuth public R viewFile(@RequestParam("appId") String appId){ List<FileSaveExampleUtil.FileDTO> fileDTOS = new ArrayList<>(); if (Cools.isEmpty(appId)){ return R.ok(fileDTOS); } Long id = Long.parseLong(appId); AppVersion appVersion = appVersionService.selectById(id); if (Cools.isEmpty(appVersion.getPath())){ return R.ok(fileDTOS); } try{ FileSaveExampleUtil.FileDTO fileDTO = new FileSaveExampleUtil.FileDTO(appVersion.getPath(),appVersion.getFileSize(),appVersion.getUrl()); fileDTO.setUserName(appVersion.getUserName()); fileDTOS.add(fileDTO); return R.ok(fileDTOS); }catch (Exception e){ return R.error(); } } @RequestMapping(value = "/appVersion/downloadApp/url/insert/file/auth") @ManagerAuth public R insertFilePriQuote(@RequestParam("appId") String appId, @RequestParam("filename") String filename, @RequestParam("filesize") Long filesize) { try { String[] split = appId.split("-"); Long id = Long.parseLong(split[1]); AppVersion appVersion = appVersionService.selectById(id); appVersion.setPath(filename); appVersion.setFileSize(filesize); appVersion.setUserName(getUser().getNickname()); String url = "http://zhongyang-ftpserver.oss-cn-hangzhou.aliyuncs.com/" + filename; appVersion.setUrl(url); appVersionService.updateById(appVersion); return R.ok(); } catch (Exception e) { System.out.println(e); return R.error(); } } } src/main/java/com/zy/crm/system/entity/AppVersion.java
@@ -1,5 +1,6 @@ package com.zy.crm.system.entity; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; @@ -42,6 +43,26 @@ @ApiModelProperty(value= "app类型 0: pda 1: lcd ") private Integer type; /** * app路径 */ @ApiModelProperty(value= "appurl") private String url; /** * app路径 */ @ApiModelProperty(value= "appSize") @TableField("file_size") private Long fileSize; /** * app路径 */ @ApiModelProperty(value= "userName") @TableField("user_name") private String userName; public AppVersion() {} public AppVersion(String version, String path, Integer latest, Integer type) { src/main/resources/mapper/AppVersionMapper.xml
@@ -9,6 +9,9 @@ <result column="path" property="path" /> <result column="latest" property="latest" /> <result column="type" property="type" /> <result column="url" property="url" /> <result column="file_size" property="fileSize" /> <result column="user_name" property="userName" /> </resultMap> src/main/webapp/static/js/appVersion/appVersion.js
@@ -1,7 +1,7 @@ var pageCurr; layui.config({ base: baseUrl + "/static/layui/lay/modules/" }).use(['table','laydate', 'form', 'admin','upload'], function(){ }).use(['table','laydate', 'form', 'admin','upload',"element", 'xmSelect'], function(){ var table = layui.table; var $ = layui.jquery; var layer = layui.layer; @@ -9,6 +9,7 @@ var form = layui.form; var admin = layui.admin; var upload = layui.upload; var element = layui.element; // 数据渲染 tableIns = table.render({ @@ -59,6 +60,99 @@ pageCurr=curr; limit(); } }); $("#data-btn-file2").on("click", (e) => { $("#data-btn-upload").click() }); var _uploadFile = null //响应上传 $("#data-btn-upload").on("change",(evt) => { var files = evt.target.files; if(files==null || files.length==0){ alert("No files wait for import"); return; } var file = files[0] var tr = $(['<tr id="upload-">' ,'<td id="upload-filename-id-'+ file.lastModified + '">' + file.name +'</td>' ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>' ,'<td id="upload-filename-userName-'+ '">' +'</td>' ,'<td id="upload-file-id-' + file.lastModified + '"><div class="layui-progress layui-progress-big" lay-showPercent="true" lay-filter="progress-demo-'+ file.lastModified +'"><div class="layui-progress-bar" lay-percent=""></div></div></td>' ,'<td>' ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>' ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>' ,'<button id="file-download" class="layui-btn layui-btn-xs demo-reload layui-hide">下载</button>' ,'</td>' ,'</tr>'].join('')); //删除 tr.find('.demo-delete').on('click', function(){ tr.remove(); $("#data-btn-upload").val("") _uploadFile = null }); $('#data-btn-file3').append(tr) element.progress('progress-demo-'+ file.lastModified, '0%'); //执行进度条。 element.init(); _uploadFile = file }) //开始上传 $("#testListAction").on("click", async (e) => { if (_uploadFile == null) { return false; } var index = layer.load(1, { shadeClose: false, title: '上传中..', shade: [0.5,'#000'] }); var file = _uploadFile putObject(file,(p) => { element.progress('progress-demo-'+ file.lastModified, (Math.round(p * 100)) + "%"); //执行进度条。 }).then((result) => { var filename = result.name layer.msg('上传成功', {icon: 1}); $("#upload-file-id-" + file.lastModified).html("上传成功") $("#upload-filename-id-" + file.lastModified).html(filename) let token = localStorage.getItem("token"); $.ajax({ url: baseUrl+"/appVersion/downloadApp/url/insert/file/auth", headers: {'token': localStorage.getItem('token')}, data: { 'appId': $('.layui-layer-title').text(), 'filename': filename, 'filesize': file.size }, method: 'POST', success: function (res) { if (res.code === 200){ layer.close(index) // console.log(res) } else if (res.code === 403){ top.location.href = baseUrl+"/"; } else { layer.msg(res.msg) } } }); }).catch((e) => { // console.log(e) layer.msg('上传失败', {icon: 2}); $("#upload-file-id-" + file.lastModified).html("上传失败") }) //清空file $("#data-btn-upload").val("") _uploadFile = null }); // 监听排序事件 @@ -136,6 +230,56 @@ table.on('tool(appVersion)', function(obj){ var data = obj.data; switch (obj.event) { case "uploadLink": // 打开弹窗 // 构建带参数的内容 layer.open({ type: 1, title: '上传文件-'+data.id, content: $('#myModal') }); // 获取路径下的文件列表,使用 jQuery 的 ajax 方法 $.ajax({ url: '/appVersion/downloadApp/url/view/file/auth', headers: {'token': localStorage.getItem('token')}, data:{ appId:data.id, }, success: function(response) { if (response.code==200){ var targetTable = document.getElementById("data-btn-file3"); // var targetTable1 = document.getElementById("layui-layer2"); // // 获取文本内容 // var text = targetTable1.textContent.trim(); // console.log(text); // 输出 '上传文件-20' targetTable.innerHTML = ''; // 将获取到的文件列表添加到文件队列中进行显示 response.data.forEach(function(file,index) { // 创建tr元素 var tr = document.createElement("tr"); tr.id = "upload-"+index; tr.innerHTML = '<td>' + file.name + '</td>' + '<td>' + (file.size / 1024).toFixed(1) + 'kb</td>' + '<td>' + file.userName + '</td>' // + '<td><div class="layui-progress" lay-filter="progress-demo-' + index ,100 + '%'+ '"><div class="layui-progress-bar" lay-percent=""></div></div></td>' + '<td>'+'已完成'+'</td>' + '<td>' + '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>' // + '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>' + '<a href="' + file.path + '" download class="layui-btn layui-btn-xs layui-btn-primary">下载</a>' + '</td>'; // 将tr元素添加到目标table中 targetTable.appendChild(tr); }); }else { console.log('Failed to get file list error.'); } }, error: function() { console.log('Failed to get file list.'); } }); break; case 'edit': showEditModel(data); break; @@ -183,6 +327,16 @@ } }); // 点击下载按钮时触发文件下载 $('#data-btn-file3').on('click', 'a', function() { var downloadUrl = $(this).attr('href'); let url = getObjectUrl(downloadUrl) layer.msg("准备下载中", {icon: 1}); // location.href = url window.open(url) return false; // 阻止默认的链接跳转行为 }); /* 弹窗 - 新增、修改 */ function showEditModel(mData) { admin.open({ src/main/webapp/views/appVersion/appVersion.html
@@ -54,17 +54,47 @@ </div> </script> <div id="myModal" style="display: none;"> <div style="padding: 10px"> <div class="layui-upload"> <button type="button" class="layui-btn layui-btn-normal" id="data-btn-file2">选择文件</button><input id="data-btn-upload" class="layui-upload-file" type="file" accept="" name="file" multiple=""> <div class="layui-upload-list" style="max-width: 1000px;height:400px;overflow: scroll"> <table class="layui-table"> <colgroup> <col> <col width="150"> <col width="260"> <col width="150"> </colgroup> <thead> <tr><th>文件名</th> <th>大小</th> <th>上传者</th> <th>上传进度</th> <th>操作</th> </tr></thead> <tbody id="data-btn-file3"></tbody> </table> </div> <button type="button" class="layui-btn" id="testListAction">开始上传</button> </div> </div> </div> <script type="text/html" id="operate"> <a class="layui-btn layui-btn-xs btn-edit" lay-event="upload">上传APP</a> <a class="layui-btn layui-btn-primary layui-btn-xs btn-edit" lay-event="download">下载APP</a> <a class="layui-btn layui-btn-xs btn-edit" lay-event="uploadLink">APP包</a> <a class="layui-btn layui-btn-primary layui-btn-xs btn-edit" lay-event="edit">修改</a> <a class="layui-btn layui-btn-danger layui-btn-xs btn-edit" lay-event="del">删除</a> </script> <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="../../static/js/FileSaver.js"></script> <script type="text/javascript" src="../../static/js/handlebars/handlebars-v4.5.3.js"></script> <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script> <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script> <script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script> <script type="text/javascript" src="../../static/layui/lay/modules/cascader/citys-data.js" charset="utf-8"></script> <script type="text/javascript" src="../../static/js/aliyun-oss-sdk.min.js" charset="utf-8"></script> <script type="text/javascript" src="../../static/js/appVersion/appVersion.js" charset="utf-8"></script> </body> <!-- 表单弹窗 -->