东西湖大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.4 KiB

2 months ago
  1. <template>
  2. <!-- 今日图书借还 -->
  3. <div class="screen-item total-lending">
  4. <div class="common-title">今日图书借还</div>
  5. <div class="small-module module-content">
  6. <div class="chart-wrapper" style="height: calc(100%);">
  7. <LineChartService :chart-data="chartData" />
  8. </div>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import LineChartService from '@/components/echart/lineChartService'
  14. import { FetchHalfYearBRNum, FetchTodayJH } from '@/api/library'
  15. export default {
  16. name: 'TodayBorrowed',
  17. components: {
  18. LineChartService
  19. },
  20. data() {
  21. return {
  22. chartData: {
  23. returnData: [],
  24. borrowedData: []
  25. }
  26. }
  27. },
  28. created() {
  29. },
  30. mounted() {
  31. this.getTodayJH()
  32. },
  33. methods: {
  34. getHalfYearBRNum() {
  35. FetchHalfYearBRNum().then(res => {
  36. if (res.errCode === 0) {
  37. this.chartData.borrowedData = res.data.borrow
  38. this.chartData.returnData = res.data.return
  39. } else {
  40. this.$message.error('接口错误')
  41. }
  42. })
  43. },
  44. getTodayJH() {
  45. FetchTodayJH().then(res => {
  46. this.chartData = {
  47. timeData: [],
  48. returnData: [],
  49. borrowedData: []
  50. }
  51. const result = res.data
  52. const time = ['07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00']
  53. time.forEach((hour, index) => {
  54. // 查找 result 中是否有对应的 logHour
  55. const foundItem = result.find(item => item.logHour === index + 7) // 因为 logHour 是从 7 开始,所以需要加上 7
  56. if (foundItem) {
  57. // 如果找到了对应的 logHour,则将数据加入 chartDayData
  58. this.chartData.timeData.push(`${foundItem.logHour}:00`)
  59. this.chartData.returnData.push(foundItem.hccDay)
  60. this.chartData.borrowedData.push(foundItem.jccDay)
  61. } else {
  62. // 如果没找到对应的 logHour,则将默认值加入 chartDayData
  63. this.chartData.timeData.push(`${hour}`)
  64. this.chartData.returnData.push(0) // 默认值为 0
  65. this.chartData.borrowedData.push(0) // 默认值为 0
  66. }
  67. })
  68. }).catch(error => {
  69. console.error('Error', error)
  70. })
  71. }
  72. }
  73. }
  74. </script>
  75. <style lang="scss">
  76. @import "~@/assets/styles/index.scss";
  77. </style>