index.vue 7.3 KB

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