refactor(credit): 移除后端标记字段并优化数据统计逻辑
- 删除了不再使用的 hasData 字段及其相关注释 - 移除了 normalizeHasData 工具函数 - 将总数统计逻辑改为基于后端返回的 count 字段或列表长度 - 更新了标签页数据检测逻辑为基于记录数判断 - 修正了标签页高亮显示的注释说明
This commit is contained in:
@@ -477,9 +477,7 @@
|
|||||||
'recommend',
|
'recommend',
|
||||||
'url',
|
'url',
|
||||||
'comments',
|
'comments',
|
||||||
'companyId',
|
'companyId'
|
||||||
// Backend flag; do not show in tables.
|
|
||||||
'hasData'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const commonTitleMap: Record<string, string> = {
|
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 = () => {
|
const syncTabsHasDataFromCounts = () => {
|
||||||
tabList.forEach((tab) => {
|
tabList.forEach((tab) => {
|
||||||
const field = tabCountFieldMap[tab.key];
|
const field = tabCountFieldMap[tab.key];
|
||||||
@@ -1604,8 +1588,9 @@
|
|||||||
|
|
||||||
const requestedPage = state.pagination.current;
|
const requestedPage = state.pagination.current;
|
||||||
let res = await fetchPage(requestedPage);
|
let res = await fetchPage(requestedPage);
|
||||||
const total = res?.count ?? 0;
|
|
||||||
let list = res?.list || [];
|
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) {
|
if (total > 0 && list.length === 0 && requestedPage > 1) {
|
||||||
setTabPagination(key, { current: 1 });
|
setTabPagination(key, { current: 1 });
|
||||||
@@ -1613,14 +1598,15 @@
|
|||||||
list = res?.list || [];
|
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.
|
// Keep the count field in sync (only when backend returns a count), so Tab highlight can update after import/refresh.
|
||||||
const countField = tabCountFieldMap[key];
|
const countField = tabCountFieldMap[key];
|
||||||
if (countField && typeof (res as any)?.count === 'number') {
|
if (countField && typeof (res as any)?.count === 'number') {
|
||||||
(form as any)[countField] = (res as any).count;
|
(form as any)[countField] = (res as any).count;
|
||||||
}
|
}
|
||||||
state.data = list;
|
state.data = list;
|
||||||
tabHasData[key] = normalizeHasData(res as any, list, state.pagination.total);
|
tabHasData[key] = (state.pagination.total ?? 0) > 0;
|
||||||
if (!state.columns.length) {
|
if (!state.columns.length) {
|
||||||
state.columns = buildColumns(key, state.data);
|
state.columns = buildColumns(key, state.data);
|
||||||
}
|
}
|
||||||
@@ -1686,7 +1672,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<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 {
|
.credit-company-tab-has-data {
|
||||||
color: #ff4d4f;
|
color: #ff4d4f;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|||||||
Reference in New Issue
Block a user