refactor(credit): 移除后端标记字段并优化数据统计逻辑

- 删除了不再使用的 hasData 字段及其相关注释
- 移除了 normalizeHasData 工具函数
- 将总数统计逻辑改为基于后端返回的 count 字段或列表长度
- 更新了标签页数据检测逻辑为基于记录数判断
- 修正了标签页高亮显示的注释说明
This commit is contained in:
2026-01-28 23:53:10 +08:00
parent f78aa97bd1
commit c5908f4376

View File

@@ -477,9 +477,7 @@
'recommend',
'url',
'comments',
'companyId',
// Backend flag; do not show in tables.
'hasData'
'companyId'
]);
const commonTitleMap: Record<string, string> = {
@@ -1541,20 +1539,6 @@
});
};
const normalizeHasData = (
res: any,
list: Record<string, any>[],
total: number
) => {
const hasDataRaw =
res?.hasData ?? (list.length ? (list[0] as any)?.hasData : undefined);
return (
Number(hasDataRaw) === 1 ||
list.some((row) => Number((row as any)?.hasData) === 1) ||
(total ?? 0) > 0
);
};
const syncTabsHasDataFromCounts = () => {
tabList.forEach((tab) => {
const field = tabCountFieldMap[tab.key];
@@ -1604,8 +1588,9 @@
const requestedPage = state.pagination.current;
let res = await fetchPage(requestedPage);
const total = res?.count ?? 0;
let list = res?.list || [];
const total =
typeof (res as any)?.count === 'number' ? (res as any).count : list.length;
if (total > 0 && list.length === 0 && requestedPage > 1) {
setTabPagination(key, { current: 1 });
@@ -1613,14 +1598,15 @@
list = res?.list || [];
}
state.pagination.total = res?.count ?? 0;
state.pagination.total =
typeof (res as any)?.count === 'number' ? (res as any).count : list.length;
// Keep the count field in sync (only when backend returns a count), so Tab highlight can update after import/refresh.
const countField = tabCountFieldMap[key];
if (countField && typeof (res as any)?.count === 'number') {
(form as any)[countField] = (res as any).count;
}
state.data = list;
tabHasData[key] = normalizeHasData(res as any, list, state.pagination.total);
tabHasData[key] = (state.pagination.total ?? 0) > 0;
if (!state.columns.length) {
state.columns = buildColumns(key, state.data);
}
@@ -1686,7 +1672,7 @@
</script>
<style scoped>
/* Tab label highlight when the backend marks this module as having data. */
/* Tab label highlight when the module record-count field is > 0. */
.credit-company-tab-has-data {
color: #ff4d4f;
font-weight: 600;