tasksql.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /**
  2. * 执行语句管理定义引用的js
  3. */
  4. var grid_selector = "#grid-table";
  5. var pager_selector = "#grid-pager";
  6. jQuery(function($) {
  7. //初始化日期控件
  8. initDateTime();
  9. // 初始化Grid
  10. initGrid();
  11. // 初始化下拉列表
  12. initDdl();
  13. });
  14. /**
  15. * 初始化Grid
  16. */
  17. function initGrid() {
  18. //resize to fit page size
  19. $(window).on('resize.jqGrid', function() {
  20. $(grid_selector).jqGrid('setGridWidth', $(".page-content").width()-1);
  21. });
  22. //resize on sidebar collapse/expand
  23. var parent_column = $(grid_selector).closest('[class*="col-"]');
  24. $(document).on(
  25. 'settings.ace.jqGrid',
  26. function(ev, event_name, collapsed) {
  27. if (event_name === 'sidebar_collapsed'
  28. || event_name === 'main_container_fixed') {
  29. //setTimeout is for webkit only to give time for DOM changes and then redraw!!!
  30. setTimeout(function() {
  31. $(grid_selector).jqGrid('setGridWidth',
  32. parent_column.width());
  33. }, 0);
  34. }
  35. });
  36. // 数据表格初始化
  37. jQuery(grid_selector).jqGrid({
  38. url : basePath + '/tasksql/initTaskSql',
  39. mtype : "POST", //提交方式
  40. datatype : "json",
  41. autowidth: false,
  42. height :"auto",
  43. shrinkToFit: true,
  44. sortname : "", //默认的排序列
  45. sortorder : "", //默认的排序列
  46. colNames : [ '','id','所在任务', '源连接地址','目标连接地址','查询语句','目标表','同步模式'],
  47. colModel : [ {
  48. name:'Edit',
  49. index:'Edit',
  50. width:30,
  51. sortable : false,
  52. fixed : true
  53. },{
  54. name : 'id',
  55. index : 'id',
  56. key : true,
  57. hidden:true,
  58. editable : false,
  59. sortable : false
  60. },{
  61. name : 'taskCode',
  62. index : 'taskCode',
  63. editable : false,
  64. sortable : true
  65. },{
  66. name : 'srcConn',
  67. index : 'srcConn',
  68. editable : false,
  69. sortable : true
  70. },{
  71. name : 'targetConn',
  72. index : 'targetConn',
  73. editable : false,
  74. sortable : true
  75. }, {
  76. name : 'querySql',
  77. index : 'querySql',
  78. editable : false,
  79. sortable : true
  80. }, {
  81. name : 'targetTable',
  82. index : 'targetTable',
  83. editable : false,
  84. sortable : true
  85. }, {
  86. name : 'mode',
  87. index : 'mode',
  88. editable : false,
  89. sortable : true
  90. ,formatter:function(cellvalue, options, rowObject){
  91. if(cellvalue == 1){
  92. return '逐条';
  93. } else if(cellvalue == 2){
  94. return '全表';
  95. } else{
  96. return "";
  97. }
  98. }
  99. } ],
  100. rowNum : _rowNum, //每页显示记录数
  101. rowList : _rowList, //用于改变显示行数的下拉列表框的元素数组。
  102. pager : pager_selector, //定义翻页用的导航栏
  103. page : 1, //设置初始的页码,初始为1
  104. pagerpos : 'right', //指定分页栏的位置
  105. altRows : true, //设置为交替行表格,默认为false
  106. multiselect : true, //可以多选
  107. multiboxonly : true, //只有选择checkbox才会起作用
  108. loadComplete : function() {
  109. var table = this;
  110. setTimeout(function() {
  111. updatePagerIcons(table);
  112. enableTooltips(table);
  113. }, 0);
  114. },
  115. prmNames : {
  116. oper : "oper",
  117. page : "page",
  118. rows : "rows",
  119. sort : "sidx",
  120. order : "sord"
  121. },
  122. postData :{
  123. wldwCode : function(){ return ""; },//问题内容
  124. wldwName : function(){ return ""; }//服务类型
  125. },
  126. jsonReader : {
  127. root : "list", // json中代表实际模型数据的入口
  128. page : "page", // json中代表当前页码的数据
  129. total : "pages", // json中代表页码总数的数据
  130. records : "total", // json中代表数据行总数的数据
  131. repeatitems : false// 如果设为false,则jqGrid在解析json时,会根据name来搜索对应的数据元素
  132. },
  133. gridComplete: function () {
  134. comGridComplete("grid-table", "editRecord");
  135. },
  136. onPaging: function(){
  137. comGridPage("grid-table");
  138. }
  139. });
  140. $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size
  141. // 隐藏水平垂直滚动条
  142. jQuery(grid_selector).closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'hidden' ,'overflow-y':'hidden'});
  143. //navButtons
  144. jQuery(grid_selector).jqGrid(
  145. 'navGrid',
  146. pager_selector,
  147. { //navbar options
  148. edit : false,
  149. editicon : 'ace-icon fa fa-pencil blue',
  150. add : false,
  151. addicon : 'ace-icon fa fa-plus-circle purple',
  152. del : false,
  153. delicon : 'ace-icon fa fa-trash-o red',
  154. search : false,
  155. searchicon : 'ace-icon fa fa-search orange',
  156. refresh : false,
  157. refreshicon : 'ace-icon fa fa-refresh green',
  158. view : false,
  159. viewicon : 'ace-icon fa fa-search-plus grey',
  160. });
  161. //初始化操作按钮
  162. intOperButton();
  163. $(document).one('ajaxloadstart.page', function(e) {
  164. $(grid_selector).jqGrid('GridUnload');
  165. $('.ui-jqdialog').remove();
  166. });
  167. setMulti();
  168. };
  169. /**
  170. * 初始化下拉列表
  171. */
  172. function initDdl() {
  173. // 初始化所在工作
  174. $.ajax({
  175. type : "POST",
  176. url : basePath + '/task/getTaskForDdl',//请求的路径
  177. dataType : "json",
  178. success : function(data) {
  179. var option1="<option selected value=''>----请选择----</option>";
  180. $("#taskCode").append(option1);
  181. if(data) {
  182. var length=data.length;
  183. if(length > 0) {
  184. for(var i=0;i<length;i++){
  185. $("<option/>").html(data[i].name).val(data[i].code).appendTo("#taskCode");
  186. }
  187. }
  188. }
  189. }
  190. });
  191. // 初始化源和目标下拉
  192. $.ajax({
  193. type : "POST",
  194. url : basePath + '/datasource/getconnForDdl',//请求的路径
  195. dataType : "json",
  196. success : function(data) {
  197. var option1="<option selected value=''>----请选择----</option>";
  198. $("#srcConn").append(option1);
  199. $("#targetConn").append(option1);
  200. if(data) {
  201. var length=data.length;
  202. if(length > 0) {
  203. for(var i=0;i<length;i++){
  204. $("<option/>").html(data[i].id).val(data[i].id).appendTo("#srcConn");
  205. $("<option/>").html(data[i].id).val(data[i].id).appendTo("#targetConn");
  206. }
  207. }
  208. }
  209. }
  210. });
  211. }
  212. /**
  213. * 初始化操作按钮
  214. */
  215. function intOperButton() {
  216. jQuery(grid_selector).navButtonAdd(pager_selector, {
  217. caption : "新增",
  218. buttonicon : "ui-icon ui-icon btn-minier ace-icon fa fa-plus-circle",
  219. onClickButton : function() {
  220. comClearFormData("form");
  221. // 隐藏校验图标
  222. hideValidateTip();
  223. $("#id").val("");
  224. $("#btnSave").show();
  225. // 启用元素
  226. comEnableElements("modal-table");
  227. $("#modal-table #myModalLabel").text("新增执行语句");
  228. $('#modal-table').modal('show');
  229. },
  230. position : "last"
  231. });
  232. jQuery(grid_selector).navButtonAdd(pager_selector, {
  233. caption : "删除",
  234. buttonicon : "ui-icon ui-icon ace-icon fa fa-trash-o red",
  235. onClickButton : function() {
  236. var idsStr = getMultiData();
  237. if(idsStr.length >=1 ){
  238. showMsgConfimDialog("确定删除吗?",function(){
  239. $.ajax({
  240. async : false,
  241. type : 'POST',
  242. dataType : "json",
  243. data : {"ids":idsStr, opt:'QY'},
  244. url : basePath + '/tasksql/delTaskSql',//请求的路径
  245. success : function(data) {
  246. // 成功后刷新页面
  247. if (data == "SUCCESS") {
  248. showMsgDialog("数据已删除!");
  249. }
  250. jQuery(grid_selector).trigger("reloadGrid");
  251. },
  252. error: function (XMLHttpRequest, textStatus, errorThrown) {
  253. showMsgDialog("error:" + errorThrown);
  254. }
  255. });
  256. });
  257. } else {
  258. showMsgDialog("请至少选择一条记录");
  259. }
  260. },
  261. position : "last"
  262. });
  263. }
  264. /**
  265. * 初始化日期控件
  266. */
  267. function initDateTime() {
  268. $('#startTime').datetimepicker({
  269. format : 'yyyy-mm-dd hh:ii:ss',
  270. minView: 1
  271. }).next().on(ace.click_event, function(){
  272. $(this).prev().focus();
  273. });
  274. $('#endTime').datetimepicker({
  275. format : 'yyyy-mm-dd hh:ii:ss',
  276. minView: 1
  277. }).next().on(ace.click_event, function(){
  278. $(this).prev().focus();
  279. });
  280. };
  281. /**
  282. * 编辑
  283. * @param rid
  284. */
  285. function editRecord(rid) {
  286. var data = jQuery("#grid-table").jqGrid('getRowData', rid);
  287. $("#btnSave").show();
  288. // 隐藏校验图标
  289. hideValidateTip();
  290. // 启用元素
  291. comEnableElements("modal-table");
  292. $("#modal-table #myModalLabel").text("编辑执行语句");
  293. initBaseInfo(rid);
  294. }
  295. /**
  296. * 获取多行选中的id
  297. */
  298. function getMultiData(opt){
  299. var ids = "";
  300. //获取选择行的id
  301. var row = jQuery(grid_selector).jqGrid('getGridParam','selarrrow');
  302. if (row.length >= 1) {
  303. for (var i = 0; i < row.length; i++) {
  304. //获取选择的行的数据,只要传入rowId即可
  305. var data = jQuery(grid_selector).jqGrid('getRowData', row[i]);
  306. ids += data.id +",";
  307. }
  308. ids = ids.substr(0, ids.length - 1);
  309. }
  310. return ids;
  311. }
  312. /**
  313. * 查询事件
  314. */
  315. function searchRecord() {
  316. //$.extend(jQuery(grid_selector)[0].p.postData);
  317. jQuery("#grid-table").trigger("reloadGrid", [{ page: 1 }]);
  318. };
  319. /**
  320. * form提交事件
  321. */
  322. function submitForm() {
  323. $.ajax({
  324. async:false,
  325. type : "post",
  326. url : basePath + '/tasksql/save',
  327. dataType:'json',
  328. data : $('#form').serialize()
  329. , //表单序列化,获取数据
  330. success : function(data) {
  331. // 成功删除后刷新页面
  332. if (data) {
  333. showMsgDialog("数据已成功保存!");
  334. closeWin();
  335. searchRecord();
  336. } else {
  337. showMsgDialog("数据保存失败!");
  338. }
  339. }, //操作成功后的操作!data是后台传过来的值
  340. error: function (XMLHttpRequest, textStatus, errorThrown) {
  341. showMsgDialog("error:" + errorThrown);
  342. }
  343. });
  344. };
  345. // 关闭弹出窗口,刷新列表
  346. function closeWin(){
  347. $('.layui-layer').hide();
  348. $('#modal-table').modal('hide');
  349. }
  350. /**
  351. * 根据id查询所有信息并赋值
  352. */
  353. function initBaseInfo(rowid, flg){
  354. // 后台获取
  355. $.ajax({
  356. async : true,
  357. type : 'POST',
  358. dataType : "json",
  359. data : {id:rowid},
  360. url : basePath + '/tasksql/initEditTaskSql', //请求的路径
  361. success : function(data) {
  362. // 填充信息
  363. $('#id').val(data.id);
  364. $('#taskCode').val(data.taskCode);
  365. $('#srcConn').val(data.srcConn);
  366. $('#targetConn').val(data.targetConn);
  367. $('#targetTable').val(data.targetTable);
  368. $('#querySql').val(data.querySql);
  369. $('#updateSql').val(data.updateSql);
  370. $('#insertSql').val(data.insertSql);
  371. $('#refreshSql').val(data.refreshSql);
  372. $('#mode').val(data.mode);
  373. if(flg && flg=="VIEW") {
  374. comDisableElements("modal-table");
  375. }
  376. },
  377. error: function (XMLHttpRequest, textStatus, errorThrown) {
  378. showMsgDialog("error:" + errorThrown);
  379. }
  380. });
  381. $('#modal-table').modal('show');
  382. };
  383. /**
  384. * 隐藏校验图标
  385. */
  386. function hideValidateTip() {
  387. }