selectHardware.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. $(function () {
  2. let url = `http://8.135.106.227:8004/`
  3. let gName = 'Gridtable'
  4. let grtable = document.querySelector("#gridtb")
  5. grtable.GM({
  6. gridManagerName: gName,
  7. height: '400px',
  8. ajaxData: function (setting) {
  9. // 传入分页及排序的配置项
  10. return getList(Object.assign({}, setting.pageData, setting.sortData));
  11. },
  12. ajaxType: "POST",
  13. checkboxConfig: {
  14. useRowCheck: true,
  15. useRadio: true,
  16. },
  17. query: { pluginId: 1 },
  18. supportAjaxPage: true,
  19. columnData: [
  20. {
  21. key: "code",
  22. text: "硬件编号",
  23. },
  24. {
  25. key: "devTypeName",
  26. text: "硬件类型",
  27. },
  28. {
  29. key: "name",
  30. text: "热点名字",
  31. },
  32. {
  33. key: "id",
  34. text: "id",
  35. }
  36. ],
  37. });
  38. // 确认事件
  39. $('#gcommit').click(function () {
  40. let item = Array.from(GridManager.getCheckedTr(gName))
  41. if (item.length<=0) {
  42. alert('请选择设备')
  43. return
  44. }
  45. alert(item)
  46. console.log(GridManager.getCheckedTr(gName));
  47. })
  48. // 取消事件
  49. $('#gcancel,.gr-header>img').click(function () {
  50. $('.jsGrid-body').hide()
  51. console.log(GridManager.getCheckedTr(gName));
  52. })
  53. //搜索事件
  54. $('.gr-header > .search').click(function () {
  55. var _query = {
  56. title: document.querySelector('[name="title"]').value,
  57. type: document.querySelector('[name="type"]').value,
  58. content: document.querySelector('[name="content"]').value,
  59. cPage: 1
  60. };
  61. grtable.GM('setQuery', _query, function(){
  62. console.log('setQuery执行成功');
  63. });
  64. })
  65. //设备添加
  66. $('#grAdd').click(function () {
  67. $('.jsGrid-body').show()
  68. })
  69. //设备删除
  70. $('#grDel').click(function () {
  71. })
  72. // 阻止冒泡
  73. $('.jsGrid-con').on('click keydown keyup keypress',function (event) {
  74. event.stopPropagation();
  75. })
  76. let getList = function(params) {
  77. return new Promise((resolve, reject) => {
  78. $.ajax({
  79. method: 'GET',
  80. headers: {
  81. 'Content-Type': 'application/json'
  82. },
  83. dataType: 'json',
  84. contentType: 'application/json',
  85. url: url + 'api/device/list',
  86. success: function(data) {
  87. console.log(data);
  88. if (data.code === 0) {
  89. resolve({
  90. ...data,
  91. totals:data.data.length
  92. });
  93. }
  94. else {
  95. reject(data);
  96. }
  97. }
  98. })
  99. })
  100. };
  101. })