From ba744d3d1d1e0fa913f0a4d0f1d0123d3186ef39 Mon Sep 17 00:00:00 2001 From: linyongLynn <15926056+linyonglynn@user.noreply.gitee.com> Date: Sun, 10 Aug 2025 11:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=A4=E4=BA=92=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/student/interaction_stats.vue | 149 +++++++++++++++++++----- 1 file changed, 123 insertions(+), 26 deletions(-) diff --git a/src/views/student/interaction_stats.vue b/src/views/student/interaction_stats.vue index 1930d8a..32e69be 100644 --- a/src/views/student/interaction_stats.vue +++ b/src/views/student/interaction_stats.vue @@ -94,40 +94,43 @@
- - - + + + @@ -135,7 +138,7 @@ @@ -195,9 +198,22 @@ export default { async fetchChartData() { try { this.loading = true + + // 根据timeRange计算开始和结束日期 + const endDate = new Date() + const startDate = new Date() + startDate.setDate(endDate.getDate() - this.filter.timeRange) + const params = { - timeRange: this.filter.timeRange, - supplyType: this.filter.supplyType || undefined + start_date: startDate.toISOString().split('T')[0], // YYYY-MM-DD格式 + end_date: endDate.toISOString().split('T')[0], // YYYY-MM-DD格式 + page_size: this.pageSize, + page: this.currentPage + } + + const type = this.getTypeValue(this.filter.supplyType) + if (type !== undefined) { + params.type = type } const response = await supplyDemandChart(params) @@ -211,8 +227,20 @@ export default { interactionChange: response.interaction_growth_rate?.rate || 0 } - // 更新总数 - this.totalCount = response.supply_demand_count || 0 + // 更新交互记录列表 + if (response.list && response.list.data) { + this.interactionList = response.list.data + } + console.log(this.interactionList) + // 更新分页数据 + if (response.list) { + this.totalCount = response.list.total || 0 + this.currentPage = response.list.current_page || 1 + this.pageSize = response.list.per_page || 10 + } else { + // 如果没有list结构,使用原有的总数 + this.totalCount = response.supply_demand_count || 0 + } } } catch (error) { console.error('获取图表数据失败:', error) @@ -249,14 +277,27 @@ export default { // 获取状态类型 getStatusType(status) { const statusMap = { - normal: 'success', - closed: 'info', - pending: 'warning', - rejected: 'danger' + 0: 'warning', // 待审核 + 1: 'success', // 通过 + 2: 'danger', // 拒绝 + 3: 'info', // 退回修改 + 4: 'info' // 永久隐藏 } return statusMap[status] || 'info' }, + // 获取状态文本 + getStatusText(status) { + const statusMap = { + 0: '待审核', + 1: '通过', + 2: '拒绝', + 3: '退回修改', + 4: '永久隐藏' + } + return statusMap[status] || '未知状态' + }, + // 获取变化样式类 getChangeClass(change) { if (change > 0) return 'change-up' @@ -276,6 +317,62 @@ export default { if (change > 0) return `+${change.toFixed(1)}%` if (change < 0) return `${change.toFixed(1)}%` return '0.0%' + }, + + // 获取类型值映射 + getTypeValue(supplyType) { + if (supplyType === 'supply') return 1 + if (supplyType === 'demand') return 2 + return undefined // 全部时不传type参数 + }, + + // 获取类型显示值 + getTypeDisplayValue(type) { + if (type === 'demand' || type === 2) return '需求' + if (type === 'supply' || type === 1) return '供应' + return '未知' + }, + + // 获取类型标签样式 + getTypeTagType(type) { + if (type === 'demand' || type === 2) return 'warning' + if (type === 'supply' || type === 1) return 'success' + return 'info' + }, + + // 格式化日期时间 + formatDateTime(dateTime) { + if (!dateTime) return '-' + + try { + // 如果是时间戳,转换为Date对象 + let date + if (typeof dateTime === 'number') { + date = new Date(dateTime * 1000) // 假设是秒级时间戳 + } else if (typeof dateTime === 'string') { + date = new Date(dateTime) + } else { + date = dateTime + } + + // 检查日期是否有效 + if (isNaN(date.getTime())) { + console.warn('Invalid date:', dateTime) + return '-' + } + + // 格式化日期 + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + const hours = String(date.getHours()).padStart(2, '0') + const minutes = String(date.getMinutes()).padStart(2, '0') + + return `${year}-${month}-${day} ${hours}:${minutes}` + } catch (error) { + console.error('格式化日期时间失败:', error, dateTime) + return '-' + } } },