main
黄海 7 months ago
parent e41ec88257
commit d89b8e4f78

@ -68,135 +68,140 @@
</head> </head>
<body class="layui-form"> <body class="layui-form">
<div class="layui-card" style="margin-top: 50px;"> <div class="layui-card" style="margin-top: 50px;">
<div class="layui-card-body"> <div class="layui-card-body">
<!-- <button type="button" class="layui-btn" id="getData">获取数据</button> --> <!-- <button type="button" class="layui-btn" id="getData">获取数据</button> -->
<div class="fix"> <div class="fix">
<button type="button" class="layui-btn" id="saveData">保存</button> <button type="button" class="layui-btn" id="saveData">保存</button>
<button type="button" class="layui-btn" id="back">返回</button> <button type="button" class="layui-btn" id="back">返回</button>
</div> </div>
<table id="ID-table-demo-data"></table> <table id="ID-table-demo-data"></table>
<script type="text/html" id="table-bar">
<span class="woo-tool-span woo-tool-text-span" lay-event="add"><a
class="woo-theme-color">向下插入</a></span>
<span class="woo-tool-span woo-tool-text-span" lay-event="delete"><a
class="woo-theme-color">删除</a></span>
</script>
<script type="text/html" id="table-bar">
<span class="woo-tool-span woo-tool-text-span" lay-event="add"><a
class="woo-theme-color">向下插入</a></span>
<span class="woo-tool-span woo-tool-text-span" lay-event="delete"><a
class="woo-theme-color">删除</a></span>
</script>
</div>
</div> </div>
</div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 --> <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="../js/layui/layui.js"></script> <script src="../js/layui/layui.js"></script>
<script> <script>
layui.use('table', function () { layui.use('table', function () {
var table = layui.table; var table = layui.table;
var $ = layui.jquery; var $ = layui.jquery;
var util = layui.util; var util = layui.util;
var id = GetQueryString("id"); var id = GetQueryString("id");
// var id = "3"; // var id = "3";
var _data = []; var _data = [];
$.ajax({ $.ajax({
type: "GET", type: "GET",
async: false, async: false,
url: '/dsBase/dataease/getDataSetContent?id=' + id, url: '/dsBase/dataease/getDataSetContent?id=' + id,
dataType: "json", dataType: "json",
success: function (res) { success: function (res) {
_data = res.data; _data = res.data;
} }
}); });
var _emptyData = {}; var _emptyData = {};
var _cols = []; var _cols = [];
let keys = Object.keys(_data[0]); let keys = Object.keys(_data[0]);
keys.forEach((item, index) => { keys.forEach((item, index) => {
_emptyData[item] = ""; _emptyData[item] = "";
var _obj = { field: item, title: item, edit: 'text', align: 'center', expandedMode: 'tips' } var _obj = {field: item, title: item, edit: 'text', align: 'center', expandedMode: 'tips'}
_cols.push(_obj); _cols.push(_obj);
}); });
_cols.push({ title: '操作', align: 'center', toolbar: '#table-bar' }); _cols.push({title: '操作', align: 'center', toolbar: '#table-bar'});
table.render({ table.render({
elem: '#ID-table-demo-data', elem: '#ID-table-demo-data',
id: 'ID-table-demo-data', id: 'ID-table-demo-data',
page: false, page: true //开启分页
cols: [_cols], , limit: 10 //每页显示的条数
data: _data , limits: [10, 20, 30]
}); , request: {
pageName: 'pageNumber' //页码的参数名称默认page
, limitName: 'pageSize' //每页数据量的参数名默认limit
},
cols: [_cols],
data: _data
});
table.on('tool(ID-table-demo-data)', function (obj) { table.on('tool(ID-table-demo-data)', function (obj) {
if (obj.event === 'add') { if (obj.event === 'add') {
_data.splice(obj.index + 1, 0, _emptyData); _data.splice(obj.index + 1, 0, _emptyData);
table.cache['ID-table-demo-data'] = _data; table.cache['ID-table-demo-data'] = _data;
table.renderData('ID-table-demo-data');
} else {
layer.confirm('确定删除吗?', {icon: 0}, function (index) {
var cacheData = table.cache['ID-table-demo-data'];
cacheData.splice(obj.index, 1)
table.renderData('ID-table-demo-data'); table.renderData('ID-table-demo-data');
} else { layer.close(index);
layer.confirm('确定删除吗?', { icon: 0 }, function (index) { });
var cacheData = table.cache['ID-table-demo-data']; }
cacheData.splice(obj.index, 1) });
table.renderData('ID-table-demo-data');
layer.close(index);
});
}
});
$("#saveData").click(function () { $("#saveData").click(function () {
const cleanedData = table.cache['ID-table-demo-data'].map(item => { const cleanedData = table.cache['ID-table-demo-data'].map(item => {
const { LAY_NUM, LAY_INDEX, ...rest } = item; const {LAY_NUM, LAY_INDEX, ...rest} = item;
return rest; return rest;
}); });
$.ajax({ $.ajax({
type: "POST", type: "POST",
dataType: "json", dataType: "json",
async: false, async: false,
url: '/dsBase/dataease/saveDataSet', url: '/dsBase/dataease/saveDataSet',
data: { data: {
"id": id, "id": id,
"data": JSON.stringify(cleanedData) "data": JSON.stringify(cleanedData)
}, },
success: function (res) { success: function (res) {
if (res.success) { if (res.success) {
layer.msg("保存成功!", { layer.msg("保存成功!", {
icon: 1, icon: 1,
time: 1300 time: 1300
}); });
} else { } else {
layer.msg(res.message, { layer.msg(res.message, {
icon: 2, icon: 2,
time: 2000 time: 2000
}); });
}
} }
}); }
}); });
});
$("#back").click(function () { $("#back").click(function () {
history.back(); history.back();
}); });
function GetQueryString(name, istop) { function GetQueryString(name, istop) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg); var r = window.location.search.substr(1).match(reg);
if (typeof (istop) != "undefined") r = top.location.search.substr(1).match(reg); if (typeof (istop) != "undefined") r = top.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); if (r != null) return unescape(r[2]);
return null; return null;
} }
}); });
</script> </script>
</body> </body>

