SmartCtrlLog.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <script setup lang="ts">
  2. import { computed, onMounted, ref } from 'vue';
  3. import { useRequest } from '@/hooks/request';
  4. import { t } from '@/i18n';
  5. import { getSmartCtrlLog, noPaginationDevicesList } from '@/api';
  6. import { disabledDate } from '@/utils';
  7. import type { ColumnType, TableProps } from 'ant-design-vue/es/table';
  8. import type { AllDevicesList, PageParams, RangeValue, SmartCtrlLogItem } from '@/types';
  9. const timeRange = ref<RangeValue>();
  10. const selectedDevices = ref<number[]>([]);
  11. const deviceList = ref<AllDevicesList[]>([]);
  12. const searchContent = ref('');
  13. const logList = ref<SmartCtrlLogItem[]>([]);
  14. const logTotal = ref(0);
  15. const pageParams = ref<PageParams>({
  16. pageIndex: 1,
  17. pageSize: 10,
  18. pageSorts: [
  19. {
  20. column: 'id',
  21. asc: false,
  22. },
  23. ],
  24. });
  25. const columns = computed<ColumnType<SmartCtrlLogItem>[]>(() => {
  26. return [
  27. {
  28. title: t('common.device'),
  29. dataIndex: 'deviceName',
  30. key: 'deviceName',
  31. },
  32. {
  33. title: t('common.content'),
  34. dataIndex: 'content',
  35. key: 'content',
  36. },
  37. {
  38. title: t('common.time'),
  39. dataIndex: 'updateTime',
  40. key: 'updateTime',
  41. },
  42. ];
  43. });
  44. onMounted(() => {
  45. getDeviceList();
  46. getLogList();
  47. });
  48. const { handleRequest } = useRequest();
  49. const getDeviceList = () => {
  50. handleRequest(async () => {
  51. deviceList.value = await noPaginationDevicesList();
  52. });
  53. };
  54. const { isLoading: isLogLoading, handleRequest: handleLogRequest } = useRequest();
  55. const getLogList = () => {
  56. handleLogRequest(async () => {
  57. const { records, total } = await getSmartCtrlLog({
  58. ...pageParams.value,
  59. deviceIds: selectedDevices.value.join(','),
  60. searchContent: searchContent.value,
  61. startTime: timeRange.value?.[0].format('YYYY-MM-DD HH:mm:ss'),
  62. endTime: timeRange.value?.[1].format('YYYY-MM-DD HH:mm:ss'),
  63. });
  64. logList.value = records;
  65. logTotal.value = total;
  66. });
  67. };
  68. const filterDevice = (input: string, option: AllDevicesList) => {
  69. return option.deviceName.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  70. };
  71. const handleSearch = () => {
  72. pageParams.value.pageIndex = 1;
  73. getLogList();
  74. };
  75. const handleReset = () => {
  76. timeRange.value = undefined;
  77. selectedDevices.value = [];
  78. searchContent.value = '';
  79. handleSearch();
  80. };
  81. const handleLogTableChange: TableProps['onChange'] = (pagination) => {
  82. pageParams.value.pageIndex = pagination.current || 1;
  83. pageParams.value.pageSize = pagination.pageSize || 10;
  84. getLogList();
  85. };
  86. </script>
  87. <template>
  88. <ACard :bordered="false">
  89. <ARow class="smart-ctrl-log-query" :gutter="[80, 16]">
  90. <ACol :span="8">
  91. <div class="smart-ctrl-log-label">{{ $t('logCenter.selectTimeRange') }}</div>
  92. <ARangePicker
  93. class="smart-ctrl-log-time"
  94. v-model:value="timeRange"
  95. :placeholder="[$t('common.startTime'), $t('common.endTime')]"
  96. :separator="$t('common.to')"
  97. :disabled-date="disabledDate"
  98. show-time
  99. >
  100. <template #suffixIcon>
  101. <SvgIcon name="calendar" color="#333" />
  102. </template>
  103. </ARangePicker>
  104. </ACol>
  105. <ACol :span="8">
  106. <div class="smart-ctrl-log-label">{{ $t('logCenter.selectDevice') }}</div>
  107. <ASelect
  108. v-model:value="selectedDevices"
  109. class="smart-ctrl-log-input"
  110. :options="deviceList"
  111. :field-names="{ label: 'deviceName', value: 'id' }"
  112. mode="multiple"
  113. :max-tag-count="2"
  114. :max-tag-text-length="10"
  115. :filter-option="filterDevice"
  116. :placeholder="$t('logCenter.plzSelectDevice')"
  117. allow-clear
  118. />
  119. </ACol>
  120. <ACol :span="8">
  121. <div class="smart-ctrl-log-label">{{ $t('common.inputContent') }}</div>
  122. <AInput
  123. v-model:value="searchContent"
  124. class="smart-ctrl-log-input"
  125. :placeholder="$t('logCenter.plzEnterContent')"
  126. allow-clear
  127. />
  128. </ACol>
  129. </ARow>
  130. <div :span="8" class="smart-ctrl-log-button">
  131. <AButton @click="handleReset">{{ $t('common.reset') }}</AButton>
  132. <AButton type="primary" @click="handleSearch">{{ $t('common.query') }}</AButton>
  133. </div>
  134. <ATable
  135. class="hvac-table"
  136. :data-source="logList"
  137. :columns="columns"
  138. row-key="id"
  139. :loading="isLogLoading"
  140. :pagination="{
  141. current: pageParams.pageIndex,
  142. pageSize: pageParams.pageSize,
  143. total: logTotal,
  144. showSizeChanger: true,
  145. showQuickJumper: true,
  146. hideOnSinglePage: false,
  147. showTotal: (total) => $t('common.pageTotal', { total }),
  148. }"
  149. @change="handleLogTableChange"
  150. />
  151. </ACard>
  152. </template>
  153. <style lang="scss" scoped>
  154. .smart-ctrl-log-query {
  155. margin-bottom: 16px;
  156. > .ant-col {
  157. display: flex;
  158. align-items: center;
  159. }
  160. }
  161. .smart-ctrl-log-label {
  162. width: 70px;
  163. margin-right: 12px;
  164. font-size: 14px;
  165. line-height: 22px;
  166. color: var(--antd-color-text);
  167. text-align: right;
  168. }
  169. .smart-ctrl-log-time {
  170. :deep(input) {
  171. text-align: center;
  172. }
  173. }
  174. .smart-ctrl-log-time,
  175. .smart-ctrl-log-input {
  176. flex: 1;
  177. }
  178. .smart-ctrl-log-button {
  179. display: flex;
  180. flex-direction: row-reverse;
  181. margin-block: 16px;
  182. button + button {
  183. margin-right: 12px;
  184. }
  185. }
  186. </style>