curriculum.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <!--
  2. * @FileDescription: 课表
  3. * @Author: 黄琪勇
  4. * @Date:2024-03-28 19:01:23
  5. -->
  6. <template>
  7. <navContainer :navs="navs">
  8. <div class="curriculum">
  9. <ElScrollbar class="elScrollbar">
  10. <div class="calendarCon"><myCalendar v-model="dateValue" @monthChange="handleMonthChange" :dayMarks="curriculumByMonth" /></div>
  11. <div class="curriculumCon">
  12. <el-skeleton class="elSkeleton" :loading="skeletonIng" :count="1">
  13. <template #template>
  14. <div class="elSkeletonCon">
  15. <el-skeleton-item class="elSkeletonItem" variant="p" />
  16. <el-skeleton-item class="elSkeletonItem" variant="p" />
  17. <el-skeleton-item class="elSkeletonItem" variant="h1" />
  18. <el-skeleton-item class="elSkeletonItem" variant="h1" />
  19. </div>
  20. </template>
  21. <template #default>
  22. <ElScrollbar v-if="curriculumByDay.length || loading" v-loading="loading" class="listElScrollbar">
  23. <component
  24. @update="handleDayChange(dateValue)"
  25. :curriculumData="curriculumByDay"
  26. :is="userStoreHook.roles === 'GYM' ? curriculumList_gym : curriculumList_gyt"
  27. />
  28. </ElScrollbar>
  29. <el-empty
  30. v-if="!curriculumByDay.length && !loading"
  31. class="empty"
  32. :image="require('@/img/layout/empty1.png')"
  33. description="您还没有待上课程哦~"
  34. />
  35. </template>
  36. </el-skeleton>
  37. </div>
  38. </ElScrollbar>
  39. </div>
  40. </navContainer>
  41. </template>
  42. <script setup lang="ts">
  43. import { format } from "@/libs/tools"
  44. import myCalendar from "@/components/myCalendar"
  45. import { ref, shallowRef, watch } from "vue"
  46. import navContainer from "@/businessComponents/navContainer"
  47. import userStore from "@/store/modules/user"
  48. import curriculumList_gym from "./components/curriculumList/curriculumList_gym.vue"
  49. import curriculumList_gyt from "./components/curriculumList/curriculumList_gyt.vue"
  50. import {
  51. getCourseScheduleDateByMonth_gym,
  52. getCourseSchedulesWithDate_gym,
  53. getCourseScheduleDateByMonth_gyt,
  54. getCourseSchedulesWithDate_gyt
  55. } from "@/api/curriculum.api"
  56. import { httpAjax } from "@/plugin/httpAjax"
  57. import { CODE_ERR_CANCELED } from "@/libs/auth"
  58. import { ElMessage } from "element-plus"
  59. import { useRoute } from "vue-router"
  60. const route = useRoute()
  61. const userStoreHook = userStore()
  62. const navs = [
  63. {
  64. name: "主页",
  65. url: "/"
  66. },
  67. {
  68. name: "课表"
  69. }
  70. ]
  71. const curriculumByMonth = shallowRef<string[]>([])
  72. const curriculumByDay = shallowRef<any[]>([])
  73. const dateValue = ref(route.query.date ? new Date(route.query.date as string) : new Date())
  74. const loading = ref(false)
  75. const skeletonIng = ref(true)
  76. let monthController: AbortController
  77. let dayController: AbortController
  78. watch(dateValue, () => {
  79. handleDayChange(dateValue.value)
  80. })
  81. handleMonthChange(dateValue.value)
  82. handleDayChange(dateValue.value)
  83. function handleMonthChange(date: Date) {
  84. getCurriculumByMonth(format(date, "yyyy-mm"))
  85. }
  86. function handleDayChange(date: Date) {
  87. getCurriculumByDay(format(date, "yyyy-mm-dd"))
  88. }
  89. function getCurriculumByDay(day: string) {
  90. if (dayController) {
  91. dayController.abort()
  92. }
  93. dayController = new AbortController()
  94. if (userStoreHook.roles === "GYM") {
  95. loading.value = true
  96. httpAjax(getCourseSchedulesWithDate_gym, day, dayController).then(res => {
  97. // 自己关闭的时候不取消加载
  98. if (res.code === CODE_ERR_CANCELED) {
  99. return
  100. }
  101. skeletonIng.value = false
  102. loading.value = false
  103. if (res.code === 200) {
  104. curriculumByDay.value = res.data?.rows || []
  105. } else {
  106. ElMessage({
  107. showClose: true,
  108. message: res.message,
  109. type: "error"
  110. })
  111. }
  112. })
  113. } else {
  114. loading.value = true
  115. httpAjax(getCourseSchedulesWithDate_gyt, day, dayController).then(res => {
  116. if (res.code === CODE_ERR_CANCELED) {
  117. return
  118. }
  119. skeletonIng.value = false
  120. loading.value = false
  121. if (res.code === 200) {
  122. curriculumByDay.value = res.data?.rows || []
  123. } else {
  124. ElMessage({
  125. showClose: true,
  126. message: res.message,
  127. type: "error"
  128. })
  129. }
  130. })
  131. }
  132. }
  133. function getCurriculumByMonth(month: string) {
  134. if (monthController) {
  135. monthController.abort()
  136. }
  137. monthController = new AbortController()
  138. if (userStoreHook.roles === "GYM") {
  139. httpAjax(getCourseScheduleDateByMonth_gym, month, monthController).then(res => {
  140. if (res.code === 200) {
  141. curriculumByMonth.value = res.data || []
  142. }
  143. })
  144. } else {
  145. httpAjax(getCourseScheduleDateByMonth_gyt, month, monthController).then(res => {
  146. if (res.code === 200) {
  147. curriculumByMonth.value = res.data || []
  148. }
  149. })
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .curriculum {
  155. width: 100%;
  156. height: 100%;
  157. & > :deep(.elScrollbar) {
  158. > .el-scrollbar__wrap {
  159. overflow-x: hidden;
  160. > .el-scrollbar__view {
  161. width: 100%;
  162. display: flex;
  163. padding: 50px 50px 0 20px;
  164. }
  165. }
  166. }
  167. .calendarCon {
  168. flex-shrink: 0;
  169. width: 787px;
  170. height: 729px;
  171. background: url("@/img/curriculum/kuang.png") no-repeat;
  172. background-size: 100% 100%;
  173. padding: 56px 72px 72px 128px;
  174. }
  175. .curriculumCon {
  176. margin-left: 26px;
  177. flex-grow: 1;
  178. overflow: hidden;
  179. height: 729px;
  180. background: linear-gradient(180deg, #ffd783 0%, #ffebc1 100%);
  181. border-radius: 42px;
  182. padding: 30px 0;
  183. & > :deep(.listElScrollbar) {
  184. > .el-loading-mask {
  185. margin: 0 30px;
  186. border-radius: 42px;
  187. }
  188. > .el-scrollbar__wrap {
  189. overflow-x: hidden;
  190. > .el-scrollbar__view {
  191. width: 100%;
  192. padding: 0 30px;
  193. }
  194. }
  195. }
  196. & > :deep(.empty) {
  197. height: 100%;
  198. background: #ffffff;
  199. border-radius: 35px;
  200. padding: 0;
  201. margin: 0 30px;
  202. .el-empty__image {
  203. width: 360px;
  204. }
  205. }
  206. .elSkeleton {
  207. padding: 0 30px;
  208. .elSkeletonCon {
  209. background: #ffffff;
  210. border-radius: 35px;
  211. padding: 20px 30px;
  212. margin-bottom: 18px;
  213. &:last-child {
  214. margin-bottom: 0;
  215. }
  216. > .elSkeletonItem {
  217. &:nth-child(1) {
  218. height: 30px;
  219. }
  220. &:nth-child(2) {
  221. margin-top: 16px;
  222. height: 45px;
  223. }
  224. &:nth-child(3) {
  225. margin-top: 14px;
  226. height: 28px;
  227. }
  228. &:nth-child(4) {
  229. margin-top: 4px;
  230. height: 22px;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }
  237. </style>
  238. <style lang="scss"></style>