| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- <template>
- <div class="container">
- <a-card class="general-card">
- <a-row>
- <a-col :flex="1">
- <a-form
- :model="formModel"
- :label-col-props="{ span: 4 }"
- :wrapper-col-props="{ span: 18 }"
- label-align="left"
- >
- <a-row :gutter="16">
- <a-col :span="6">
- <a-form-item
- field="address"
- :label="t('dashboard.form.address')"
- label-col-flex="50px"
- >
- <a-input
- v-model="formModel.address"
- :placeholder="t('dashboard.form.address')"
- allow-clear
- />
- </a-form-item>
- </a-col>
- <a-col :span="6">
- <a-form-item
- field="name"
- :label="t('dashboard.form.name')"
- label-col-flex="50px"
- >
- <a-input
- v-model="formModel.name"
- :placeholder="t('dashboard.form.name')"
- allow-clear
- />
- </a-form-item>
- </a-col>
- <a-col :span="6">
- <a-form-item
- field="entityType"
- :label="t('dashboard.form.entityType')"
- label-col-flex="60px"
- >
- <a-select
- v-model="formModel.entityType"
- :placeholder="t('dashboard.form.entityType')"
- allow-clear
- @clear="formModel.entityType = null"
- >
- <a-option
- v-for="item of deviceTypeList"
- :value="item.dictCode"
- :label="item.name"
- />
- </a-select>
- </a-form-item>
- </a-col>
- <a-col :span="6">
- <a-form-item
- field="statusTypeList"
- :label="t('dashboard.form.status')"
- label-col-flex="60px"
- >
- <a-select
- v-model="formModel.status"
- :placeholder="t('dashboard.form.status')"
- allow-clear
- @clear="formModel.status = null"
- >
- <a-option
- v-for="item of statusTypeList"
- :value="item.value"
- :label="item.label"
- />
- </a-select>
- </a-form-item>
- </a-col>
- <a-col :span="6">
- <a-form-item
- :label="t('dashboard.form.timeRange')"
- label-col-flex="60px"
- >
- <a-range-picker v-model="formModel.time" />
- </a-form-item>
- </a-col>
- </a-row>
- </a-form>
- </a-col>
- <a-divider :style="{ height: '84px' }" direction="vertical" />
- <a-col :flex="'86px'">
- <a-space :size="10">
- <a-button type="primary" @click="search">
- <template #icon>
- <icon-search />
- </template>
- {{ t('searchTable.form.search') }}
- </a-button>
- <a-button @click="reset">
- <template #icon>
- <icon-refresh />
- </template>
- {{ t('searchTable.form.reset') }}
- </a-button>
- </a-space>
- <a-space class="right-side">
- <a-button type="primary" @click="downloadExcel">
- <template #icon>
- <icon-download />
- </template>
- {{ t('searchTable.form.down') }}
- </a-button>
- </a-space>
- </a-col>
- </a-row>
- <a-table
- class="table-list"
- row-key="name"
- :loading="loading"
- :pagination="pagination"
- :columns="cloneColumns as TableColumnData[]"
- :data="renderData"
- :bordered="false"
- :size="size"
- :scrollbar="true"
- @page-change="onPageChange"
- @row-dblclick="handleClick"
- >
- <template #index="{ rowIndex }">
- {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
- </template>
- <template #entityType="{ record }">
- <span>
- {{
- deviceTypeList.find(item => item.dictCode === record.entityType)
- ?.name
- }}
- </span>
- </template>
- <template #status="{ record }">
- <BTag :status="record.status">
- {{
- statusTypeList.find(item => item.value === record.status)?.label
- }}
- </BTag>
- </template>
- <template #time="{ record }">
- <span>{{
- record.time && dayjs(record.time).format('YYYY-MM-DD HH:mm:ss')
- }}</span>
- </template>
- </a-table>
- </a-card>
- <a-modal
- v-model:visible="visible"
- title-align="start"
- @cancel="handleCancel"
- >
- <template #title>{{ t('dashboard.dialog.title') }}</template>
- <div>
- <a-descriptions :data="deviceInfo" bordered :column="2" />
- </div>
- <template #footer>
- <a-button @click="handleCancel">取消</a-button>
- <!-- 只保留取消按钮,确认按钮被隐藏 -->
- </template>
- </a-modal>
- </div>
- </template>
- <script lang="ts" setup name="Dashboard">
- import {
- ref,
- reactive,
- shallowRef,
- h,
- getCurrentInstance,
- computed,
- } from 'vue';
- import { queryDashboardList, exportDashboardList } from '@/api/dashboard';
- import type { DashboardParams, DataList } from '@/api/dashboard';
- import { SizeProps, Pagination } from '@/types/global';
- import BTag from '@/components/business/b-tag/index.vue';
- import type { TableColumnData } from '@arco-design/web-vue';
- import useLoading from '@/hooks/loading';
- import { useI18n } from 'vue-i18n';
- import { statusTypeList } from './conf';
- import { DeviceInfo } from '@/utils/const';
- import type { AdditionalProp } from '@/api/dict';
- import { getDictQueryList } from '@/api/dict';
- import dayjs from 'dayjs';
- import { downLoadFun } from '@/utils/const';
- import { useIntervalFn } from '@vueuse/core';
- const { t } = useI18n();
- const { loading, setLoading } = useLoading(true);
- const cloneColumns = computed(() => [
- {
- title: t('searchTable.table.number'),
- dataIndex: 'index',
- slotName: 'index',
- ellipsis: true,
- tooltip: true,
- width: 70,
- },
- {
- title: t('dashboard.table.time'),
- dataIndex: 'time',
- slotName: 'time',
- ellipsis: true,
- },
- {
- title: t('dashboard.form.status'),
- dataIndex: 'status',
- slotName: 'status',
- width: 120,
- },
- {
- title: t('dashboard.form.name'),
- dataIndex: 'name',
- slotName: 'name',
- },
- {
- title: t('dashboard.form.entityType'),
- dataIndex: 'entityType',
- slotName: 'entityType',
- },
- {
- title: t('dashboard.form.address'),
- dataIndex: 'address',
- ellipsis: true,
- tooltip: true,
- },
- ]);
- const basePagination: Pagination = {
- current: 1,
- pageSize: 20,
- };
- const pagination = reactive({
- ...basePagination,
- });
- const generateFormModel = () => {
- return {
- pageIndex: 1,
- pageSize: 20,
- name: null,
- address: null,
- status: null,
- startTime: null,
- endTime: null,
- time: ['', ''],
- entityType: null,
- } as DashboardParams;
- };
- const renderData = ref<DataList[]>([] as DataList[]);
- const size = ref<SizeProps>('medium');
- const formModel = ref<DashboardParams>(generateFormModel());
- const visible = shallowRef<boolean>(false);
- const this_ = getCurrentInstance()?.appContext.config.globalProperties;
- const deviceInfo = ref<DeviceInfo[]>([] as DeviceInfo[]);
- const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
- getDictQueryList({ names: ['DeviceType'] }).then(res => {
- deviceTypeList.value.push(...res.data['DeviceType']);
- });
- function searchTable() {
- // setLoading(true);
- const [startTime, endTime] = formModel.value.time
- ? formModel.value.time
- : ['', ''];
- formModel.value.startTime = startTime ? startTime : null;
- formModel.value.endTime = endTime ? endTime : null;
- queryDashboardList(formModel.value)
- .then(res => {
- pagination.current = formModel.value.pageIndex;
- pagination.pageSize = pagination.pageSize;
- pagination.total = res.totalCount;
- renderData.value = res.data;
- })
- .finally(() => {
- setLoading(false);
- });
- }
- searchTable();
- const { pause, resume, isActive } = useIntervalFn(() => {
- /* your function */
- formModel.value.pageIndex = 1;
- searchTable();
- }, 1000);
- const search = () => {
- searchTable();
- };
- const reset = () => {
- formModel.value = generateFormModel();
- };
- const downloadExcel = () => {
- setLoading(true);
- const [startTime, endTime] = formModel.value.time;
- formModel.value.startTime = startTime ? startTime : null;
- formModel.value.endTime = endTime ? endTime : null;
- exportDashboardList(formModel.value)
- .then(res => {
- if (!res.success) {
- return;
- }
- const url = res.data;
- downLoadFun(url);
- })
- .finally(() => {
- setLoading(false);
- });
- };
- const onPageChange = (current: number) => {
- formModel.value.pageIndex = current;
- if (current === 1) {
- resume();
- } else {
- pause();
- }
- searchTable();
- };
- const handleClick = (value: DataList) => {
- if (value.data) {
- deviceInfo.value.length = 0;
- const obj = JSON.parse(value.data);
- for (const key in obj) {
- deviceInfo.value.push({
- label: key,
- value: obj[key],
- });
- }
- visible.value = true;
- } else {
- this_ &&
- this_.$message.warning('No device information available at the moment');
- }
- };
- const handleCancel = () => {
- visible.value = false;
- };
- </script>
- <style lang="less" scoped>
- .container {
- padding: 10px 10px 20px;
- .general-card {
- padding-top: 20px;
- .right-side {
- margin-top: 20px;
- }
- }
- .table-list {
- margin-top: 0;
- }
- }
- </style>
|