feat: homepage line chart display
This commit is contained in:
@@ -318,13 +318,16 @@ func GetBasicStatisticData() (BasicStatisticData, error) {
|
||||
}
|
||||
|
||||
// GetTrendStatisticData 获取趋势统计数据(使用 send_stats 表)
|
||||
func GetTrendStatisticData() (TrendStatisticData, error) {
|
||||
func GetTrendStatisticData(days int) (TrendStatisticData, error) {
|
||||
var statistic TrendStatisticData
|
||||
var latestData []LatestSendData
|
||||
statsTable := GetSchema(SendStats{})
|
||||
|
||||
// 最近30天数据
|
||||
days := 30
|
||||
// 默认30天,如果传入参数则使用参数值
|
||||
if days <= 0 {
|
||||
days = 30
|
||||
}
|
||||
|
||||
now := util.GetNowTime()
|
||||
past := now.AddDate(0, 0, -days)
|
||||
pastDate := past.Format("2006-01-02")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"message-nest/pkg/app"
|
||||
"message-nest/service/statistic_service"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetStatisticData 获取发送统计数据
|
||||
@@ -28,6 +29,15 @@ func GetStatisticData(c *gin.Context) {
|
||||
}
|
||||
appG.CResponse(http.StatusOK, "获取基础统计成功", data)
|
||||
case "trend":
|
||||
// 获取 days 参数,默认30天
|
||||
days := 30
|
||||
if daysParam := c.Query("days"); daysParam != "" {
|
||||
if d, err := strconv.Atoi(daysParam); err == nil && d > 0 {
|
||||
days = d
|
||||
}
|
||||
}
|
||||
|
||||
msgService.Days = days
|
||||
data, err := msgService.GetTrendStatisticData()
|
||||
if err != nil {
|
||||
appG.CResponse(http.StatusInternalServerError, fmt.Sprintf("获取趋势统计失败!原因:%s", err), nil)
|
||||
|
||||
@@ -20,7 +20,11 @@ func (sw *StatisticService) GetBasicStatisticData() (models.BasicStatisticData,
|
||||
|
||||
// GetTrendStatisticData 获取趋势统计数据
|
||||
func (sw *StatisticService) GetTrendStatisticData() (models.TrendStatisticData, error) {
|
||||
return models.GetTrendStatisticData()
|
||||
days := sw.Days
|
||||
if days <= 0 {
|
||||
days = 30 // 默认30天
|
||||
}
|
||||
return models.GetTrendStatisticData(days)
|
||||
}
|
||||
|
||||
// GetChannelStatisticData 获取渠道统计数据
|
||||
|
||||
@@ -63,7 +63,11 @@ const getBasicStatisticData = async () => {
|
||||
const getTrendStatisticData = async () => {
|
||||
state.loading.trend = true;
|
||||
try {
|
||||
const rsp = await request.get('/statistic?type=trend');
|
||||
// 根据屏幕大小决定请求的天数
|
||||
const isSmallScreen = window.innerWidth < 768;
|
||||
const days = isSmallScreen ? 15 : 30;
|
||||
|
||||
const rsp = await request.get(`/statistic?type=trend&days=${days}`);
|
||||
if (rsp && rsp.data && rsp.data.code == 200) {
|
||||
state.trendData = rsp.data.data;
|
||||
// 数据加载完成后重新渲染折线图
|
||||
@@ -112,6 +116,7 @@ const loadAllStatisticData = async () => {
|
||||
|
||||
const renderLineChart = () => {
|
||||
const latestSendData = state.trendData.latest_send_data || [];
|
||||
|
||||
const options = {
|
||||
series: [
|
||||
{
|
||||
@@ -321,8 +326,10 @@ const renderLineChart = () => {
|
||||
height: 300
|
||||
},
|
||||
legend: {
|
||||
position: 'bottom',
|
||||
offsetY: 0
|
||||
position: 'top',
|
||||
horizontalAlign: 'center',
|
||||
offsetY: 0,
|
||||
offsetX: 0
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
||||
Reference in New Issue
Block a user