@ -9,6 +9,7 @@ import com.dsideal.base.DataEase.Util.Step3_CopyBigScreen;
import com.dsideal.base.Interceptor.EmptyInterface; import com.dsideal.base.Interceptor.EmptyInterface;
import com.dsideal.base.Interceptor.IsLoginInterface; import com.dsideal.base.Interceptor.IsLoginInterface;
import com.dsideal.base.Interceptor.IsNumericInterface; import com.dsideal.base.Interceptor.IsNumericInterface;
import com.dsideal.base.Interceptor.LayUiPageInfoInterface;
import com.dsideal.base.Res.Model.ResourceModel; import com.dsideal.base.Res.Model.ResourceModel;
import com.dsideal.base.Util.CommonUtil; import com.dsideal.base.Util.CommonUtil;
import com.dsideal.base.Util.CookieUtil; import com.dsideal.base.Util.CookieUtil;
@ -18,6 +19,7 @@ import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST; import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile; import com.jfinal.upload.UploadFile;
import io.github.yedaxia.apidocs.ApiDoc; import io.github.yedaxia.apidocs.ApiDoc;
@ -74,6 +76,7 @@ public class DataEaseController extends Controller {
/** /**
* 使 * 使
*
* @param city_name * @param city_name
*/ */
@Before({GET.class}) @Before({GET.class})
@ -215,7 +218,6 @@ public class DataEaseController extends Controller {
} }
/** /**
* Excel * Excel
* *
@ -314,12 +316,16 @@ public class DataEaseController extends Controller {
/** /**
* *
* *
* @param id id * @param id id
* @param pageNumber
* @param pageSize
*/ */
@Before(GET.class) @Before(GET.class)
@IsLoginInterface({}) @IsLoginInterface({})
@IsNumericInterface({"id"}) @IsNumericInterface({"id"})
public void getDataSetContent(int id) { public void getDataSetContent(int id, int pageNumber, int pageSize) {
if (pageNumber == 0) pageNumber = 1;
if (pageSize == 0) pageSize = 20;
//登录的人员 //登录的人员
int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id")); int identity_id = Integer.parseInt(CookieUtil.getValue(getRequest(), "identity_id"));
String person_id = CookieUtil.getValue(getRequest(), "person_id"); String person_id = CookieUtil.getValue(getRequest(), "person_id");
@ -330,8 +336,8 @@ public class DataEaseController extends Controller {
//根据区域码,获取区域名称 //根据区域码,获取区域名称
String area_name = rm.getAreaName(area_code); String area_name = rm.getAreaName(area_code);
List<Record> list = dm.getDataSetContent(id, identity_id, area_name); Page<Record> pageList = dm.getDataSetContent(id, identity_id, area_name, pageNumber, pageSize);
renderJson(CommonUtil.renderJsonForLayUI(list)); renderJson(CommonUtil.renderJsonForLayUI(pageList));
} }
/** /**

@ -5,6 +5,7 @@ import com.dsideal.base.Util.ExcelCommonUtil;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara; import com.jfinal.plugin.activerecord.SqlPara;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
@ -584,17 +585,18 @@ public class DataEaseModel {
* @param id id * @param id id
* @return * @return
*/ */
public List<Record> getDataSetContent(int id, int identity_id, String area_name) { public Page<Record> getDataSetContent(int id, int identity_id, String area_name, int pageNumber, int pageSize) {
Record record = Db.findById("t_dp_dataset", "id", id); Record record = Db.findById("t_dp_dataset", "id", id);
String tableName = record.getStr("table_name"); String tableName = record.getStr("table_name");
Page<Record> p;
if (identity_id > 1) { if (identity_id > 1) {
String sql = "select * from `" + tableName + "` where `行政区划`='" + area_name + "' or `上级行政区划`='" + area_name + "'"; p = Db.paginate(pageNumber, pageSize,
return Db.use(DB_NAME).find(sql); "SELECT *", "from "+DB_NAME+".`" + tableName + "` where `行政区划`='" + area_name + "' or `上级行政区划`='" + area_name + "'");
} else { } else {
String sql = "select * from `" + tableName + "`"; p = Db.paginate(pageNumber, pageSize,
return Db.use(DB_NAME).find(sql); "SELECT *", "from "+DB_NAME+".`" + tableName + "`");
} }
return p;
} }
/** /**

Loading…
Cancel
Save