index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. <template>
  2. <div class="sunshineRun">
  3. <div class="sunshineRun-top">
  4. <div class="sunshineRun-top-center">
  5. <div class="logo">
  6. <img v-if="userInfo?.logo_url" :src="userInfo.logo_url" />
  7. <img v-else src="@/assets/images/common/logo.png" />
  8. </div>
  9. <div class="sunshineRun-title"><img src="@/assets/images/sunshineRun/title.png" /></div>
  10. <div class="toolList">
  11. <div class="li">{{ date }}</div>
  12. <div class="li btn screen" :class="{ 'on': screen, 'off': !screen }" @click="getFullScreen"></div>
  13. <div class="li btn closeBtn" @click="confirmExit"></div>
  14. </div>
  15. </div>
  16. </div>
  17. <div class="sunshineRun-main">
  18. <div class="sunshineRun-left">
  19. <div class="list-box">
  20. <div class="sunshineRun-columns-title">
  21. <div class="title">实时数据</div>
  22. </div>
  23. <div class="testList">
  24. <ul>
  25. <TransitionGroup>
  26. <li v-for="(item, index) in testList" :key="item.student_id">
  27. <!-- <img v-if="item.student_id && item.student_icon_url" :src="item.student_icon_url" />
  28. <img class="noPic"
  29. v-else src="@/assets/images/common/noImg.png" /> -->
  30. <div class="nameBox">{{ item.name }}</div>
  31. <div class="pic" v-if="item.student_id && item.student_icon_url"
  32. :style="{ backgroundImage: 'url(' + item.student_icon_url + ')' }"></div>
  33. <div class="con">
  34. <!-- <div class="name">{{ item.name }}</div> -->
  35. <div class="score">
  36. <div class="quanshu">{{ item.ring_count || 0 }}<i>圈</i></div>
  37. <div>{{ item.distance }}<span>{{ unit }}</span></div>
  38. </div>
  39. </div>
  40. </li>
  41. </TransitionGroup>
  42. </ul>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="sunshineRun-right">
  47. <div class="list-box">
  48. <div class="sunshineRun-columns-title">
  49. <div class="title">排行榜</div>
  50. </div>
  51. <div class="reportList">
  52. <ul>
  53. <li v-for="(item, index) in reportList" :key="index">
  54. <div class="left">
  55. <div class="pai"
  56. :class="{ 'pai1': item.rankid == 1, 'pai2': item.rankid == 2, 'pai3': item.rankid == 3 }">
  57. <div>{{ item.rankid }}</div>
  58. </div>
  59. <!-- <div class="pic"><img :src="item.icon" /></div> -->
  60. <div class="txt">
  61. <div>
  62. <div class="name">{{ item.student_name }}</div>
  63. <div class="className">{{ item.class_name }}</div>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="right">
  68. <div class="score">{{ item.run_distance }}
  69. </div>
  70. <div class="unit">{{ unit }}</div>
  71. </div>
  72. </li>
  73. </ul>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script setup name="SunshineRun" lang="ts">
  81. import { useSunshineRunSocket } from '@/utils/sunshineRunWs';
  82. const { proxy } = getCurrentInstance() as any;
  83. const router = useRouter();
  84. const myInfo: any = localStorage.getItem("userInfo");
  85. const { sunshineRunWs, startConnect } = useSunshineRunSocket();
  86. const data = reactive<any>({
  87. timerManager: {},//计时器管理
  88. userInfo: {},//用户信息
  89. testList: [],//测试列表
  90. reportList: [],//排行榜
  91. date: "",//当前时间
  92. unit: "",//单位
  93. screen: true,//全屏控制
  94. studentPage: {
  95. current: 1,
  96. size: 8,
  97. pages: 1
  98. }, //学生分页
  99. });
  100. const {
  101. timerManager,
  102. userInfo,
  103. testList,
  104. reportList,
  105. date,
  106. unit,
  107. screen,
  108. studentPage,
  109. } = toRefs(data);
  110. /**
  111. * 更新时间
  112. */
  113. const setDate = () => {
  114. timerManager.value.currentTime = setInterval(() => {
  115. date.value = proxy?.$utils.getDate();
  116. }, 1000)
  117. };
  118. /**
  119. * 屏幕模式
  120. */
  121. const getFullScreen = () => {
  122. screen.value = !screen.value;
  123. localStorage.setItem("screen", screen.value);
  124. proxy?.$utils.fullScreen();
  125. };
  126. /**
  127. * 确定退出
  128. */
  129. const confirmExit = async () => {
  130. if (import.meta.env.DEV) {
  131. getClearTimer();
  132. proxy?.$modal.msgSuccess('测试环境免密退出');
  133. await proxy?.$http.common.logout({}).then((res: any) => {
  134. });
  135. proxy?.$modal?.closeLoading()
  136. //清空缓存
  137. localStorage.clear();
  138. //跳转
  139. router.push({ path: '/login/sunshineRun' });
  140. } else {
  141. let myInfo: any = localStorage.getItem("userInfo");
  142. let userInfo = JSON.parse(myInfo);
  143. proxy?.$modal.prompt(`【${userInfo.login_name}】,请输入密码`, 'password').then((e: any) => {
  144. // console.log("e", e)
  145. if (e.action == 'confirm' && e.value) {
  146. getClearTimer();
  147. let params = {
  148. password: e.value
  149. };
  150. proxy?.$http.common.checkPassword(params).then(async (res: any) => {
  151. if (res.status === 200 || res.status === 1) {
  152. await proxy?.$http.common.logout({}).then((res: any) => {
  153. });
  154. proxy?.$modal?.closeLoading()
  155. //清空缓存
  156. localStorage.clear();
  157. //跳转
  158. router.push({ path: '/login/sunshineRun' });
  159. } else {
  160. proxy?.$modal.msgError(res.message);
  161. }
  162. });
  163. }
  164. }).finally(() => {
  165. });
  166. }
  167. };
  168. /**
  169. * 清空定时任务
  170. */
  171. const getClearTimer = (data?: any) => {
  172. if (data) {
  173. //清除指定
  174. clearInterval(timerManager.value[data])
  175. timerManager.value[data] = null;
  176. } else {
  177. //清除全部
  178. for (let key in timerManager.value) {
  179. if (timerManager.value.hasOwnProperty(key)) {
  180. clearInterval(timerManager.value[key])
  181. timerManager.value[key] = null;
  182. }
  183. }
  184. }
  185. };
  186. /**
  187. * 获取排名
  188. */
  189. const getStudentList = () => {
  190. let params: any = {
  191. page: studentPage.value.current,
  192. per_page: studentPage.value.size,
  193. };
  194. proxy?.$http.ranking.sunshineRunRanking(params).then((res: any) => {
  195. if (res.status == 200) {
  196. let list: any = res.sunlight_rank_data;
  197. reportList.value = list;
  198. getPages(res.total);
  199. }
  200. });
  201. };
  202. /**
  203. * 计算页码
  204. */
  205. const getPages = (data: any) => {
  206. studentPage.value.pages = Math.ceil(data / studentPage.value.size);
  207. };
  208. /**
  209. * 自动切换排行榜
  210. */
  211. const getAutoplay = () => {
  212. getStudentList();
  213. timerManager.value.autoplayTime = setInterval(() => {
  214. // 切换页码
  215. if (studentPage.value.current >= studentPage.value.pages || studentPage.value.current >= 5) {
  216. studentPage.value.current = 1;
  217. } else {
  218. studentPage.value.current++;
  219. }
  220. getStudentList();
  221. }, 10000);
  222. };
  223. /**
  224. * 获取模拟数据
  225. */
  226. const getSunshineRunPushData = async () => {
  227. let params = {
  228. password: "fb083a6fe1e14600910b06977c1d037e",
  229. school_id: "3"
  230. };
  231. await proxy?.$http.common.sunshineRunPushData(params).then((res: any) => {
  232. });
  233. };
  234. /**
  235. * 加载WS
  236. */
  237. const initSunshineRun = () => {
  238. sunshineRunWs((e: any) => {
  239. console.log("eeeee", e)
  240. if (e?.wksid) {
  241. startConnect();
  242. }
  243. //接收第一次成绩列表
  244. if (e?.cmd == 'sunlight_init_result' && e?.data.length) {
  245. let ids = e.data.map((item: any) => {
  246. return item.student_id;
  247. })
  248. let list = testList.value.filter((item: any) => {
  249. return !ids.includes(item.student_id);
  250. })
  251. testList.value = [...e.data, ...list];
  252. //模拟数据
  253. // setInterval(() => {
  254. // getSunshineRunPushData();
  255. // }, 1000)
  256. }
  257. //接收推送数据
  258. if (e?.cmd == 'sunlight_one_result' && e?.data) {
  259. let myIndex = testList.value.findIndex((item: any) => {
  260. return item.student_id == e.data.student_id;
  261. })
  262. if (myIndex != -1) {
  263. //如果已经存在就删除
  264. testList.value.splice(myIndex, 1);//删除数据
  265. }
  266. testList.value.unshift(e.data);//插入数据
  267. }
  268. });
  269. };
  270. onBeforeMount(() => {
  271. //获取当前时间
  272. setDate();
  273. //用户信息
  274. userInfo.value = JSON.parse(myInfo);
  275. //屏幕
  276. let screenData = localStorage.getItem("screen");
  277. if (screenData != undefined && screenData == 'false') {
  278. screen.value = false;
  279. } else {
  280. screen.value = true;
  281. }
  282. //单位
  283. unit.value = "M";
  284. //初始化手势
  285. initSunshineRun();
  286. //排行榜
  287. getAutoplay();
  288. })
  289. onMounted(() => {
  290. })
  291. onBeforeUnmount(() => {
  292. getClearTimer();
  293. })
  294. </script>
  295. <style lang="scss" scoped>
  296. .sunshineRun {
  297. width: 100%;
  298. height: 100%;
  299. padding: 0 0 1vw 0;
  300. display: flex;
  301. flex-direction: column;
  302. box-sizing: border-box;
  303. background: #3BDDCE url("@/assets/images/sunshineRun/bg.png") top center no-repeat;
  304. background-size: cover;
  305. .sunshineRun-top {
  306. padding: 0px 1vw;
  307. .sunshineRun-top-center {
  308. height: 10vh;
  309. position: relative;
  310. display: flex;
  311. justify-content: center;
  312. .logo {
  313. position: absolute;
  314. left: 0;
  315. top: 2vh;
  316. img {
  317. height: 5vh;
  318. }
  319. }
  320. .sunshineRun-title {
  321. display: inline-block;
  322. img {
  323. height: 15vh;
  324. }
  325. }
  326. .toolList {
  327. position: absolute;
  328. right: 0;
  329. top: 2vh;
  330. color: #EFEFEF;
  331. font-size: 2.5vh;
  332. display: flex;
  333. align-items: center;
  334. text-shadow: 1px 1px 1px #a3a3a3;
  335. .li {
  336. margin-left: 2vw;
  337. }
  338. .btn {
  339. width: 3vh;
  340. height: 3vh;
  341. display: block;
  342. background-position: center;
  343. background-repeat: no-repeat;
  344. background-size: 100% auto;
  345. cursor: pointer;
  346. }
  347. .closeBtn {
  348. background-image: url("@/assets/images/sunshineRun/close.png");
  349. }
  350. .screen.on {
  351. background-image: url("@/assets/images/sunshineRun/screen1.png");
  352. }
  353. .screen.off {
  354. background-image: url("@/assets/images/sunshineRun/screen2.png");
  355. }
  356. }
  357. }
  358. }
  359. .sunshineRun-main {
  360. display: flex;
  361. justify-content: space-evenly;
  362. height: 100%;
  363. .sunshineRun-columns-title {
  364. display: flex;
  365. .title {
  366. height: 5vh;
  367. line-height: 5vh;
  368. font-size: 3vh;
  369. color: #1A293A;
  370. padding: 0px 2vw;
  371. letter-spacing: 3px;
  372. border-top-left-radius: 2vh;
  373. border-top-right-radius: 2vh;
  374. background: radial-gradient(374% 336% at 36% 50%, #FFFFFF 0%, #07FFE7 100%);
  375. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.5577);
  376. }
  377. }
  378. .sunshineRun-left {
  379. width: 76%;
  380. display: flex;
  381. flex-direction: column;
  382. position: relative;
  383. .list-box {
  384. display: flex;
  385. flex-direction: column;
  386. height: 100%;
  387. .testList {
  388. width: 100%;
  389. height: calc(100vh - 1vw - 10vh - 5vh);
  390. border-radius: 2vh;
  391. overflow-x: hidden;
  392. overflow-y: scroll;
  393. background: linear-gradient(170deg, #276066 -13%, #09111B 87%);
  394. box-sizing: border-box;
  395. border: 1px solid #FFFFFF;
  396. box-shadow: 0px 0px 6px 2px rgba(255, 255, 255, 0.5);
  397. border-top-left-radius: 0px;
  398. &::-webkit-scrollbar {
  399. width: 0px;
  400. }
  401. &::-webkit-scrollbar-thumb {
  402. border-width: 2px;
  403. border-radius: 4px;
  404. border-style: dashed;
  405. border-color: transparent;
  406. background-color: rgba(26, 62, 78, 0.9);
  407. background-clip: padding-box;
  408. }
  409. &::-webkit-scrollbar-button:hover {
  410. border-radius: 6px;
  411. background: rgba(26, 62, 78, 1);
  412. }
  413. ul {
  414. display: flex;
  415. flex-wrap: wrap;
  416. padding: 1.6vh 0.8vh 0px 0.8vh;
  417. li {
  418. position: relative;
  419. width: calc((100% / 6) - 1.6vh);
  420. height: calc(((100vh - 1vw - 10vh - 5vh - 1.6vh) / 3) - 1.6vh);
  421. margin: 0px 0.8vh 1.6vh 0.8vh;
  422. box-sizing: border-box;
  423. border: 1px solid #ffffff;
  424. border-radius: 1.6vh;
  425. overflow: hidden;
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. img {
  430. width: 100%;
  431. height: 100%;
  432. }
  433. .nameBox {
  434. position: absolute;
  435. left: 0;
  436. top: 0;
  437. font-size: 1.5vw;
  438. color: #ffffff;
  439. line-height: 1;
  440. width: auto;
  441. text-align: left;
  442. margin-bottom: 0.7vh;
  443. font-weight: bold;
  444. display: inline-block;
  445. padding: 0.8vh 8% 0.8vh 5%;
  446. box-sizing: border-box;
  447. // background: linear-gradient(180deg, rgba(0, 0, 0, 0.87) 45%, rgba(18, 133, 124, 0.7367) 135%);
  448. background: linear-gradient(to right, rgba(15,25,38,1) 0%,rgba(49,95,126,0.6) 100%);
  449. border-radius: 0px 0px 1vh 0px;
  450. }
  451. .pic {
  452. width: 100%;
  453. height: 100%;
  454. background-size: cover;
  455. background-position: center
  456. }
  457. .noPic {
  458. width: auto;
  459. height: auto;
  460. max-width: 60% !important;
  461. max-height: 60% !important;
  462. opacity: 0.2;
  463. }
  464. .con {
  465. position: absolute;
  466. bottom: 0;
  467. width: 100%;
  468. // padding: 0.7vh 4%;
  469. padding: 0.8vh 4%;
  470. display: flex;
  471. align-items: center;
  472. // justify-content: space-between;
  473. flex-direction: column;
  474. box-sizing: border-box;
  475. background: linear-gradient(180deg, rgba(0, 0, 0, 0.87) 45%, rgba(18, 133, 124, 0.7367) 135%);
  476. .name {
  477. font-size: 1.5vw;
  478. color: #ffffff;
  479. line-height: 1;
  480. width: 100%;
  481. text-align: left;
  482. margin-bottom: 0.7vh;
  483. font-weight: bold;
  484. }
  485. .score {
  486. width: 100%;
  487. font-size: 1.8vw;
  488. color: #00FFE8;
  489. font-family: 'Saira-ExtraBold';
  490. font-style: italic;
  491. line-height: 1;
  492. text-align: right;
  493. display: flex;
  494. justify-content: space-between;
  495. .quanshu {
  496. font-style: normal;
  497. }
  498. span {
  499. font-size: 1.8vw;
  500. }
  501. i {
  502. font-size: 1.1vw;
  503. margin-left: 2px;
  504. }
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. }
  512. .sunshineRun-right {
  513. width: 21%;
  514. display: flex;
  515. flex-direction: column;
  516. position: relative;
  517. .list-box {
  518. display: flex;
  519. flex-direction: column;
  520. height: 100%;
  521. .reportList {
  522. width: 100%;
  523. border-radius: 2vh;
  524. overflow: hidden;
  525. background: radial-gradient(90% 90% at 50% 100%, #38869E 0%, #38869E 50%, #17323D 100%);
  526. box-sizing: border-box;
  527. border: 1px solid #FFFFFF;
  528. display: flex;
  529. flex-direction: column;
  530. height: 100%;
  531. border-top-left-radius: 0px;
  532. ul {
  533. height: 100%;
  534. // overflow-y: scroll;
  535. li {
  536. height: calc(100% / 8);
  537. border-bottom: 1px solid #48677E;
  538. padding: 0px 5%;
  539. display: flex;
  540. justify-content: space-between;
  541. align-items: center;
  542. transition: all 0.2s;
  543. box-sizing: border-box;
  544. // &:hover {
  545. // background: rgba(255, 255, 255, 0.4);
  546. // }
  547. .left {
  548. display: flex;
  549. align-items: center;
  550. padding-right: 5%;
  551. width: 100%;
  552. .pai {
  553. width: 2.5vw;
  554. height: 2vw;
  555. line-height: 1;
  556. text-align: center;
  557. color: #F9F9F9;
  558. font-size: 1.5vw;
  559. font-family: 'Saira-ExtraBold';
  560. margin-right: 10%;
  561. flex-shrink: 0;
  562. display: flex;
  563. align-items: center;
  564. justify-content: center;
  565. font-style: italic;
  566. }
  567. .pai1,
  568. .pai2,
  569. .pai3 {
  570. align-items: end;
  571. }
  572. .pai1 {
  573. background: url("@/assets/images/ranking/pai1.png") left center no-repeat;
  574. background-size: 100% 100%;
  575. }
  576. .pai2 {
  577. background: url("@/assets/images/ranking/pai2.png") left center no-repeat;
  578. background-size: 100% 100%;
  579. }
  580. .pai3 {
  581. background: url("@/assets/images/ranking/pai3.png") left center no-repeat;
  582. background-size: 100% 100%;
  583. }
  584. .pic {
  585. width: 7vh;
  586. height: 7vh;
  587. border-radius: 50%;
  588. display: flex;
  589. justify-content: center;
  590. align-items: center;
  591. overflow: hidden;
  592. box-sizing: border-box;
  593. border: 1px solid rgba(255, 255, 255, 0.5);
  594. margin-right: 5%;
  595. flex-shrink: 0;
  596. img {
  597. width: 100%;
  598. }
  599. }
  600. .txt {
  601. display: flex;
  602. align-items: center;
  603. .name {
  604. color: #F9F9F9;
  605. // font-size: 1vw;
  606. font-size: 1.6vw;
  607. }
  608. .className {
  609. color: #13ED84;
  610. // font-size: 0.8vw;
  611. font-size: 1vw;
  612. }
  613. }
  614. }
  615. .right {
  616. flex-shrink: 0;
  617. font-family: 'Saira-ExtraBold';
  618. // font-size: 1.4vw;
  619. font-size: 1.8vw;
  620. font-style: italic;
  621. .score {
  622. color: #ffffff;
  623. display: inline-block;
  624. }
  625. .unit {
  626. color: #ffffff;
  627. margin-left: 2px;
  628. display: inline-block;
  629. }
  630. }
  631. }
  632. &::-webkit-scrollbar {
  633. width: 0px;
  634. }
  635. &::-webkit-scrollbar-thumb {
  636. border-width: 2px;
  637. border-radius: 4px;
  638. border-style: dashed;
  639. border-color: transparent;
  640. background-color: rgba(216, 216, 216, 0.8);
  641. background-clip: padding-box;
  642. }
  643. &::-webkit-scrollbar-button:hover {
  644. border-radius: 6px;
  645. background: rgba(216, 216, 216, 0.8);
  646. }
  647. }
  648. }
  649. }
  650. }
  651. }
  652. }
  653. </style>