practiceData.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import { Ref, computed, defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from '../index2.module.less';
  3. import { NButton, NDataTable, NNumberAnimation } from 'naive-ui';
  4. import numeral from 'numeral';
  5. import { useECharts } from '@/hooks/web/useECharts';
  6. import Pagination from '/src/components/pagination';
  7. import { getTestStat } from '@/views/data-module/api';
  8. import { getMinutes, getSecend, getTimes } from '/src/utils/dateFormat';
  9. import { useRoute, useRouter } from 'vue-router';
  10. import { getTrainingStatList } from '../../classList/api';
  11. import dayjs from 'dayjs';
  12. import TheEmpty from '/src/components/TheEmpty';
  13. export default defineComponent({
  14. name: 'home-practiceData',
  15. props: {
  16. timer: {
  17. type: Array,
  18. defaut: () => []
  19. }
  20. },
  21. setup(props, { expose }) {
  22. const chartRef = ref<HTMLDivElement | null>(null);
  23. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  24. const practiceFlag = ref(true);
  25. const payForm = reactive({
  26. height: '360px',
  27. width: '100%',
  28. practiceUserCount: 0,
  29. paymentAmount: 0,
  30. practiceDurationAvg: 0,
  31. practiceDays: 0,
  32. practiceDurationTotal: 0,
  33. dateList: [],
  34. timeList: []
  35. });
  36. const state = reactive({
  37. loading: false,
  38. pagination: {
  39. page: 1,
  40. rows: 10,
  41. pageTotal: 4
  42. },
  43. tableList: [] as any,
  44. goCourseVisiable: false
  45. });
  46. const currentTimer = computed(() => {
  47. return props.timer;
  48. });
  49. const columns = () => {
  50. return [
  51. {
  52. title: '日期',
  53. key: 'date'
  54. },
  55. {
  56. title: '练习人数',
  57. key: 'practiceUserCount',
  58. render(row: any) {
  59. return <>{row.practiceUserCount}人</>;
  60. }
  61. },
  62. {
  63. title: '平均每天练习时长',
  64. key: 'practiceDuration',
  65. render(row: any) {
  66. return (
  67. <>
  68. {' '}
  69. <>
  70. {row.practiceDuration
  71. ? getMinutes(row.practiceDuration) > 0
  72. ? getMinutes(row.practiceDuration) +
  73. '分' +
  74. getSecend(row.practiceDuration) +
  75. '秒'
  76. : getSecend(row.practiceDuration) + '秒'
  77. : 0 + '分钟'}
  78. </>
  79. </>
  80. );
  81. }
  82. }
  83. ];
  84. };
  85. const getList = async () => {
  86. try {
  87. const res = await getTrainingStatList({
  88. page: 1,
  89. rows: 999,
  90. ...getTimes(
  91. currentTimer.value,
  92. ['startTime', 'endTime'],
  93. 'YYYY-MM-DD'
  94. )
  95. });
  96. const res2 = await getTestStat({
  97. page: 1,
  98. rows: 999,
  99. ...getTimes(
  100. currentTimer.value,
  101. ['startTime', 'endTime'],
  102. 'YYYY-MM-DD'
  103. )
  104. });
  105. state.tableList = res.data.rows;
  106. payForm.practiceDurationAvg = res2.data.practiceDurationAvg;
  107. payForm.practiceUserCount = res2.data.practiceUserCount;
  108. payForm.dateList = res2.data.trainingStatDetailList.map((item: any) => {
  109. return item.date;
  110. });
  111. payForm.timeList = res2.data.trainingStatDetailList.map((item: any) => {
  112. return item.practiceUserCount;
  113. });
  114. setChart();
  115. } catch (e) {
  116. console.log(e);
  117. }
  118. };
  119. expose({ getList });
  120. const setChart = () => {
  121. setOptions({
  122. tooltip: {
  123. trigger: 'axis',
  124. axisPointer: {
  125. type: 'shadow'
  126. }
  127. },
  128. legend: {
  129. show: false,
  130. selected: {
  131. //在这里设置默认展示就ok了
  132. 练习人数: practiceFlag.value
  133. }
  134. },
  135. xAxis: {
  136. type: 'category',
  137. boundaryGap: true,
  138. axisLabel: {
  139. show: true,
  140. interval: 0
  141. },
  142. data: payForm.dateList
  143. },
  144. yAxis: [
  145. {
  146. type: 'value',
  147. axisLabel: {
  148. formatter: '{value}人'
  149. },
  150. axisTick: {
  151. show: false
  152. },
  153. splitArea: {
  154. show: false,
  155. areaStyle: {
  156. color: ['rgba(255,255,255,0.2)']
  157. }
  158. },
  159. minInterval: 1,
  160. splitNumber: 5
  161. }
  162. ],
  163. grid: {
  164. left: '1%',
  165. right: '1%',
  166. top: '2%',
  167. bottom: 0,
  168. containLabel: true
  169. },
  170. series: [
  171. {
  172. // smooth: true,
  173. data: payForm.timeList,
  174. type: 'line',
  175. smooth: true,
  176. // barWidth: '48px',
  177. // label: {
  178. // // 柱图头部显示值
  179. // show: true,
  180. // position: 'top',
  181. // color: '#333',
  182. // fontSize: '12px',
  183. // fontWeight: 600
  184. // },
  185. itemStyle: {
  186. normal: {
  187. //这里设置柱形图圆角 [左上角,右上角,右下角,左下角]
  188. barBorderRadius: [8, 8, 0, 0],
  189. color: '#3583FA'
  190. },
  191. emphasis: {
  192. color: '#3583FA' //hover时改变柱子颜色
  193. // borderWidth: 4,
  194. // borderColor: 'rgba(213, 233, 255,.4)',
  195. // borderType: 'solid'
  196. }
  197. } as any
  198. }
  199. ],
  200. formatter: (item: any) => {
  201. if (Array.isArray(item)) {
  202. return [
  203. item[0].axisValueLabel,
  204. ...item.map((d: any) => {
  205. return `<br/>${d.marker}<span style="margin-top:10px;margin-left:5px;font-size: 13px;font-weight: 500;
  206. color: #131415;font-weight: 600;
  207. margin-top:12px
  208. line-height: 18px;">练习人数: ${d.value}人 </span>`;
  209. })
  210. ].join('');
  211. } else {
  212. return item;
  213. }
  214. }
  215. // dataZoom: [
  216. // {
  217. // type: 'slider',
  218. // start: 5,
  219. // end: 100,
  220. // filterMode: 'empty'
  221. // }
  222. // ]
  223. });
  224. };
  225. onMounted(() => {
  226. getList();
  227. });
  228. return () => (
  229. <>
  230. <div class={styles.homeTrainData}>
  231. <div class={styles.TrainDataTop}>
  232. <div class={styles.TrainDataTopLeft}>
  233. <div class={styles.TrainDataItem}>
  234. <p class={styles.TrainDataItemTitle}>
  235. <div>
  236. <span>
  237. <NNumberAnimation
  238. from={0}
  239. to={payForm.practiceUserCount}></NNumberAnimation>
  240. </span>
  241. </div>
  242. </p>
  243. <p class={styles.TrainDataItemsubTitle}>练习人数</p>
  244. </div>
  245. <div class={styles.TrainDataItem}>
  246. <p class={styles.TrainDataItemTitle}>
  247. {getMinutes(payForm.practiceDurationAvg) > 0 ? (
  248. <div>
  249. <span>
  250. <NNumberAnimation
  251. from={0}
  252. to={getMinutes(
  253. payForm.practiceDurationAvg
  254. )}></NNumberAnimation>
  255. </span>
  256. </div>
  257. ) : null}
  258. <div>
  259. <span>
  260. <NNumberAnimation
  261. from={0}
  262. to={getSecend(
  263. payForm.practiceDurationAvg
  264. )}></NNumberAnimation>
  265. </span>
  266. </div>
  267. </p>
  268. <p class={styles.TrainDataItemsubTitle}>平均每天练习时长</p>
  269. </div>
  270. </div>
  271. <div class={styles.TrainDataTopRight}>
  272. {/* <div
  273. onClick={() => {
  274. practiceFlag.value = !practiceFlag.value;
  275. setChart();
  276. }}
  277. class={[
  278. styles.DataTopRightItem,
  279. practiceFlag.value ? '' : styles.DataTopRightItemDis
  280. ]}>
  281. <div
  282. class={[
  283. styles.DataTopRightDot,
  284. styles.DataTopRightDotBlue
  285. ]}></div>
  286. <p>练习人数</p>
  287. </div> */}
  288. </div>
  289. </div>
  290. <div class={styles.chatrs}>
  291. <div
  292. ref={chartRef}
  293. style={{ height: payForm.height, width: payForm.width }}></div>
  294. </div>
  295. <div class={styles.tableWrap}>
  296. <NDataTable
  297. v-slots={{
  298. empty: () => <TheEmpty></TheEmpty>
  299. }}
  300. class={styles.classTable}
  301. loading={state.loading}
  302. columns={columns()}
  303. data={state.tableList}></NDataTable>
  304. {/* <Pagination
  305. v-model:page={state.pagination.page}
  306. v-model:pageSize={state.pagination.rows}
  307. v-model:pageTotal={state.pagination.pageTotal}
  308. onList={getList}
  309. sync
  310. saveKey="orchestraRegistration-key"
  311. /> */}
  312. </div>
  313. </div>
  314. </>
  315. );
  316. }
  317. });