栖息地本地接口对接,加BasicTable组件增加超出隐藏和文字提示,如果有空数据就显示-,添加排序功能。

This commit is contained in:
王兴凯 2026-06-04 11:43:16 +08:00
commit a8456cea47
5 changed files with 161 additions and 64 deletions

View File

@ -2,7 +2,7 @@ import request from '@/utils/request';
//栖息地保护工作开展情况
export function fhGetKendoListCust(data: any) {
return request({
url: '/api/wmp-env-server/env/fh/GetKendoListCust',
url: '/fh/GetKendoListCust',
method: 'post',
data
});
@ -10,7 +10,7 @@ export function fhGetKendoListCust(data: any) {
//获取所属栖息地
export function msstbprptGetKendoList(data: any) {
return request({
url: '/api/dec-lygk-base-server/base/msstbprpt/GetKendoList',
url: '/fh/msstbprpt/GetKendoList',
method: 'post',
data
});
@ -18,7 +18,7 @@ export function msstbprptGetKendoList(data: any) {
//水温监测数据
export function sdrvwtsGetKendoList(data: any) {
return request({
url: '/api/wmp-env-server/base/sdrvwts/GetKendoList',
url: '/fh/sdrvwts/GetKendoList',
method: 'post',
data
});
@ -26,7 +26,7 @@ export function sdrvwtsGetKendoList(data: any) {
//水文监测
export function sdriverdaysGetKendoList(data: any) {
return request({
url: '/api/wmp-swqx-server/zq/sdriverdays/GetKendoList',
url: '/fh/zq/sdriverdays/GetKendoList',
method: 'post',
data
});
@ -34,7 +34,7 @@ export function sdriverdaysGetKendoList(data: any) {
//主要栖息地基本信息
export function fhGetKendoListCustom(data: any) {
return request({
url: '/api/wmp-env-server/env/fh/GetKendoListCustom',
url: '/fh/GetKendoListCustom',
method: 'post',
data
});

View File

@ -1,16 +1,8 @@
<template>
<div class="table-container" ref="tableContainerRef">
<a-table
size="small"
:loading="loading"
:row-selection="enableRowSelection ? rowSelection : undefined"
:data-source="tableData"
:columns="columns"
:pagination="paginationConfig"
:scroll="scrollConfig"
:row-key="rowKey"
@change="handleTableChange"
>
<a-table size="small" :loading="loading" :row-selection="enableRowSelection ? rowSelection : undefined"
:data-source="tableData" :columns="enhancedColumns" :pagination="paginationConfig" :scroll="scrollConfig"
:row-key="rowKey" @change="handleTableChange">
<!-- 透传插槽支持自定义列内容 -->
<template v-for="slot in Object.keys($slots)" #[slot]="scope" :key="slot">
<slot :name="slot" v-bind="scope"></slot>
@ -20,7 +12,8 @@
</template>
<script setup lang="ts">
import { ref, computed, onMounted, watch, nextTick } from "vue";
import { ref, computed, onMounted, watch, nextTick, h } from "vue";
import { Tooltip } from "ant-design-vue";
import { calcTableScrollY } from "@/utils/index";
// --- Types ---
@ -36,6 +29,10 @@ interface Props {
isPage?: boolean;
getCheckboxProps?: (record: any) => any;
transformData?: (res: any) => { records: any[]; total: number };
emptyPlaceholder?: string; //
processEmptyValues?: boolean; //
enableEllipsis?: boolean; //
enableSort?: boolean; //
}
const props = withDefaults(defineProps<Props>(), {
@ -48,11 +45,16 @@ const props = withDefaults(defineProps<Props>(), {
getCheckboxProps: undefined,
transformData: undefined,
scrollY: undefined,
emptyPlaceholder: "-",
processEmptyValues: true, //
enableEllipsis: true, //
enableSort: false, //
});
const emit = defineEmits<{
(e: "data-loaded", params: any, data: any): void;
(e: "selection-change", selectedRowKeys: string[], selectedRows: any[]): void;
(e: "sort-change", sortInfo: { field: string; order: 'ascend' | 'descend' | null }): void;
}>();
// --- State ---
@ -147,7 +149,7 @@ const getList = async (filter?: Record<string, any>) => {
finalTotal = res.data?.data?.total || res?.data?.total || res?.total || 0;
}
tableData.value = finalRecords;
tableData.value = processData(finalRecords);
total.value = finalTotal;
emit("data-loaded", params, { records: finalRecords, total: finalTotal });
} catch (error) {
@ -159,10 +161,19 @@ const getList = async (filter?: Record<string, any>) => {
}
};
const handleTableChange = (pag: any) => {
const handleTableChange = (pag: any, filters: any, sorter: any) => {
page.value = pag.current;
size.value = pag.pageSize;
if (props.enableSort) {
if (sorter && sorter.field) {
emit("sort-change", { field: sorter.field, order: sorter.order });
} else {
emit("sort-change", { field: '', order: null });
}
}else {
getList();
}
};
const reset = () => {
@ -197,6 +208,52 @@ defineExpose({
const observer = new ResizeObserver(() => {
tableScrollY.value = calcTableScrollY(tableContainerRef.value);
});
// --- ---
const processData = (records: any[]) => {
if (!props.processEmptyValues || !Array.isArray(records)) return records;
return records.map(record => {
const processedRecord: any = { ...record };
for (const key in processedRecord) {
if (Object.prototype.hasOwnProperty.call(processedRecord, key)) {
const val = processedRecord[key];
if (val === null || val === undefined || val === "") {
processedRecord[key] = props.emptyPlaceholder;
}
}
}
return processedRecord;
});
};
// --- + Tooltip---
const enhancedColumns = computed(() => {
if (!props.enableEllipsis) return props.columns;
return props.columns.map(col => {
if (col.customRender) {
return col; //
}
return {
...col,
ellipsis: true, // Ant Design Vue ellipsis
customRender: ({ text }: any) => {
const content = String(text ?? props.emptyPlaceholder);
return h(
Tooltip,
{ title: content },
() => h('div', {
class: 'table-cell-ellipsis',
style: { overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }
}, content)
);
},
};
});
});
onMounted(() => {
nextTick(() => {
tableScrollY.value = calcTableScrollY(tableContainerRef.value);
@ -205,7 +262,7 @@ onMounted(() => {
}
});
if (props.data && props.data.length > 0) {
tableData.value = props.data || [];
tableData.value = processData(props.data);
}
});
</script>

View File

@ -11,7 +11,7 @@
<a-select v-model:value="searchData.baseId" placeholder="请选择所属基地" style="width: 200px" show-search
:filter-option="filterOption" :options="jiDiList" @change="handleHydropowerStationChange" />
<div>所属栖息地:</div>
<a-select v-model:value="searchData.fhstcd" placeholder=" " style="width: 200px" allow-clear show-search
<a-select v-model:value="searchData.fhstcd" placeholder=" " style="width: 200px" show-search
:filter-option="filterOption" :options="stationOptions" />
<a-input v-model:value="searchData.stnm" placeholder="请输入电站或设施名称" style="width: 200px" allow-clear />
@ -22,8 +22,8 @@
</a-space>
</div>
<!-- 列表 -->
<BasicTable ref="tableRef" :scrollY="360" :columns="columns" :list-url="fhGetKendoListCust"
:search-params="{ sort: sortConfig }" :transform-data="customTransform">
<BasicTable ref="tableRef" :scrollY="360" :columns="columns" :list-url="fhGetKendoListCust" :enable-sort="true" @sort-change="handleSortChange"
:search-params="searchParams" :transform-data="customTransform">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'ennm'">
<a @click="handleViewDetail(record, 'dz')" class="text-link">
@ -44,7 +44,7 @@
</template>
<script lang="ts" setup>
import { ref, computed, watch, onMounted } from 'vue'
import { ref, computed, watch, onMounted,nextTick } from 'vue'
import { msstbprptGetKendoList, fhGetKendoListCust } from '@/api/qxd'
import BasicTable from '@/components/BasicTable/index.vue'
import { useModelStore } from "@/store/modules/model";
@ -67,6 +67,7 @@ const searchData = ref<any>({
const modelStore = useModelStore();
const tableRef = ref()
const stationOptions: any = ref([])
// ==================== () ====================
const jiDiList: any = ref([
{
@ -151,67 +152,78 @@ const columns = [
key: 'stnm',
title: '设施名称',
dataIndex: 'stnm',
width: '176px'
width: '176px',
sorter: true,
},
{
key: 'baseName',
title: '所在基地',
dataIndex: 'baseName',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'ennm',
title: '所属电站',
dataIndex: 'ennm',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'fhstnm',
title: '所属栖息地',
dataIndex: 'fhstnm',
width: '176px'
width: '176px',
sorter: true,
},
{
key: 'ststdt',
title: '开工日期',
dataIndex: 'ststdt',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'esstdt',
title: '建成日期',
dataIndex: 'esstdt',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'mway',
title: '监测方式',
dataIndex: 'mway',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'vlsr',
title: '数据接入来源',
dataIndex: 'vlsr',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'hydrodtin_type',
title: '数据接入类型',
dataIndex: 'hydrodtinType',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'enable',
title: '是否启用',
dataIndex: 'enable',
width: '150px'
width: '150px',
sorter: true,
},
{
key: 'dtin',
title: '是否接入',
dataIndex: 'dtin',
width: '150px'
width: '150px',
sorter: true,
},
{
title: '操作',
@ -221,9 +233,29 @@ const columns = [
fixed: 'right' as const
}
];
//
const sortConfig = computed(() => [
{
// 1.
const sortState = ref<{ field: string; order: string } | null>(null);
// 2.
const handleSortChange = (info: { field: string; order: string | null }) => {
if (info.field) {
sortState.value = info;
} else {
sortState.value = null; //
}
nextTick(() => {
handleSearch()
});
}
const searchParams = computed(() => {
const params: any = { group: [],groupResultFlat: false,select:[] };
if (sortState.value) {
// [{ field: 'name', dir: 'asc' }]
params.sort = [{
field: sortState.value.field,
dir: sortState.value.order === 'ascend' ? 'asc' : 'desc'
}];
}else{
params.sort = [{
"field": "baseStepSort",
"dir": "asc"
},
@ -234,8 +266,11 @@ const sortConfig = computed(() => [
{
"field": "rstcdStepSort",
"dir": "asc"
}]
}
])
return params;
});
const handleTabChange = (key: string) => {
console.log('【Tab切换】', key)
tabIndex.value = key
@ -299,7 +334,7 @@ const handleSearch = () => {
searchData.value.baseId != 'all' ? {
"field": "baseId",
"operator": "eq",
"value": "01"
"value": searchData.value.baseId
} : null,
searchData.value.fhstcd != 'all' ? {
"field": "fhstcd",
@ -353,8 +388,6 @@ const customTransform = (res: any) => {
}
//
const handleViewDetail = (record: any, type: any) => {
console.log(tabIndex.value)
debugger
if (type == 'dz') {
modelStore.modalVisible = true;
modelStore.params.sttp = "ENG";
@ -379,10 +412,11 @@ const handleViewDetail = (record: any, type: any) => {
modelStore.title = record.stnm + " 详情信息";
modelStore.params.stcd = record.stcd;
} else if (tabIndex.value == 'VD') {
// modelStore.modalVisible = true;
// modelStore.params.sttp = "fh_zq_point";
// modelStore.title = record.stnm + " ";
// modelStore.params.stcd = record.stcd;
modelStore.modalVisible = true;
modelStore.params.sttp = "stinfo_ai_video_point";
modelStore.title = "视频监控站详情信息";
modelStore.isBasicEdit = true;
modelStore.params.stcd = record.stcd;
}
}

View File

@ -572,8 +572,7 @@ const getselsectData = async () => {
}
let res = await msstbprptGetKendoList(params)
console.log(res)
if (!res?.data?.data) {
if (!res?.data?.data || res.data.data.length == 0) {
select.value.value = ''
select.value.options = []
return

View File

@ -384,17 +384,24 @@ const getChartData = async (startDate: string, endDate: string, stcd: string) =>
"value": endDate // : "2026-06-30 23:59:59"
},
{
"field": "STCD",
"field": "stcd",
"operator": "eq",
"dataType": "string",
"value": stcd
}
]
},
"sort": [
{
"field": "dt",
"dir": "asc"
}
]
};
// API
const res = await sdrvwtsGetKendoList(params);
debugger
console.log('API返回结果:', res);
let data = res?.data?.data || [];
@ -577,12 +584,12 @@ const getselsectData = async () => {
}
let res = await msstbprptGetKendoList(params)
console.log(res)
if (!res?.data?.data) {
if (!res?.data?.data || res.data.data.length == 0) {
select.value.value = ''
select.value.options = []
return
}
select.value.value = res.data.data[0].stcd
select.value.options = res.data.data.map((item: any) => {
return {