index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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('device.form.address')"
  17. label-col-flex="50px"
  18. >
  19. <a-input
  20. v-model="formModel.address"
  21. :placeholder="t('device.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('device.form.name')"
  30. label-col-flex="50px"
  31. >
  32. <a-input
  33. v-model="formModel.name"
  34. :placeholder="t('device.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('device.form.entityType')"
  43. label-col-flex="60px"
  44. >
  45. <a-select
  46. v-model="formModel.entityType"
  47. :placeholder="t('device.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="status"
  62. :label="t('device.form.status')"
  63. label-col-flex="60px"
  64. >
  65. <a-select
  66. v-model="formModel.status"
  67. :placeholder="t('device.form.status')"
  68. allow-clear
  69. @clear="formModel.status = null"
  70. >
  71. <a-option
  72. v-for="item of deviceStatusList"
  73. :value="item.dictCode"
  74. :label="item.name"
  75. />
  76. </a-select>
  77. </a-form-item>
  78. </a-col>
  79. <a-col :span="6">
  80. <a-form-item
  81. :label="t('device.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.export') }}
  112. </a-button>
  113. </a-space>
  114. </a-col>
  115. </a-row>
  116. <a-table
  117. row-key="name"
  118. :loading="loading"
  119. :pagination="pagination"
  120. :columns="cloneColumns as TableColumnData[]"
  121. :data="renderData"
  122. :bordered="false"
  123. :size="size"
  124. :scrollbar="true"
  125. @page-change="onPageChange"
  126. @row-dblclick="handleClick"
  127. >
  128. <template #index="{ rowIndex }">
  129. {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
  130. </template>
  131. <template #entityType="{ record }">
  132. <span>
  133. {{
  134. deviceTypeList.find(item => item.dictCode === record.entityType)
  135. ?.name
  136. }}
  137. </span>
  138. </template>
  139. <template #status="{ record }">
  140. <BTag :status="record.status">
  141. {{
  142. deviceStatusList.find(item => item.dictCode === record.status)
  143. ?.name
  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. <DeviceInfoDialog
  155. v-model="showDeviceInfoDialog"
  156. :id="deviceId"
  157. :deviceInfo="deviceInfo"
  158. :deviceType="deviceType"
  159. >
  160. </DeviceInfoDialog>
  161. </div>
  162. </template>
  163. <script lang="ts" setup name="DevicePage">
  164. import {
  165. ref,
  166. reactive,
  167. shallowRef,
  168. h,
  169. getCurrentInstance,
  170. computed,
  171. } from 'vue';
  172. import { queryDeviceList, exportDeviceList } from '@/api/device';
  173. import type { DeviceParams, DataList } from '@/api/device';
  174. import { SizeProps, Pagination } from '@/types/global';
  175. import BTag from '@/components/business/b-tag/index.vue';
  176. import type { TableColumnData } from '@arco-design/web-vue';
  177. import useLoading from '@/hooks/loading';
  178. import { useI18n } from 'vue-i18n';
  179. import type { AdditionalProp } from '@/api/dict';
  180. import dayjs from 'dayjs';
  181. import { useIntervalFn } from '@vueuse/core';
  182. import DeviceInfoDialog from './device-info/index.vue';
  183. import useDictList from '@/hooks/dict-list';
  184. import { downLoadFun, DeviceInfo } from '@/utils/const';
  185. const { t } = useI18n();
  186. const { loading, setLoading } = useLoading(true);
  187. const cloneColumns = computed(() => [
  188. {
  189. title: t('searchTable.table.number'),
  190. dataIndex: 'index',
  191. slotName: 'index',
  192. ellipsis: true,
  193. tooltip: true,
  194. width: 70,
  195. },
  196. {
  197. title: t('device.table.time'),
  198. dataIndex: 'time',
  199. slotName: 'time',
  200. ellipsis: true,
  201. },
  202. {
  203. title: t('device.form.status'),
  204. dataIndex: 'status',
  205. slotName: 'status',
  206. width: 120,
  207. },
  208. {
  209. title: t('device.form.name'),
  210. dataIndex: 'name',
  211. slotName: 'name',
  212. },
  213. {
  214. title: t('device.form.entityType'),
  215. dataIndex: 'entityType',
  216. slotName: 'entityType',
  217. },
  218. {
  219. title: t('device.form.address'),
  220. dataIndex: 'address',
  221. ellipsis: true,
  222. tooltip: true,
  223. },
  224. ]);
  225. const basePagination: Pagination = {
  226. current: 1,
  227. pageSize: 20,
  228. };
  229. const pagination = reactive({
  230. ...basePagination,
  231. });
  232. const generateFormModel = () => {
  233. return {
  234. pageIndex: 1,
  235. pageSize: 20,
  236. name: null,
  237. address: null,
  238. status: null,
  239. startTime: null,
  240. endTime: null,
  241. time: ['', ''],
  242. entityType: null,
  243. } as DeviceParams;
  244. };
  245. const renderData = ref<DataList[]>([] as DataList[]);
  246. const size = ref<SizeProps>('medium');
  247. const formModel = ref<DeviceParams>(generateFormModel());
  248. const showDeviceInfoDialog = shallowRef<boolean>(false);
  249. const this_ = getCurrentInstance()?.appContext.config.globalProperties;
  250. const deviceInfo = ref<DeviceInfo[]>([] as DeviceInfo[]);
  251. const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
  252. const deviceStatusList = ref<AdditionalProp[]>([] as AdditionalProp[]);
  253. const deviceId = shallowRef<number>(0);
  254. const deviceType = shallowRef<number | null>(1);
  255. useDictList(['DeviceType', 'DeviceStatus']).then(res => {
  256. deviceTypeList.value.push(...res['DeviceType']);
  257. deviceStatusList.value.push(...res['DeviceStatus']);
  258. });
  259. function searchTable() {
  260. // setLoading(true);
  261. const [startTime, endTime] = formModel.value.time
  262. ? formModel.value.time
  263. : ['', ''];
  264. formModel.value.startTime = startTime ? startTime : null;
  265. formModel.value.endTime = endTime ? endTime : null;
  266. queryDeviceList(formModel.value)
  267. .then(res => {
  268. pagination.current = formModel.value.pageIndex;
  269. pagination.pageSize = pagination.pageSize;
  270. pagination.total = res.totalCount;
  271. renderData.value = res.data;
  272. })
  273. .finally(() => {
  274. setLoading(false);
  275. });
  276. }
  277. searchTable();
  278. const { pause, resume, isActive } = useIntervalFn(() => {
  279. /* your function */
  280. formModel.value.pageIndex = 1;
  281. searchTable();
  282. }, 1000);
  283. const search = () => {
  284. searchTable();
  285. };
  286. const reset = () => {
  287. formModel.value = generateFormModel();
  288. };
  289. const downloadExcel = () => {
  290. setLoading(true);
  291. const [startTime, endTime] = formModel.value.time;
  292. formModel.value.startTime = startTime ? startTime : null;
  293. formModel.value.endTime = endTime ? endTime : null;
  294. exportDeviceList(formModel.value)
  295. .then(res => {
  296. if (!res.success) {
  297. return;
  298. }
  299. const url = res.data;
  300. downLoadFun(url);
  301. })
  302. .finally(() => {
  303. setLoading(false);
  304. });
  305. };
  306. const onPageChange = (current: number) => {
  307. formModel.value.pageIndex = current;
  308. if (current === 1) {
  309. resume();
  310. } else {
  311. pause();
  312. }
  313. searchTable();
  314. };
  315. const handleClick = (value: DataList) => {
  316. if (value.data) {
  317. deviceInfo.value.length = 0;
  318. const obj = JSON.parse(value.data);
  319. for (const key in obj) {
  320. deviceInfo.value.push({
  321. label: key,
  322. value: obj[key],
  323. });
  324. }
  325. console.log('dddd', value.entityType);
  326. deviceType.value = value.entityType;
  327. showDeviceInfoDialog.value = true;
  328. } else {
  329. this_ &&
  330. this_.$message.warning('No device information available at the moment');
  331. }
  332. };
  333. </script>
  334. <style lang="less" scoped>
  335. .container {
  336. padding: 10px 10px 20px;
  337. .general-card {
  338. padding-top: 20px;
  339. .right-side {
  340. margin-top: 20px;
  341. }
  342. }
  343. }
  344. </style>