main
黄海 3 years ago
parent 024f485edb
commit 553d94de59

@ -13,7 +13,7 @@
<body>
<table class="layui-table" lay-filter="idTest" id="idTest"></table>
<script type="text/html" id="barDemo">
<script type="text/html" id="bar1">
{{#if(d.filled){ }}
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="modify">修改</a>
{{#}else{ }}
@ -21,14 +21,27 @@
{{#} }}
</script>
<script type="text/html" id="bar2">
{{#if(d.doc_file){ }}
<a class="layui-btn layui-btn-xs layui-btn-warm update_doc" lay-event="upload_doc" page="{{d.page}}">重新上传</a>
{{#}else{ }}
{{#if(d.filled){ }}
<a class="layui-btn layui-btn-xs layui-btn upload_doc" lay-event="upload_doc" page="{{d.page}}">上传</a>
{{#} }}
{{#} }}
</script>
<script>
layui.use(['layer', 'form', 'table'], function () {
layui.use(['layer', 'form', 'table', 'upload'], function () {
var layer = layui.layer;
var form = layui.form;
var table = layui.table;
var upload = layui.upload; //得到 upload 对象
//需要获取当前的url中参数module_id和page
let module_id = $.getUrlParam('module_id');
function bindTable() {
table.render({
elem: '#idTest'
, url: '/FengHuang/zjb/getModulePageFillInfo'
@ -37,21 +50,45 @@
}
, cols: [[
{field: '', title: '序号', align: 'center', type: 'numbers', fixed: true, width: '5%'}
, {field: 'json', title: '内容', align: 'center'}
, {fixed: 'right', title: '操作', toolbar: '#barDemo', align: 'center', width: 480}
, {
field: 'json', title: '内容', align: 'center', templet: function (d) {
if (d.json.length > 2)
return '已填写'
else
return '待填写'
}
}
, {fixed: 'right', title: '页面构建', toolbar: '#bar1', align: 'center', width: 240}
, {fixed: 'right', title: '模板上传', toolbar: '#bar2', align: 'center', width: 240}
]]
, page: false
, height: 'full'
, done: function (res) {
$("[data-field='json']").children().each(function () {
if ($(this).text() == "[]") {
$(this).text("未填写");
} else {
$(this).text("已填写");
//创建一个上传组件
upload.render({
elem: '.upload_doc'
, url: '/FengHuang/zjb/uploadDoc?module_id=' + module_id,
before: function () {
var tableElem = this.item;
let page = tableElem.attr('page');
this.url = this.url + "&page=" + page;
},
done: function () {
layer.msg('保存成功!', {icon: 1, time: 1500},
function (index) {
bindTable();
}
);
},
accept: 'file',
acceptMime: "application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
exts: 'docx|doc', //只允许上传word文件
})
}
});
}
bindTable();
table.on('tool(idTest)', function (obj) {
var data = obj.data;
if (obj.event === "modify") {

@ -91,4 +91,17 @@ public class ZjbController extends Controller {
zm.clearUpload(task_id, page);
renderJson(CommonUtil.returnMessageJson(true, "清除成功!"));
}
@Before({POST.class})
@IsNumericInterface({"module_id", "page"})
public void uploadDoc(int module_id, int page) {
UploadFile uploadFile = getFile();
String fileName = uploadFile.getFileName();
File file = uploadFile.getFile();
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).trim();
File target = new File(PathKit.getWebRootPath() + "/upload/" + UUID.randomUUID() + "." + suffix);
file.renameTo(target);
zm.saveDoc(module_id, page, target.getName());
renderJson(CommonUtil.returnMessageJson(true, "上传成功!"));
}
}

@ -84,9 +84,12 @@ public class ZjbModel {
String sql = "select * from t_zjb_module_page where module_id=?";
List<Record> exist = Db.find(sql, module_id);
Map<Integer, String> _map = new HashMap<>();
Map<Integer, String> _map2 = new HashMap<>();
for (Record record : exist) {
_map.put(record.getInt("page"), record.getStr("json"));
_map2.put(record.getInt("page"), record.getStr("doc_file"));
}
Record record = getMoudleInfo(module_id);
int page_count = record.getInt("page_count");
List<Record> res = new ArrayList<>();
@ -100,6 +103,7 @@ public class ZjbModel {
r.set("json", "[]");
r.set("filled", false);
}
r.set("doc_file", _map2.get(i));
res.add(r);
}
return res;
@ -162,6 +166,11 @@ public class ZjbModel {
Db.save("t_zjb_task_fill_upload", "task_id,page,upload_id,file_name", record);
}
public void saveDoc(int module_id, int page, String doc_file) {
String sql = "update t_zjb_module_page set doc_file=? where module_id=? and page=?";
Db.update(sql, doc_file, module_id, page);
}
public void clearUpload(int task_id, int page) {
String sql = "delete from t_zjb_task_fill_upload where task_id=? and page=?";
Db.update(sql, task_id, page);

Loading…
Cancel
Save