| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- <template>
- <div :class="pageStyle">
- <Headside></Headside>
- <!-- 学生列表-->
- <div class="userList">
- <student :students="students" :students-class-name="studentsClassName"></student>
- </div>
- <!--图示-->
- <levelIcon></levelIcon>
- <!-- 突破纪录-->
- <newRecord :toper-info="toperInfo"></newRecord>
- <!-- 欢迎新同学-->
- <newStudent :student-info="studentInfo"></newStudent>
- </div>
- </template>
- <script>
- import Headside from '@/components/Headside'
- import newRecord from '@/components/newRecord'
- import newStudent from '@/components/newStudent'
- import levelIcon from '@/components/levelIcon'
- import student from '@/components/student'
- import
- {
- getHello,
- getClassStat,
- getRecordBreak,
- getNewUser
- } from '@/api/getApiRes'
- import '../libs/rem';
- import '../Global'
- let qs = require('qs');
- export default {
- data() {
- return {
- eqSn: '30:9C:23:0C:8B:1E',
- pageStyle: RandomBg(),
- trueDate: true,//真实数据 true false
- times: 1,
- thisClassName: '',
- studentsClassName: [],
- students: [],
- single: [],
- dialogVisible: false,
- serachBtnStatus: false,
- dialogMsg: '',
- imgsrc: '../static/img/people/',
- totalTime: 30,
- studentTime: 15,
- toperInfo: {
- dialogVisible: false,
- toper: {},
- },
- studentInfo: {
- dialogVisible: false,
- Rs: [],
- percent: 0
- },
- fakeEgg: {
- Rs: {
- "DuId": 37,
- "UserId": 0,
- "UserName": "郑伟",
- "Sex": 1,
- "Head": "https://img-operation.csdnimg.cn/csdn/silkroad/img/1604989753379.png",
- "Cle": 400,
- "CleTitle": "个人单次卡路里记录",
- "CleUnit": "千卡",
- "CkTitle": "个人单次CK记录",
- "Ck": 99.9,
- "CkUnit": "CK值",
- }
- },
- mainTimer: null,
- timer2: null,
- }
- },
- mounted() {
- // this.$router.push({path: '/2pkRank'});
- if (this.trueDate) {
- this.init();
- } else {
- // 彩蛋
- // this.OpenEgg(this.fakeEgg);
- // 1 2 4 6 9 10 13 16 21 24
- let Rs = fakeNews(33);
- this.giveClassName(Rs);
- this.students = Rs;
- // this.createNewStudent();
- }
- },
- watch: {
- '$route': function (val) {
- if (val.path == '/main') {
- if (this.trueDate) {
- this.init();
- } else {
- this.students = fakeNews(2);
- this.giveClassName(this.students);
- // this.createEgg(this.students[5]);
- }
- } else {
- clearInterval(this.mainTimer);
- clearInterval(this.timer2);
- clearInterval(this.timer3);
- }
- }
- },
- beforeDestroy() {
- clearInterval(this.mainTimer);
- clearInterval(this.timer2);
- clearInterval(this.timer3);
- this.mainTimer = null;
- this.timer2 = null;
- this.timer3 = null;
- },
- methods: {
- init() {
- // console.log(headTest);
- this.GetgetUserList();
- this.createEgg();
- this.createNewStudent();
- this.curgetClassStat();
- this.mainTimer = setInterval(() => {
- // this.$router.push({path: '/'});
- this.GetgetUserList();
- this.curgetClassStat();
- }, 1000);
- this.timer2 = setInterval(() => {
- this.createEgg();
- }, 31000);
- this.timer3 = setInterval(() => {
- this.createNewStudent();
- }, 6000);
- },
- alertInfo(info) {
- alert(info);
- },
- // 启动一个成就彩蛋
- createEgg() {
- let that = this;
- let param = {
- token: localStorage.token,
- eqSn: localStorage.eqSn
- };
- let postdata = qs.stringify(param);
- getRecordBreak(postdata).then(res => {
- let json = res;
- if (json.Code == 0) {
- // 欢迎新学生时不显示彩蛋
- if (that.studentInfo.dialogVisible == true) {
- console.log('正在显示新学生');
- return false
- } else {
- this.OpenEgg(json);
- }
- } else {
- // 并没有人破记录
- if (json.Code == 999) return false;
- if (json.Code != 999) that.$message.error(json.Memo + '[ 错误码]' + json.Code);
- }
- })
- },
- // 欢迎新同学
- createNewStudent() {
- let that = this;
- let param = {
- token: localStorage.token,
- eqSn: localStorage.eqSn
- };
- let postdata = qs.stringify(param);
- getNewUser(postdata).then(res => {
- let json = res;
- if (json.Code == 0) {
- console.log('来新生了');
- // 显示彩蛋时不欢迎新学生
- if (that.toperInfo.dialogVisible == true) {
- console.log('正在显示彩蛋');
- return false
- } else {
- console.log(json.Rs);
- that.OpenStudent(json.Rs);
- // OpenStudent(json.Rs,that);
- }
- } else {
- // 并没有人破记录
- if (json.Code == 999) return false;
- if (json.Code != 999) that.$message.error(json.Memo + '[ 错误码]' + json.Code);
- }
- })
- },
- OpenEgg(msg) {
- this.toperInfo.toper = msg.Rs;
- this.toperInfo.dialogVisible = true;
- // 倒计时5秒自动关闭
- let that = this;
- this.totalTime = 30;
- let clock = window.setInterval(() => {
- this.totalTime--;
- if (parseInt(this.totalTime) < 0) {
- that.toperInfo.dialogVisible = false;
- clearInterval(clock);
- }
- }, 1000)
- },
- OpenStudent(msg) {
- let that = this;
- that.studentInfo.Rs = msg;
- that.studentInfo.dialogVisible = true;
- this.studentInfo.percent = 0;
- // 倒计时5秒自动关闭
- this.studentTime = 15;
- let clock = window.setInterval(() => {
- this.studentTime--;
- let num = (15 - this.studentTime) / 15 * 100;
- this.studentInfo.percent = parseInt(num) > 100 ? 100 : num;
- console.log('num' + num);
- if (parseInt(this.studentTime) <= 0) {
- that.studentInfo.dialogVisible = false;
- clearInterval(clock);
- }
- }, 1000)
- },
- GetgetUserList() {
- let that = this;
- let param = {
- token: localStorage.token,
- eqSn: localStorage.eqSn
- };
- let postdata = qs.stringify(param);
- getHello(postdata).then(res => {
- let json = res;
- if (json.Code == 0) {
- that.students = json.Rs;
- that.giveClassName(json.Rs);
- } else {
- // 已下课
- if (json.Code == '999') {
- that.students = ""
- } else {
- // 已出错
- that.$message.error(json.Memo);
- }
- }
- })
- },
- curgetClassStat() {
- let that = this;
- let param = {
- token: localStorage.token,
- eqSn: localStorage.eqSn
- };
- let postdata = qs.stringify(param);
- getClassStat(postdata).then(res => {
- let json = res;
- if (json.Code == 0) {
- // 没开课
- if (json.ClassOn == 0) {
- console.log("下课了");
- // 0: 下课 团课/私教 排名
- // 1:团课/私教 todo
- // 2:竞技课2PK
- // 3:竞技课threepk
- switch (parseInt(json.dp)) {
- case 0:
- that.$router.push({path: '/rank'});
- break;
- case 1:
- that.$router.push({path: '/'});
- break;
- case 2:
- that.$router.push({path: '/pk'});
- break;
- case 3:
- that.$router.push({path: '/threepk'});
- break;
- }
- }
- } else {
- console.log("已上课");
- }
- })
- },
- // 给每一个数据加类名,一次遍历全部赋值
- giveClassName(res) {
- let that = this;
- let numberClass = '';
- let colorClass = '';
- for (let i = 0; i < parseInt(res.length); i++) {
- switch (true) {
- case parseInt(res.length) == 1:
- numberClass = 'max';
- break;
- case parseInt(res.length) == 2:
- numberClass = 'two';
- break;
- case parseInt(res.length) <= 4 && parseInt(res.length) > 2:
- numberClass = 'three';
- break;
- case parseInt(res.length) <= 6 && parseInt(res.length) > 4:
- numberClass = 'six';
- break;
- case parseInt(res.length) <= 9 && parseInt(res.length) > 6:
- numberClass = 'nine';
- break;
- case parseInt(res.length) <= 12 && parseInt(res.length) > 9:
- numberClass = 'ten';
- break;
- case parseInt(res.length) <= 15 && parseInt(res.length) > 12:
- numberClass = 'twelve';
- break;
- case parseInt(res.length) <= 20 && parseInt(res.length) > 15:
- numberClass = 'sixteen';
- break;
- case parseInt(res.length) <= 24 && parseInt(res.length) > 20:
- numberClass = 'twenty';
- break;
- case parseInt(res.length) <= 30 && parseInt(res.length) > 24:
- numberClass = 'twentyFour';
- break;
- case parseInt(res.length) >= 31:
- numberClass = 'twentyFour';
- break;
- }
- let per = parseInt(res[i].ActivePercent);
- switch (true) {
- case per >= 90:
- colorClass = 'red';
- break;
- case per <= 89 && per > 79:
- colorClass = 'brown';
- break;
- case per <= 79 && per > 69:
- colorClass = 'yellow';
- break;
- case per <= 69 && per > 54:
- colorClass = 'green';
- break;
- case per <= 54 && per > 39:
- colorClass = 'violet';
- break;
- case per <= 39:
- colorClass = 'blue';
- break
- }
- that.studentsClassName[i] = {
- name: numberClass + ' ' + colorClass,
- }
- }
- },
- },
- components: {
- Headside, levelIcon, newRecord, newStudent, student
- }
- }
- </script>
- <style lang="scss" scoped>
- //@import "../assets/css/bg.css";
- @import "../assets/css/bg.scss";
- * {
- font-family: vista;
- }
- .pages {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- width: 100%;
- overflow: hidden;
- display: block;
- margin: 0 auto;
- font-family: vista;
- overflow-y: scroll;
- }
- </style>
|