Dashboard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div>
  3. <el-row :gutter="20">
  4. <el-col :span="8">
  5. <el-card shadow="hover" class="mgb20" style="height:252px;">
  6. <div class="user-info">
  7. <img src="../../assets/img/img.jpg" class="user-avator" alt="">
  8. <div class="user-info-cont">
  9. <div class="user-info-name">{{name}}</div>
  10. <div>{{role}}</div>
  11. </div>
  12. </div>
  13. <div class="user-info-list">上次登录时间:<span>2018-01-01</span></div>
  14. <div class="user-info-list">上次登录地点:<span>东莞</span></div>
  15. </el-card>
  16. <el-card shadow="hover" style="height:252px;">
  17. <div slot="header" class="clearfix">
  18. <span>语言详情</span>
  19. </div>
  20. Vue
  21. <el-progress :percentage="71.3" color="#42b983"></el-progress>
  22. JavaScript
  23. <el-progress :percentage="24.1" color="#f1e05a"></el-progress>
  24. CSS
  25. <el-progress :percentage="3.7"></el-progress>
  26. HTML
  27. <el-progress :percentage="0.9" color="#f56c6c"></el-progress>
  28. </el-card>
  29. </el-col>
  30. <el-col :span="16">
  31. <el-row :gutter="20" class="mgb20">
  32. <el-col :span="8">
  33. <el-card shadow="hover" :body-style="{padding: '0px'}">
  34. <div class="grid-content grid-con-1">
  35. <i class="el-icon-lx-people grid-con-icon"></i>
  36. <div class="grid-cont-right">
  37. <div class="grid-num">1234</div>
  38. <div>用户访问量</div>
  39. </div>
  40. </div>
  41. </el-card>
  42. </el-col>
  43. <el-col :span="8">
  44. <el-card shadow="hover" :body-style="{padding: '0px'}">
  45. <div class="grid-content grid-con-2">
  46. <i class="el-icon-lx-notice grid-con-icon"></i>
  47. <div class="grid-cont-right">
  48. <div class="grid-num">321</div>
  49. <div>系统消息</div>
  50. </div>
  51. </div>
  52. </el-card>
  53. </el-col>
  54. <el-col :span="8">
  55. <el-card shadow="hover" :body-style="{padding: '0px'}">
  56. <div class="grid-content grid-con-3">
  57. <i class="el-icon-lx-goods grid-con-icon"></i>
  58. <div class="grid-cont-right">
  59. <div class="grid-num">5000</div>
  60. <div>数量</div>
  61. </div>
  62. </div>
  63. </el-card>
  64. </el-col>
  65. </el-row>
  66. <el-card shadow="hover" style="height:403px;">
  67. <div slot="header" class="clearfix">
  68. <span>待办事项</span>
  69. <el-button style="float: right; padding: 3px 0" type="text">添加</el-button>
  70. </div>
  71. <el-table :data="todoList" :show-header="false" height="304" style="width: 100%;font-size:14px;">
  72. <el-table-column width="40">
  73. <template slot-scope="scope">
  74. <el-checkbox v-model="scope.row.status"></el-checkbox>
  75. </template>
  76. </el-table-column>
  77. <el-table-column>
  78. <template slot-scope="scope">
  79. <div class="todo-item" :class="{'todo-item-del': scope.row.status}">{{scope.row.title}}</div>
  80. </template>
  81. </el-table-column>
  82. <el-table-column width="60">
  83. <template slot-scope="scope">
  84. <i class="el-icon-edit"></i>
  85. <i class="el-icon-delete"></i>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. </el-card>
  90. </el-col>
  91. </el-row>
  92. <el-row :gutter="20">
  93. <el-col :span="12">
  94. <el-card shadow="hover">
  95. <schart ref="bar" class="schart" canvasId="bar" :data="data" type="bar" :options="options"></schart>
  96. </el-card>
  97. </el-col>
  98. <el-col :span="12">
  99. <el-card shadow="hover">
  100. <schart ref="line" class="schart" canvasId="line" :data="data" type="line" :options="options2"></schart>
  101. </el-card>
  102. </el-col>
  103. </el-row>
  104. </div>
  105. </template>
  106. <script>
  107. import Schart from 'vue-schart';
  108. import bus from '../common/bus';
  109. export default {
  110. name: 'dashboard',
  111. data() {
  112. return {
  113. name: localStorage.getItem('ms_username'),
  114. todoList: [{
  115. title: '今天要修复100个bug',
  116. status: false,
  117. },
  118. {
  119. title: '今天要修复100个bug',
  120. status: false,
  121. },
  122. {
  123. title: '今天要写100行代码加几个bug吧',
  124. status: false,
  125. }, {
  126. title: '今天要修复100个bug',
  127. status: false,
  128. },
  129. {
  130. title: '今天要修复100个bug',
  131. status: true,
  132. },
  133. {
  134. title: '今天要写100行代码加几个bug吧',
  135. status: true,
  136. }
  137. ],
  138. data: [{
  139. name: '2018/09/04',
  140. value: 1083
  141. },
  142. {
  143. name: '2018/09/05',
  144. value: 941
  145. },
  146. {
  147. name: '2018/09/06',
  148. value: 1139
  149. },
  150. {
  151. name: '2018/09/07',
  152. value: 816
  153. },
  154. {
  155. name: '2018/09/08',
  156. value: 327
  157. },
  158. {
  159. name: '2018/09/09',
  160. value: 228
  161. },
  162. {
  163. name: '2018/09/10',
  164. value: 1065
  165. }
  166. ],
  167. options: {
  168. title: '最近七天每天的用户访问量',
  169. showValue: false,
  170. fillColor: 'rgb(45, 140, 240)',
  171. bottomPadding: 30,
  172. topPadding: 30
  173. },
  174. options2: {
  175. title: '最近七天用户访问趋势',
  176. fillColor: '#FC6FA1',
  177. axisColor: '#008ACD',
  178. contentColor: '#EEEEEE',
  179. bgColor: '#F5F8FD',
  180. bottomPadding: 30,
  181. topPadding: 30
  182. }
  183. }
  184. },
  185. components: {
  186. Schart
  187. },
  188. computed: {
  189. role() {
  190. return this.name === 'admin' ? '超级管理员' : '普通用户';
  191. }
  192. },
  193. created(){
  194. this.handleListener();
  195. this.changeDate();
  196. },
  197. activated(){
  198. this.handleListener();
  199. },
  200. deactivated(){
  201. window.removeEventListener('resize', this.renderChart);
  202. bus.$off('collapse', this.handleBus);
  203. },
  204. methods: {
  205. changeDate(){
  206. const now = new Date().getTime();
  207. this.data.forEach((item, index) => {
  208. const date = new Date(now - (6 - index) * 86400000);
  209. item.name = `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}`
  210. })
  211. },
  212. handleListener(){
  213. bus.$on('collapse', this.handleBus);
  214. // 调用renderChart方法对图表进行重新渲染
  215. window.addEventListener('resize', this.renderChart)
  216. },
  217. handleBus(msg){
  218. setTimeout(() => {
  219. this.renderChart()
  220. }, 300);
  221. },
  222. renderChart(){
  223. this.$refs.bar.renderChart();
  224. this.$refs.line.renderChart();
  225. }
  226. }
  227. }
  228. </script>
  229. <style scoped>
  230. .el-row {
  231. margin-bottom: 20px;
  232. }
  233. .grid-content {
  234. display: flex;
  235. align-items: center;
  236. height: 100px;
  237. }
  238. .grid-cont-right {
  239. flex: 1;
  240. text-align: center;
  241. font-size: 14px;
  242. color: #999;
  243. }
  244. .grid-num {
  245. font-size: 30px;
  246. font-weight: bold;
  247. }
  248. .grid-con-icon {
  249. font-size: 50px;
  250. width: 100px;
  251. height: 100px;
  252. text-align: center;
  253. line-height: 100px;
  254. color: #fff;
  255. }
  256. .grid-con-1 .grid-con-icon {
  257. background: rgb(45, 140, 240);
  258. }
  259. .grid-con-1 .grid-num {
  260. color: rgb(45, 140, 240);
  261. }
  262. .grid-con-2 .grid-con-icon {
  263. background: rgb(100, 213, 114);
  264. }
  265. .grid-con-2 .grid-num {
  266. color: rgb(45, 140, 240);
  267. }
  268. .grid-con-3 .grid-con-icon {
  269. background: rgb(242, 94, 67);
  270. }
  271. .grid-con-3 .grid-num {
  272. color: rgb(242, 94, 67);
  273. }
  274. .user-info {
  275. display: flex;
  276. align-items: center;
  277. padding-bottom: 20px;
  278. border-bottom: 2px solid #ccc;
  279. margin-bottom: 20px;
  280. }
  281. .user-avator {
  282. width: 120px;
  283. height: 120px;
  284. border-radius: 50%;
  285. }
  286. .user-info-cont {
  287. padding-left: 50px;
  288. flex: 1;
  289. font-size: 14px;
  290. color: #999;
  291. }
  292. .user-info-cont div:first-child {
  293. font-size: 30px;
  294. color: #222;
  295. }
  296. .user-info-list {
  297. font-size: 14px;
  298. color: #999;
  299. line-height: 25px;
  300. }
  301. .user-info-list span {
  302. margin-left: 70px;
  303. }
  304. .mgb20 {
  305. margin-bottom: 20px;
  306. }
  307. .todo-item {
  308. font-size: 14px;
  309. }
  310. .todo-item-del {
  311. text-decoration: line-through;
  312. color: #999;
  313. }
  314. .schart {
  315. width: 100%;
  316. height: 300px;
  317. }
  318. </style>