index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <script setup lang="ts">
  2. import {DashboardData} from "@/api/dashboard/types";
  3. import {Area, AreaCard, AreaLineData, AreaParams} from "@/api/areaboard/types";
  4. import AreaDataCard from "@/views/areaboard/components/AreaDataCard.vue";
  5. import LiquidChart from "@/components/Charts/LiquidChart.vue";
  6. import PercentBarChart from "@/components/Charts/PercentBarChart.vue";
  7. import CircleChart from "@/components/Charts/CircleChart.vue";
  8. import LineChart from "@/components/Charts/LineChart.vue";
  9. import AverageBarChart from "@/components/Charts/AverageBarChart.vue";
  10. import {GradeList} from "@/api/grade/types";
  11. import {getGradeSelect} from "@/api/grade";
  12. import {getAreaAddress, getAreaBoardLines, getAreaBoardPies, getAreaCard, getAreaSchool} from "@/api/areaboard";
  13. import {SchoolList} from "@/api/school/types";
  14. defineOptions({
  15. name: "DashboardArea",
  16. inheritAttrs: false,
  17. });
  18. /**
  19. * 筛选条件
  20. */
  21. const dataParams: AreaParams = reactive({
  22. province_id: 0,
  23. city_id: 0,
  24. school_id: 0,
  25. grade_id: 0,
  26. start_time: Math.ceil(Date.parse("2023/1/1 00:00") / 1000),
  27. end_time: Math.ceil(Date.now() / 1000),
  28. });
  29. const datePicker = ref<number[]>([Date.parse("2023/1/1 00:00"), Date.now()]);
  30. const provinceData = ref<Area[]>();
  31. const cityData = ref<Area[]>();
  32. async function getAddressData(id: number) {
  33. getAreaAddress(id)
  34. .then(({data}) => {
  35. if (id == 0) {
  36. provinceData.value = data;
  37. provinceData.value?.unshift({area_id: 0, area_name: "全部省"});
  38. } else {
  39. cityData.value = data;
  40. cityData.value?.unshift({area_id: 0, area_name: "全部市"});
  41. }
  42. // 重新获取学校
  43. getSchoolData(dataParams);
  44. })
  45. .catch((error) => {
  46. console.log(error.message);
  47. if (id == 0) {
  48. provinceData.value = [{area_id: 0, area_name: "全部省"}];
  49. } else {
  50. cityData.value = [{area_id: 0, area_name: "全部市"}];
  51. }
  52. });
  53. }
  54. //getAreaSchool
  55. /**
  56. * 获取学校
  57. */
  58. const schoolData = ref<SchoolList[]>();
  59. async function getSchoolData(params: AreaParams) {
  60. getAreaSchool(params.province_id, params.city_id)
  61. .then(({data}) => {
  62. schoolData.value = data;
  63. schoolData.value?.unshift({num: "", school_id: 0, name: "全部学校"});
  64. })
  65. .catch((error) => {
  66. schoolData.value = [];
  67. schoolData.value?.unshift({num: "", school_id: 0, name: "全部学校"});
  68. console.log(error.message);
  69. });
  70. }
  71. /**
  72. * 班级数据
  73. */
  74. const gradeData = ref<GradeList[]>();
  75. async function getGradeData(schoolId: number) {
  76. getGradeSelect(schoolId)
  77. .then(({data}) => {
  78. gradeData.value = data;
  79. gradeData.value?.unshift({id: 0, name: "全部班级"});
  80. })
  81. .catch((error) => {
  82. gradeData.value = [];
  83. gradeData.value?.unshift({id: 0, name: "全部班级"});
  84. console.log(error.message);
  85. });
  86. }
  87. // 改变时间
  88. function changeDate() {
  89. dataParams.start_time = Math.ceil(datePicker.value[0] / 1000);
  90. dataParams.end_time = Math.ceil(datePicker.value[1] / 1000);
  91. }
  92. /**
  93. * 数据卡片
  94. */
  95. const cardStatus = ref(false);
  96. const cards = ref<AreaCard>();
  97. async function getDataCard(params: AreaParams) {
  98. getAreaCard(params)
  99. .then(({data}) => {
  100. cards.value = data;
  101. cardStatus.value = true;
  102. })
  103. .catch((error) => {
  104. console.log(error.message);
  105. });
  106. }
  107. /**
  108. * 饼图数据
  109. */
  110. const pieStatus = ref(false);
  111. const pieMessage = ref("加载中...");
  112. const pieChartData = ref<DashboardData>();
  113. async function getPieChartData(params: AreaParams) {
  114. pieStatus.value = false;
  115. getAreaBoardPies(params)
  116. .then(({data}) => {
  117. pieChartData.value = data;
  118. pieStatus.value = true;
  119. })
  120. .catch((error) => {
  121. pieStatus.value = false;
  122. pieMessage.value = error.message;
  123. console.log(error.message);
  124. });
  125. }
  126. /**
  127. * 折线图数据
  128. */
  129. const lineStatus = ref(false);
  130. const lineMessage = ref("加载中...");
  131. const lineChartData = ref<AreaLineData>();
  132. const averageData = ref<number[][]>();
  133. const curveData = ref<number[][]>();
  134. async function getLineChartData(params: AreaParams) {
  135. lineStatus.value = false;
  136. getAreaBoardLines(params)
  137. .then(({data}) => {
  138. lineChartData.value = data;
  139. // 柱状图
  140. averageData.value = [];
  141. averageData.value?.push(lineChartData.value?.frontNum || []);
  142. averageData.value?.push(lineChartData.value?.afterNum || []);
  143. // 曲线图
  144. curveData.value = [];
  145. curveData.value?.push(lineChartData.value?.curve || []);
  146. curveData.value?.push(lineChartData.value?.num || []);
  147. lineStatus.value = true;
  148. })
  149. .catch((error) => {
  150. lineStatus.value = false;
  151. lineMessage.value = error.message;
  152. console.log(error.message);
  153. });
  154. }
  155. /**
  156. * 获取页面数据
  157. */
  158. function getPageData() {
  159. // 数据卡片
  160. getDataCard(dataParams);
  161. // 饼图数据
  162. getPieChartData(dataParams);
  163. // 折线图数据
  164. getLineChartData(dataParams);
  165. }
  166. onMounted(() => {
  167. // 获取省份
  168. getAddressData(0);
  169. cityData.value = [{area_id: 0, area_name: "全部市"}];
  170. // 获取学校
  171. getSchoolData(dataParams);
  172. gradeData.value = [{id: 0, name: "全部班级"}];
  173. // 获取页面数据
  174. getPageData();
  175. });
  176. </script>
  177. <template>
  178. <div class="area-container">
  179. <div class="area-top">
  180. <div class="search-box">
  181. <el-select
  182. v-model="dataParams.province_id"
  183. placeholder="全部省"
  184. size="large"
  185. @change="getAddressData(dataParams.province_id)">
  186. <el-option v-for="item in provinceData" :key="item.area_id" :label="item.area_name" :value="item.area_id" />
  187. </el-select>
  188. <el-select v-model="dataParams.city_id" placeholder="全部市" size="large" @change="getSchoolData(dataParams)">
  189. <el-option v-for="item in cityData" :key="item.area_id" :label="item.area_name" :value="item.area_id" />
  190. </el-select>
  191. <div>
  192. <el-date-picker
  193. v-model="datePicker"
  194. type="daterange"
  195. size="large"
  196. start-placeholder="开始日期"
  197. end-placeholder="结束日期"
  198. format="YYYY-MM-DD"
  199. value-format="x"
  200. @change="changeDate()" />
  201. </div>
  202. <el-button color="#4284f2" size="large" @click="getPageData()">查找</el-button>
  203. </div>
  204. <div class="card-box">
  205. <!-- 数据卡片 -->
  206. <template v-if="cardStatus">
  207. <AreaDataCard
  208. :key="cards?.toString()"
  209. :schools="cards?.school || 0"
  210. :games="cards?.game || 0"
  211. :students="cards?.student || 0" />
  212. </template>
  213. </div>
  214. </div>
  215. <div class="search-box s2">
  216. <el-select
  217. v-model="dataParams.school_id"
  218. placeholder="全部学校"
  219. size="large"
  220. @change="getGradeData(dataParams.school_id)">
  221. <el-option v-for="item in schoolData" :key="item.school_id" :label="item.name" :value="item.school_id" />
  222. </el-select>
  223. <el-select v-model="dataParams.grade_id" placeholder="全部班级" size="large">
  224. <el-option v-for="item in gradeData" :key="item.id" :label="item.name" :value="item.id" />
  225. </el-select>
  226. <el-button color="#4284f2" size="large" @click="getPageData()">查找</el-button>
  227. </div>
  228. <!-- Echarts 图表 -->
  229. <div class="charts-container">
  230. <el-row :gutter="20">
  231. <el-col :xs="24" :span="8">
  232. <div class="charts-item">
  233. <p class="title">学员专注力平均值整体对比分析</p>
  234. <template v-if="pieStatus">
  235. <el-row justify="space-between">
  236. <el-col :span="12">
  237. <div class="item">
  238. <LiquidChart
  239. id="liquidChart1"
  240. :key="pieChartData?.frontAverage"
  241. :data="pieChartData?.frontAverage || 0"
  242. height="200px"
  243. width="200px"
  244. color="#3a7fc2"
  245. bg-color="#accded"
  246. class="chart" />
  247. <p>全体学员初期</p>
  248. <p>专注力评估均值</p>
  249. </div>
  250. </el-col>
  251. <el-col :span="12">
  252. <div class="item">
  253. <LiquidChart
  254. id="liquidChart2"
  255. :key="pieChartData?.afterAverage"
  256. :data="pieChartData?.afterAverage || 0"
  257. height="200px"
  258. width="200px"
  259. color="#5563ac"
  260. bg-color="#cacce6"
  261. class="chart" />
  262. <p>全体学员训练近期</p>
  263. <p>专注力评估均值</p>
  264. </div>
  265. </el-col>
  266. </el-row>
  267. <el-row justify="space-between">
  268. <el-col :span="12">
  269. <div class="item">
  270. <CircleChart
  271. id="circleChart1"
  272. :key="pieChartData?.front"
  273. :data="pieChartData?.front || 0"
  274. height="200px"
  275. width="200px"
  276. color="#3a7fc2"
  277. bg-color="#e4e7f4"
  278. font-color="#3a7fc2"
  279. font-size="30px"
  280. :round-cap="Boolean(true)" />
  281. <p>初期训练</p>
  282. <p>专注力50以上人数比例</p>
  283. </div>
  284. </el-col>
  285. <el-col :span="12">
  286. <div class="item">
  287. <CircleChart
  288. id="circleChart2"
  289. :key="pieChartData?.after"
  290. :data="pieChartData?.after || 0"
  291. height="200px"
  292. width="200px"
  293. color="#5563ac"
  294. bg-color="#e4e7f4"
  295. font-color="#5563ac"
  296. font-size="30px"
  297. :round-cap="Boolean(true)" />
  298. <p>近期训练</p>
  299. <p>专注力50以上人数比例</p>
  300. </div>
  301. </el-col>
  302. </el-row>
  303. </template>
  304. <div v-else class="empty">
  305. <img src="../../assets/empty.png" alt="数据为空" />
  306. <p>{{ pieMessage }}</p>
  307. </div>
  308. </div>
  309. </el-col>
  310. <!-- 学员专注力评分分级占比分析 -->
  311. <el-col :xs="24" :span="16">
  312. <div class="charts-item">
  313. <p class="title">样本每次训练专注力评分均值整体变化曲线</p>
  314. <template v-if="lineStatus">
  315. <line-chart
  316. id="lineChart1"
  317. :key="curveData?.toString()"
  318. :data-sets="curveData || [[], []]"
  319. height="558px"
  320. width="100%" />
  321. </template>
  322. <div v-else class="empty">
  323. <img src="../../assets/empty.png" alt="数据为空" />
  324. <p>{{ lineMessage }}</p>
  325. </div>
  326. </div>
  327. </el-col>
  328. </el-row>
  329. </div>
  330. <div class="charts-container">
  331. <el-row :gutter="20">
  332. <el-col :xs="24" :span="8">
  333. <div class="charts-item">
  334. <p class="title pos">学员专注力训练高专注占比分析</p>
  335. <template v-if="lineStatus">
  336. <AverageBarChart
  337. id="averageBarChart1"
  338. :key="averageData?.toString()"
  339. :data-sets="averageData || [[], []]"
  340. :data-max="lineChartData?.max_num || 10"
  341. width="520px"
  342. height="520px"
  343. class="chart" />
  344. </template>
  345. <div v-else class="empty">
  346. <img src="../../assets/empty.png" alt="数据为空" />
  347. <p>{{ lineMessage }}</p>
  348. </div>
  349. <el-row :gutter="15" class="bottom">
  350. <el-col :span="12">
  351. <p class="l">
  352. <span>训练前期全体学员</span>
  353. <span>高专注占比平均值</span>
  354. <b>{{ lineChartData?.frontHeight }}</b>
  355. </p>
  356. </el-col>
  357. <el-col :span="12">
  358. <p class="r">
  359. <span>训练后期全体学员</span>
  360. <span>高专注占比平均值</span>
  361. <b>{{ lineChartData?.afterHeight }}</b>
  362. </p>
  363. </el-col>
  364. </el-row>
  365. </div>
  366. </el-col>
  367. <!-- 学员专注力评分分级占比分析 -->
  368. <el-col :xs="24" :span="16">
  369. <div class="charts-item">
  370. <p class="title">学员专注力评分分级占比分析</p>
  371. <el-row v-if="pieStatus" justify="space-between">
  372. <el-col :xs="24" :span="12">
  373. <div class="bar">
  374. <PercentBarChart
  375. id="barChart1"
  376. :key="pieChartData?.frontProportion.toString()"
  377. width="400px"
  378. height="500px"
  379. title="全体学员初期训练专注力评分占比"
  380. :percent="pieChartData?.frontProportion.percentage"
  381. :data="pieChartData?.frontProportion.num"
  382. class="chart" />
  383. </div>
  384. </el-col>
  385. <el-col :xs="24" :span="12">
  386. <div class="bar">
  387. <PercentBarChart
  388. id="barChart2"
  389. :key="pieChartData?.afterProportion.toString()"
  390. width="400px"
  391. height="500px"
  392. title="全体学员训练近期专注力评分平均占比"
  393. :percent="pieChartData?.afterProportion.percentage"
  394. :data="pieChartData?.afterProportion.num"
  395. class="chart" />
  396. </div>
  397. </el-col>
  398. </el-row>
  399. <div v-else class="empty">
  400. <img src="../../assets/empty.png" alt="数据为空" />
  401. <p>{{ pieMessage }}</p>
  402. </div>
  403. </div>
  404. </el-col>
  405. </el-row>
  406. </div>
  407. </div>
  408. </template>
  409. <style lang="scss" scoped>
  410. .area-top {
  411. background: #fff;
  412. }
  413. .card-box {
  414. padding: 0 30px 20px;
  415. }
  416. .search-box {
  417. display: flex;
  418. padding: 20px 55px;
  419. line-height: 40px;
  420. .el-select {
  421. width: 140px;
  422. margin-right: 10px;
  423. }
  424. .el-button {
  425. padding: 0 26px;
  426. margin: 0 20px;
  427. font-size: 16px;
  428. border-radius: 10px;
  429. }
  430. }
  431. :deep(.el-select),
  432. :deep(.el-date-editor) {
  433. --el-select-input-focus-border-color: none !important;
  434. width: 300px;
  435. margin: 0;
  436. overflow: hidden;
  437. border: 1px solid #ddd;
  438. border-radius: 10px;
  439. }
  440. :deep(.search-box.s2 .el-select) {
  441. border: none;
  442. }
  443. :deep(.el-date-editor) {
  444. --el-select-input-focus-border-color: none !important;
  445. }
  446. :deep(.el-input__wrapper) {
  447. box-shadow: none !important;
  448. }
  449. :deep(.el-input__wrapper.is-focus) {
  450. box-shadow: none !important;
  451. }
  452. :deep(.el-select:hover:not(.el-select--disabled) .el-input__wrapper) {
  453. box-shadow: none !important;
  454. }
  455. .charts-container {
  456. position: relative;
  457. padding: 0 30px 20px;
  458. }
  459. .charts-item {
  460. position: relative;
  461. text-align: center;
  462. background: #fff;
  463. border: 1px solid #e8eaec;
  464. border-radius: 24px;
  465. .title {
  466. height: 78px;
  467. margin: 0;
  468. font-size: 18px;
  469. line-height: 78px;
  470. text-align: left;
  471. text-indent: 2em;
  472. &.pos {
  473. margin-bottom: -50px;
  474. }
  475. }
  476. .item {
  477. padding-bottom: 30px;
  478. }
  479. .chart {
  480. margin: 0 auto;
  481. }
  482. p {
  483. margin: 0;
  484. font-size: 16px;
  485. line-height: 24px;
  486. }
  487. .bar {
  488. margin-top: 60px;
  489. }
  490. .bottom {
  491. padding: 0 20px 20px;
  492. .el-col p {
  493. position: relative;
  494. box-sizing: border-box;
  495. padding: 10px 20px;
  496. color: #fff;
  497. text-align: left;
  498. white-space: nowrap;
  499. border-radius: 10px;
  500. &.l {
  501. background: #f8b865;
  502. }
  503. &.r {
  504. background: #8877ef;
  505. }
  506. span {
  507. display: block;
  508. }
  509. b {
  510. position: absolute;
  511. top: 22px;
  512. right: 20px;
  513. font-size: 26px;
  514. font-style: normal;
  515. }
  516. }
  517. }
  518. .empty {
  519. padding: 200px 0;
  520. }
  521. }
  522. .mobile .el-col {
  523. margin-bottom: 10px;
  524. }
  525. </style>