index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. const day =
  218. this.radioValue === "1" ? 7 : this.radioValue === "2" ? 30 : 360;
  219. let pxChartDom = document.getElementById(`${tabActive}PxChartDom`);
  220. let ksChartDom = document.getElementById(`${tabActive}KsChartDom`);
  221. pxChartDom && pxChartDom.removeAttribute("_echarts_instance_");
  222. ksChartDom && ksChartDom.removeAttribute("_echarts_instance_");
  223. this[fn1]({
  224. statDateL: new Date(new Date() - 3600 * 1000 * 24 * day).formatDate(
  225. "yyyy-MM-dd hh:mm:ss"
  226. ),
  227. statDateR: new Date().formatDate("yyyy-MM-dd hh:mm:ss"),
  228. }).then((res) => {
  229. let myChart = echarts.init(pxChartDom);
  230. let option;
  231. let xAxisData = [];
  232. let pxSeriesData = [];
  233. res.data.forEach((ele) => {
  234. xAxisData.push(tabActive === "bm" ? ele.deptName : ele.realName);
  235. pxSeriesData.push(ele.total);
  236. });
  237. option = {
  238. title: {
  239. showTitle: true,
  240. text: `${
  241. tabActive === "bm" ? "部门培训课时排行" : "职工培训课时排行top20"
  242. }`,
  243. subtext: "可滚轮缩放、左右拖动查看",
  244. x: "center",
  245. y: "top",
  246. },
  247. xAxis: {
  248. type: "category",
  249. data: xAxisData,
  250. axisLabel: {
  251. rotate: -40,
  252. },
  253. },
  254. yAxis: {
  255. type: "value",
  256. },
  257. tooltip: {
  258. show: true,
  259. trigger: "axis",
  260. formatter(data) {
  261. let str = "";
  262. data.forEach((ele) => {
  263. let circle = `<span style="display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:${ele.color}"></span>`;
  264. str += circle + `${ele.name}: ${ele.value}分钟 <br />`;
  265. });
  266. return str;
  267. },
  268. },
  269. dataZoom: [
  270. {
  271. id: "dataZoomX",
  272. type: "inside",
  273. xAxisIndex: [0],
  274. filterMode: "none",
  275. start: 0,
  276. end: tabActive === "bm" ? 50 : 20,
  277. },
  278. ],
  279. series: [
  280. {
  281. data: pxSeriesData,
  282. type: "line",
  283. smooth: true,
  284. itemStyle: {
  285. color: "#1890ff",
  286. },
  287. },
  288. ],
  289. };
  290. option && myChart.setOption(option);
  291. });
  292. this[fn2]({
  293. statDateL: new Date(new Date() - 3600 * 1000 * 24 * day).formatDate(
  294. "yyyy-MM-dd hh:mm:ss"
  295. ),
  296. statDateR: new Date().formatDate("yyyy-MM-dd hh:mm:ss"),
  297. }).then((res) => {
  298. let myChart = echarts.init(ksChartDom);
  299. let option;
  300. let xAxisData = [];
  301. let pxSeriesData = [];
  302. res.data.forEach((ele) => {
  303. xAxisData.push(tabActive === "bm" ? ele.deptName : ele.realName);
  304. pxSeriesData.push(ele.total);
  305. });
  306. option = {
  307. title: {
  308. showTitle: true,
  309. text: `${
  310. tabActive === "bm"
  311. ? "部门考试及格率排行"
  312. : "职工考试及格率排行top20"
  313. }`,
  314. subtext: "可滚轮缩放、左右拖动查看",
  315. x: "center",
  316. y: "top",
  317. },
  318. xAxis: {
  319. type: "category",
  320. data: xAxisData,
  321. },
  322. yAxis: {
  323. type: "value",
  324. },
  325. tooltip: {
  326. show: true,
  327. trigger: "axis",
  328. formatter(data) {
  329. let str = "";
  330. data.forEach((ele) => {
  331. let circle = `<span style="display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;left:5px;background-color:${ele.color}"></span>`;
  332. str += circle + `${ele.name}: ${ele.value}% <br />`;
  333. });
  334. return str;
  335. },
  336. },
  337. dataZoom: [
  338. {
  339. id: "dataZoomX",
  340. type: "inside",
  341. xAxisIndex: [0],
  342. filterMode: "none",
  343. start: 0,
  344. end: tabActive === "bm" ? 50 : 20,
  345. },
  346. ],
  347. series: [
  348. {
  349. data: pxSeriesData,
  350. type: "line",
  351. smooth: true,
  352. itemStyle: {
  353. color: "#1890ff",
  354. },
  355. },
  356. ],
  357. };
  358. option && myChart.setOption(option);
  359. });
  360. },
  361. // 获取当前考试
  362. getCurrentExam() {
  363. getCurrentExam().then((res) => {
  364. this.ksList = res.data || [];
  365. });
  366. },
  367. },
  368. };
  369. </script>
  370. <style lang="scss" >
  371. .fnBox {
  372. width: 100%;
  373. h3 {
  374. width: 100%;
  375. }
  376. }
  377. .statisticsBox {
  378. display: flex;
  379. justify-content: flex-start;
  380. align-items: center;
  381. flex-wrap: wrap;
  382. .statisticsItem {
  383. margin-left: 20px;
  384. background: #1890ff;
  385. padding: 5px;
  386. cursor: pointer;
  387. .el-card__body {
  388. display: flex;
  389. justify-content: flex-start;
  390. align-items: center;
  391. user-select: none;
  392. .l {
  393. width: 50px;
  394. height: 50px;
  395. margin-right: 40px;
  396. img {
  397. width: 100%;
  398. height: 100%;
  399. background-size: 100% 100%;
  400. }
  401. }
  402. .r {
  403. display: flex;
  404. flex-direction: column;
  405. justify-content: flex-start;
  406. align-items: center;
  407. font-weight: 700;
  408. color: #fff;
  409. .statisticsTitle {
  410. font-size: 16px;
  411. margin-bottom: 10px;
  412. }
  413. .statisticsNum {
  414. font-size: 18px;
  415. }
  416. }
  417. }
  418. &:nth-child(2) {
  419. margin-left: 0;
  420. }
  421. }
  422. }
  423. .contentBox {
  424. width: 100%;
  425. display: flex;
  426. justify-content: space-between;
  427. align-items: flex-start;
  428. .contentItem {
  429. width: 48%;
  430. height: 225px;
  431. .quickBox {
  432. width: 100%;
  433. height: 100%;
  434. .el-scrollbar__view {
  435. display: flex;
  436. justify-content: space-between;
  437. align-items: center;
  438. flex-wrap: wrap;
  439. }
  440. .quickItem {
  441. width: 48%;
  442. display: flex;
  443. justify-content: flex-start;
  444. align-items: center;
  445. user-select: none;
  446. cursor: pointer;
  447. margin-bottom: 18px;
  448. .el-card__body {
  449. display: flex;
  450. justify-content: space-between;
  451. align-items: center;
  452. user-select: none;
  453. .l {
  454. width: 50px;
  455. height: 50px;
  456. margin-right: 20px;
  457. img {
  458. width: 100%;
  459. height: 100%;
  460. background-size: 100% 100%;
  461. }
  462. }
  463. .r {
  464. display: flex;
  465. flex-direction: column;
  466. justify-content: flex-start;
  467. align-items: flex-start;
  468. font-weight: 700;
  469. color: #000;
  470. .quickItemTitle {
  471. font-size: 16px;
  472. margin-bottom: 10px;
  473. }
  474. .quickItemDesc {
  475. font-size: 12px;
  476. color: #666;
  477. overflow: hidden;
  478. text-overflow: ellipsis;
  479. white-space: nowrap;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. .evaluateBox {
  486. width: 100%;
  487. height: 100%;
  488. .el-scrollbar__view {
  489. display: flex;
  490. justify-content: space-between;
  491. align-items: center;
  492. flex-wrap: wrap;
  493. }
  494. .evaluateItem {
  495. width: 48%;
  496. margin-bottom: 18px;
  497. cursor: pointer;
  498. .evaluateItemHeader {
  499. display: flex;
  500. justify-content: space-between;
  501. align-items: center;
  502. .iconBox {
  503. display: flex;
  504. justify-content: flex-start;
  505. align-items: center;
  506. i {
  507. margin-left: 8px;
  508. cursor: pointer;
  509. }
  510. }
  511. }
  512. }
  513. .el-card__body {
  514. padding: 20px;
  515. }
  516. .el-form-item {
  517. margin-bottom: 0;
  518. height: 36px;
  519. .ovf {
  520. display: inline-block;
  521. width: 100%;
  522. overflow: hidden;
  523. text-overflow: ellipsis;
  524. white-space: nowrap;
  525. }
  526. }
  527. }
  528. }
  529. }
  530. .chartBox {
  531. width: 100%;
  532. margin-top: 50px;
  533. position: relative;
  534. .radioBox {
  535. position: absolute;
  536. right: 0;
  537. top: 45px;
  538. z-index: 100;
  539. }
  540. .chartItem {
  541. width: 100%;
  542. display: flex;
  543. justify-content: space-between;
  544. align-items: center;
  545. }
  546. }
  547. </style>