moniPointCtrl.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. app.controller('moniPointCtrl', ['$scope', '$http', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $http, $state, $timeout, uiGridConstants, i18nService, toaster) {
  2. i18nService.setCurrentLang("zh-cn");
  3. moment.locale('zh-cn');
  4. $scope.gridOptions = {
  5. data: 'myData',
  6. showGridFooter: true, //是否显示grid footer
  7. //-------- 分页属性 ----------------
  8. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  9. paginationCurrentPage: 1, //当前页码
  10. paginationPageSize: 10, //每页显示个数
  11. totalItems: 0,// 总数量
  12. useExternalPagination: true,//是否使用分页按钮
  13. //过滤
  14. // enableFiltering: true,
  15. columnDefs: [],
  16. //---------------api---------------------
  17. onRegisterApi: function (gridApi) {
  18. $scope.gridApi = gridApi;
  19. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  20. if ($scope.setPagingData) {
  21. $scope.getPagedDataAsync(newPage, pageSize);
  22. }
  23. });
  24. }
  25. };
  26. //枚举常量
  27. $scope.enum = {
  28. };
  29. //查询条件
  30. $scope.query = {
  31. searchKey: "",
  32. };
  33. $scope.ngEvent = {
  34. //查询
  35. query: function () {
  36. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  37. },
  38. };
  39. function setColumnDefs() {
  40. $scope.gridOptions.columnDefs = [
  41. {field: 'name', displayName: '名称',},
  42. {field: 'key', displayName: '接口关键字',},
  43. {field: 'desc', displayName: '说明',},
  44. {
  45. field: 'operation',
  46. displayName: '操作',
  47. enableFiltering: false,
  48. enableSorting: false,
  49. enableHiding: false,//禁止在列选择器中隐藏
  50. enableColumnMenu: false,// 是否显示列头部菜单按钮
  51. minWidth: 150,
  52. cellTemplate: '<div class="grid-button">' +
  53. '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.edit(row.entity)"><i class="fa fa-edit"></i> 编辑</button>' +
  54. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.delete(row.entity)"><i class="fa fa-trash-o"></i> 删除</button>' +
  55. '</div>'
  56. },
  57. ];
  58. var fields = $scope.gridOptions.columnDefs;
  59. for (var index in fields) {
  60. var item = fields[index];
  61. if (item && item['minWidth'] == null) {
  62. item['minWidth'] = 100;
  63. }
  64. }
  65. }
  66. $scope.setPagingData = function (data) {
  67. var pagedData = data.data.dataList;
  68. $scope.myData = pagedData;
  69. $scope.gridOptions.totalItems = data.data.total;
  70. };
  71. $scope.getPagedDataAsync = function (curPage, pageSize) {
  72. var params = {
  73. pageSize: pageSize,
  74. pageIndex: curPage
  75. };
  76. var query = $scope.query;
  77. params.searchKey = query.searchKey
  78. $http.get('/superadmin/getMoniPointList', {
  79. params: params
  80. }).then(function (data) {
  81. data = data.data
  82. $scope.setPagingData(data, curPage, pageSize);
  83. }).catch(function (data) {
  84. toaster.pop("error", "提示", "获取数据列表失败");
  85. });
  86. };
  87. function initDataGrid() {
  88. //首次加载表格
  89. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  90. }
  91. setColumnDefs();
  92. initDataGrid();
  93. $scope.dialogData = {};
  94. $scope.add = function () {
  95. $scope.dialogData = {};
  96. $("#moniEdit").modal()
  97. }
  98. $scope.edit = function (entity) {
  99. $("#moniEdit").modal()
  100. $scope.dialogData = $.extend(true, {}, entity);
  101. }
  102. $scope.save = function () {
  103. //表单未校验通过不能提交
  104. if ($scope.moniEdit.$invalid) {
  105. return;
  106. }
  107. $http({
  108. method: 'POST',
  109. url: "/superadmin/editMoniPoint",
  110. data: $scope.dialogData
  111. }).then(function (response) {
  112. $('#moniEdit').modal('hide');//弹窗消失
  113. toaster.pop("success", "提示", "保存成功!");
  114. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  115. }, function (response) {
  116. toaster.pop("error", "提示", "保存失败!");
  117. });
  118. }
  119. $scope.delete = function (entity) {
  120. $.confirm({
  121. content: '确定删除?',
  122. buttons: {
  123. ok: {
  124. btnClass: 'btn-red',
  125. action: function () {
  126. $http({
  127. method: 'POST',
  128. url: '/superadmin/deleteMoniPoint',
  129. data: {ids: [entity.id]}
  130. }).then(function (response) {
  131. initDataGrid();
  132. }, function (response) {
  133. toaster.pop("error", "提示", "删除失败!");
  134. });
  135. }
  136. },
  137. }
  138. });
  139. }
  140. }]);