index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <div class="teaching-activity-analysis">
  3. <!-- 页面头部 -->
  4. <div class="header">
  5. <h1>📚 教学活动分析</h1>
  6. <p>为教学过程及课程内容改进提供数据支撑</p>
  7. </div>
  8. <!-- 筛选条件 -->
  9. <div class="filter-section">
  10. <h3>🔍 数据筛选</h3>
  11. <div class="filter-controls">
  12. <div class="filter-group">
  13. <label>选择课程</label>
  14. <a-select
  15. v-model:value="filters.courseId"
  16. placeholder="全部课程"
  17. @change="updateStats"
  18. :loading="loading"
  19. allowClear
  20. >
  21. <a-select-option v-for="option in courseOptions" :key="option.courseId" :value="option.courseId">
  22. {{ option.courseName }}
  23. </a-select-option>
  24. </a-select>
  25. </div>
  26. <div class="filter-group">
  27. <label>时间范围</label>
  28. <a-select v-model:value="filters.timeRange" @change="updateStats">
  29. <a-select-option :value="1">最近30天</a-select-option>
  30. <a-select-option :value="2">最近90天</a-select-option>
  31. <a-select-option :value="3">最近180天</a-select-option>
  32. <a-select-option :value="4">最近一年</a-select-option>
  33. </a-select>
  34. </div>
  35. <div class="filter-group">
  36. <a-button type="primary" @click="updateStats" :loading="loading">查询</a-button>
  37. </div>
  38. </div>
  39. </div>
  40. <!-- 核心统计数据 -->
  41. <div class="stats-grid">
  42. <div class="stat-card">
  43. <h3>📖 文档观看统计</h3>
  44. <div class="stat-number">{{ stats.allUserCount }}</div>
  45. <div class="stat-label">总观看人数</div>
  46. <div class="stat-number">{{ stats.alreadyUserCount }}</div>
  47. <div class="stat-label">完成观看人数</div>
  48. <div class="completion-rate">{{ stats.finishRate }}%</div>
  49. <div class="stat-label">完成率</div>
  50. </div>
  51. <div class="stat-card">
  52. <h3>🚪 文档跳出分析</h3>
  53. <div class="stat-number">{{ stats.allHourCount }}</div>
  54. <div class="stat-label">总跳出次数</div>
  55. <div class="stat-number">{{ stats.allHourCount }}%</div>
  56. <div class="stat-label">跳出率</div>
  57. <div class="stat-number">{{ stats.jumpAvgTime }}</div>
  58. <div class="stat-label">平均跳出时间</div>
  59. </div>
  60. <div class="stat-card" v-if="forumType">
  61. <h3>💬 讨论互动统计</h3>
  62. <div class="stat-number">{{ stats.totalDiscussions }}</div>
  63. <div class="stat-label">讨论总数</div>
  64. <div class="stat-number">{{ stats.totalReplies }}</div>
  65. <div class="stat-label">回帖总数</div>
  66. <div class="stat-number">{{ stats.avgRepliesPerDiscussion }}</div>
  67. <div class="stat-label">平均回帖数</div>
  68. </div>
  69. </div>
  70. <!-- 每日访问统计图表 -->
  71. <div class="chart-container">
  72. <h3>📈 开课每日访问人数统计</h3>
  73. <div ref="dailyVisitsChart" class="chart"></div>
  74. </div>
  75. <!-- 每周发帖回帖统计 -->
  76. <div class="weekly-stats" v-if="forumType">
  77. <div class="weekly-card">
  78. <h4>👨‍🎓 学员每周发帖统计</h4>
  79. <div class="weekly-number">{{ weeklyStats.studentWeeklyPosts }}</div>
  80. <div class="weekly-label">本周发帖数</div>
  81. <div class="weekly-number">{{ weeklyStats.studentWeeklyReplies }}</div>
  82. <div class="weekly-label">本周回帖数</div>
  83. <div class="weekly-number">{{ weeklyStats.studentAvgPostsPerDay }}</div>
  84. <div class="weekly-label">日均发帖数</div>
  85. </div>
  86. <div class="weekly-card">
  87. <h4>👨‍🏫 教员每周发帖统计</h4>
  88. <div class="weekly-number">{{ weeklyStats.teacherWeeklyPosts }}</div>
  89. <div class="weekly-label">本周发帖数</div>
  90. <div class="weekly-number">{{ weeklyStats.teacherWeeklyReplies }}</div>
  91. <div class="weekly-label">本周回帖数</div>
  92. <div class="weekly-number">{{ weeklyStats.teacherAvgPostsPerDay }}</div>
  93. <div class="weekly-label">日均发帖数</div>
  94. </div>
  95. </div>
  96. <!-- 讨论详情表格 -->
  97. <div class="data-table" v-if="forumType">
  98. <h3>💬 课程讨论详情</h3>
  99. <a-table
  100. :columns="discussionColumns"
  101. :data-source="discussionData"
  102. :pagination="discussionPagination"
  103. :loading="loading"
  104. row-key="id"
  105. @change="handleDiscussionTableChange"
  106. />
  107. </div>
  108. <!-- 文档观看详细统计 -->
  109. <div class="data-table">
  110. <h3>📚 文档观看详细统计</h3>
  111. <a-table
  112. :columns="documentColumns"
  113. :data-source="documentData"
  114. :pagination="documentPagination"
  115. :loading="loading"
  116. row-key="id"
  117. @change="handleDocumentTableChange"
  118. />
  119. </div>
  120. </div>
  121. </template>
  122. <script setup>
  123. import { ref, reactive, onMounted, nextTick, h } from 'vue'
  124. import * as echarts from 'echarts'
  125. import {
  126. getCourseOptions,
  127. getTeachingStats,
  128. documentJumpStatistic,
  129. getWeeklyStats,
  130. getDailyVisits,
  131. getDiscussionData,
  132. getDocumentStats
  133. } from '@/api/statisticalAnalysis/analysisTeachingActivities'
  134. import tool from '@/utils/tool'
  135. const forumType = computed(() => (tool.dictList('FORUM_TYPE')[0].value == 1 ? true : false))
  136. console.log('什么呢的',tool.dictList('FORUM_TYPE')[0])
  137. // 响应式数据
  138. const filters = reactive({
  139. courseId: '',
  140. timeRange: 1
  141. })
  142. const stats = reactive({
  143. totalDiscussions: 0,
  144. totalReplies: 0,
  145. avgRepliesPerDiscussion: 0
  146. })
  147. const weeklyStats = reactive({
  148. studentWeeklyPosts: 0,
  149. studentWeeklyReplies: 0,
  150. studentAvgPostsPerDay: 0,
  151. teacherWeeklyPosts: 0,
  152. teacherWeeklyReplies: 0,
  153. teacherAvgPostsPerDay: 0
  154. })
  155. // 课程选项
  156. const courseOptions = ref([])
  157. // 图表引用
  158. const dailyVisitsChart = ref(null)
  159. let chartInstance = null
  160. // 讨论表格列定义
  161. const discussionColumns = [
  162. {
  163. title: '讨论主题',
  164. dataIndex: 'title',
  165. key: 'title'
  166. },
  167. {
  168. title: '发起人',
  169. dataIndex: 'author',
  170. key: 'author'
  171. },
  172. {
  173. title: '发起时间',
  174. dataIndex: 'createTime',
  175. key: 'createTime'
  176. },
  177. {
  178. title: '回帖数',
  179. dataIndex: 'replyCount',
  180. key: 'replyCount'
  181. },
  182. {
  183. title: '最后回复',
  184. dataIndex: 'lastReplyTime',
  185. key: 'lastReplyTime'
  186. }
  187. ]
  188. // 讨论数据
  189. const discussionData = ref([])
  190. const discussionPagination = reactive({
  191. current: 1,
  192. pageSize: 10,
  193. total: 0
  194. })
  195. // 文档表格列定义
  196. const documentColumns = [
  197. {
  198. title: '文档名称',
  199. dataIndex: 'fileName',
  200. key: 'fileName'
  201. },
  202. {
  203. title: '文档类型',
  204. dataIndex: 'extendName',
  205. key: 'extendName',
  206. width: '100px'
  207. },
  208. {
  209. title: '观看人数',
  210. dataIndex: 'seeNum',
  211. key: 'seeNum',
  212. width: '100px'
  213. },
  214. {
  215. title: '完成人数',
  216. dataIndex: 'finishNum',
  217. key: 'finishNum',
  218. width: '100px'
  219. },
  220. {
  221. title: '完成率',
  222. dataIndex: 'finishRate',
  223. key: 'finishRate',
  224. customRender: ({ text }) => {
  225. const rate = parseFloat(text)
  226. const className = rate >= 70 ? 'completion-rate' : rate < 50 ? 'low-engagement' : ''
  227. return h('span', { class: className }, `${text}%`)
  228. }
  229. },
  230. {
  231. title: '平均阅读时长',
  232. dataIndex: 'jumpAvgTime',
  233. key: 'jumpAvgTime',
  234. width: '130px'
  235. },
  236. {
  237. title: '跳出率',
  238. dataIndex: 'jumpRate',
  239. key: 'jumpRate',
  240. customRender: ({ text }) => {
  241. const rate = parseFloat(text)
  242. const className = rate > 30 ? 'low-engagement' : ''
  243. return h('span', { class: className }, `${text}%`)
  244. }
  245. },
  246. {
  247. title: '下载次数',
  248. dataIndex: 'downNum',
  249. key: 'downNum',
  250. width: '100px'
  251. }
  252. ]
  253. // 文档数据
  254. const documentData = ref([])
  255. const documentPagination = reactive({
  256. current: 1,
  257. pageSize: 10,
  258. total: 0
  259. })
  260. // 图表数据
  261. const chartData = reactive({
  262. dates: [],
  263. visits: []
  264. })
  265. // 加载状态
  266. const loading = ref(false)
  267. // 初始化图表
  268. const initChart = () => {
  269. if (!dailyVisitsChart.value) return
  270. chartInstance = echarts.init(dailyVisitsChart.value)
  271. updateChartData()
  272. // 响应式处理
  273. window.addEventListener('resize', () => {
  274. chartInstance?.resize()
  275. })
  276. }
  277. // 更新图表数据
  278. const updateChartData = () => {
  279. if (!chartInstance) return
  280. const days = filters.timeRange
  281. const { dates, visits } = chartData
  282. const option = {
  283. title: {
  284. text: `最近${days}天访问人数趋势`,
  285. left: 'center',
  286. textStyle: {
  287. color: '#2c3e50',
  288. fontSize: 16,
  289. fontWeight: 'bold'
  290. }
  291. },
  292. tooltip: {
  293. trigger: 'axis',
  294. backgroundColor: 'rgba(255, 255, 255, 0.95)',
  295. borderColor: '#3498db',
  296. borderWidth: 1,
  297. textStyle: {
  298. color: '#333'
  299. },
  300. formatter: function (params) {
  301. let result = params[0].name + '<br/>'
  302. params.forEach((param) => {
  303. result += param.marker + param.seriesName + ': ' + param.value + '人<br/>'
  304. })
  305. return result
  306. }
  307. },
  308. legend: {
  309. data: ['访问人数'],
  310. top: 30,
  311. textStyle: {
  312. color: '#2c3e50'
  313. }
  314. },
  315. grid: {
  316. left: '3%',
  317. right: '4%',
  318. bottom: '3%',
  319. containLabel: true
  320. },
  321. xAxis: {
  322. type: 'category',
  323. boundaryGap: false,
  324. data: dates,
  325. axisLine: {
  326. lineStyle: {
  327. color: '#bdc3c7'
  328. }
  329. },
  330. axisLabel: {
  331. color: '#2c3e50',
  332. rotate: days > 30 ? 45 : 0
  333. }
  334. },
  335. yAxis: {
  336. type: 'value',
  337. name: '访问人数',
  338. nameTextStyle: {
  339. color: '#2c3e50'
  340. },
  341. axisLine: {
  342. lineStyle: {
  343. color: '#bdc3c7'
  344. }
  345. },
  346. axisLabel: {
  347. color: '#2c3e50'
  348. },
  349. splitLine: {
  350. lineStyle: {
  351. color: '#ecf0f1'
  352. }
  353. }
  354. },
  355. series: [
  356. {
  357. name: '访问人数',
  358. type: 'line',
  359. smooth: true,
  360. data: visits,
  361. itemStyle: {
  362. color: '#3498db'
  363. },
  364. areaStyle: {
  365. color: {
  366. type: 'linear',
  367. x: 0,
  368. y: 0,
  369. x2: 0,
  370. y2: 1,
  371. colorStops: [
  372. {
  373. offset: 0,
  374. color: 'rgba(52, 152, 219, 0.3)'
  375. },
  376. {
  377. offset: 1,
  378. color: 'rgba(52, 152, 219, 0.1)'
  379. }
  380. ]
  381. }
  382. },
  383. lineStyle: {
  384. width: 3
  385. },
  386. symbol: 'circle',
  387. symbolSize: 8
  388. }
  389. ]
  390. }
  391. chartInstance.setOption(option, true)
  392. }
  393. // 获取课程选项
  394. const loadCourseOptions = async () => {
  395. try {
  396. const response = await getCourseOptions()
  397. courseOptions.value = response
  398. } catch (error) {
  399. console.error('获取课程选项失败:', error)
  400. }
  401. }
  402. // 获取核心统计数据
  403. const loadTeachingStats = async () => {
  404. try {
  405. const response = await getTeachingStats({
  406. courseId: filters.courseId,
  407. type: filters.timeRange
  408. })
  409. const statistic = await documentJumpStatistic({
  410. courseId: filters.courseId,
  411. type: filters.timeRange
  412. })
  413. Object.assign(stats, response, statistic)
  414. } catch (error) {
  415. console.error('获取统计数据失败:', error)
  416. }
  417. }
  418. // 获取每周统计数据
  419. const loadWeeklyStats = async () => {
  420. try {
  421. const response = await getWeeklyStats({
  422. courseId: filters.courseId
  423. })
  424. Object.assign(weeklyStats, response)
  425. } catch (error) {
  426. console.error('获取每周统计数据失败:', error)
  427. }
  428. }
  429. // 获取每日访问数据
  430. const loadDailyVisits = async () => {
  431. try {
  432. const response = await getDailyVisits({
  433. type: filters.timeRange,
  434. courseId: filters.courseId
  435. })
  436. chartData.dates = response.map((r) => r.TIME)
  437. chartData.visits = response.map((r) => r.num)
  438. updateChartData()
  439. } catch (error) {
  440. console.error('获取每日访问数据失败:', error)
  441. }
  442. }
  443. // 获取讨论数据
  444. const loadDiscussionData = async () => {
  445. try {
  446. const response = await getDiscussionData({
  447. courseId: filters.courseId,
  448. page: discussionPagination.current,
  449. pageSize: discussionPagination.pageSize
  450. })
  451. discussionData.value = response.list
  452. discussionPagination.total = response.total
  453. } catch (error) {
  454. console.error('获取讨论数据失败:', error)
  455. }
  456. }
  457. // 获取文档数据
  458. const loadDocumentData = async () => {
  459. try {
  460. const response = await getDocumentStats({
  461. courseId: filters.courseId,
  462. page: documentPagination.current,
  463. pageSize: documentPagination.pageSize,
  464. type: filters.timeRange
  465. })
  466. documentData.value = response
  467. documentPagination.total = response.total
  468. } catch (error) {
  469. console.error('获取文档数据失败:', error)
  470. }
  471. }
  472. // 更新所有数据
  473. const updateStats = async () => {
  474. loading.value = true
  475. try {
  476. await Promise.all([
  477. loadTeachingStats(),
  478. loadWeeklyStats(),
  479. loadDailyVisits(),
  480. loadDiscussionData(),
  481. loadDocumentData()
  482. ])
  483. } finally {
  484. loading.value = false
  485. }
  486. }
  487. // 初始化所有数据
  488. const initData = async () => {
  489. loading.value = true
  490. try {
  491. await Promise.all([
  492. loadCourseOptions(),
  493. loadTeachingStats(),
  494. loadWeeklyStats(),
  495. loadDailyVisits(),
  496. loadDiscussionData(),
  497. loadDocumentData()
  498. ])
  499. } finally {
  500. loading.value = false
  501. }
  502. }
  503. // 处理讨论表格分页变化
  504. const handleDiscussionTableChange = (pagination) => {
  505. discussionPagination.current = pagination.current
  506. discussionPagination.pageSize = pagination.pageSize
  507. loadDiscussionData()
  508. }
  509. // 处理文档表格分页变化
  510. const handleDocumentTableChange = (pagination) => {
  511. documentPagination.current = pagination.current
  512. documentPagination.pageSize = pagination.pageSize
  513. loadDocumentData()
  514. }
  515. // 组件挂载后初始化
  516. onMounted(() => {
  517. nextTick(() => {
  518. initChart()
  519. initData()
  520. })
  521. })
  522. </script>
  523. <style scoped>
  524. .teaching-activity-analysis {
  525. padding: 20px;
  526. /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
  527. }
  528. .header {
  529. background: rgba(255, 255, 255, 0.95);
  530. backdrop-filter: blur(10px);
  531. border-radius: 15px;
  532. padding: 30px;
  533. margin-bottom: 30px;
  534. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  535. text-align: center;
  536. }
  537. .header h1 {
  538. color: #2c3e50;
  539. font-size: 2.5em;
  540. margin-bottom: 10px;
  541. }
  542. .header p {
  543. color: #7f8c8d;
  544. font-size: 1.1em;
  545. }
  546. .filter-section {
  547. background: rgba(255, 255, 255, 0.95);
  548. backdrop-filter: blur(10px);
  549. border-radius: 15px;
  550. padding: 25px;
  551. margin-bottom: 30px;
  552. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  553. }
  554. .filter-section h3 {
  555. color: #2c3e50;
  556. margin-bottom: 20px;
  557. font-size: 1.5em;
  558. }
  559. .filter-controls {
  560. display: grid;
  561. grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  562. gap: 15px;
  563. align-items: end;
  564. }
  565. .filter-group {
  566. display: flex;
  567. flex-direction: column;
  568. }
  569. .filter-group label {
  570. margin-bottom: 8px;
  571. color: #2c3e50;
  572. font-weight: 600;
  573. }
  574. .stats-grid {
  575. display: grid;
  576. grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  577. gap: 25px;
  578. margin-bottom: 30px;
  579. }
  580. .stat-card {
  581. background: rgba(255, 255, 255, 0.95);
  582. backdrop-filter: blur(10px);
  583. border-radius: 15px;
  584. padding: 25px;
  585. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  586. transition: transform 0.3s ease, box-shadow 0.3s ease;
  587. }
  588. .stat-card:hover {
  589. transform: translateY(-5px);
  590. box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  591. }
  592. .stat-card h3 {
  593. color: #2c3e50;
  594. margin-bottom: 15px;
  595. font-size: 1.3em;
  596. border-bottom: 2px solid #3498db;
  597. padding-bottom: 10px;
  598. }
  599. .stat-number {
  600. font-size: 2.5em;
  601. font-weight: bold;
  602. color: #3498db;
  603. margin-bottom: 10px;
  604. }
  605. .stat-label {
  606. color: #7f8c8d;
  607. font-size: 0.9em;
  608. }
  609. .chart-container {
  610. background: rgba(255, 255, 255, 0.95);
  611. backdrop-filter: blur(10px);
  612. border-radius: 15px;
  613. padding: 25px;
  614. margin-bottom: 30px;
  615. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  616. }
  617. .chart-container h3 {
  618. color: #2c3e50;
  619. margin-bottom: 20px;
  620. font-size: 1.5em;
  621. }
  622. .chart {
  623. height: 400px;
  624. border-radius: 10px;
  625. }
  626. .weekly-stats {
  627. display: grid;
  628. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  629. gap: 20px;
  630. margin-bottom: 30px;
  631. }
  632. .weekly-card {
  633. background: rgba(255, 255, 255, 0.95);
  634. backdrop-filter: blur(10px);
  635. border-radius: 15px;
  636. padding: 20px;
  637. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  638. }
  639. .weekly-card h4 {
  640. color: #2c3e50;
  641. margin-bottom: 15px;
  642. font-size: 1.2em;
  643. }
  644. .weekly-number {
  645. font-size: 2em;
  646. font-weight: bold;
  647. color: #3498db;
  648. margin-bottom: 5px;
  649. }
  650. .weekly-label {
  651. color: #7f8c8d;
  652. font-size: 0.9em;
  653. }
  654. .data-table {
  655. background: rgba(255, 255, 255, 0.95);
  656. backdrop-filter: blur(10px);
  657. border-radius: 15px;
  658. padding: 25px;
  659. margin-bottom: 30px;
  660. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  661. }
  662. .data-table h3 {
  663. color: #2c3e50;
  664. margin-bottom: 20px;
  665. font-size: 1.5em;
  666. }
  667. :deep(.completion-rate) {
  668. color: #27ae60;
  669. font-weight: bold;
  670. font-size: 2.5em;
  671. }
  672. :deep(.low-engagement) {
  673. color: #e74c3c;
  674. font-weight: bold;
  675. }
  676. @media (max-width: 768px) {
  677. .stats-grid {
  678. grid-template-columns: 1fr;
  679. }
  680. .filter-controls {
  681. grid-template-columns: 1fr;
  682. }
  683. .header h1 {
  684. font-size: 2em;
  685. }
  686. .weekly-stats {
  687. grid-template-columns: 1fr;
  688. }
  689. }
  690. </style>