ComboCharts.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <script setup lang="ts">
  2. import CircleChart from "@/components/Charts/CircleChart.vue";
  3. import LiquidChart from "@/components/Charts/LiquidChart.vue";
  4. import LineChart from "@/components/Charts/LineChart.vue";
  5. import PercentBarChart from "@/components/Charts/PercentBarChart.vue";
  6. import {DashboardData} from "@/api/dashboard/types";
  7. import {AreaChartParams, AreaLineData} from "@/api/areaboard/types";
  8. import {getAreaBoardLines, getAreaBoardPies} from "@/api/areaboard";
  9. import {Ref} from "vue";
  10. const props = defineProps({
  11. provinceId: {
  12. type: Number,
  13. default: 0,
  14. },
  15. cityId: {
  16. type: Number,
  17. default: 0,
  18. },
  19. schoolId: {
  20. type: Number,
  21. default: 0,
  22. },
  23. gradeId: {
  24. type: Number,
  25. default: 0,
  26. },
  27. startTime: {
  28. type: Number,
  29. default: Math.ceil(Date.parse("2023/1/1 00:00") / 1000),
  30. },
  31. endTime: {
  32. type: Number,
  33. default: Math.ceil(Date.now() / 1000),
  34. },
  35. });
  36. /**
  37. * 饼图数据
  38. */
  39. const pieStatus = ref(false);
  40. const pieMessage = ref("加载中...");
  41. const pieChartData = ref<DashboardData>();
  42. async function getPieChartData(params: AreaChartParams) {
  43. pieStatus.value = false;
  44. getAreaBoardPies(params)
  45. .then(({data}) => {
  46. pieChartData.value = data;
  47. pieStatus.value = true;
  48. })
  49. .catch((error) => {
  50. pieStatus.value = false;
  51. pieMessage.value = error.message;
  52. console.log(error.message);
  53. });
  54. }
  55. /**
  56. * 折线图数据
  57. */
  58. const lineStatus = ref(false);
  59. const lineMessage = ref("加载中...");
  60. const lineChartData = ref<AreaLineData>();
  61. const curveData = ref<number[][]>();
  62. const swCurveData = ref<number[][]>();
  63. const klCurveData = ref<number[][]>();
  64. const zzlCurveData = ref<number[][]>();
  65. async function getLineChartData(params: AreaChartParams) {
  66. lineStatus.value = false;
  67. getAreaBoardLines(params)
  68. .then(({data}) => {
  69. lineChartData.value = data;
  70. // 曲线图
  71. curveData.value = [];
  72. curveData.value?.push(lineChartData.value?.curve || []);
  73. curveData.value?.push(lineChartData.value?.num || []);
  74. lineStatus.value = true;
  75. lineChartData.value = undefined;
  76. })
  77. .catch((error) => {
  78. lineStatus.value = false;
  79. lineMessage.value = error.message;
  80. console.log(error.message);
  81. });
  82. }
  83. async function getLineChartDataSub(result: Ref<number[][] | undefined>, params: AreaChartParams) {
  84. let tempData: AreaLineData;
  85. getAreaBoardLines(params).then(({data}) => {
  86. tempData = data;
  87. result.value = [];
  88. result.value?.push(tempData?.curve || []);
  89. result.value?.push(tempData?.num || []);
  90. });
  91. }
  92. /**
  93. * 筛选条件
  94. */
  95. const dataParams: AreaChartParams = reactive({
  96. province_id: 0,
  97. city_id: 0,
  98. school_id: 0,
  99. grade_id: 0,
  100. device_id: 0,
  101. start_time: Math.ceil(Date.parse("2023/1/1 00:00") / 1000),
  102. end_time: Math.ceil(Date.now() / 1000),
  103. });
  104. // 监听数据变化
  105. watchEffect(() => {
  106. dataParams.province_id = <number>props.provinceId;
  107. dataParams.city_id = <number>props.cityId;
  108. dataParams.school_id = <number>props.schoolId;
  109. dataParams.grade_id = <number>props.gradeId;
  110. dataParams.start_time = <number>props.startTime;
  111. dataParams.end_time = <number>props.endTime;
  112. // 饼图数据
  113. getPieChartData(dataParams);
  114. // 折线图数据
  115. dataParams.device_id = 0;
  116. getLineChartData(dataParams);
  117. dataParams.device_id = 1;
  118. getLineChartDataSub(swCurveData, dataParams);
  119. dataParams.device_id = 6;
  120. getLineChartDataSub(klCurveData, dataParams);
  121. dataParams.device_id = 7;
  122. getLineChartDataSub(zzlCurveData, dataParams);
  123. });
  124. </script>
  125. <template>
  126. <!-- Echarts 图表 -->
  127. <div class="charts-container">
  128. <el-row :gutter="20">
  129. <el-col :xs="24" :span="8">
  130. <div class="charts-item">
  131. <p class="title">学员专注力平均值整体对比分析</p>
  132. <template v-if="pieStatus">
  133. <el-row justify="space-between">
  134. <el-col :span="12">
  135. <div class="item">
  136. <LiquidChart
  137. id="liquidChart1"
  138. :key="pieChartData?.frontAverage"
  139. :data="pieChartData?.frontAverage || 0"
  140. height="200px"
  141. width="200px"
  142. color="#3a7fc2"
  143. bg-color="#accded"
  144. class="chart" />
  145. <p>全体学员初期</p>
  146. <p>专注力评估均值</p>
  147. </div>
  148. </el-col>
  149. <el-col :span="12">
  150. <div class="item">
  151. <template v-if="pieChartData?.countRecord && pieChartData.countRecord > 4">
  152. <LiquidChart
  153. id="liquidChart2"
  154. :key="pieChartData?.afterAverage"
  155. :data="pieChartData?.afterAverage || 0"
  156. height="200px"
  157. width="200px"
  158. color="#5563ac"
  159. bg-color="#cacce6"
  160. class="chart" />
  161. </template>
  162. <div v-else class="pieEmpty p1">训练数据不足</div>
  163. <p>全体学员训练近期</p>
  164. <p>专注力评估均值</p>
  165. </div>
  166. </el-col>
  167. </el-row>
  168. <el-row justify="space-between">
  169. <el-col :span="12">
  170. <div class="item">
  171. <CircleChart
  172. id="circleChart1"
  173. :key="pieChartData?.front"
  174. :data="pieChartData?.front || 0"
  175. height="200px"
  176. width="200px"
  177. color="#3a7fc2"
  178. bg-color="#e4e7f4"
  179. font-color="#3a7fc2"
  180. font-size="30px"
  181. :round-cap="Boolean(true)" />
  182. <p>初期训练</p>
  183. <p>专注力50以上训练占比</p>
  184. </div>
  185. </el-col>
  186. <el-col :span="12">
  187. <div class="item">
  188. <template v-if="pieChartData?.countRecord && pieChartData.countRecord > 4">
  189. <CircleChart
  190. id="circleChart2"
  191. :key="pieChartData?.after"
  192. :data="pieChartData?.after || 0"
  193. height="200px"
  194. width="200px"
  195. color="#5563ac"
  196. bg-color="#e4e7f4"
  197. font-color="#5563ac"
  198. font-size="30px"
  199. :round-cap="Boolean(true)" />
  200. </template>
  201. <div v-else class="pieEmpty p2">训练数据不足</div>
  202. <p>近期训练</p>
  203. <p>专注力50以上训练占比</p>
  204. </div>
  205. </el-col>
  206. </el-row>
  207. </template>
  208. <div v-else class="empty">
  209. <img src="../../../assets/empty.png" alt="数据为空" />
  210. <p>{{ pieMessage }}</p>
  211. </div>
  212. </div>
  213. </el-col>
  214. <!-- 学员专注力评分分级占比分析 -->
  215. <el-col :xs="24" :span="16">
  216. <div class="charts-item">
  217. <p class="title">样本每次训练专注力评分均值整体变化曲线</p>
  218. <template v-if="lineStatus">
  219. <line-chart
  220. id="lineChart1"
  221. :key="dataParams?.toString()"
  222. :dataSets="curveData || [[], []]"
  223. :dataSW="swCurveData || [[], []]"
  224. :dataKL="klCurveData || [[], []]"
  225. :dataZZL="zzlCurveData || [[], []]"
  226. height="558px"
  227. width="100%" />
  228. </template>
  229. <div v-else class="empty">
  230. <img src="../../../assets/empty.png" alt="数据为空" />
  231. <p>{{ lineMessage }}</p>
  232. </div>
  233. </div>
  234. </el-col>
  235. </el-row>
  236. </div>
  237. <div class="charts-container">
  238. <el-row :gutter="20">
  239. <!-- 学员专注力评分分级占比分析 -->
  240. <el-col :xs="24" :span="16">
  241. <div class="charts-item">
  242. <p class="title">学员专注力评分分级占比分析</p>
  243. <el-row v-if="pieStatus" justify="space-between">
  244. <el-col :xs="24" :span="12">
  245. <div class="bar">
  246. <PercentBarChart
  247. id="barChart1"
  248. :key="pieChartData?.frontProportion.toString()"
  249. width="400px"
  250. height="500px"
  251. title="全体学员初期训练专注力评分占比"
  252. :percent="pieChartData?.frontProportion.percentage"
  253. :data="pieChartData?.frontProportion.num"
  254. class="chart" />
  255. </div>
  256. </el-col>
  257. <el-col :xs="24" :span="12">
  258. <div class="bar">
  259. <PercentBarChart
  260. id="barChart2"
  261. :key="pieChartData?.afterProportion.toString()"
  262. width="400px"
  263. height="500px"
  264. title="全体学员训练近期专注力评分平均占比"
  265. :percent="pieChartData?.afterProportion.percentage"
  266. :data="pieChartData?.afterProportion.num"
  267. class="chart" />
  268. </div>
  269. </el-col>
  270. </el-row>
  271. <div v-else class="empty">
  272. <img src="../../../assets/empty.png" alt="数据为空" />
  273. <p>{{ pieMessage }}</p>
  274. </div>
  275. </div>
  276. </el-col>
  277. </el-row>
  278. </div>
  279. </template>
  280. <style scoped lang="scss">
  281. .charts-container {
  282. position: relative;
  283. padding: 30px 30px 20px;
  284. }
  285. .charts-item {
  286. position: relative;
  287. text-align: center;
  288. background: #fff;
  289. border: 1px solid #e8eaec;
  290. border-radius: 24px;
  291. .title {
  292. height: 78px;
  293. margin: 0;
  294. font-size: 18px;
  295. line-height: 78px;
  296. text-align: left;
  297. text-indent: 2em;
  298. &.pos {
  299. margin-bottom: -50px;
  300. }
  301. }
  302. .item {
  303. padding-bottom: 30px;
  304. }
  305. .chart {
  306. margin: 0 auto;
  307. }
  308. p {
  309. margin: 0;
  310. font-size: 16px;
  311. line-height: 24px;
  312. }
  313. .bar {
  314. margin-top: 60px;
  315. }
  316. .bottom {
  317. padding: 0 20px 20px;
  318. .el-col p {
  319. position: relative;
  320. box-sizing: border-box;
  321. padding: 10px 20px;
  322. color: #fff;
  323. text-align: left;
  324. white-space: nowrap;
  325. border-radius: 10px;
  326. &.l {
  327. background: #f8b865;
  328. }
  329. &.r {
  330. background: #8877ef;
  331. }
  332. span {
  333. display: block;
  334. }
  335. b {
  336. position: absolute;
  337. top: 22px;
  338. right: 20px;
  339. font-size: 26px;
  340. font-style: normal;
  341. }
  342. }
  343. }
  344. .empty {
  345. padding: 200px 0;
  346. }
  347. .pieEmpty {
  348. box-sizing: border-box;
  349. width: 180px;
  350. height: 180px;
  351. margin: 10px auto;
  352. color: red;
  353. border-radius: 50%;
  354. &.p1 {
  355. line-height: 160px;
  356. border: 5px solid #2f539b;
  357. }
  358. &.p2 {
  359. line-height: 120px;
  360. border: 20px solid #2f539b;
  361. }
  362. }
  363. }
  364. </style>