| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <template>
- <div class="vent-table">
- <BasicTable ref="ventTableRef" @register="registerTable" :rowSelection="rowSelection" :pagination="false" :loading="loading">
- <template #tableTitle>
- <div></div>
- </template>
- <template #tableTop>
- <div></div>
- </template>
- <template #bodyCell="{ column, record }">
- <slot name="filterCell" v-bind="{ column, record }"></slot>
- </template>
- </BasicTable>
- </div>
- </template>
- <script lang="ts" setup>
- //ts语法
- import { defineExpose, toRaw, watch, ref, onMounted, onUnmounted } from 'vue';
- import { BasicTable } from '/@/components/Table';
- import { useListPage } from '/@/hooks/system/useListPage';
- import { list, deleteUser, batchDeleteUser, getImportUrl, getExportUrl, frozenBatch, syncUser } from '../../../system/user/user.api';
- import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
- import { findIndex } from 'lodash-es';
- import { computed } from '@vue/reactivity';
- const listApi = '/ventanaly-device/monitor/device';
- const props = defineProps({
- columnsType: {
- type: String,
- required: true,
- },
- dataSource: {
- type: Array,
- required: true,
- },
- deviceType: {
- type: String,
- },
- designScope: {
- type: String,
- },
- title: {
- type: String,
- },
- size: {
- type: String,
- default: 'small',
- },
- });
- const emits = defineEmits(['selectRow']);
- const dataTableSource = ref([]);
- const loading = ref(true);
- const ventTableRef = ref();
- // 默认初始是第一行
- const selectRowIndex = ref(0);
- const tableMaxHeight = 150;
- watch(
- () => {
- return props.dataSource;
- },
- (newVal, oldVal) => {
- if (oldVal.length < 1 && newVal.length > 0) {
- // 第一次
- setSelectedRowKeys([newVal[0].deviceID]);
- }
- const list = [];
- newVal.forEach((item) => {
- list.push(toRaw(item));
- });
- dataTableSource.value = list;
- loading.value = false;
- }
- );
- const columns = getTableHeaderColumns(props.columnsType);
- console.log('[ columns ] >', columns);
- // 列表页面公共参数、方法
- const { prefixCls, tableContext, doRequest } = useListPage({
- designScope: props.designScope,
- tableProps: {
- title: props.title,
- // api: list,
- dataSource: dataTableSource,
- columns: columns,
- rowSelection: { type: 'radio' },
- size: props.size,
- useSearchForm: false,
- showTableSetting: false,
- showActionColumn: false,
- maxHeight: tableMaxHeight,
- bordered: false,
- rowKey: 'deviceID',
- striped: true,
- actionColumn: {
- width: 180,
- },
- pagination: {
- current: 1,
- pageSize: 5,
- pageSizeOptions: ['5', '10', '20'],
- },
- beforeFetch: (params) => {
- return Object.assign({ column: 'createTime', order: 'desc' }, params);
- },
- },
- });
- //注册table数据
- const [registerTable, { reload, setLoading, setSelectedRowKeys }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;
- watch(
- selectedRowKeys,
- (oldKeys, newKeys) => {
- const index = findIndex(dataTableSource.value, (data: any) => {
- return data.deviceID == selectedRowKeys.value[0];
- });
- emits('selectRow', selectedRows.value[0], index);
- },
- { immediate: false }
- );
- defineExpose({
- doRequest,
- setSelectedRowKeys,
- });
- onMounted(() => {
- // 如果是https
- // 反之是websocket
- });
- onUnmounted(() => {});
- </script>
- <style scoped lang="less">
- :deep(.ant-table-body) {
- height: auto !important;
- }
- :deep(.jeecg-basic-table .ant-table-wrapper .ant-table-title) {
- min-height: 0;
- }
- .jeecg-basic-table-row__striped {
- background: #97efff11 !important;
- }
- </style>
|