index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <div>
  3. <div class="fnBox statisticsBox">
  4. <h3>统计</h3>
  5. <el-card class="statisticsItem" @click.native="jump('SysUser')">
  6. <div class="l">
  7. <img src="@/assets/dash/xyzs.png" />
  8. </div>
  9. <div class="r">
  10. <span class="statisticsTitle">学员总数</span>
  11. <span class="statisticsNum">{{ usernum }}</span>
  12. </div>
  13. </el-card>
  14. <el-card class="statisticsItem" @click.native="jump('ExamTmpl')">
  15. <div class="l">
  16. <img src="@/assets/dash/sjzs.png" />
  17. </div>
  18. <div class="r">
  19. <span class="statisticsTitle">试卷总数</span>
  20. <span class="statisticsNum">{{ tmplnum }}</span>
  21. </div>
  22. </el-card>
  23. <el-card class="statisticsItem" @click.native="jump('QuList')">
  24. <div class="l">
  25. <img src="@/assets/dash/stzs.png" />
  26. </div>
  27. <div class="r">
  28. <span class="statisticsTitle">试题总数</span>
  29. <span class="statisticsNum">{{ titlenum }}</span>
  30. </div>
  31. </el-card>
  32. <el-card class="statisticsItem" @click.native="jump('ListCourse')">
  33. <div class="l">
  34. <img src="@/assets/dash/stzs.png" />
  35. </div>
  36. <div class="r">
  37. <span class="statisticsTitle">课程总数</span>
  38. <span class="statisticsNum">{{ coursenum }}</span>
  39. </div>
  40. </el-card>
  41. </div>
  42. <div class="fnBox contentBox">
  43. <div class="contentItem">
  44. <h3>快捷入口</h3>
  45. <div class="quickBox">
  46. <el-scrollbar style="width: 100%; height: 100%">
  47. <el-card
  48. class="quickItem"
  49. @click.native="jump('AddExam', { tmplId: '0' })"
  50. >
  51. <div class="l">
  52. <img src="@/assets/dash/a1.png" />
  53. </div>
  54. <div class="r">
  55. <span class="quickItemTitle">创建考试</span>
  56. <span class="quickItemDesc"
  57. >快速创建一场考试,支持多种选题方式</span
  58. >
  59. </div>
  60. </el-card>
  61. <el-card class="quickItem" @click.native="jump('AddCourse')">
  62. <div class="l">
  63. <img src="@/assets/dash/a2.png" />
  64. </div>
  65. <div class="r">
  66. <span class="quickItemTitle">添加课程</span>
  67. <span class="quickItemDesc"
  68. >添加课程课件,支持Office/PDF/视频</span
  69. >
  70. </div>
  71. </el-card>
  72. <el-card class="quickItem" @click.native="jump('ListRepo')">
  73. <div class="l">
  74. <img src="@/assets/dash/a3.png" />
  75. </div>
  76. <div class="r">
  77. <span class="quickItemTitle">题库管理</span>
  78. <span class="quickItemDesc"
  79. >批量导入导出、设定章节、题目难易程度</span
  80. >
  81. </div>
  82. </el-card>
  83. <el-card class="quickItem" @click.native="jump('SysNotice')">
  84. <div class="l">
  85. <img src="@/assets/dash/a4.png" />
  86. </div>
  87. <div class="r">
  88. <span class="quickItemTitle">公告管理</span>
  89. <span class="quickItemDesc">发布日常公告、新闻及提醒事项</span>
  90. </div>
  91. </el-card>
  92. </el-scrollbar>
  93. </div>
  94. </div>
  95. <div class="contentItem">
  96. <h3>当前考试({{ ksList.length }})</h3>
  97. <div class="evaluateBox">
  98. <el-scrollbar style="width: 100%; height: 100%">
  99. <el-card
  100. v-for="item in ksList"
  101. :key="item.id"
  102. class="evaluateItem"
  103. @click.native="jump('ExamTmplPreview', { id: item.tmplId })"
  104. >
  105. <div slot="header" class="evaluateItemHeader">
  106. <div>{{ item.title }}</div>
  107. </div>
  108. <el-form label-width="90px">
  109. <el-form-item label="考试时间:">
  110. <el-tooltip
  111. class="item"
  112. effect="dark"
  113. :content="`${item.startTime} - ${item.endTime}`"
  114. placement="top"
  115. >
  116. <span class="ovf"
  117. >{{ item.startTime }} - {{ item.endTime }}</span
  118. >
  119. </el-tooltip>
  120. </el-form-item>
  121. <el-form-item label="考试时长:">
  122. <span>{{ item.totalTime }}</span>
  123. </el-form-item>
  124. <el-form-item label="考试总分:">
  125. <span>{{ item.totalScore }}</span>
  126. </el-form-item>
  127. </el-form>
  128. </el-card>
  129. </el-scrollbar>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="fnBox chartBox">
  134. <div class="radioBox">
  135. <el-radio-group v-model="radioValue" size="mini" @change="initChart">
  136. <el-radio-button label="1">本周</el-radio-button>
  137. <el-radio-button label="2">本月</el-radio-button>
  138. <el-radio-button label="3">本年</el-radio-button>
  139. </el-radio-group>
  140. </div>
  141. <el-tabs v-model="tabActive" @tab-click="reLayoutTable">
  142. <el-tab-pane class="chartItem" label="部门" name="bm">
  143. <div id="bmPxChartDom" style="width: 48%; height: 280px"></div>
  144. <div id="bmKsChartDom" style="width: 48%; height: 280px"></div>
  145. </el-tab-pane>
  146. <el-tab-pane class="chartItem" label="职工" name="zg">
  147. <div id="zgPxChartDom" style="width: 48%; height: 280px"></div>
  148. <div id="zgKsChartDom" style="width: 48%; height: 280px"></div>
  149. </el-tab-pane>
  150. </el-tabs>
  151. </div>
  152. </div>
  153. </template>
  154. <script>
  155. import * as echarts from "echarts";
  156. import {
  157. getCttTotal,
  158. getCurrentExam,
  159. getDepartRank,
  160. getPassedRate,
  161. getUserRank,
  162. getUserRate,
  163. } from "@/api/dashboard/index";
  164. export default {
  165. components: {},
  166. data() {
  167. return {
  168. usernum: 0,
  169. tmplnum: 0,
  170. titlenum: 0,
  171. coursenum: 0,
  172. tabActive: "bm",
  173. radioValue: "2",
  174. ksList: [],
  175. getDepartRank,
  176. getPassedRate,
  177. getUserRank,
  178. getUserRate,
  179. };
  180. },
  181. mounted() {
  182. this.initChart();
  183. this.getCttTotal();
  184. this.getCurrentExam();
  185. },
  186. methods: {
  187. // 获取统计数值
  188. getCttTotal() {
  189. getCttTotal().then(({ data }) => {
  190. this.usernum = data.usernum;
  191. this.tmplnum = data.tmplnum;
  192. this.titlenum = data.titlenum;
  193. this.coursenum = data.coursenum;
  194. });
  195. },
  196. // 页面跳转
  197. jump(name, params = {}) {
  198. this.$router.push({ name, params });
  199. },
  200. // 重置表格布局
  201. reLayoutTable() {
  202. this.$nextTick(() => {
  203. this.initChart();
  204. });
  205. },
  206. // 初始化图表
  207. initChart() {
  208. this.$nextTick(() => {
  209. this.tabActive === "bm"
  210. ? this.callFn("getDepartRank", "getPassedRate")
  211. : this.callFn("getUserRank", "getUserRate");
  212. });
  213. },
  214. // 调用函数
  215. callFn(fn1, fn2) {
  216. const tabActive = this.tabActive;
  217. let pxChartDom = document.getElementById(`${tabActive}PxChartDom`);
  218. let ksChartDom = document.getElementById(`${tabActive}KsChartDom`);
  219. pxChartDom && pxChartDom.removeAttribute("_echarts_instance_");
  220. ksChartDom && ksChartDom.removeAttribute("_echarts_instance_");
  221. const nowDate = new Date()
  222. let startDate = null
  223. let endDate = null
  224. let monthDays = null // 当前月共多少天
  225. const weekDay = nowDate.getDay() // 获取当前为周几
  226. const month = nowDate.getMonth() + 1 // 获取当前为几月
  227. if (this.radioValue === '1') {
  228. nowDate.setDate(nowDate.getDate() - weekDay)
  229. startDate = nowDate.formatDate("yyyy-MM-dd 00:00:00")
  230. nowDate.setDate(nowDate.getDate() + 6)
  231. endDate = nowDate.formatDate("yyyy-MM-dd 23:59:59")
  232. } else if (this.radioValue === '2') {
  233. nowDate.setMonth(month)
  234. nowDate.setDate(0)
  235. monthDays = nowDate.getDate()
  236. nowDate.setMonth(month - 1)
  237. startDate = nowDate.formatDate("yyyy-MM-01 00:00:00")
  238. endDate = nowDate.formatDate(`yyyy-MM-${monthDays} 23:59:59`)
  239. } else {
  240. startDate = nowDate.formatDate("yyyy-01-01 00:00:00")
  241. endDate = nowDate.formatDate('yyyy-12-31 23:59:59')
  242. }
  243. this[fn1]({
  244. statDateL: startDate,
  245. statDateR: endDate
  246. }).then((res) => {
  247. let myChart = echarts.init(pxChartDom);
  248. let option;
  249. let xAxisData = [];
  250. let pxSeriesData = [];
  251. res.data.forEach((ele) => {
  252. xAxisData.push(tabActive === "bm" ? ele.deptName : ele.realName);
  253. pxSeriesData.push(ele.total);
  254. });
  255. option = {
  256. title: {
  257. showTitle: true,
  258. text: `${
  259. tabActive === "bm" ? "部门培训课程排行" : "职工培训时长排行top20"
  260. }`,
  261. subtext: "可滚轮缩放、左右拖动查看",
  262. x: "center",
  263. y: "top",
  264. },
  265. xAxis: {
  266. type: "category",
  267. data: xAxisData,
  268. axisLabel: {
  269. rotate: -40,
  270. },
  271. },
  272. yAxis: {
  273. type: "value",
  274. minInterval: 1,
  275. },
  276. tooltip: {
  277. show: true,
  278. trigger: "axis",
  279. formatter(data) {
  280. let str = "";
  281. data.forEach((ele) => {
  282. let circle = `<span style="display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:${ele.color}"></span>`;
  283. str += circle + `${ele.name} : ${ele.value}${tabActive === 'bm' ? '' : '分钟'} <br />`;
  284. });
  285. return str;
  286. },
  287. },
  288. dataZoom: [
  289. {
  290. id: "dataZoomX",
  291. type: "inside",
  292. xAxisIndex: [0],
  293. filterMode: "none",
  294. start: 0,
  295. end: tabActive === "bm" ? 50 : 20,
  296. },
  297. ],
  298. series: [
  299. {
  300. data: pxSeriesData,
  301. type: "line",
  302. smooth: true,
  303. itemStyle: {
  304. color: "#1890ff",
  305. },
  306. },
  307. ],
  308. };
  309. option && myChart.setOption(option);
  310. });
  311. this[fn2]({
  312. statDateL: startDate,
  313. statDateR: endDate,
  314. }).then((res) => {
  315. let myChart = echarts.init(ksChartDom);
  316. let option;
  317. let xAxisData = [];
  318. let pxSeriesData = [];
  319. res.data.forEach((ele) => {
  320. xAxisData.push(tabActive === "bm" ? ele.deptName : ele.realName);
  321. pxSeriesData.push(ele.total > 0 ? (ele.passed / ele.total) * 100 : 0);
  322. });
  323. option = {
  324. title: {
  325. showTitle: true,
  326. text: `${
  327. tabActive === "bm"
  328. ? "部门考试及格率排行"
  329. : "职工考试及格率排行top20"
  330. }`,
  331. subtext: "可滚轮缩放、左右拖动查看",
  332. x: "center",
  333. y: "top",
  334. },
  335. xAxis: {
  336. type: "category",
  337. data: xAxisData,
  338. },
  339. yAxis: {
  340. type: "value",
  341. },
  342. tooltip: {
  343. show: true,
  344. trigger: "axis",
  345. formatter(data) {
  346. let str = "";
  347. data.forEach((ele) => {
  348. let circle = `<span style="display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:${ele.color}"></span>`;
  349. str += circle + `${ele.name} : ${ele.value}% <br />`;
  350. });
  351. return str;
  352. },
  353. },
  354. dataZoom: [
  355. {
  356. id: "dataZoomX",
  357. type: "inside",
  358. xAxisIndex: [0],
  359. filterMode: "none",
  360. start: 0,
  361. end: tabActive === "bm" ? 50 : 20,
  362. },
  363. ],
  364. series: [
  365. {
  366. data: pxSeriesData,
  367. type: "line",
  368. smooth: true,
  369. itemStyle: {
  370. color: "#1890ff",
  371. },
  372. },
  373. ],
  374. };
  375. option && myChart.setOption(option);
  376. });
  377. },
  378. // 获取当前考试
  379. getCurrentExam() {
  380. getCurrentExam().then((res) => {
  381. this.ksList = res.data || [];
  382. });
  383. },
  384. },
  385. };
  386. </script>
  387. <style lang="scss" >
  388. .fnBox {
  389. width: 100%;
  390. h3 {
  391. width: 100%;
  392. }
  393. }
  394. .statisticsBox {
  395. display: flex;
  396. justify-content: flex-start;
  397. align-items: center;
  398. flex-wrap: wrap;
  399. .statisticsItem {
  400. margin-left: 20px;
  401. background: #1890ff;
  402. padding: 5px;
  403. cursor: pointer;
  404. .el-card__body {
  405. display: flex;
  406. justify-content: flex-start;
  407. align-items: center;
  408. user-select: none;
  409. .l {
  410. width: 50px;
  411. height: 50px;
  412. margin-right: 40px;
  413. img {
  414. width: 100%;
  415. height: 100%;
  416. background-size: 100% 100%;
  417. }
  418. }
  419. .r {
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: flex-start;
  423. align-items: center;
  424. font-weight: 700;
  425. color: #fff;
  426. .statisticsTitle {
  427. font-size: 16px;
  428. margin-bottom: 10px;
  429. }
  430. .statisticsNum {
  431. font-size: 18px;
  432. }
  433. }
  434. }
  435. &:nth-child(2) {
  436. margin-left: 0;
  437. }
  438. }
  439. }
  440. .contentBox {
  441. width: 100%;
  442. display: flex;
  443. justify-content: space-between;
  444. align-items: flex-start;
  445. .contentItem {
  446. width: 48%;
  447. height: 225px;
  448. .quickBox {
  449. width: 100%;
  450. height: 100%;
  451. .el-scrollbar__view {
  452. display: flex;
  453. justify-content: space-between;
  454. align-items: center;
  455. flex-wrap: wrap;
  456. }
  457. .quickItem {
  458. width: 48%;
  459. display: flex;
  460. justify-content: flex-start;
  461. align-items: center;
  462. user-select: none;
  463. cursor: pointer;
  464. margin-bottom: 18px;
  465. .el-card__body {
  466. display: flex;
  467. justify-content: space-between;
  468. align-items: center;
  469. user-select: none;
  470. .l {
  471. width: 50px;
  472. height: 50px;
  473. margin-right: 20px;
  474. img {
  475. width: 100%;
  476. height: 100%;
  477. background-size: 100% 100%;
  478. }
  479. }
  480. .r {
  481. display: flex;
  482. flex-direction: column;
  483. justify-content: flex-start;
  484. align-items: flex-start;
  485. font-weight: 700;
  486. color: #000;
  487. .quickItemTitle {
  488. font-size: 16px;
  489. margin-bottom: 10px;
  490. }
  491. .quickItemDesc {
  492. font-size: 12px;
  493. color: #666;
  494. overflow: hidden;
  495. text-overflow: ellipsis;
  496. white-space: nowrap;
  497. }
  498. }
  499. }
  500. }
  501. }
  502. .evaluateBox {
  503. width: 100%;
  504. height: 100%;
  505. .el-scrollbar__view {
  506. display: flex;
  507. justify-content: space-between;
  508. align-items: center;
  509. flex-wrap: wrap;
  510. }
  511. .evaluateItem {
  512. width: 48%;
  513. margin-bottom: 18px;
  514. cursor: pointer;
  515. .evaluateItemHeader {
  516. display: flex;
  517. justify-content: space-between;
  518. align-items: center;
  519. .iconBox {
  520. display: flex;
  521. justify-content: flex-start;
  522. align-items: center;
  523. i {
  524. margin-left: 8px;
  525. cursor: pointer;
  526. }
  527. }
  528. }
  529. }
  530. .el-card__body {
  531. padding: 20px;
  532. }
  533. .el-form-item {
  534. margin-bottom: 0;
  535. height: 36px;
  536. .ovf {
  537. display: inline-block;
  538. width: 100%;
  539. overflow: hidden;
  540. text-overflow: ellipsis;
  541. white-space: nowrap;
  542. }
  543. }
  544. }
  545. }
  546. }
  547. .chartBox {
  548. width: 100%;
  549. margin-top: 50px;
  550. position: relative;
  551. .radioBox {
  552. position: absolute;
  553. right: 0;
  554. top: 45px;
  555. z-index: 100;
  556. }
  557. .chartItem {
  558. width: 100%;
  559. display: flex;
  560. justify-content: space-between;
  561. align-items: center;
  562. }
  563. }
  564. </style>