index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 getDeviceInfo = async () => {
  112. let deviceid = localStorage.getItem('deviceid') || '';
  113. if (deviceid) {
  114. //如果有设备就先查设备配置信息
  115. let params = {
  116. search_info: deviceid,
  117. page: 1,
  118. per_page: 1
  119. };
  120. await proxy?.$http.common
  121. .deviceInfo(params)
  122. .then((res: any) => {
  123. if (res.data.length) {
  124. deviceInfo.value = res.data[0];
  125. }
  126. })
  127. .catch(() => {})
  128. .finally(() => {});
  129. }
  130. };
  131. /**
  132. * 初始化项目
  133. */
  134. const getInitExam = () => {
  135. getExam();
  136. //定时刷新
  137. timerManager.value.exam = setInterval(() => {
  138. getExam();
  139. }, 5000);
  140. };
  141. /**
  142. * 退出
  143. */
  144. const getExit = () => {
  145. router.go(-1);
  146. };
  147. onBeforeMount(async () => {
  148. await getDeviceInfo()
  149. await getInitExam();
  150. });
  151. onBeforeUnmount(() => {
  152. getClearTimer();
  153. });
  154. </script>
  155. <style lang="scss" scoped>
  156. $topPadding: 5.19rem;
  157. $waiPadding: 6.51rem;
  158. .menu {
  159. width: calc(100% - ($waiPadding * 2));
  160. height: 72vh;
  161. padding-top: 10rem;
  162. margin: 0 auto;
  163. .li {
  164. // width: calc((100% / 6) - 1rem + (1rem/6));
  165. // margin-right: 1rem;
  166. // margin-bottom: 1rem;
  167. width: 100%;
  168. height: calc((72vh / 2) - 10px);
  169. padding: 2.2vh 0;
  170. border-radius: 1.6rem;
  171. box-sizing: border-box;
  172. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
  173. display: flex;
  174. justify-content: center;
  175. align-items: center;
  176. cursor: pointer;
  177. .pic {
  178. width: 11.36vw;
  179. height: 11.36vw;
  180. border-radius: 50%;
  181. background: radial-gradient(78% 78% at 53% 50%, #07121a 0%, #2a4256 49%, #5180a9 100%);
  182. box-shadow: 0px 0px 2px 2px #ffffff;
  183. margin-bottom: 2.5vh;
  184. overflow: hidden;
  185. display: flex;
  186. align-items: center;
  187. justify-content: center;
  188. flex-shrink: 0;
  189. img {
  190. max-width: 88%;
  191. max-height: 88%;
  192. transition: all 1s;
  193. }
  194. }
  195. .name {
  196. width: 100%;
  197. font-size: 2.48rem;
  198. color: #1a293a;
  199. text-align: center;
  200. }
  201. &:hover {
  202. img {
  203. transform: translateY(-0.5vw);
  204. }
  205. }
  206. }
  207. .swiper-slide {
  208. border-radius: 1.6rem;
  209. overflow: hidden;
  210. }
  211. }
  212. .menu1 {
  213. .swiper-slide {
  214. margin-bottom: 20px;
  215. .li {
  216. background: radial-gradient(96% 96% at 2% 32%, #ffffff 0%, #fcfdfd 54%, #e1e4e7 100%);
  217. }
  218. &:nth-child(2),
  219. &:nth-child(4),
  220. &:nth-child(6),
  221. &:nth-child(7),
  222. &:nth-child(9),
  223. &:nth-child(11) {
  224. .li {
  225. background: radial-gradient(167% 126% at 97% 6%, #35ffc6 0%, #00ffe8 100%);
  226. }
  227. }
  228. }
  229. }
  230. .menu2 {
  231. display: flex;
  232. .swiper-slide {
  233. &:nth-child(1),
  234. &:nth-child(4),
  235. &:nth-child(5),
  236. &:nth-child(8),
  237. &:nth-child(9),
  238. &:nth-child(12),
  239. &:nth-child(13),
  240. &:nth-child(16),
  241. &:nth-child(17),
  242. &:nth-child(20),
  243. &:nth-child(21),
  244. &:nth-child(24),
  245. &:nth-child(25),
  246. &:nth-child(28),
  247. &:nth-child(29),
  248. &:nth-child(32),
  249. &:nth-child(33),
  250. &:nth-child(36),
  251. &:nth-child(37),
  252. &:nth-child(40),
  253. &:nth-child(41),
  254. &:nth-child(44) {
  255. .li {
  256. background: radial-gradient(96% 96% at 2% 32%, #ffffff 0%, #fcfdfd 54%, #e1e4e7 100%);
  257. }
  258. }
  259. &:nth-child(2),
  260. &:nth-child(3),
  261. &:nth-child(6),
  262. &:nth-child(7),
  263. &:nth-child(10),
  264. &:nth-child(11),
  265. &:nth-child(14),
  266. &:nth-child(15),
  267. &:nth-child(18),
  268. &:nth-child(19),
  269. &:nth-child(22),
  270. &:nth-child(23),
  271. &:nth-child(26),
  272. &:nth-child(27),
  273. &:nth-child(30),
  274. &:nth-child(31),
  275. &:nth-child(34),
  276. &:nth-child(35),
  277. &:nth-child(38),
  278. &:nth-child(39),
  279. &:nth-child(42),
  280. &:nth-child(43) {
  281. .li {
  282. background: radial-gradient(167% 126% at 97% 6%, #35ffc6 0%, #00ffe8 100%);
  283. }
  284. }
  285. }
  286. }
  287. ::v-deep(.menu) {
  288. .swiper-horizontal {
  289. width: 100%;
  290. }
  291. }
  292. @media screen and (max-width: 1450px) {
  293. .menu {
  294. .li {
  295. .name {
  296. font-size: 1.8rem;
  297. }
  298. .pic {
  299. width: 10vw;
  300. height: 10vw;
  301. }
  302. }
  303. }
  304. }
  305. </style>