Dashboard.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div class="dashboard-wrapper">
  3. <el-row :gutter="20" class="stat-row">
  4. <el-col :span="24">
  5. <el-card shadow="never" class="role-card">
  6. <div class="role-container">
  7. <span class="role-label"><i class="el-icon-medal"></i> 当前权限角色:</span>
  8. <el-tag
  9. v-for="(item, index) in roles"
  10. :key="index"
  11. effect="dark"
  12. size="medium"
  13. class="role-tag"
  14. @click="goToRole(item)"
  15. >
  16. {{ item }}
  17. </el-tag>
  18. </div>
  19. </el-card>
  20. </el-col>
  21. </el-row>
  22. <el-row :gutter="20" class="process-row">
  23. <el-col :span="24">
  24. <el-card shadow="hover">
  25. <div slot="header" class="card-header">
  26. <span><i class="el-icon-refresh"></i> CI/CD 流水线</span>
  27. </div>
  28. <div class="steps-wrapper">
  29. <el-steps :active="1" finish-status="success" align-center>
  30. <el-step title="更新代码" icon="el-icon-edit-outline" />
  31. <el-step title="编译代码" icon="el-icon-set-up" />
  32. <el-step title="应用打包" icon="el-icon-box" />
  33. <el-step title="推送应用" icon="el-icon-upload" />
  34. <el-step title="拉取应用" icon="el-icon-download" />
  35. <el-step title="部署应用" icon="el-icon-monitor" />
  36. </el-steps>
  37. </div>
  38. </el-card>
  39. </el-col>
  40. </el-row>
  41. <el-row :gutter="20">
  42. <el-col :md="12" :sm="24">
  43. <el-card shadow="hover" class="data-card">
  44. <div slot="header" class="card-header">
  45. <span><i class="el-icon-cpu"></i> 机器节点状态</span>
  46. </div>
  47. <el-table :data="machineStatList" border stripe size="small">
  48. <el-table-column prop="env" label="运行环境">
  49. <template slot-scope="scope">
  50. <el-tag size="mini" effect="plain">{{ scope.row.env }}</el-tag>
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="total" label="资产总数" align="center" />
  54. <el-table-column label="健康状况" align="center">
  55. <template slot-scope="scope">
  56. <div class="status-cell">
  57. <span class="status-dot online"></span>
  58. <span class="status-count">{{ scope.row.onlineCount }}</span>
  59. <span class="status-divider">/</span>
  60. <span class="status-dot offline"></span>
  61. <span class="status-count">{{ scope.row.offlineCount }}</span>
  62. </div>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. </el-card>
  67. </el-col>
  68. <el-col :md="12" :sm="24">
  69. <el-card shadow="hover" class="data-card">
  70. <div slot="header" class="card-header">
  71. <span><i class="el-icon-info"></i> 系统核心信息</span>
  72. </div>
  73. <el-descriptions v-if="sysInfo !== null" :column="1" border size="small">
  74. <el-descriptions-item label="应用版本">
  75. <el-link
  76. type="primary"
  77. target="_blank"
  78. :href="`https://git.reghao.cn/reghao/devops/commit/${sysInfo.commitId}`"
  79. icon="el-icon-link"
  80. >
  81. {{ sysInfo.commitId.substring(0, 8) }}
  82. </el-link>
  83. </el-descriptions-item>
  84. <el-descriptions-item label="机器地址">
  85. <code>{{ sysInfo.ipv4 }}</code>
  86. </el-descriptions-item>
  87. <el-descriptions-item label="操作系统">
  88. <i class="el-icon-monitor"></i> {{ sysInfo.osInfo }}
  89. </el-descriptions-item>
  90. <el-descriptions-item label="JVM 环境">
  91. <el-tooltip effect="dark" :content="sysInfo.jvmInfo" placement="top">
  92. <span class="text-truncate">{{ sysInfo.jvmInfo }}</span>
  93. </el-tooltip>
  94. </el-descriptions-item>
  95. <el-descriptions-item label="启动/PID">
  96. <el-tag size="mini" type="success">{{ sysInfo.startAt }}</el-tag>
  97. <el-tag size="mini" type="warning" style="margin-left:5px">PID: {{ sysInfo.pid }}</el-tag>
  98. </el-descriptions-item>
  99. </el-descriptions>
  100. </el-card>
  101. </el-col>
  102. </el-row>
  103. </div>
  104. </template>
  105. <script>
  106. import { getDashboard } from '@/api/devops'
  107. import { getAuthedUser } from '@/utils/auth'
  108. export default {
  109. name: 'Dashboard',
  110. data() {
  111. return {
  112. roles: [],
  113. machineStatList: [],
  114. sysInfo: null
  115. }
  116. },
  117. created() {
  118. const { roles } = getAuthedUser()
  119. this.roles = roles
  120. document.title = 'Dashboard'
  121. this.getData()
  122. },
  123. methods: {
  124. getData() {
  125. this.getDevopsDashboard()
  126. },
  127. getDevopsDashboard() {
  128. getDashboard().then(resp => {
  129. if (resp.code === 0) {
  130. this.sysInfo = resp.data.sysInfo
  131. this.machineStatList = resp.data.machineStatList
  132. } else {
  133. this.$message.error(resp.msg)
  134. }
  135. }).catch(error => {
  136. this.$message.error(error.message)
  137. })
  138. },
  139. goToRole(data) {
  140. this.$message.info('当前操作角色: ' + data)
  141. },
  142. // 其余逻辑保持不变...
  143. goToDisk() { const path = '/disk'; this.handleRoute(path) },
  144. goToVod() { const path = '/vod'; this.handleRoute(path) },
  145. goToBlog() { const path = '/blog'; this.handleRoute(path) },
  146. handleRoute(path) {
  147. if (this.$route.path === path) { this.$router.go(0); return }
  148. this.$router.push(path)
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. .dashboard-wrapper {
  155. padding: 10px;
  156. }
  157. .stat-row {
  158. margin-bottom: 20px;
  159. }
  160. .role-card {
  161. background: #fcfcfc;
  162. border-left: 4px solid #409EFF;
  163. }
  164. .role-container {
  165. display: flex;
  166. align-items: center;
  167. }
  168. .role-label {
  169. font-weight: bold;
  170. color: #606266;
  171. margin-right: 15px;
  172. }
  173. .role-tag {
  174. margin-right: 10px;
  175. cursor: pointer;
  176. transition: all 0.3s;
  177. }
  178. .role-tag:hover {
  179. opacity: 0.8;
  180. transform: translateY(-1px);
  181. }
  182. .card-header {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. font-weight: bold;
  187. }
  188. .process-row {
  189. margin-bottom: 20px;
  190. }
  191. .steps-wrapper {
  192. padding: 20px 0;
  193. }
  194. .data-card {
  195. min-height: 380px;
  196. }
  197. /* 状态点样式 */
  198. .status-cell {
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. }
  203. .status-dot {
  204. width: 8px;
  205. height: 8px;
  206. border-radius: 50%;
  207. margin: 0 5px;
  208. }
  209. .online {
  210. background-color: #67C23A;
  211. box-shadow: 0 0 5px #67C23A;
  212. }
  213. .offline {
  214. background-color: #F56C6C;
  215. box-shadow: 0 0 5px #F56C6C;
  216. }
  217. .status-count {
  218. font-weight: bold;
  219. }
  220. .status-divider {
  221. margin: 0 8px;
  222. color: #DCDFE6;
  223. }
  224. .text-truncate {
  225. display: inline-block;
  226. max-width: 250px;
  227. overflow: hidden;
  228. text-overflow: ellipsis;
  229. white-space: nowrap;
  230. vertical-align: middle;
  231. }
  232. code {
  233. background-color: #f5f7fa;
  234. padding: 2px 4px;
  235. border-radius: 4px;
  236. color: #e6a23c;
  237. font-family: monospace;
  238. }
  239. ::v-deep .el-descriptions-item__label {
  240. width: 120px;
  241. background-color: #fafafa !important;
  242. }
  243. </style>