index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="train">
  3. <Header @confirmExit="getExit" :showTool="false" closeClass="close2"></Header>
  4. <div class="menu" v-if="projectList.length" :class="projectList.length <= 12 ? 'menu1' : 'menu2'" :key="projectList.length">
  5. <swiper
  6. :slides-per-view="6"
  7. :modules="[Grid]"
  8. :grid="{
  9. fill: projectList.length <= 12 ? 'row' : 'column',
  10. rows: 2,
  11. }"
  12. :space-between="20"
  13. :slides-per-group="12"
  14. >
  15. <swiper-slide v-for="(item, index) in projectList " :key="index" @click="getOption(item)">
  16. <div class="li">
  17. <div>
  18. <div class="pic"><img :src="'static/images/train/' + item.key + '.png'" /></div>
  19. <div class="name">
  20. {{ item.name }}
  21. </div>
  22. </div>
  23. </div>
  24. </swiper-slide>
  25. </swiper>
  26. </div>
  27. <OptionWindow ref="optionWindowRef" :projectList="projectList" />
  28. </div>
  29. </template>
  30. <script setup name="TrainIndex" lang="ts">
  31. import { Swiper, SwiperSlide } from 'swiper/vue';
  32. import { Grid } from 'swiper/modules';
  33. import 'swiper/css';
  34. import 'swiper/css/grid';
  35. const router = useRouter();
  36. const { proxy } = getCurrentInstance() as any;
  37. const optionWindowRef = ref();
  38. const data = reactive<any>({
  39. projectList: [],
  40. timerManager: {},
  41. deviceInfo: {}
  42. });
  43. const { projectList, timerManager, deviceInfo } = toRefs(data);
  44. /**
  45. * 获取项目
  46. */
  47. const getExam = () => {
  48. let deviceid = localStorage.getItem('deviceid');
  49. let myList = deviceInfo.value?.project_list || [];
  50. let examList = myList.map((item: any) => {
  51. return item.exam_name;
  52. });
  53. proxy?.$http.train.projectList().then((res: any) => {
  54. projectList.value = proxy?.$utils.getProject(res.exams).filter((item: any) => {
  55. //只显示能开的
  56. if (deviceid) {
  57. return item.area.length > 0 && examList.includes(item.key);
  58. } else {
  59. return item.area.length > 0;
  60. }
  61. });
  62. });
  63. };
  64. /**
  65. * 弹出选项窗口
  66. */
  67. const getOption = (data: any) => {
  68. let deviceid = localStorage.getItem('deviceid');
  69. if (deviceid) {
  70. //设备快捷入口
  71. let project = data;
  72. if (project == undefined) {
  73. proxy?.$modal.msgError('获取不到项目信息');
  74. return false;
  75. }
  76. let obj = deviceInfo.value.project_list.find((item: any) => {
  77. return item.exam_name == project.key;
  78. });
  79. if (obj == undefined) {
  80. proxy?.$modal.msgError('该项目没有配置参数');
  81. return false;
  82. }
  83. let dataObj = {
  84. gesture: obj.gesture ? true : false,
  85. demo: obj?.demo || 0,
  86. area: obj?.area_test_id || '',
  87. ctrl: obj?.area_ctrl_id || '',
  88. time: obj?.test_time || '',
  89. music: obj?.music_info?.id || '',
  90. };
  91. optionWindowRef.value.getGesture(project, dataObj);
  92. } else {
  93. //弹窗选项
  94. optionWindowRef.value.open(data);
  95. }
  96. };
  97. /**
  98. * 清空定时任务
  99. */
  100. const getClearTimer = () => {
  101. for (let key in timerManager.value) {
  102. if (timerManager.value.hasOwnProperty(key)) {
  103. clearInterval(timerManager.value[key]);
  104. timerManager.value[key] = null;
  105. }
  106. }
  107. };
  108. /**
  109. * 初始化项目
  110. */
  111. const getInitExam = () => {
  112. getExam();
  113. //定时刷新
  114. timerManager.value.exam = setInterval(() => {
  115. getExam();
  116. }, 5000);
  117. };
  118. /**
  119. * 退出
  120. */
  121. const getExit = () => {
  122. router.go(-1);
  123. };
  124. onBeforeMount(async () => {
  125. let deviceid = localStorage.getItem('deviceid') || '';
  126. if (deviceid) {
  127. //如果有设备就先查设备配置信息
  128. let params = {
  129. search_info: deviceid,
  130. page: 1,
  131. per_page: 1
  132. };
  133. await proxy?.$http.common
  134. .deviceInfo(params)
  135. .then((res: any) => {
  136. if (res.data.length) {
  137. deviceInfo.value = res.data[0];
  138. }
  139. })
  140. .catch(() => {})
  141. .finally(() => {});
  142. }
  143. getInitExam();
  144. });
  145. onBeforeUnmount(() => {
  146. getClearTimer();
  147. });
  148. </script>
  149. <style lang="scss" scoped>
  150. $topPadding: 5.19rem;
  151. $waiPadding: 6.51rem;
  152. .menu {
  153. width: calc(100% - ($waiPadding * 2));
  154. height: 72vh;
  155. padding-top: 10rem;
  156. margin: 0 auto;
  157. .li {
  158. // width: calc((100% / 6) - 1rem + (1rem/6));
  159. // margin-right: 1rem;
  160. // margin-bottom: 1rem;
  161. width: 100%;
  162. height: calc((72vh / 2) - 10px);
  163. padding: 2.2vh 0;
  164. border-radius: 1.6rem;
  165. box-sizing: border-box;
  166. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
  167. display: flex;
  168. justify-content: center;
  169. align-items: center;
  170. cursor: pointer;
  171. .pic {
  172. width: 11.36vw;
  173. height: 11.36vw;
  174. border-radius: 50%;
  175. background: radial-gradient(78% 78% at 53% 50%, #07121a 0%, #2a4256 49%, #5180a9 100%);
  176. box-shadow: 0px 0px 2px 2px #ffffff;
  177. margin-bottom: 2.5vh;
  178. overflow: hidden;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. flex-shrink: 0;
  183. img {
  184. max-width: 88%;
  185. max-height: 88%;
  186. transition: all 1s;
  187. }
  188. }
  189. .name {
  190. width: 100%;
  191. font-size: 2.48rem;
  192. color: #1a293a;
  193. text-align: center;
  194. }
  195. &:hover {
  196. img {
  197. transform: translateY(-0.5vw);
  198. }
  199. }
  200. }
  201. .swiper-slide {
  202. border-radius: 1.6rem;
  203. overflow: hidden;
  204. }
  205. }
  206. .menu1 {
  207. .swiper-slide {
  208. margin-bottom: 20px;
  209. .li {
  210. background: radial-gradient(96% 96% at 2% 32%, #ffffff 0%, #fcfdfd 54%, #e1e4e7 100%);
  211. }
  212. &:nth-child(2),
  213. &:nth-child(4),
  214. &:nth-child(6),
  215. &:nth-child(7),
  216. &:nth-child(9),
  217. &:nth-child(11) {
  218. .li {
  219. background: radial-gradient(167% 126% at 97% 6%, #35ffc6 0%, #00ffe8 100%);
  220. }
  221. }
  222. }
  223. }
  224. .menu2 {
  225. display: flex;
  226. .swiper-slide {
  227. &:nth-child(1),
  228. &:nth-child(4),
  229. &:nth-child(5),
  230. &:nth-child(8),
  231. &:nth-child(9),
  232. &:nth-child(12),
  233. &:nth-child(13),
  234. &:nth-child(16),
  235. &:nth-child(17),
  236. &:nth-child(20),
  237. &:nth-child(21),
  238. &:nth-child(24),
  239. &:nth-child(25),
  240. &:nth-child(28),
  241. &:nth-child(29),
  242. &:nth-child(32),
  243. &:nth-child(33),
  244. &:nth-child(36),
  245. &:nth-child(37),
  246. &:nth-child(40),
  247. &:nth-child(41),
  248. &:nth-child(44) {
  249. .li {
  250. background: radial-gradient(96% 96% at 2% 32%, #ffffff 0%, #fcfdfd 54%, #e1e4e7 100%);
  251. }
  252. }
  253. &:nth-child(2),
  254. &:nth-child(3),
  255. &:nth-child(6),
  256. &:nth-child(7),
  257. &:nth-child(10),
  258. &:nth-child(11),
  259. &:nth-child(14),
  260. &:nth-child(15),
  261. &:nth-child(18),
  262. &:nth-child(19),
  263. &:nth-child(22),
  264. &:nth-child(23),
  265. &:nth-child(26),
  266. &:nth-child(27),
  267. &:nth-child(30),
  268. &:nth-child(31),
  269. &:nth-child(34),
  270. &:nth-child(35),
  271. &:nth-child(38),
  272. &:nth-child(39),
  273. &:nth-child(42),
  274. &:nth-child(43) {
  275. .li {
  276. background: radial-gradient(167% 126% at 97% 6%, #35ffc6 0%, #00ffe8 100%);
  277. }
  278. }
  279. }
  280. }
  281. ::v-deep(.menu) {
  282. .swiper-horizontal {
  283. width: 100%;
  284. }
  285. }
  286. @media screen and (max-width: 1450px) {
  287. .menu {
  288. .li {
  289. .name {
  290. font-size: 1.8rem;
  291. }
  292. .pic {
  293. width: 10vw;
  294. height: 10vw;
  295. }
  296. }
  297. }
  298. }
  299. </style>