diff --git a/pages/institutionalStructure/components/institutional-item.vue b/pages/institutionalStructure/components/institutional-item.vue index b71e748..655807f 100644 --- a/pages/institutionalStructure/components/institutional-item.vue +++ b/pages/institutionalStructure/components/institutional-item.vue @@ -2,8 +2,8 @@ - {{ item.topLeft || '暂无数据' }} - {{ item.topRight || '暂无数据' }} + {{ item.topLeft || "暂无数据" }} + {{ item.topRight || "暂无数据" }} @@ -15,154 +15,158 @@ 捐赠名单 - {{ item.year || '暂无数据' }} - {{ item.amount || '暂无数据' }} - {{ item.donorCount || '暂无数据' }} - 查看详情 + {{ item.year || "暂无数据" }} + {{ item.amount || "暂无数据" }} + {{ + item.donorCount || "持续招募中" + }} + 查看详情 diff --git a/pages/institutionalStructure/utils/data-formatter.js b/pages/institutionalStructure/utils/data-formatter.js index 88fa4d1..69e0b4e 100644 --- a/pages/institutionalStructure/utils/data-formatter.js +++ b/pages/institutionalStructure/utils/data-formatter.js @@ -8,15 +8,15 @@ export class InstitutionalDataFormatter { * @returns {string} 格式化后的金额字符串 */ static formatAmount(amount) { - if (!amount) return '不详' + if (!amount) return "不详"; // 超过一亿以亿为单位 if (amount >= 100000000) { - return `约${(amount / 100000000).toFixed(1)}亿` + return `约${(amount / 100000000).toFixed(1)}亿`; } else if (amount >= 10000) { - return `约${(amount / 10000).toFixed(1)}万` + return `约${(amount / 10000).toFixed(1)}万`; } else { - return `约${amount.toLocaleString()}元` + return `约${amount.toLocaleString()}元`; } } @@ -26,16 +26,16 @@ export class InstitutionalDataFormatter { * @param {string} currency 货币单位 * @returns {string} 格式化后的金额字符串 */ - static formatHistoricalAmount(amount, currency = '银元') { - if (!amount) return '不详' + static formatHistoricalAmount(amount, currency = "银元") { + if (!amount) return "不详"; // 超过一亿以亿为单位 if (amount >= 100000000) { - return `约${currency}${(amount / 100000000).toFixed(1)}亿` + return `约${currency}${(amount / 100000000).toFixed(1)}亿`; } else if (amount >= 10000) { - return `约${currency}${(amount / 10000).toFixed(0)}万` + return `约${currency}${(amount / 10000).toFixed(0)}万`; } else { - return `约${currency}${amount.toLocaleString()}` + return `约${currency}${amount.toLocaleString()}`; } } @@ -46,8 +46,8 @@ export class InstitutionalDataFormatter { */ static formatTopLeft(projectName) { // 如果年份和项目名称都为空,返回暂无数据 - if (!projectName) return '暂无数据' - return projectName + if (!projectName) return "暂无数据"; + return projectName; } /** @@ -57,15 +57,15 @@ export class InstitutionalDataFormatter { * @returns {string} 格式化后的项目名称 */ static formatProjectName(projectName, isHistorical = false) { - if (!projectName) return '暂无数据' + if (!projectName) return "暂无数据"; // 如果是历史项目,可能需要特殊处理 - if (isHistorical && projectName.includes('寺')) { + if (isHistorical && projectName.includes("寺")) { // 对于寺庙项目,保持原有格式 - return projectName + return projectName; } - return projectName + return projectName; } /** @@ -74,14 +74,14 @@ export class InstitutionalDataFormatter { * @returns {string} 格式化后的年份 */ static formatYear(year) { - if (!year) return '暂无数据' + if (!year) return "暂无数据"; // 如果已经是格式化过的字符串(包含"年"字),直接返回 - if (typeof year === 'string' && year.includes('年')) { - return year + if (typeof year === "string" && year.includes("年")) { + return year; } - return `${year}年` + return `${year}年`; } /** @@ -90,30 +90,30 @@ export class InstitutionalDataFormatter { * @returns {string} 格式化后的年份 */ static formatHistoricalYear(year) { - if (!year) return '暂无数据' + if (!year) return "暂无数据"; // 如果已经是格式化过的字符串,直接返回 - if (typeof year === 'string') { - if (year.includes('年')) { - return year + if (typeof year === "string") { + if (year.includes("年")) { + return year; } - if (year.includes('时期') || year.includes('朝代')) { - return year + if (year.includes("时期") || year.includes("朝代")) { + return year; } } // 如果是公元前的年份 if (year < 0) { - return `公元前${Math.abs(year)}年` + return `公元前${Math.abs(year)}年`; } // 如果是公元后的年份,但小于1000年 if (year < 1000) { - return `${year}年` + return `${year}年`; } // 正常年份 - return `${year}年` + return `${year}年`; } /** @@ -123,16 +123,16 @@ export class InstitutionalDataFormatter { */ static getStatusText(state) { switch (state) { - case '1': - return '规划' - case '2': - return '进行中' - case '3': - return '已完成' - case '4': - return '已取消' + case "1": + return "规划"; + case "2": + return "进行中"; + case "3": + return "已完成"; + case "4": + return "已取消"; default: - return '未知状态' + return "未知状态"; } } @@ -142,31 +142,35 @@ export class InstitutionalDataFormatter { * @returns {boolean} 是否为历史项目 */ static isHistoricalProject(year) { - if (!year) return false + if (!year) return false; // 处理字符串格式的年份(如"916年"、"明末时期") - if (typeof year === 'string') { + if (typeof year === "string") { // 如果包含"年"字,提取数字部分 - if (year.includes('年')) { - const yearNum = parseInt(year.replace('年', '')) - return yearNum < 1900 + if (year.includes("年")) { + const yearNum = parseInt(year.replace("年", "")); + return yearNum < 1900; } // 如果包含历史时期描述,认为是历史项目 - if (year.includes('时期') || year.includes('朝代') || year.includes('古代')) { - return true + if ( + year.includes("时期") || + year.includes("朝代") || + year.includes("古代") + ) { + return true; } // 尝试解析纯数字 - const yearNum = parseInt(year) + const yearNum = parseInt(year); if (!isNaN(yearNum)) { - return yearNum < 1900 + return yearNum < 1900; } } // 处理数字格式的年份 - const yearNum = parseInt(year) - return yearNum < 1900 + const yearNum = parseInt(year); + return yearNum < 1900; } /** @@ -176,12 +180,12 @@ export class InstitutionalDataFormatter { * @returns {string} 格式化后的人数 */ static formatDonorCount(count, isHistorical = false) { - if (!count || count === 0) return '暂无数据' + if (!count || count === 0) return "持续招募中"; if (isHistorical) { - return `约${count}人` + return `约${count}人`; } else { - return `${count}人` + return `${count}人`; } } @@ -191,36 +195,45 @@ export class InstitutionalDataFormatter { * @returns {Array} 转换后的数据 */ static transformData(rows) { - console.log('原始数据:', rows) // 添加调试日志 + console.log("原始数据:", rows); // 添加调试日志 - return rows.map(item => { - console.log('处理项目:', item) // 添加调试日志 + return rows.map((item) => { + console.log("处理项目:", item); // 添加调试日志 - const year = item.formedYear || item.startYear || item.start_year || item.year - const isHistorical = InstitutionalDataFormatter.isHistoricalProject(year) + const year = + item.formedYear || item.startYear || item.start_year || item.year; + const isHistorical = InstitutionalDataFormatter.isHistoricalProject(year); - const projectName = item.proName || item.pro_name || item.projectName + const projectName = item.proName || item.pro_name || item.projectName; return { topLeft: InstitutionalDataFormatter.formatTopLeft( - InstitutionalDataFormatter.formatProjectName(projectName, isHistorical) + InstitutionalDataFormatter.formatProjectName( + projectName, + isHistorical, + ), ), topRight: InstitutionalDataFormatter.getStatusText(item.state), year: isHistorical ? InstitutionalDataFormatter.formatHistoricalYear(year) : InstitutionalDataFormatter.formatYear(year), amount: isHistorical - ? InstitutionalDataFormatter.formatHistoricalAmount(item.totalAmount || item.total_amount) - : InstitutionalDataFormatter.formatAmount(item.totalAmount || item.total_amount), + ? // ? InstitutionalDataFormatter.formatHistoricalAmount( + InstitutionalDataFormatter.formatAmount( + item.totalAmount || item.total_amount, + ) + : InstitutionalDataFormatter.formatAmount( + item.totalAmount || item.total_amount, + ), donorCount: InstitutionalDataFormatter.formatDonorCount( item.donorCount || item.donor_count || 0, - isHistorical + isHistorical, ), // 保存原始数据,用于跳转 formedId: item.id, // 保存项目类型信息 isHistorical: isHistorical, - } - }) + }; + }); } }