From e89e7ea755316b38fc9c7705764bed10bc1d3c8d Mon Sep 17 00:00:00 2001 From: marvzhang Date: Sun, 22 Mar 2020 09:25:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=BB=E9=A1=B5=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/model/project.go | 13 +++ backend/routes/stats.go | 9 ++ frontend/src/i18n/zh.js | 1 + frontend/src/views/home/Home.vue | 138 ++++++++++++++++++++----------- 4 files changed, 112 insertions(+), 49 deletions(-) diff --git a/backend/model/project.go b/backend/model/project.go index 09f52f41..2889d6aa 100644 --- a/backend/model/project.go +++ b/backend/model/project.go @@ -152,3 +152,16 @@ func RemoveProject(id bson.ObjectId) error { return nil } + +func GetProjectCount(filter interface{}) (int, error) { + s, c := database.GetCol("projects") + defer s.Close() + + count, err := c.Find(filter).Count() + if err != nil { + return 0, err + } + + return count, nil +} + diff --git a/backend/routes/stats.go b/backend/routes/stats.go index 497083e5..46c1afc8 100644 --- a/backend/routes/stats.go +++ b/backend/routes/stats.go @@ -15,6 +15,7 @@ func GetHomeStats(c *gin.Context) { SpiderCount int `json:"spider_count"` ActiveNodeCount int `json:"active_node_count"` ScheduleCount int `json:"schedule_count"` + ProjectCount int `json:"project_count"` } type Data struct { @@ -50,6 +51,13 @@ func GetHomeStats(c *gin.Context) { return } + // 项目数 + projectCount, err := model.GetProjectCount(bson.M{"user_id": services.GetCurrentUserId(c)}) + if err != nil { + HandleError(http.StatusInternalServerError, c, err) + return + } + // 每日任务数 items, err := model.GetDailyTaskStats(bson.M{"user_id": services.GetCurrentUserId(c)}) if err != nil { @@ -66,6 +74,7 @@ func GetHomeStats(c *gin.Context) { TaskCount: taskCount, SpiderCount: spiderCount, ScheduleCount: scheduleCount, + ProjectCount: projectCount, }, Daily: items, }, diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 725a48d1..2a95dea1 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -274,6 +274,7 @@ export default { // 项目 'All Tags': '全部标签', + 'Projects': '项目', 'Project Name': '项目名称', 'Project Description': '项目描述', 'Tags': '标签', diff --git a/frontend/src/views/home/Home.vue b/frontend/src/views/home/Home.vue index ebfb7563..9eb4932a 100644 --- a/frontend/src/views/home/Home.vue +++ b/frontend/src/views/home/Home.vue @@ -3,20 +3,33 @@ @@ -41,10 +54,11 @@ export default { overviewStats: {}, dailyTasks: [], metrics: [ - { name: 'task_count', label: 'Total Tasks', icon: ['fa', 'play'], color: '#f56c6c', path: 'tasks' }, - { name: 'spider_count', label: 'Spiders', icon: ['fa', 'bug'], color: '#67c23a', path: 'spiders' }, - { name: 'active_node_count', label: 'Active Nodes', icon: ['fa', 'server'], color: '#409EFF', path: 'nodes' }, - { name: 'schedule_count', label: 'Schedules', icon: ['fa', 'clock'], color: '#409EFF', path: 'schedules' } + { name: 'task_count', label: 'Total Tasks', icon: 'fa fa-check', color: 'blue', path: 'tasks' }, + { name: 'spider_count', label: 'Spiders', icon: 'fa fa-bug', color: 'green', path: 'spiders' }, + { name: 'active_node_count', label: 'Active Nodes', icon: 'fa fa-server', color: 'red', path: 'nodes' }, + { name: 'schedule_count', label: 'Schedules', icon: 'fa fa-clock-o', color: 'orange', path: 'schedules' }, + { name: 'project_count', label: 'Projects', icon: 'fa fa-code-fork', color: 'grey', path: 'projects' } ] } }, @@ -105,45 +119,71 @@ export default { margin-right: 0; } - .metric-item { - flex-basis: 25%; + .metric-item:hover { + transform: scale(1.05); + transition: transform 0.5s ease; + } - .metric-card:hover { + .metric-item { + flex-basis: 20%; + height: 64px; + display: flex; + color: white; + cursor: pointer; + + .metric-icon { + display: inline-flex; + width: 64px; + align-items: center; + justify-content: center; + border-top-left-radius: 5px; + border-bottom-left-radius: 5px; + font-size: 24px; + + svg { + width: 24px; + } } - .metric-card { - margin-right: 30px; - cursor: pointer; + .metric-content { + display: flex; + width: calc(100% - 80px); + align-items: center; + opacity: 0.85; + font-size: 14px; + padding-left: 15px; + border-top-right-radius: 5px; + border-bottom-right-radius: 5px; - .icon-col { - text-align: right; - - i { - margin-bottom: 15px; - font-size: 56px; - } + .metric-number { + font-weight: bolder; + margin-bottom: 5px; } + } - .text-col { - padding-left: 20px; - height: 76px; - text-align: center; + .metric-icon.blue, + .metric-content.blue { + background: #409eff; + } - .label { - cursor: pointer; - font-size: 16px; - display: block; - height: 24px; - color: grey; - font-weight: 900; - } + .metric-icon.green, + .metric-content.green { + background: #67c23a; + } - .value { - font-size: 24px; - display: block; - height: 32px; - } - } + .metric-icon.red, + .metric-content.red { + background: #f56c6c; + } + + .metric-icon.orange, + .metric-content.orange { + background: #E6A23C; + } + + .metric-icon.grey, + .metric-content.grey { + background: #97a8be; } } }