layout02UserWidgetT.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="tbl-wrapper">
  3. <div class="tbl-wrap">
  4. <!-- ag-grid -->
  5. <ag-grid-vue
  6. style="width:100%; height:calc(50vh - 11rem)"
  7. class="ag-theme-quartz"
  8. :grid-options="gridOptions"
  9. :row-data="props.items"
  10. :pagination-page-size="props.pageObj.pageSize"
  11. :pagination-page-size-selector="columnList"
  12. :suppress-pagination-panel="true"
  13. @grid-ready="fnOnGridReady"
  14. />
  15. </div>
  16. </div>
  17. </template>
  18. <script setup>
  19. /***********************
  20. * import
  21. ************************/
  22. import { useI18n } from "vue-i18n"
  23. import apiUrl from '@/composables/useApi';
  24. import useAxios from '@/composables/useAxios';
  25. import useUtil from '@/composables/useUtil';
  26. import "ag-grid-community/styles/ag-grid.css";
  27. import "ag-grid-community/styles/ag-theme-quartz.css";
  28. import { AgGridVue } from "ag-grid-vue3";
  29. import dayjs from "#build/dayjs.imports.mjs";
  30. /***********************
  31. * plugins inject
  32. ************************/
  33. const { $toast, $log, $dayjs, $eventBus } = useNuxtApp()
  34. // props
  35. const props = defineProps({
  36. items: {
  37. type: Array,
  38. default: () => []
  39. },
  40. pageObj: {
  41. type: Object,
  42. default: () => {
  43. return {
  44. page: 1,
  45. pageSize: 10,
  46. totalCnt: 0,
  47. }
  48. }
  49. }
  50. })
  51. // 참조가능 데이터 설정
  52. defineExpose({})
  53. // 발신 이벤트 선언
  54. const emit = defineEmits([]);
  55. const i18n = useI18n();
  56. /***********************
  57. * data & created
  58. ************************/
  59. const remToPx = () => parseFloat(getComputedStyle(document.documentElement).fontSize);
  60. const vhToPx = (vh) => window.innerHeight * (vh / 100);
  61. const rowHeightRem = 2.2; // 원하는 rem 값
  62. const rowHeightPx = rowHeightRem * remToPx();
  63. const gridApi = shallowRef();
  64. const getHeaders = computed(() => [
  65. { headerName: 'No', field: 'no', maxWidth: 75},
  66. { headerName: '테넌트 명', field: 'tenantName'},
  67. { headerName: '사용량', maxWidth: 150, cellRenderer: fnPercentCellRenderer},
  68. { headerName: '만료일', maxWidth: 150, cellRenderer: fnExpiredDateCellRenderer},
  69. { headerName: '계정 현황 (사용/최대)', cellRenderer: fnAccountStatusRenderer},
  70. { headerName: '세션 현황 (접속/최대)', cellRenderer: fnSessionStatusRenderer},
  71. ])
  72. // gridOption
  73. const gridOptions = {
  74. columnDefs: getHeaders.value,
  75. rowData: props.items, // 테이블 데이터
  76. suppressMovableColumns: true,
  77. autoSizeStrategy: {
  78. type: "fitGridWidth", // width맞춤
  79. },
  80. headerHeight : rowHeightPx,
  81. rowHeight: rowHeightPx,
  82. pagination: true,
  83. suppressPaginationPanel: true, // 하단 default 페이징 컨트롤 숨김
  84. suppressRowClickSelection: true, // 행 클릭 체크박스 무시
  85. localeText: {
  86. noRowsToShow: i18n.t('common.noData')
  87. },
  88. defaultColDef: {
  89. lockVisible: true, // 열을 그리드 밖으로 꺼내지 않음
  90. },
  91. }
  92. /***********************
  93. * Methods
  94. ************************/
  95. // Grid 데이터 바인딩
  96. function fnOnGridReady(params){
  97. gridApi.value = params.api
  98. }
  99. // 사용량 렌더러
  100. function fnPercentCellRenderer(params) {
  101. const { data } = params;
  102. return `<span class="${data.tablePercentClass}">${data.perSubscriber}%</span>`;
  103. }
  104. // 만료일 렌더러
  105. function fnExpiredDateCellRenderer(params) {
  106. return dayjs(params.expirationDate).format('YYYY-MM-DD');
  107. }
  108. // 계정현황 렌더러
  109. function fnAccountStatusRenderer(params) {
  110. const { data } = params;
  111. return `${useUtil.toRoundFix(data.currentAccountCount, 0)}/${useUtil.toRoundFix(data.maxAccount, 0)}`
  112. }
  113. // 세션현황 렌더러
  114. function fnSessionStatusRenderer(params) {
  115. const { data } = params;
  116. return `${useUtil.toRoundFix(data.currentConnectingCount, 0)}/${useUtil.toRoundFix(data.maxSession, 0)}`
  117. }
  118. </script>