Main.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div :class="pageStyle">
  3. <Headside></Headside>
  4. <!-- 学生列表-->
  5. <div class="userList">
  6. <student :students="students" :students-class-name="studentsClassName"></student>
  7. </div>
  8. <!--图示-->
  9. <levelIcon></levelIcon>
  10. <!-- 突破纪录-->
  11. <newRecord :toper-info="toperInfo"></newRecord>
  12. <!-- 欢迎新同学-->
  13. <newStudent :student-info="studentInfo"></newStudent>
  14. </div>
  15. </template>
  16. <script>
  17. import Headside from '@/components/Headside'
  18. import newRecord from '@/components/newRecord'
  19. import newStudent from '@/components/newStudent'
  20. import levelIcon from '@/components/levelIcon'
  21. import student from '@/components/student'
  22. import
  23. {
  24. getHello,
  25. getClassStat,
  26. getRecordBreak,
  27. getNewUser
  28. } from '@/api/getApiRes'
  29. import '../libs/rem';
  30. import '../Global'
  31. let qs = require('qs');
  32. export default {
  33. data() {
  34. return {
  35. eqSn: '30:9C:23:0C:8B:1E',
  36. pageStyle: RandomBg(),
  37. trueDate: true,//真实数据 true false
  38. times: 1,
  39. thisClassName: '',
  40. studentsClassName: [],
  41. students: [],
  42. single: [],
  43. dialogVisible: false,
  44. serachBtnStatus: false,
  45. dialogMsg: '',
  46. imgsrc: '../static/img/people/',
  47. totalTime: 30,
  48. studentTime: 15,
  49. toperInfo: {
  50. dialogVisible: false,
  51. toper: {},
  52. },
  53. studentInfo: {
  54. dialogVisible: false,
  55. Rs: [],
  56. percent: 0
  57. },
  58. fakeEgg: {
  59. Rs: {
  60. "DuId": 37,
  61. "UserId": 0,
  62. "UserName": "郑伟",
  63. "Sex": 1,
  64. "Head": "https://img-operation.csdnimg.cn/csdn/silkroad/img/1604989753379.png",
  65. "Cle": 400,
  66. "CleTitle": "个人单次卡路里记录",
  67. "CleUnit": "千卡",
  68. "CkTitle": "个人单次CK记录",
  69. "Ck": 99.9,
  70. "CkUnit": "CK值",
  71. }
  72. },
  73. mainTimer: null,
  74. timer2: null,
  75. }
  76. },
  77. mounted() {
  78. // this.$router.push({path: '/2pkRank'});
  79. if (this.trueDate) {
  80. this.init();
  81. } else {
  82. // 彩蛋
  83. // this.OpenEgg(this.fakeEgg);
  84. // 1 2 4 6 9 10 13 16 21 24
  85. let Rs = fakeNews(33);
  86. this.giveClassName(Rs);
  87. this.students = Rs;
  88. // this.createNewStudent();
  89. }
  90. },
  91. watch: {
  92. '$route': function (val) {
  93. if (val.path == '/main') {
  94. if (this.trueDate) {
  95. this.init();
  96. } else {
  97. this.students = fakeNews(2);
  98. this.giveClassName(this.students);
  99. // this.createEgg(this.students[5]);
  100. }
  101. } else {
  102. clearInterval(this.mainTimer);
  103. clearInterval(this.timer2);
  104. clearInterval(this.timer3);
  105. }
  106. }
  107. },
  108. beforeDestroy() {
  109. clearInterval(this.mainTimer);
  110. clearInterval(this.timer2);
  111. clearInterval(this.timer3);
  112. this.mainTimer = null;
  113. this.timer2 = null;
  114. this.timer3 = null;
  115. },
  116. methods: {
  117. init() {
  118. // console.log(headTest);
  119. this.GetgetUserList();
  120. this.createEgg();
  121. this.createNewStudent();
  122. this.curgetClassStat();
  123. this.mainTimer = setInterval(() => {
  124. // this.$router.push({path: '/'});
  125. this.GetgetUserList();
  126. this.curgetClassStat();
  127. }, 1000);
  128. this.timer2 = setInterval(() => {
  129. this.createEgg();
  130. }, 31000);
  131. this.timer3 = setInterval(() => {
  132. this.createNewStudent();
  133. }, 6000);
  134. },
  135. alertInfo(info) {
  136. alert(info);
  137. },
  138. // 启动一个成就彩蛋
  139. createEgg() {
  140. let that = this;
  141. let param = {
  142. token: localStorage.token,
  143. eqSn: localStorage.eqSn
  144. };
  145. let postdata = qs.stringify(param);
  146. getRecordBreak(postdata).then(res => {
  147. let json = res;
  148. if (json.Code == 0) {
  149. // 欢迎新学生时不显示彩蛋
  150. if (that.studentInfo.dialogVisible == true) {
  151. console.log('正在显示新学生');
  152. return false
  153. } else {
  154. this.OpenEgg(json);
  155. }
  156. } else {
  157. // 并没有人破记录
  158. if (json.Code == 999) return false;
  159. if (json.Code != 999) that.$message.error(json.Memo + '[ 错误码]' + json.Code);
  160. }
  161. })
  162. },
  163. // 欢迎新同学
  164. createNewStudent() {
  165. let that = this;
  166. let param = {
  167. token: localStorage.token,
  168. eqSn: localStorage.eqSn
  169. };
  170. let postdata = qs.stringify(param);
  171. getNewUser(postdata).then(res => {
  172. let json = res;
  173. if (json.Code == 0) {
  174. console.log('来新生了');
  175. // 显示彩蛋时不欢迎新学生
  176. if (that.toperInfo.dialogVisible == true) {
  177. console.log('正在显示彩蛋');
  178. return false
  179. } else {
  180. console.log(json.Rs);
  181. that.OpenStudent(json.Rs);
  182. // OpenStudent(json.Rs,that);
  183. }
  184. } else {
  185. // 并没有人破记录
  186. if (json.Code == 999) return false;
  187. if (json.Code != 999) that.$message.error(json.Memo + '[ 错误码]' + json.Code);
  188. }
  189. })
  190. },
  191. OpenEgg(msg) {
  192. this.toperInfo.toper = msg.Rs;
  193. this.toperInfo.dialogVisible = true;
  194. // 倒计时5秒自动关闭
  195. let that = this;
  196. this.totalTime = 30;
  197. let clock = window.setInterval(() => {
  198. this.totalTime--;
  199. if (parseInt(this.totalTime) < 0) {
  200. that.toperInfo.dialogVisible = false;
  201. clearInterval(clock);
  202. }
  203. }, 1000)
  204. },
  205. OpenStudent(msg) {
  206. let that = this;
  207. that.studentInfo.Rs = msg;
  208. that.studentInfo.dialogVisible = true;
  209. this.studentInfo.percent = 0;
  210. // 倒计时5秒自动关闭
  211. this.studentTime = 15;
  212. let clock = window.setInterval(() => {
  213. this.studentTime--;
  214. let num = (15 - this.studentTime) / 15 * 100;
  215. this.studentInfo.percent = parseInt(num) > 100 ? 100 : num;
  216. console.log('num' + num);
  217. if (parseInt(this.studentTime) <= 0) {
  218. that.studentInfo.dialogVisible = false;
  219. clearInterval(clock);
  220. }
  221. }, 1000)
  222. },
  223. GetgetUserList() {
  224. let that = this;
  225. let param = {
  226. token: localStorage.token,
  227. eqSn: localStorage.eqSn
  228. };
  229. let postdata = qs.stringify(param);
  230. getHello(postdata).then(res => {
  231. let json = res;
  232. if (json.Code == 0) {
  233. that.students = json.Rs;
  234. that.giveClassName(json.Rs);
  235. } else {
  236. // 已下课
  237. if (json.Code == '999') {
  238. that.students = ""
  239. } else {
  240. // 已出错
  241. that.$message.error(json.Memo);
  242. }
  243. }
  244. })
  245. },
  246. curgetClassStat() {
  247. let that = this;
  248. let param = {
  249. token: localStorage.token,
  250. eqSn: localStorage.eqSn
  251. };
  252. let postdata = qs.stringify(param);
  253. getClassStat(postdata).then(res => {
  254. let json = res;
  255. if (json.Code == 0) {
  256. // 没开课
  257. if (json.ClassOn == 0) {
  258. console.log("下课了");
  259. // 0: 下课 团课/私教 排名
  260. // 1:团课/私教 todo
  261. // 2:竞技课2PK
  262. // 3:竞技课threepk
  263. switch (parseInt(json.dp)) {
  264. case 0:
  265. that.$router.push({path: '/rank'});
  266. break;
  267. case 1:
  268. that.$router.push({path: '/'});
  269. break;
  270. case 2:
  271. that.$router.push({path: '/pk'});
  272. break;
  273. case 3:
  274. that.$router.push({path: '/threepk'});
  275. break;
  276. }
  277. }
  278. } else {
  279. console.log("已上课");
  280. }
  281. })
  282. },
  283. // 给每一个数据加类名,一次遍历全部赋值
  284. giveClassName(res) {
  285. let that = this;
  286. let numberClass = '';
  287. let colorClass = '';
  288. for (let i = 0; i < parseInt(res.length); i++) {
  289. switch (true) {
  290. case parseInt(res.length) == 1:
  291. numberClass = 'max';
  292. break;
  293. case parseInt(res.length) == 2:
  294. numberClass = 'two';
  295. break;
  296. case parseInt(res.length) <= 4 && parseInt(res.length) > 2:
  297. numberClass = 'three';
  298. break;
  299. case parseInt(res.length) <= 6 && parseInt(res.length) > 4:
  300. numberClass = 'six';
  301. break;
  302. case parseInt(res.length) <= 9 && parseInt(res.length) > 6:
  303. numberClass = 'nine';
  304. break;
  305. case parseInt(res.length) <= 12 && parseInt(res.length) > 9:
  306. numberClass = 'ten';
  307. break;
  308. case parseInt(res.length) <= 15 && parseInt(res.length) > 12:
  309. numberClass = 'twelve';
  310. break;
  311. case parseInt(res.length) <= 20 && parseInt(res.length) > 15:
  312. numberClass = 'sixteen';
  313. break;
  314. case parseInt(res.length) <= 24 && parseInt(res.length) > 20:
  315. numberClass = 'twenty';
  316. break;
  317. case parseInt(res.length) <= 30 && parseInt(res.length) > 24:
  318. numberClass = 'twentyFour';
  319. break;
  320. case parseInt(res.length) >= 31:
  321. numberClass = 'twentyFour';
  322. break;
  323. }
  324. let per = parseInt(res[i].ActivePercent);
  325. switch (true) {
  326. case per >= 90:
  327. colorClass = 'red';
  328. break;
  329. case per <= 89 && per > 79:
  330. colorClass = 'brown';
  331. break;
  332. case per <= 79 && per > 69:
  333. colorClass = 'yellow';
  334. break;
  335. case per <= 69 && per > 54:
  336. colorClass = 'green';
  337. break;
  338. case per <= 54 && per > 39:
  339. colorClass = 'violet';
  340. break;
  341. case per <= 39:
  342. colorClass = 'blue';
  343. break
  344. }
  345. that.studentsClassName[i] = {
  346. name: numberClass + ' ' + colorClass,
  347. }
  348. }
  349. },
  350. },
  351. components: {
  352. Headside, levelIcon, newRecord, newStudent, student
  353. }
  354. }
  355. </script>
  356. <style lang="scss" scoped>
  357. //@import "../assets/css/bg.css";
  358. @import "../assets/css/bg.scss";
  359. * {
  360. font-family: vista;
  361. }
  362. .pages {
  363. position: absolute;
  364. top: 0;
  365. left: 0;
  366. right: 0;
  367. bottom: 0;
  368. width: 100%;
  369. overflow: hidden;
  370. display: block;
  371. margin: 0 auto;
  372. font-family: vista;
  373. overflow-y: scroll;
  374. }
  375. </style>