AdministratorApe.js 9.3 KB
//*
// 管理员界面
// */

import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
let loger = Loger.getLoger('PC-AdministratorApe');

const adminListTit = `<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" id="t_box" class="t_box">
                        <tbody>
                            <tr align="center" height="44" class="tr_center" bgcolor="#fff" bordercolor="#e6e6e6">
                                <th width="8%" class="tr_center">
                                    课堂主题
                                </th>
                                <th width="9%" class="tr_center">
                                    课堂号
                                </th>
                                <th width="8%" class="tr_center">
                                    老师
                                </th>
                                <th width="6%" class="tr_center">
                                    课堂状态
                                </th>
                                <th width="20%" class="tr_center">
                                    课堂时间
                                </th>
                                <th width="6%" class="tr_center">
                                    在线人数
                                </th>
                                <th width="20%" class="tr_center">
                                    操作
                                </th>
                            </tr>
`;
//管理首页
const adminList = `<tr align="center" bgcolor="#FFFFFF" height="44" bordercolor="#e6e6e6">
                                <td width="8%" class="tr_main tr_mainLeft">{_meetingName}</td>
                                <td width="8%" class="tr_main">{_esenglish}</td>
                                <td width="8%" class="tr_main">{_userName}</td>
                                <td width="6%" class="tr_main">{_stateInfo}</td>
                                <td  width="18%" class="tr_main">{_time}</td>
                                <td width="4%" class="tr_main">{_onlineLen}</td>
                                <td  width="20%" class="tr_main tr_mainRight" align="center" >
                                    <a id="{_DocInd}" class="classHandlePort" href="#">文档</a>
                                    <a id="{_mediaInd}" class="classHandlePort" href="">多媒体</a>
                                    <a id="{_musicInd}" class="classHandlePort" href="">伴音</a>
                                    <a id="{_updateInd}" class="classHandlePort" href="">修改</a>
                                    <a id="{_removeInd}" class="classHandlePort" href="">删除</a>
                                    <a id="{_joinInd}" class="classHandlePort" href="">加入课堂</a>
                                </td>
                            </tr>
`;
const adminListEnd = `</tbody></table>`;
class AdministratorApe extends Ape {
    constructor() {
        super();
        this.classDateList = {};//课堂的所有数据
        this.pageNo = 0;
        this.presentInd = 0;
        this.isLocalStorage();
        this.addEvent();
        this.init();
    }

    init() {
        this.detailPage();
        $('#collectYes').hide();

        $('#classHandlerHomePage').on('click',this._homePageHandler.bind(this));//首页
        $('#classHandlerUpPage').on('click',this._upPageHandler.bind(this));//上页
        $('#classHandlerDownPage').on('click',this._downPageHandler.bind(this));//下页
        $('#classHandlerEndPage').on('click',this._endPageHandler.bind(this));//尾页
        $('#classHandlerSpecificPage').on('click',this._assignPageHandler.bind(this));//指定页
    }

    addEvent() {

    }
    isLocalStorage(){
        if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_2){
            this.detailPage();
        }
    }
    //首页
    _homePageHandler(){
        this.presentInd = 1;
        this._pageNumBtnHandler(this.presentInd);
    }
    //上页
    _upPageHandler(){
        if(this.presentInd >1){
            this.presentInd--;
            this._pageNumBtnHandler(this.presentInd);
        }
    }
    //下页
    _downPageHandler(){
        if(this.presentInd < this.pageNo){
            this.presentInd++;
            this._pageNumBtnHandler(this.presentInd);
        }
    }
    //尾页
    _endPageHandler(){
        this.presentInd = this.pageNo;
        this._pageNumBtnHandler(this.presentInd);
    }
    //指定页
    _assignPageHandler(){
        let inputVal = $('#classHandlerPageInfoInput').val();
        if(parseInt(inputVal) <= this.pageNo || parseInt(inputVal) >= 1 ){
            this._pageNumBtnHandler(parseInt(inputVal));
        }
    }

    //点击翻页
    _pageNumBtnHandler(ind){
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        let that = this;
        $.ajax({
            type: "POST",
            url: _url,
            data:{siteId:'markettest'},
            headers: {'page':ind,
                type:8,
                'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo',
            },
            success:function(_data){
                if(_data.code != 200 ){
                    loger.warn(_data.returnData.data.msg)
                }
                that.classDateList = _data.returnData.data;
                that._gainClassData(_data.returnData.data);
            },
            error:function(error){
                console.log(error,'失败')
            }
        })

    }
    detailPage(){
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        let that = this;
        $.ajax({
            type: "POST",
            url: _url,
            data:{siteId:'markettest'},
            headers: {siteId:'markettest',
                type:8,
                'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
            success:function(_data){
                if(_data || _data.code == 200){
                    that._gainClassData(_data.returnData.data);
                }
            },
            error:function(error){
                console.log(error,'失败')
            }
        })
    }
    _classDateTitle(){
        $('#classifyListTitle').html($('.header_listMsgCheck').attr('data'));
    }
    _gainClassData(_data){
        let courseContent = $('#courseContent');
        courseContent.empty();
        let count = _data.count;
        let page = _data.page;
        let pageno = _data.pageno;
        let _dataList = _data.meetingInfo;
        this.pageNo = pageno;
        $('#classHandlerPageMsg').html('第'+page+'页/共'+pageno+'页,有'+count+'个记录');
        courseContent.append(adminListTit);
        if(_dataList){
            if(_dataList.length <= 1){
                $('#classHandlerPageBox').hide();
            }
            for(let i = 0;i<_dataList.length;i++){
                let _adminList = this._format(adminList,{
                    _meetingName : _dataList[i].meetingName,
                    _esenglish : _dataList[i].meetingNumber,
                    _userName : _dataList[i].create_user,
                    _stateInfo : '准备',
                    _time: _dataList[i].beginTime+' - '+_dataList[i].endTime,
                    _onlineLen : '0',
                    _DocInd : 'classDoc'+i,
                    _mediaInd : 'classMedia'+i,
                    _musicInd : 'classMusic'+i,
                    _updateInd : 'classUpdate'+i,
                    _removeInd : 'classRemove'+i,
                    _joinInd : 'classJoin'+i
                })
             courseContent.append(_adminList);
            }
            courseContent.append(adminListEnd);
        }
    }
    _classDatepageNum(_data){ //page
        let _pageContent = _data.count;
        let _pageNum = Math.ceil(_pageContent / _data.pageno);

        this.pagingConstruct(1,_pageNum);
    }
    pagingConstruct(paging,total){
        let pageNumContentBox = $('#pageNumContentBox');
        pageNumContentBox.empty();
        let pagingDivInnerHTML = '<div class="pageNumContent">';
        let isHiddenExist = 0;
        for(let i =1 ;i<=total;i++){
            if(i == paging){
                pagingDivInnerHTML +='<span class="pageNumBtn pageNumBtnCheck">'+i+'</span>';
            }else{
                if (i < 4 || i < (paging + 4) && i > (paging - 2) && i < (total / 2 + 2) || i > (total - 2)) {
                    pagingDivInnerHTML +='<span class="pageNumBtn">'+i+'</span>';
                    isHiddenExist = 0;
                }else{
                    if(isHiddenExist == 0){
                        pagingDivInnerHTML += '<span class="pageNumBtn">...</span>';
                        isHiddenExist = 1;
                    }
                }
            }
        }
        pagingDivInnerHTML += '</div>';
        pageNumContentBox.append(pagingDivInnerHTML);
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default AdministratorApe;