index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div class="train">
  3. <Header @confirmExit="getExit" :showTool="false" closeClass="close2"></Header>
  4. <div class="main">
  5. <div class="left"></div>
  6. <div class="menu" v-if="projectList.length" :class="projectList.length <= 10 ? 'menu1' : 'menu2'">
  7. <swiper :slides-per-view="5" :modules="[Grid]" :grid="{
  8. fill: projectList.length <= 10 ? 'row' : 'column',
  9. rows: 2,
  10. }" :space-between="20" :slides-per-group="10">
  11. <swiper-slide v-for="(item, index) in projectList " :key="index" @click="getOption(item)">
  12. <div class="li">
  13. <div class="pic"><img :src="'static/images/train/' + item.key + '.png'"></div>
  14. <div class="name">
  15. {{ item.name }}
  16. </div>
  17. </div>
  18. </swiper-slide>
  19. </swiper>
  20. </div>
  21. </div>
  22. <OptionWindow ref="optionWindowRef" :projectList="projectList" />
  23. </div>
  24. </template>
  25. <script setup name="TrainIndex" lang="ts">
  26. import { Swiper, SwiperSlide } from 'swiper/vue';
  27. import { Grid } from 'swiper/modules';
  28. import 'swiper/css';
  29. import 'swiper/css/grid';
  30. const router = useRouter();
  31. const { proxy } = getCurrentInstance() as any;
  32. const optionWindowRef = ref();
  33. const data = reactive<any>({
  34. projectList: [],
  35. timerManager: {},
  36. });
  37. const { projectList, timerManager } = toRefs(data);
  38. /**
  39. * 获取项目
  40. */
  41. const getExam = () => {
  42. proxy?.$http.train.projectList().then((res: any) => {
  43. projectList.value = proxy?.$utils.getProject(res.exams).filter((item: any) => {
  44. //只显示能开的
  45. return item.area.length > 0;
  46. });
  47. });
  48. };
  49. /**
  50. * 弹出选项窗口
  51. */
  52. const getOption = (data: any) => {
  53. optionWindowRef.value.open(data);
  54. };
  55. /**
  56. * 清空定时任务
  57. */
  58. const getClearTimer = () => {
  59. for (let key in timerManager.value) {
  60. if (timerManager.value.hasOwnProperty(key)) {
  61. clearInterval(timerManager.value[key])
  62. timerManager.value[key] = null;
  63. }
  64. }
  65. };
  66. /**
  67. * 初始化项目
  68. */
  69. const getInitExam = () => {
  70. getExam();
  71. //定时刷新
  72. timerManager.value.exam = setInterval(() => {
  73. getExam();
  74. }, 5000)
  75. };
  76. /**
  77. * 退出
  78. */
  79. const getExit = () => {
  80. router.go(-1);
  81. };
  82. onBeforeMount(() => {
  83. getInitExam();
  84. })
  85. onBeforeUnmount(() => {
  86. getClearTimer();
  87. })
  88. </script>
  89. <style lang="scss" scoped>
  90. $topPadding: 5.19rem;
  91. $waiPadding: 6.51rem;
  92. .main {
  93. width: calc(100% - ($waiPadding * 2));
  94. height: 72vh;
  95. padding-top: 10rem;
  96. margin: 0 auto;
  97. display: flex;
  98. justify-content: space-between;
  99. }
  100. .left {
  101. width: calc(23.4% - 20px);
  102. height: 72vh;
  103. }
  104. .menu {
  105. width: calc(100% - 23.4% - 20px);
  106. height: 72vh;
  107. .li {
  108. // width: calc((100% / 6) - 1rem + (1rem/6));
  109. // margin-right: 1rem;
  110. // margin-bottom: 1rem;
  111. width: 100%;
  112. height: calc((72vh / 2) - 10px);
  113. padding: 2.2vh 0;
  114. border-radius: 1.6rem;
  115. box-sizing: border-box;
  116. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
  117. display: flex;
  118. flex-wrap: wrap;
  119. justify-content: center;
  120. text-align: center;
  121. flex-shrink: 0;
  122. cursor: pointer;
  123. .name {
  124. width: 100%;
  125. font-size: 2.48rem;
  126. color: #1A293A;
  127. padding: 0.5rem 0;
  128. }
  129. .pic {
  130. width: 11.36vw;
  131. height: 11.36vw;
  132. border-radius: 50%;
  133. background: radial-gradient(78% 78% at 53% 50%, #07121A 0%, #2A4256 49%, #5180A9 100%);
  134. box-shadow: 0px 0px 2px 2px #FFFFFF;
  135. margin-bottom: 2vh;
  136. overflow: hidden;
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. flex-shrink: 0;
  141. img {
  142. max-width: 88%;
  143. max-height: 88%;
  144. transition: all 1s;
  145. }
  146. }
  147. &:hover {
  148. img {
  149. transform: translateY(-0.5vw);
  150. }
  151. }
  152. }
  153. .swiper-slide {
  154. border-radius: 1.6rem;
  155. overflow: hidden;
  156. }
  157. }
  158. .menu1 {
  159. .swiper-slide {
  160. margin-bottom: 20px;
  161. .li {
  162. background: radial-gradient(96% 96% at 2% 32%, #FFFFFF 0%, #FCFDFD 54%, #E1E4E7 100%);
  163. }
  164. &:nth-child(2),
  165. &:nth-child(4),
  166. &:nth-child(6),
  167. &:nth-child(7),
  168. &:nth-child(9),
  169. &:nth-child(11) {
  170. .li {
  171. background: radial-gradient(167% 126% at 97% 6%, #35FFC6 0%, #00FFE8 100%);
  172. }
  173. }
  174. }
  175. }
  176. .menu2 {
  177. display: flex;
  178. .swiper-slide {
  179. &:nth-child(1),
  180. &:nth-child(4),
  181. &:nth-child(5),
  182. &:nth-child(8),
  183. &:nth-child(9),
  184. &:nth-child(12),
  185. &:nth-child(13),
  186. &:nth-child(16),
  187. &:nth-child(17),
  188. &:nth-child(20),
  189. &:nth-child(21),
  190. &:nth-child(24),
  191. &:nth-child(25),
  192. &:nth-child(28),
  193. &:nth-child(29),
  194. &:nth-child(32),
  195. &:nth-child(33),
  196. &:nth-child(36),
  197. &:nth-child(37),
  198. &:nth-child(40),
  199. &:nth-child(41),
  200. &:nth-child(44) {
  201. .li {
  202. background: radial-gradient(96% 96% at 2% 32%, #FFFFFF 0%, #FCFDFD 54%, #E1E4E7 100%);
  203. }
  204. }
  205. &:nth-child(2),
  206. &:nth-child(3),
  207. &:nth-child(6),
  208. &:nth-child(7),
  209. &:nth-child(10),
  210. &:nth-child(11),
  211. &:nth-child(14),
  212. &:nth-child(15),
  213. &:nth-child(18),
  214. &:nth-child(19),
  215. &:nth-child(22),
  216. &:nth-child(23),
  217. &:nth-child(26),
  218. &:nth-child(27),
  219. &:nth-child(30),
  220. &:nth-child(31),
  221. &:nth-child(34),
  222. &:nth-child(35),
  223. &:nth-child(38),
  224. &:nth-child(39),
  225. &:nth-child(42),
  226. &:nth-child(43) {
  227. .li {
  228. background: radial-gradient(167% 126% at 97% 6%, #35FFC6 0%, #00FFE8 100%);
  229. }
  230. }
  231. }
  232. }
  233. ::v-deep(.menu) {
  234. .swiper-horizontal {
  235. width: 100%;
  236. }
  237. }
  238. @media screen and (max-width: 1450px) {
  239. .menu {
  240. .li {
  241. .name {
  242. font-size: 1.8rem;
  243. }
  244. .pic {
  245. width: 10vw;
  246. height: 10vw;
  247. }
  248. }
  249. }
  250. }
  251. </style>