2
0

Dashboard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div class="qcontent">
  3. <div class="qcontent-header hidden-xs">服务器概览 <button type="button" class="btn btn-xs btn-default full-btn" @click.prevent="fullscreen" title="点击大屏展示"><i class="fa fa-arrows-alt"></i></button></div>
  4. <div class="container-fluid" :style="`height:${this.pageHeight}px;min-height:500px;`">
  5. <div class="col-xs-12 col-md-6">
  6. <div class="view-dashboard view-left">
  7. <div class="panel">
  8. <div class="panel-body">
  9. <div class="col-md-12 panel-title">
  10. 通道信息
  11. </div>
  12. <div class="col-xs-6 auth-view" style="text-align:center;">
  13. <el-progress color="#337ab7" type="circle" :height="this.authViewHeight" :width="this.authViewHeight" :percentage="authData.DeviceTotal == 0 ? 0: parseFloat((authData.DeviceOnline/authData.DeviceTotal*100).toFixed(2))"></el-progress>
  14. <div class="auth-title">在线数:<span class="auth-num">{{authData.DeviceOnline}}</span><br>总设备:<span class="auth-num">{{authData.DeviceTotal}}</span></div>
  15. </div>
  16. <div class="col-xs-6 auth-view" style="text-align:center">
  17. <el-progress color="#337ab7" type="circle" :height="this.authViewHeight" :width="this.authViewHeight" :percentage="authData.ChannelTotal == 0 ? 0: parseFloat((authData.ChannelOnline/authData.ChannelTotal*100).toFixed(2))"></el-progress>
  18. <div class="auth-title">在线数:<span class="auth-num">{{authData.ChannelOnline}}</span><br>总通道:<span class="auth-num">{{authData.ChannelTotal}}</span></div>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="view-dashboard view-left view-split">
  24. <div class="panel">
  25. <div class="panel-body">
  26. <ve-bar ref="storeChart" height="100%" :colors="chartColors" :data="storeData" :settings="storeSettings" legend-position="bottom" :title="{text:'存储使用', left: 'center'}"></ve-bar>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="col-xs-12 col-md-6">
  32. <div class="view-dashboard view-right view-split-m">
  33. <div class="panel">
  34. <div class="panel-body">
  35. <ve-line ref="cpuChart" height="100%" :colors="chartColors" :data="cpuData" :settings="memSettings" :legend-visible="false" :title="{text:'CPU使用', left: 'center'}"></ve-line>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="view-dashboard view-right view-split">
  40. <div class="panel">
  41. <div class="panel-body">
  42. <ve-line ref="memChart" height="100%" :colors="chartColors" :data="memData" :settings="memSettings" :legend-visible="false" :title="{text:'内存使用', left: 'center'}"></ve-line>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import Vue from 'vue'
  52. import moment from "moment";
  53. import {
  54. mapState
  55. } from "vuex";
  56. import fullscreen from 'vue-fullscreen'
  57. Vue.use(fullscreen);
  58. export default {
  59. computed: {
  60. ...mapState(["serverInfo", "userInfo"])
  61. },
  62. components: {},
  63. data() {
  64. return {
  65. chartColors: ["#337ab7", "#7FFFD4"],
  66. pageWidth: 0,
  67. pageHeight: 0,
  68. protocol: location.protocol,
  69. authViewHeight: 80,
  70. timer: 0,
  71. vods: {},
  72. duration: 30,
  73. memData: {
  74. columns: ["time", "use"],
  75. rows: []
  76. },
  77. memSettings: {
  78. area: true,
  79. xAxisType: "time",
  80. yAxisType: ["percent"],
  81. min: [0],
  82. max: [1],
  83. labelMap: {
  84. use: '使用'
  85. },
  86. },
  87. cpuData: {
  88. columns: ["time", "use"],
  89. rows: []
  90. },
  91. vodData: {
  92. columns: ["type", "count"],
  93. rows: []
  94. },
  95. vodSettings: {
  96. label: {
  97. show: true,
  98. formatter: "{b}: {c}"
  99. },
  100. roseType: "area" //'radius'
  101. },
  102. storeData: {
  103. columns: ["Name", "Used", "FreeSpace"],
  104. rows: []
  105. },
  106. storeSettings: {
  107. dimension: ["Name"],
  108. metrics: ["Used", "FreeSpace"],
  109. stack: {
  110. store: ["Used", "FreeSpace"]
  111. },
  112. legendName: {
  113. Used: '已使用(G)',
  114. FreeSpace: '剩余(G)'
  115. },
  116. labelMap: {
  117. Used: '已使用(G)',
  118. FreeSpace: '剩余(G)'
  119. }
  120. },
  121. authData: {
  122. ChannelOnline: 0,
  123. ChannelTotal: 0,
  124. ChannelCount: 0,
  125. DeviceOnline: 0,
  126. DeviceTotal: 0,
  127. },
  128. bandwidthData: {
  129. columns: ["time", "use"],
  130. rows: []
  131. },
  132. bandwidthSettings: {
  133. area: true,
  134. xAxisType: "time",
  135. labelMap: {
  136. use: "使用(Mbps)"
  137. }
  138. }
  139. };
  140. },
  141. mounted() {
  142. this.top();
  143. this.timer1 = setInterval(() => {
  144. this.top();
  145. }, 2000);
  146. this.store();
  147. this.timer2 = setInterval(() => {
  148. this.store();
  149. }, 5000);
  150. this.timer3 = setTimeout(() => {
  151. this.resizeCharts();
  152. }, 1000);
  153. $(window).on('resize', this.resize);
  154. $(document).on('expanded.pushMenu', this.resizeCharts);
  155. $(document).on('collapsed.pushMenu', this.resizeCharts);
  156. this.fixAuthView();
  157. },
  158. created() {
  159. this.initHeight();
  160. },
  161. beforeDestroy() {
  162. if (this.timer1) {
  163. clearInterval(this.timer1);
  164. this.timer1 = 0;
  165. }
  166. if (this.timer2) {
  167. clearInterval(this.timer2);
  168. this.timer2 = 0;
  169. }
  170. if (this.timer3) {
  171. clearTimeout(this.timer3);
  172. this.timer3 = 0;
  173. }
  174. $(window).off('resize', this.resize);
  175. $(document).off('expanded.pushMenu', this.resizeCharts);
  176. $(document).off('collapsed.pushMenu', this.resizeCharts);
  177. },
  178. methods: {
  179. fullscreen() {
  180. this.$fullscreen.enter(this.$el.querySelector(".container-fluid"), {
  181. wrap: false,
  182. callback: () => {
  183. this.resize();
  184. this.resizeCharts();
  185. }
  186. })
  187. },
  188. top() {
  189. $.get("/api/v1/dashboard/top").then(result => {
  190. var data = result.data;
  191. this.memData.rows = data.memData;
  192. this.cpuData.rows = data.cpuData;
  193. });
  194. },
  195. store() {
  196. $.get("/api/v1/dashboard/store").then(result => {
  197. var data = result.data;
  198. this.storeData.rows = data;
  199. });
  200. $.get("/api/v1/dashboard/auth").then(result => {
  201. var data = result.data;
  202. this.authData = data;
  203. });
  204. },
  205. isIE() {
  206. if (!!window.ActiveXObject || "ActiveXObject" in window)
  207. return true;
  208. else
  209. return false;
  210. },
  211. initHeight() {
  212. this.pageWidth = window.innerWidth;
  213. this.pageHeight = window.innerHeight;
  214. if (typeof this.pageWidth != "number") {
  215. if (document.compatMode == "CSS1Compat") {
  216. this.pageWidth = document.documentElement.clientWidth;
  217. this.pageHeight = document.documentElement.clientHeight;
  218. } else {
  219. this.pageWidth = document.body.clientWidth;
  220. this.pageHeight = document.body.clientHeight;
  221. }
  222. }
  223. this.pageHeight = this.pageHeight - 140;
  224. },
  225. resizeCharts() {
  226. this.$refs["storeChart"].resize();
  227. this.$refs["cpuChart"].resize();
  228. this.$refs["memChart"].resize();
  229. },
  230. resize() {
  231. this.initHeight();
  232. this.fixAuthView();
  233. },
  234. fixAuthView() {
  235. if (this.pageHeight >= 600) {
  236. $(".auth-view").css("padding-top", `${this.pageHeight/10}px`);
  237. } else {
  238. $(".auth-view").css("padding-top", `20px`);
  239. }
  240. return
  241. }
  242. }
  243. };
  244. </script>
  245. <style lang="less" scoped>
  246. .qcontent .fullscreen {
  247. position: fixed;
  248. left: 0;
  249. top: 0;
  250. right: 0;
  251. bottom: 0;
  252. background-color: #ecf0f5;
  253. }
  254. .qcontent .full-btn {
  255. margin-left: 2px;
  256. margin-top: -3px;
  257. }
  258. .qcontent .col-md-6 {
  259. padding-left: 0px;
  260. padding-right: 0px;
  261. height: 100%;
  262. }
  263. .qcontent .panel {
  264. height: 100%;
  265. }
  266. .qcontent .panel-body {
  267. height: 100%;
  268. }
  269. .qcontent .panel-title {
  270. text-align: center;
  271. font-weight: bold;
  272. font-size: 18px;
  273. }
  274. .qcontent .container-fluid {
  275. padding-bottom: 20px;
  276. padding-left: 10px;
  277. padding-right: 10px;
  278. padding-top: 10px;
  279. }
  280. .qcontent {
  281. margin: -16px -15px;
  282. }
  283. .view-dashboard {
  284. height: 50%;
  285. }
  286. .view-left {
  287. margin-right: 5px;
  288. }
  289. .view-right {
  290. margin-left: 5px;
  291. }
  292. .view-split {
  293. margin-top: 10px;
  294. }
  295. .auth-vlive,
  296. .auth-live {
  297. margin-top: 6%;
  298. }
  299. .auth-num {
  300. margin-top: 20%;
  301. font-size: 14px;
  302. font-weight: bold;
  303. color: #337ab7;
  304. }
  305. .auth-view {
  306. min-height: 200px;
  307. padding-top: 78px;
  308. }
  309. .auth-title {
  310. font-size: 12px;
  311. color: #1d3b55;
  312. }
  313. .auth-promt-div {
  314. margin-top: 10%;
  315. }
  316. @screen-md-min: 992px;
  317. @media (max-width: @screen-md-min) {
  318. .col-md-6 {
  319. width: 100%;
  320. }
  321. .container-fluid {
  322. height: 100% !important;
  323. }
  324. .view-dashboard {
  325. height: 320px;
  326. }
  327. .view-left {
  328. margin-right: 0;
  329. }
  330. .view-right {
  331. margin-left: 0;
  332. }
  333. .view-split-m,
  334. .view-split {
  335. margin-top: 10px;
  336. }
  337. .auth-vlive,
  338. .auth-live {
  339. margin-top: 0%;
  340. }
  341. .auth-num {
  342. margin-top: 20%;
  343. font-size: 14px;
  344. font-weight: bold;
  345. color: #337ab7;
  346. }
  347. .auth-view {
  348. height: 200px !important;
  349. padding-top: 78px !important;
  350. }
  351. .qcontent .container-fluid {
  352. padding-bottom: 10px;
  353. }
  354. }
  355. </style>