index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <div class="gesture">
  3. <Header :showTool="false" @confirmExit="getLogout"></Header>
  4. <div class="menu">
  5. <swiper v-if="projectList.length" :slides-per-view="5" :space-between="0" :initialSlide="2" :loop="true"
  6. :centeredSlides="true" :modules="[Navigation]" @swiper="onSwiper">
  7. <swiper-slide v-for="(item, index) in projectList" :key="index">
  8. <div class="li">
  9. <div class="pic"><img :src="'static/images/train/' + item.key + '.png'"></div>
  10. <div class="name">
  11. {{ item.name }}
  12. </div>
  13. </div>
  14. </swiper-slide>
  15. </swiper>
  16. </div>
  17. <OptionWindow ref="optionWindowRef" :projectList="projectList" />
  18. <div style=" width: 100%; color: #ffffff; font-size:1.5rem; text-align: center; position:fixed; bottom: 10px; ">
  19. <div style="margin-bottom: 10px;">模拟发送手势:</div>
  20. <div @click="getCmdtest(1)" style="margin-bottom: 10px;">1、左滑动</div>
  21. <div @click="getCmdtest(2)" style="margin-bottom: 10px;">2、举左手</div>
  22. <div @click="getCmdtest(3)">3、双手胸前交叉</div>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup name="Gesture" lang="ts">
  27. import { handWs, startHand, closeHand } from '@/utils/handWs'
  28. import { deviceWs, startDevice } from '@/utils/deviceWs'
  29. import { Swiper, SwiperSlide } from 'swiper/vue';
  30. import { Navigation } from 'swiper/modules';
  31. import 'swiper/css';
  32. import 'swiper/scss/navigation';
  33. const router = useRouter();
  34. const route = useRoute();
  35. const { proxy } = getCurrentInstance() as any;
  36. const optionWindowRef = ref();
  37. const mySwiper = ref();
  38. const data = reactive<any>({
  39. projectList: [],
  40. timerManager: {},
  41. device_info: {}
  42. });
  43. const { projectList, timerManager, device_info } = toRefs(data);
  44. /**
  45. * 清空定时任务
  46. */
  47. const getClearTimer = () => {
  48. for (let key in timerManager.value) {
  49. if (timerManager.value.hasOwnProperty(key)) {
  50. clearInterval(timerManager.value[key])
  51. timerManager.value[key] = null;
  52. }
  53. }
  54. };
  55. /**
  56. * 初始化项目
  57. */
  58. const getInitExam = () => {
  59. getExam();
  60. //定时刷新
  61. timerManager.value.exam = setInterval(() => {
  62. getExam();
  63. }, 5000)
  64. };
  65. /**
  66. * 弹出选项窗口
  67. */
  68. const getOption = (data: any) => {
  69. optionWindowRef.value.open(data);
  70. };
  71. /**
  72. * 获取项目
  73. */
  74. const getExam = async () => {
  75. let examList = device_info.value?.project_list.map((item: any) => {
  76. return item.exam_name;
  77. })
  78. await proxy?.$http.train.projectList().then((res: any) => {
  79. projectList.value = proxy?.$utils.getProject(res.exams).filter((item: any) => {
  80. //只显示能开的
  81. return item.area.length > 0 && examList.includes(item.key);
  82. });
  83. console.log("projectList.value", projectList.value)
  84. });
  85. };
  86. /**
  87. * 获取实例
  88. */
  89. const onSwiper = ($ev) => {
  90. mySwiper.value = $ev;
  91. };
  92. /**
  93. * 切换上一页
  94. */
  95. const slidePrev = () => {
  96. mySwiper.value.slidePrev();
  97. };
  98. /**
  99. * 切换下一页
  100. */
  101. const slideNext = () => {
  102. mySwiper.value.slideNext();
  103. };
  104. /**
  105. * 确定并进入
  106. */
  107. const confirm = () => {
  108. let project = projectList.value[mySwiper.value.realIndex];
  109. console.log("project", project)
  110. let obj = device_info.value.project_list.find((item: any) => {
  111. return item.exam_name == project.key;
  112. })
  113. if (obj == undefined) {
  114. proxy?.$modal.msgError("该项目没有配置参数");
  115. return false;
  116. }
  117. let data = {
  118. gesture: obj.gesture ? true : false,
  119. demo: obj.demo,
  120. area: obj.area_test_id,
  121. ctrl: obj.area_ctrl_id,
  122. time: obj.test_time,
  123. music: obj.music_info.url,
  124. handcontroller: device_info.value.handcontroller_id,
  125. }
  126. console.log("111", project)
  127. optionWindowRef.value.getGesture(JSON.parse(JSON.stringify(project)), data);
  128. };
  129. /**
  130. * 手势
  131. */
  132. const getHandWs = () => {
  133. //加载手势WS
  134. handWs((e: any) => {
  135. //发送设备
  136. if (e?.wksid) {
  137. console.log("e.wksid", e.wksid)
  138. let handcontroller_id = device_info.value.handcontroller_id;
  139. if (handcontroller_id) {
  140. startHand(handcontroller_id)
  141. } else {
  142. proxy?.$modal.msgError("请配置手势ID");
  143. }
  144. }
  145. //左滑动
  146. if (e?.data?.result == "next_item") {
  147. slideNext();
  148. }
  149. //举左手
  150. if (e?.data?.result == "left_hand") {
  151. confirm();
  152. }
  153. //退出
  154. if (e?.data?.result == "exit") {
  155. }
  156. });
  157. };
  158. /**
  159. * 模拟发送手势
  160. */
  161. const getCmdtest = (data: any) => {
  162. let params = {
  163. hctrl_name: `handcontroller_${device_info.value.handcontroller_id}`,
  164. cmd: data
  165. };
  166. proxy?.$http.common.cmdtest(params).then((res: any) => {
  167. });
  168. };
  169. /**
  170. * 退出
  171. */
  172. const getLogout = () => {
  173. proxy?.$modal.prompt('请输入密码', 'password').then((e: any) => {
  174. // console.log("e", e)
  175. if (e.action == 'confirm' && e.value) {
  176. let params = {
  177. password: e.value
  178. };
  179. proxy?.$http.common.checkPassword(params).then((res: any) => {
  180. if (res.status === 200 || res.status === 1) {
  181. proxy?.$http.common.logout({}).then((res: any) => {
  182. });
  183. proxy?.$modal?.closeLoading()
  184. //清空缓存
  185. localStorage.clear();
  186. //跳转
  187. router.push({ path: '/login/qrcode' });
  188. } else {
  189. proxy?.$modal.msgError(res.message);
  190. }
  191. });
  192. }
  193. }).finally(() => {
  194. });
  195. };
  196. onBeforeMount(() => {
  197. //加载设备WS
  198. deviceWs((e: any) => {
  199. //发送设备
  200. if (e?.wksid) {
  201. console.log("e.wksid", e.wksid)
  202. let deviceid = localStorage.getItem("deviceid");
  203. startDevice({ deviceid: deviceid })
  204. }
  205. //接收百度语音token
  206. if (e?.bdapi_token) {
  207. console.log("e.bdapi_token", e.bdapi_token)
  208. let tok = e.bdapi_token;
  209. localStorage.setItem('tok', tok);
  210. }
  211. //接收参数
  212. if (e?.device_info) {
  213. console.log("e.device_info", e.device_info)
  214. device_info.value = e.device_info
  215. getInitExam();
  216. getHandWs();
  217. }
  218. });
  219. })
  220. onMounted(() => {
  221. })
  222. onBeforeUnmount(() => {
  223. getClearTimer();
  224. })
  225. </script>
  226. <style lang="scss" scoped>
  227. $topPadding: 5.19rem;
  228. $waiPadding: 6.51rem;
  229. .menu {
  230. width: calc(100% - ($waiPadding * 2));
  231. height: 100vh;
  232. margin: 0 auto;
  233. display: flex;
  234. align-items: center;
  235. .li {
  236. // width: calc((100% / 6) - 1rem + (1rem/6));
  237. // margin-right: 1rem;
  238. // margin-bottom: 1rem;
  239. width: 100%;
  240. height: 100%;
  241. padding: 3vh 0;
  242. border-radius: 1.6rem;
  243. box-sizing: border-box;
  244. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
  245. display: flex;
  246. flex-wrap: wrap;
  247. justify-content: center;
  248. text-align: center;
  249. background: radial-gradient(96% 96% at 2% 32%, #FFFFFF 0%, #FCFDFD 54%, #E1E4E7 100%);
  250. flex-shrink: 0;
  251. cursor: pointer;
  252. .name {
  253. width: 100%;
  254. font-size: 2.48rem;
  255. color: #1A293A;
  256. padding: 0.5rem 0;
  257. }
  258. .pic {
  259. width: 11.36vw;
  260. height: 11.36vw;
  261. border-radius: 50%;
  262. background: radial-gradient(78% 78% at 53% 50%, #07121A 0%, #2A4256 49%, #5180A9 100%);
  263. box-shadow: 0px 0px 2px 2px #FFFFFF;
  264. margin-bottom: 2vh;
  265. overflow: hidden;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. flex-shrink: 0;
  270. img {
  271. max-width: 88%;
  272. max-height: 88%;
  273. transition: all 1s;
  274. }
  275. }
  276. &:hover {
  277. img {
  278. transform: translateY(-0.5vw);
  279. }
  280. }
  281. }
  282. .swiper {
  283. width: 100%;
  284. }
  285. .swiper-slide {
  286. transform: scale(0.8);
  287. transition: all 0.3s ease-in-out;
  288. border-radius: 1.6rem;
  289. opacity: 0.6;
  290. overflow: hidden;
  291. }
  292. .swiper-slide-active {
  293. opacity: 1;
  294. transform: scale(1);
  295. .li {
  296. background: radial-gradient(167% 126% at 97% 6%, #35FFC6 0%, #00FFE8 100%);
  297. }
  298. }
  299. }
  300. </style>