selectHardware.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. window.editTool.hotpoint.addHardware(item[0])
  46. //alert(item)
  47. console.log(GridManager.getCheckedTr(gName));
  48. })
  49. // 取消事件
  50. $('#gcancel,.gr-header>img').click(function () {
  51. $('.jsGrid-body').hide()
  52. console.log(GridManager.getCheckedTr(gName));
  53. })
  54. //搜索事件
  55. $('.gr-header > .search').click(function () {
  56. var _query = {
  57. title: document.querySelector('[name="title"]').value,
  58. type: document.querySelector('[name="type"]').value,
  59. content: document.querySelector('[name="content"]').value,
  60. cPage: 1
  61. };
  62. grtable.GM('setQuery', _query, function(){
  63. console.log('setQuery执行成功');
  64. });
  65. })
  66. //设备添加
  67. $('#grAdd').click(function () {
  68. $('.jsGrid-body').show()
  69. })
  70. //设备删除
  71. $('#grDel').click(function () {
  72. })
  73. // 阻止冒泡
  74. $('.jsGrid-con').on('click keydown keyup keypress',function (event) {
  75. event.stopPropagation();
  76. })
  77. let getList = function(params) {
  78. return new Promise((resolve, reject) => {
  79. $.ajax({
  80. method: 'GET',
  81. headers: {
  82. 'Content-Type': 'application/json'
  83. },
  84. dataType: 'json',
  85. contentType: 'application/json',
  86. url: url + 'api/device/list',
  87. success: function(data) {
  88. console.log(data);
  89. if (data.code === 0) {
  90. resolve({
  91. ...data,
  92. totals:data.data.length
  93. });
  94. }
  95. else {
  96. reject(data);
  97. }
  98. }
  99. })
  100. })
  101. };
  102. })