index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <div class="container">
  3. <a-card class="general-card">
  4. <a-row>
  5. <a-col :flex="1">
  6. <a-form
  7. :model="formModel"
  8. :label-col-props="{ span: 4 }"
  9. :wrapper-col-props="{ span: 18 }"
  10. label-align="left"
  11. >
  12. <a-row :gutter="16">
  13. <a-col :span="6">
  14. <a-form-item
  15. field="address"
  16. :label="t('dashboard.form.address')"
  17. label-col-flex="50px"
  18. >
  19. <a-input
  20. v-model="formModel.address"
  21. :placeholder="t('dashboard.form.address')"
  22. allow-clear
  23. />
  24. </a-form-item>
  25. </a-col>
  26. <a-col :span="6">
  27. <a-form-item
  28. field="name"
  29. :label="t('dashboard.form.name')"
  30. label-col-flex="50px"
  31. >
  32. <a-input
  33. v-model="formModel.name"
  34. :placeholder="t('dashboard.form.name')"
  35. allow-clear
  36. />
  37. </a-form-item>
  38. </a-col>
  39. <a-col :span="6">
  40. <a-form-item
  41. field="entityType"
  42. :label="t('dashboard.form.entityType')"
  43. label-col-flex="60px"
  44. >
  45. <a-select
  46. v-model="formModel.entityType"
  47. :placeholder="t('dashboard.form.entityType')"
  48. allow-clear
  49. @clear="formModel.entityType = null"
  50. >
  51. <a-option
  52. v-for="item of deviceTypeList"
  53. :value="item.dictCode"
  54. :label="item.name"
  55. />
  56. </a-select>
  57. </a-form-item>
  58. </a-col>
  59. <a-col :span="6">
  60. <a-form-item
  61. field="statusTypeList"
  62. :label="t('dashboard.form.status')"
  63. label-col-flex="60px"
  64. >
  65. <a-select
  66. v-model="formModel.status"
  67. :placeholder="t('dashboard.form.status')"
  68. allow-clear
  69. @clear="formModel.status = null"
  70. >
  71. <a-option
  72. v-for="item of statusTypeList"
  73. :value="item.value"
  74. :label="item.label"
  75. />
  76. </a-select>
  77. </a-form-item>
  78. </a-col>
  79. <a-col :span="6">
  80. <a-form-item
  81. :label="t('dashboard.form.timeRange')"
  82. label-col-flex="60px"
  83. >
  84. <a-range-picker v-model="formModel.time" />
  85. </a-form-item>
  86. </a-col>
  87. </a-row>
  88. </a-form>
  89. </a-col>
  90. <a-divider :style="{ height: '84px' }" direction="vertical" />
  91. <a-col :flex="'86px'">
  92. <a-space :size="10">
  93. <a-button type="primary" @click="search">
  94. <template #icon>
  95. <icon-search />
  96. </template>
  97. {{ t('searchTable.form.search') }}
  98. </a-button>
  99. <a-button @click="reset">
  100. <template #icon>
  101. <icon-refresh />
  102. </template>
  103. {{ t('searchTable.form.reset') }}
  104. </a-button>
  105. </a-space>
  106. <a-space class="right-side">
  107. <a-button type="primary" @click="downloadExcel">
  108. <template #icon>
  109. <icon-download />
  110. </template>
  111. {{ t('searchTable.form.down') }}
  112. </a-button>
  113. </a-space>
  114. </a-col>
  115. </a-row>
  116. <a-table
  117. class="table-list"
  118. row-key="name"
  119. :loading="loading"
  120. :pagination="pagination"
  121. :columns="cloneColumns as TableColumnData[]"
  122. :data="renderData"
  123. :bordered="false"
  124. :size="size"
  125. :scrollbar="true"
  126. @page-change="onPageChange"
  127. @row-dblclick="handleClick"
  128. >
  129. <template #index="{ rowIndex }">
  130. {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
  131. </template>
  132. <template #entityType="{ record }">
  133. <span>
  134. {{
  135. deviceTypeList.find(item => item.dictCode === record.entityType)
  136. ?.name
  137. }}
  138. </span>
  139. </template>
  140. <template #status="{ record }">
  141. <BTag :status="record.status">
  142. {{
  143. statusTypeList.find(item => item.value === record.status)?.label
  144. }}
  145. </BTag>
  146. </template>
  147. <template #time="{ record }">
  148. <span>{{
  149. record.time && dayjs(record.time).format('YYYY-MM-DD HH:mm:ss')
  150. }}</span>
  151. </template>
  152. </a-table>
  153. </a-card>
  154. <a-modal
  155. v-model:visible="visible"
  156. title-align="start"
  157. @cancel="handleCancel"
  158. >
  159. <template #title>{{ t('dashboard.dialog.title') }}</template>
  160. <div>
  161. <a-descriptions :data="deviceInfo" bordered :column="2" />
  162. </div>
  163. <template #footer>
  164. <a-button @click="handleCancel">取消</a-button>
  165. <!-- 只保留取消按钮,确认按钮被隐藏 -->
  166. </template>
  167. </a-modal>
  168. </div>
  169. </template>
  170. <script lang="ts" setup name="Dashboard">
  171. import {
  172. ref,
  173. reactive,
  174. shallowRef,
  175. h,
  176. getCurrentInstance,
  177. computed,
  178. } from 'vue';
  179. import { queryDashboardList, exportDashboardList } from '@/api/dashboard';
  180. import type { DashboardParams, DataList } from '@/api/dashboard';
  181. import { SizeProps, Pagination } from '@/types/global';
  182. import BTag from '@/components/business/b-tag/index.vue';
  183. import type { TableColumnData } from '@arco-design/web-vue';
  184. import useLoading from '@/hooks/loading';
  185. import { useI18n } from 'vue-i18n';
  186. import { statusTypeList } from './conf';
  187. import { DeviceInfo } from '@/utils/const';
  188. import type { AdditionalProp } from '@/api/dict';
  189. import { getDictQueryList } from '@/api/dict';
  190. import dayjs from 'dayjs';
  191. import { downLoadFun } from '@/utils/const';
  192. import { useIntervalFn } from '@vueuse/core';
  193. const { t } = useI18n();
  194. const { loading, setLoading } = useLoading(true);
  195. const cloneColumns = computed(() => [
  196. {
  197. title: t('searchTable.table.number'),
  198. dataIndex: 'index',
  199. slotName: 'index',
  200. ellipsis: true,
  201. tooltip: true,
  202. width: 70,
  203. },
  204. {
  205. title: t('dashboard.table.time'),
  206. dataIndex: 'time',
  207. slotName: 'time',
  208. ellipsis: true,
  209. },
  210. {
  211. title: t('dashboard.form.status'),
  212. dataIndex: 'status',
  213. slotName: 'status',
  214. width: 120,
  215. },
  216. {
  217. title: t('dashboard.form.name'),
  218. dataIndex: 'name',
  219. slotName: 'name',
  220. },
  221. {
  222. title: t('dashboard.form.entityType'),
  223. dataIndex: 'entityType',
  224. slotName: 'entityType',
  225. },
  226. {
  227. title: t('dashboard.form.address'),
  228. dataIndex: 'address',
  229. ellipsis: true,
  230. tooltip: true,
  231. },
  232. ]);
  233. const basePagination: Pagination = {
  234. current: 1,
  235. pageSize: 20,
  236. };
  237. const pagination = reactive({
  238. ...basePagination,
  239. });
  240. const generateFormModel = () => {
  241. return {
  242. pageIndex: 1,
  243. pageSize: 20,
  244. name: null,
  245. address: null,
  246. status: null,
  247. startTime: null,
  248. endTime: null,
  249. time: ['', ''],
  250. entityType: null,
  251. } as DashboardParams;
  252. };
  253. const renderData = ref<DataList[]>([] as DataList[]);
  254. const size = ref<SizeProps>('medium');
  255. const formModel = ref<DashboardParams>(generateFormModel());
  256. const visible = shallowRef<boolean>(false);
  257. const this_ = getCurrentInstance()?.appContext.config.globalProperties;
  258. const deviceInfo = ref<DeviceInfo[]>([] as DeviceInfo[]);
  259. const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
  260. getDictQueryList({ names: ['DeviceType'] }).then(res => {
  261. deviceTypeList.value.push(...res.data['DeviceType']);
  262. });
  263. function searchTable() {
  264. // setLoading(true);
  265. const [startTime, endTime] = formModel.value.time
  266. ? formModel.value.time
  267. : ['', ''];
  268. formModel.value.startTime = startTime ? startTime : null;
  269. formModel.value.endTime = endTime ? endTime : null;
  270. queryDashboardList(formModel.value)
  271. .then(res => {
  272. pagination.current = formModel.value.pageIndex;
  273. pagination.pageSize = pagination.pageSize;
  274. pagination.total = res.totalCount;
  275. renderData.value = res.data;
  276. })
  277. .finally(() => {
  278. setLoading(false);
  279. });
  280. }
  281. searchTable();
  282. const { pause, resume, isActive } = useIntervalFn(() => {
  283. /* your function */
  284. formModel.value.pageIndex = 1;
  285. searchTable();
  286. }, 1000);
  287. const search = () => {
  288. searchTable();
  289. };
  290. const reset = () => {
  291. formModel.value = generateFormModel();
  292. };
  293. const downloadExcel = () => {
  294. setLoading(true);
  295. const [startTime, endTime] = formModel.value.time;
  296. formModel.value.startTime = startTime ? startTime : null;
  297. formModel.value.endTime = endTime ? endTime : null;
  298. exportDashboardList(formModel.value)
  299. .then(res => {
  300. if (!res.success) {
  301. return;
  302. }
  303. const url = res.data;
  304. downLoadFun(url);
  305. })
  306. .finally(() => {
  307. setLoading(false);
  308. });
  309. };
  310. const onPageChange = (current: number) => {
  311. formModel.value.pageIndex = current;
  312. if (current === 1) {
  313. resume();
  314. } else {
  315. pause();
  316. }
  317. searchTable();
  318. };
  319. const handleClick = (value: DataList) => {
  320. if (value.data) {
  321. deviceInfo.value.length = 0;
  322. const obj = JSON.parse(value.data);
  323. for (const key in obj) {
  324. deviceInfo.value.push({
  325. label: key,
  326. value: obj[key],
  327. });
  328. }
  329. visible.value = true;
  330. } else {
  331. this_ &&
  332. this_.$message.warning('No device information available at the moment');
  333. }
  334. };
  335. const handleCancel = () => {
  336. visible.value = false;
  337. };
  338. </script>
  339. <style lang="less" scoped>
  340. .container {
  341. padding: 10px 10px 20px;
  342. .general-card {
  343. padding-top: 20px;
  344. .right-side {
  345. margin-top: 20px;
  346. }
  347. }
  348. .table-list {
  349. margin-top: 0;
  350. }
  351. }
  352. </style>