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