"use strict";
import { util } from '../util/util.js';
import {header} from "./header/header.js";
import {menu} from "./menu/menu.js";
import {pageInfoMap} from "../pageInfoMap.js";
import {form} from "./page/form/form.js";
import {bpm} from "./bpm/bpm.js";
import {fullMap} from "../fullMap.js";
import {khcModal} from "./alert/khcModal.js";
import {page} from "./page/page.js";
import {httpUtil} from "../util/httpUtil.js";
import {khcAlert} from "./alert/khcAlert.js";
import {charts} from "./charts/charts.js";
import {config} from "../config.js";
import {khcToastr} from "./alert/khcToastr.js";
import {simpleCard} from "./simplecard/simpleCard.js";
import {menuConfig} from "./menu/menuConfig.js";
import {menuSettingsConfig} from "./menu/menuSettingsConfig.js";
import {iframe} from "./iframe/iframe.js";
import {pageForm} from "./form/pageForm.js";
import {htmlView} from "./htmlview/htmlView.js";
import {openLink} from "./openlink/openLink.js";
import {nav} from "./nav/nav.js";

class home {
    constructor(data) {
        this.pageCode='';
        this.parentObjID=data.parentObjID;
        this.isPageTabs=false;
        this.menuObj=null; //左侧菜单对象
        this.headerObj=null;//顶部菜单对象
        this.pageFormMap = new Map();//所生成的pageForm对象使用
        this.renderPageCodeArray=[];
    }
    render() {
        return new Promise(async (resolve, reject) => {
            await this.renderMenu();
            if(this.isRenderPage){
                resolve();
            }
        })
    }
    renderMenu(){
        let that=this;
        let params = { version: '1.0.0', dsCode: 'ds_system_menu', methodName: 'getMenu' }
        let obj={url:config.getConfigJson().myActionUrl,params:params}
        that.isRenderPage=true;
        obj.errorCallback= (response)=>{
            that.isRenderPage=false;
        }
        return httpUtil.post(obj,(response)=>{
            let menuData = { menuList: response.data.data.menuList };
            let thisHeader = new header({ userName: response.data.data.userName });
            that.setLocalDefaultInfo(response);
            that.homeKeydownFunc();
            let thisMenu = null
            if(response.data.data.menuRenderType=='2'){

            }else{

            }
            document.getElementById('app').classList.add('page-done')
            document.getElementById('app').innerHTML=menuConfig.getMenuConfigJson().defaultTemplate;
            thisMenu=new menu(menuData);
            menuSettingsConfig.initFunc()
            document.querySelector('title').innerText=config.getConfigJson().systemFullName;//set 系统名称
            document.getElementById('systemNameA').innerText=config.getConfigJson().systemShortName;//set 系统名称(简称)
            document.getElementById('systemNameSpan').innerText=config.getConfigJson().systemShortName;//set 系统名称(简称)
            document.getElementById('systemLogoImgPC').src=config.getConfigJson().logoPath;//set logo 大屏
            document.getElementById('systemLogoImgAPP').src=config.getConfigJson().logoPath;//set logo 小屏
            document.querySelector('link[rel="icon"]').href=config.getConfigJson().iconPath;//set icon
            //通过url输入路径的处理
            thisHeader.render().then(() => {
                thisMenu.render();
                if(response.data.data.passwordStatus=='2'){//即将过期
                    khcToastr.showWarningMessage({msg:response.data.data.passwordMessage,closeButton:true});
                }else if(response.data.data.passwordStatus=='1'){//已过期
                    khcToastr.showErrorMessage(response.data.data.passwordMessage);
                    document.getElementById(that.headerObj.objID+'rePassword').click();
                }
            })
            that.menuObj=thisMenu;
            that.headerObj=thisHeader;
            fullMap.push('home',that);
        })
    }
    getPageCode(){
        return this.pageCode;
    }
    setPageCode(pageCode){
        if (window.location.search.length>0) {
            util.setSessionStorageItem('pageCode',window.location.search);
        }else{
            let componentCode=util.getUrlParam('component_code');
            let componentUrl=``;
            if(!util.isNull(componentCode)){
                componentUrl=`&component_code=${componentCode}`;
            }

            util.setSessionStorageItem('pageCode','?pageCode='+pageCode+'&queryInfo=%7B%7D'+componentUrl);
        }
        this.pageCode=pageCode;
    }
    getParentPageDivId(){
        return this.parentObjID+'_'+this.getPageCode();
    }
    setLocalDefaultInfo(response){
        util.setLocalStorageItem('userName', response.data.data.userName);
        util.setLocalStorageItem('userId', response.data.data.userId);
        util.setLocalStorageItem('orgId', response.data.data.orgId);
        util.setLocalStorageItem('orgName', response.data.data.orgName);
        util.setLocalStorageItem('isUserSecondment', response.data.data.isUserSecondment);
        util.setLocalStorageItem('isKhcAdmin', response.data.data.isKhcAdmin);
        util.setLocalStorageItem('passwordStatus', response.data.data.passwordStatus);
        util.setLocalStorageItem('passwordMessage', response.data.data.passwordMessage);
        util.setLocalStorageItem('menuRenderType', response.data.data.menuRenderType);//1是渲染
        util.setLocalStorageItem('version', response.data.data.version);
        if(response.data.data.userPic=='[]'||util.isNull(response.data.data.userPic)){
            util.setLocalStorageItem('userPic', '../css/img/avatars/1.png');
        }else{
            let fileInfo=JSON.parse(response.data.data.userPic)[0]
            let userPic=util.getFileUrl(fileInfo);
            util.setLocalStorageItem('userPic', userPic);
        }
    }
    homeKeydownFunc(){
        let that=this;
        // 定义一个变量来存储用户按键的顺序
        let keySequence = [];
        // 定义需要检测的顺序
        const targetSequenceSecondary = ['ArrowDown', 'ArrowLeft', 'ArrowRight']; // 二级设置快捷键
        const targetSequencePrimary = ['ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowLeft', 'ArrowRight', 'ArrowRight']; // 一级设置快捷键
        let isKhcAdmin=util.getLocalStorageItem('isKhcAdmin');
        if(isKhcAdmin=='Y'){
            document.addEventListener('keydown', function(event) {
                // 将按下的键添加到顺序中
                keySequence.push(event.key);
                // 检查顺序是否与目标顺序匹配
                if (keySequence.length === targetSequenceSecondary.length &&
                    keySequence.every((value, index) => value === targetSequenceSecondary[index])) {
                    util.setSessionStorageItem('isEditComponent','S'); // 二级设置启用（N：不启用任何开发模式，S：二级开发模式，P一级开发模式）
                    khcToastr.showSuccessMessage('启用二级开发模式')
                    setTimeout(function (){
                        let alertData = {};
                        alertData.title = '是否重新加载';
                        alertData.text = '启用二级开发模式需要重新加载页面生效';
                        alertData.preConfirm = () => {
                            window.location.reload()
                        }
                        khcAlert.showConfirm(alertData, () => {})
                    },200)
                    // 重置顺序数组
                    keySequence = [];
                }else if (keySequence.length === targetSequencePrimary.length &&
                    keySequence.every((value, index) => value === targetSequencePrimary[index])) {
                    util.setSessionStorageItem('isEditComponent', 'P'); // 一级设置启用
                    khcToastr.showSuccessMessage('启用一级开发模式')
                    setTimeout(function (){
                        let alertData = {};
                        alertData.title = '是否重新加载';
                        alertData.text = '启用一级开发模式需要重新加载页面生效';
                        alertData.preConfirm = () => {
                            window.location.reload()
                        }
                        khcAlert.showConfirm(alertData, () => {})
                    },200)
                }else if(event.key=='ArrowUp'){
                    // 重置顺序数组
                    keySequence = [];
                    util.setSessionStorageItem('isEditComponent','N'); // 不启用
                }
            });
        }else{
            util.setSessionStorageItem('isEditComponent','N'); // 不启用
        }
    }
    //渲染页面，有参数的则根据参数渲染，无参的则根据PageCode渲染
    renderPageInfo() {
        let that=this;
        for (let i = 0; i < that.renderPageCodeArray.length; i++) {
            let parentPageDivId=that.parentObjID+'_'+that.renderPageCodeArray[i];
            document.getElementById(parentPageDivId).style.display='none';
        }
        if (!this.renderPageCodeArray.includes(that.pageCode)) {
            this.renderPageCodeArray.push(that.pageCode);
            let htmlTemplate=`<div id="${that.getParentPageDivId()}" style="display: none" class="app-main row"></div>`
            document.getElementById(objParentObjID).insertAdjacentHTML("beforeEnd", htmlTemplate);
        }
        document.getElementById(that.getParentPageDivId()).style.display='';
        document.getElementById(that.getParentPageDivId()).innerHTML='';
        that.isPageTabs=false;
        return new Promise((resolve, reject) => {
            let pageCode = that.pageCode;
            let urlPageCode = config.getPageCode();
            let formShowType = null;
            formShowType = util.getUrlParam('formShowType');
            if(formShowType!=null&&formShowType!=''){
                let params = {};
                params.dsCode = util.getUrlParam('dsCode');
                params.queryCode = util.getUrlParam('queryCode');
                params.formCode = util.getUrlParam('formCode');
                params.formVersion = util.getUrlParam('formVersion');
                if (formShowType == 'page') {//页面编辑
                    /*let khcModalForForm=pageInfoMap.getObj('khcModalForForm#'+formShowType);
                    khcModalForForm.hide();*/
                    $('#' + config.getConfigJson().modalAreaID).children().modal('hide');
                    document.getElementById(`${that.parentObjID+'_'+pageCode}`).className='';//清空class row 不然表单会变形
                    document.getElementById(config.getConfigJson().modalAreaID).innerHTML = '';
                    let uuid = util.getUUID();
                    let formData = { parentObjID: that.getParentPageDivId(), code: params, pageID: uuid}
                    let formView = new form(formData);
                    formView.render().then(() => {
                        params.pkId = util.getUrlParam('pkId');
                        if(!util.isNull(util.getUrlParam('pkFieldId'))){
                            params.pkFieldId=util.getUrlParam('pkFieldId');
                        }
                        let obj={url:config.getConfigJson().queryOneUrl,params:params}
                        httpUtil.post(obj,(response)=>{
                            if (response.data.status == 'ok') {
                                let eleMap = formView.getFormMap();
                                let content = response.data.data;
                                for (let key in content) {
                                    eleMap.get(key).setValue(content[key])
                                }
                                if(!util.isNull(formView.formStructureData.formInfo.myjs)){
                                    util.import(formView.formStructureData.formInfo.myjs,formView.objID,'init','edit')//todo 这里调用方式还是旧的，待更新（fEdit）
                                }
                                formView.oldEditData=JSON.parse(JSON.stringify(formView.getFormValue()));
                                let thisBpm=new bpm({formView:formView});
                                thisBpm.render();
                                formView.formEdit();
                            }
                        })
                    });
                    formView.setFormShowType(formShowType);
                    //同理可以实现saveBefore
                    formView.setSaveAfter(()=> {
                        //aaaa
                    })
                    fullMap.push(formView.getObjID(), formView);
                } else if(formShowType=='modals'){//modals 弹窗(编辑)
                    let khcModalForForm = new khcModal({ modalAreaID: config.getConfigJson().modalAreaID });
                    khcModalForForm.render().then(() => {
                        let formComponent = new form({ parentObjID: khcModalForForm.getEleID(), code: params });
                        khcModalForForm.formObjID=formComponent.getObjID()
                        let khcModalForFormKey='khcModalForForm#'+formComponent.getObjID();
                        pageInfoMap.push(khcModalForFormKey,khcModalForForm);
                        formComponent.setFormShowType('modals')
                        formComponent.buttons = [
                            { button_name: 'save1', button_title: '保存', button_class: 'primary', button_method: 'save', button_event: 'click', js_path: '' },
                            { button_name: 'close', button_title: '返回', button_class: 'dark', button_method: 'close', button_event: 'click', js_path: '../component/header/headerAction.js' },
                        ];
                        formComponent.render().then(() => {
                            params.pkId = util.getUrlParam('pkId');
                            let obj={url:config.getConfigJson().queryOneUrl,params:params}
                            httpUtil.post(obj,(response)=>{
                                let eleMap = formComponent.getFormMap();
                                let content = response.data.data;
                                for (let key in content) {
                                    eleMap.get(key).setValue(content[key])
                                }
                            })
                            formComponent.formEdit();
                            khcModalForForm.show();
                        });
                        //同理可以实现saveBefore
                        formComponent.setSaveAfter(()=> {
                            khcModalForForm.hide();
                        })
                    })
                }
            } else {
                let queryInfo= null;
                let urlPageCode = util.getUrlParam('pageCode');
                if(formShowType==null&&!util.isNull(urlPageCode)){
                    queryInfo = JSON.parse(util.getUrlParam('queryInfo'));
                    pageCode=urlPageCode;
                    that.pageCode=urlPageCode;
                }
                let pageParam = { pageCode: pageCode }
                if(!util.isNull(queryInfo)){
                    pageParam['queryInfo']=queryInfo
                }
                let obj={url:config.getConfigJson().pageInfoUrl,params:pageParam,isClientCache:true}
                obj.errorCallback= (response)=>{
                    let htmlTemplate=`<div class="col-12 khc-theme-status-info-bf-color khc-theme-status-info-color">
                    <div class="container d-flex align-items-center text-white" style="height: 92vh">
                        <div class="row align-content-center align-items-start align-items-md-center w-100 py-5">
                            <div class="col-md-6 order-2 order-md-1 text-md-left text-center">
                                <h1 class="display-2 font-weight-bolder mb-4">无法访问</h1>
                                <div class="text-xlarge font-weight-light mb-5">404，网址错误或已失效。请检查网址</div>
                                <button type="button" class="btn btn-outline-white" name="toHomeBtn">返回首页</button>
                            </div>
                            <div class="col-md-6 order-1 order-md-2 text-center mb-5 mb-md-0">
                                <div class="ui-device macbook w-100 rounded" style="max-width: 500px">
                                    <img class="device-img" src="../css/img/devices/macbook-gold.png" alt="">
                                    <div class="device-content">
                                        <div class="error-device-content khc-theme-status-info-bf-color khc-theme-status-info-color ">
                                            <div class="error-device-code text-white font-weight-bolder">404</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>`
                    document.getElementById(that.getParentPageDivId()).innerHTML=htmlTemplate;
                    util.setSessionStorageItem('pageCode','');
                    document.getElementById(that.getParentPageDivId()).querySelector('button[name=toHomeBtn]').addEventListener('click',function (){
                        window.location.href=config.getIndexUrl()+'#'+config.getHomePageCode();
                    })
                }
                httpUtil.post(obj,(response)=>{
                    let pageType = response.data.data.page_type;
                    let menuShowType = response.data.data.menu_show_type;
                    let pageContentHeaderHtml=`<div id="${that.getParentPageDivId()}_header"  class="col-12 mb-1" style="display: none">
                        <div class="layout-example-block layout-example-block-navbar mb-1 mt-1" style="background: #fff;">
                        <div class="col-12" id="${that.getParentPageDivId()}_header_content_div">
                            <div id="${that.getParentPageDivId()}_header_default" style="color: #666;font-size: 18px;font-family: 'MiSans Bold', 'MiSans Normal', 'MiSans', sans-serif;font-weight: 700;font-style: normal;font-size: 18px;">
                            </div>
                        </div>
                    </div></div>`
                    document.getElementById(that.getParentPageDivId()).insertAdjacentHTML("beforeEnd",pageContentHeaderHtml);
                    if(!util.isNull(response.data.data.js_file)&&!util.isNull(response.data.data['page_render_before'])){
                        let jsonConfig={objID:'home',button_method:response.data.data['page_render_before']}
                        util.import2023(response.data.data.js_file,jsonConfig);
                    }
                    that.refreshMenuByType(menuShowType)
                    let componentArray = response.data.data.componentData;
                    let isEditComponent=util.getSessionStorageItem('isEditComponent');
                    if(componentArray.length==0&&util.isNull(response.data.data.js_file)){
                        let htmlTemplate=`<div style="margin-bottom:20px;" class="col-12 "><h3>我们还在整理完善 <strong>${response.data.data['page_name']}</strong> 内容，我们会尽快更新内容，敬请期待。</h3></div>`
                        document.getElementById(that.getParentPageDivId()).innerHTML=htmlTemplate;
                    }
                    if(isEditComponent=='P'){
                        let pageUUID = response.data.data.uuid;
                        if(pageCode=='page_component'){
                            util.setSessionStorageItem('pageCode','');
                        }else{
                            if(componentArray.length>0){
                                componentArray=util.clone(componentArray)
                            }
                            //模拟一个当前页面组件配置
                            componentArray.push({
                                "col": "12",
                                "component_height": "1000",
                                "charts_code": "",
                                "create_time": "2024-09-09 09:11:16",
                                "component_name": "当前页面组件配置",
                                "ds_code": "",
                                "sort": 150,
                                "uuid": "1b2e97e923154e77b33719cc64de3fcf",
                                "layout": "",
                                "page_id": 0,
                                "page_parent_uuid": "3a5c8ec04ad046c8bf4ff19918e76da7",
                                "component_type": "iframe",
                                "update_time": "2024-09-09 15:06:06",
                                "update_user": "",
                                "component_status": "0",
                                "user_area": "",
                                "query_code": "",
                                "component_url": "./index.html?pageCode=page_component&queryInfo={\"page_parent_uuid\":\""+pageUUID+"\"}",
                                "id": 87,
                                "create_user": "",
                                "form_code": "",
                                "simple_card_code": "",
                                "status": "0"
                            })
                        }
                    }
                    if(response.data.data['is_warm_tip']=='Y'){
                        document.getElementById(that.getParentPageDivId()).insertAdjacentHTML("beforeEnd",`<div id="${that.getParentPageDivId()}_warm_tip" style="display: block;position: fixed;right: 50px;bottom: 80px;    cursor: pointer;background: url(../css/img/warm_tips.png) 0 0 no-repeat;width: 101px;height: 66px;z-index: 999"></div>`);
                        let khcModalForForm = new khcModal({ modalAreaID: config.getConfigJson().modalAreaID });
                        let showObjId=util.getUUID();
                        let khcModalHtml = '';
                        khcModalHtml += '<div class="card">'
                        khcModalHtml += '<h5 class="card-header">'
                        khcModalHtml += `${response.data.data['page_name']}`
                        khcModalHtml += '</h5>';
                        khcModalHtml += '<div style="padding: 0.1rem;" class="" id="'+showObjId+'">'
                        khcModalHtml += '</div></div>';
                        khcModalForForm.render().then(() => {
                            document.getElementById(khcModalForForm.getEleID()).insertAdjacentHTML("beforeEnd", khcModalHtml);
                            let html='<div class="ql-editor">'
                            html+= util.toOldChar(response.data.data['warm_tip_content']);
                            html+='</div>'

                            document.getElementById(showObjId).insertAdjacentHTML("beforeEnd", html);
                        })
                        document.getElementById(`${that.getParentPageDivId()}_warm_tip`).addEventListener('click',function (){
                            khcModalForForm.show();
                        })
                    }

                    let renderPageNum=0
                    that.queryComponentInfo(componentArray).then((parentPageDivId)=>{
                        //pageType：ordinary普通 pageTabs为页面选项卡
                        if(componentArray.length>=4){
                            fullMap.getObj('mask').showByElement(that.getParentPageDivId(),1500);
                        }
                        that.componentArray=componentArray;
                        for (let i = 0; i < componentArray.length; i++) {
                            let componentInfo = componentArray[i];
                            if(formShowType==null){
                                pageInfoMap.push(componentInfo.query_code,queryInfo);
                            }
                            let pageData = { parentObjID: parentPageDivId,pageType:pageType };
                            if(componentInfo.component_type=='dataSource'){
                                renderPageNum=renderPageNum+1;
                                let timeout=0;
                                if(renderPageNum>2){
                                    timeout=2000;//两个page以上则后面的需要延迟2秒渲染，优先渲染前两个page
                                }
                                let code={ version: '1.0.0', dsCode: componentInfo.ds_code,
                                    formCode: componentInfo.form_code,queryCode: componentInfo.query_code,col: componentInfo.col};
                                let formCode = { parentObjID: util.getUUID() + 'div', type: 'form', code: code }
                                let queryCode = { parentObjID: util.getUUID() + 'div', type: 'query', code: code };
                                pageData['componentName']=componentInfo.component_name
                                pageData['componentInfo']=componentInfo
                                pageData['pageCode'] = that.pageCode;
                                pageData['formCode'] = formCode;
                                pageData['queryCode'] = queryCode;
                                pageData['timeoutRender'] = timeout;
                                let thisFormPage = new page(pageData);
                                thisFormPage.render();
                                fullMap.push(thisFormPage.objID, thisFormPage);
                            }
                            if(componentInfo.component_type=='form'){
                                let code={ version: '1.0.0', dsCode: componentInfo.ds_code,
                                    formCode: componentInfo.form_code,col: componentInfo.col,formViewMode:componentInfo['form_view_mode'],formFindOneMethodName:componentInfo['form_find_one_method_name']};
                                let formCode = { parentObjID: util.getUUID() + 'div', type: 'form', code: code }
                                pageData['componentName']=componentInfo.component_name
                                pageData['componentInfo']=componentInfo
                                pageData['pageCode'] = that.pageCode;
                                pageData['formCode'] = formCode;
                                let thisFormPage = new pageForm(pageData);
                                thisFormPage.render();
                                fullMap.push(thisFormPage.objID, thisFormPage);
                                that.pageFormMap.set(thisFormPage.objID, thisFormPage);
                            }
                            if(componentInfo.component_type=='charts'){
                                let code={ version: '1.0.0',chartsCode:componentInfo.charts_code,chartsData:componentInfo,col: componentInfo.col,chartsHeight: componentInfo.component_height};
                                let chartsCode = { parentObjID: util.getUUID() + 'div', type: 'charts', code: code }
                                pageData['componentInfo']=componentInfo
                                pageData['chartsCode']=chartsCode
                                let thisEcharts = new charts(pageData);
                                thisEcharts.render();
                                fullMap.push(thisEcharts.objID, thisEcharts);
                                that[componentInfo['charts_code']]=thisEcharts;
                            }
                            if(componentInfo.component_type=='simpleCard'){
                                let code={ version: '1.0.0',simpleCardCode:componentInfo.simple_card_code,simpleCardData:componentInfo,col: componentInfo.col};
                                let simpleCardCode = { parentObjID: util.getUUID() + 'div', type: 'simpleCard', code: code }
                                pageData['simpleCardCode']=simpleCardCode
                                let thisSimpleCard = new simpleCard(pageData);
                                thisSimpleCard.render();
                                fullMap.push(thisSimpleCard.objID, thisSimpleCard);
                                that[componentInfo['simple_card_code']]=thisSimpleCard;
                            }
                            if(componentInfo.component_type=='htmlView'){
                                let code={ version: '1.0.0',htmlViewCode:componentInfo.html_view_code,htmlViewData:componentInfo,col: componentInfo.col,htmlViewHeight: componentInfo.component_height};
                                let htmlViewCode = { parentObjID: util.getUUID() + 'div', type: 'htmlView', code: code }
                                pageData['componentInfo']=componentInfo
                                pageData['htmlViewCode']=htmlViewCode
                                let thisHtmlView = new htmlView(pageData);
                                thisHtmlView.render();
                                fullMap.push(thisHtmlView.objID, thisHtmlView);
                                that[componentInfo['html_view_code']]=thisHtmlView;
                            }
                            if(componentInfo.component_type=='iframe'){
                                let code={ version: '1.0.0',iframeURL:componentInfo.component_url,iframeHeight: componentInfo.component_height,col: componentInfo.col};
                                let iframeCode = { parentObjID: util.getUUID() + 'div', type: 'iframe', code: code }
                                pageData['componentInfo']=componentInfo
                                pageData['iframeCode']=iframeCode
                                let thisIframe = new iframe(pageData);
                                thisIframe.render();
                                fullMap.push(thisIframe.objID, thisIframe);
                                that[componentInfo['iframe']]=thisIframe;
                            }
                            if(componentInfo.component_type=='openLink'){
                                let code={ version: '1.0.0',openURL:componentInfo.component_url,componentName:componentInfo.component_name};
                                let openLinkCode = { parentObjID: util.getUUID() + 'div', type: 'openLink', code: code }
                                pageData['componentInfo']=componentInfo
                                pageData['openLinkCode']=openLinkCode
                                let thisOpenLink = new openLink(pageData);
                                thisOpenLink.render();
                                fullMap.push(thisOpenLink.objID, thisOpenLink);
                            }
                            if(componentInfo.component_type=='nav'){
                                let code={ version: '1.0.0',navCode:componentInfo.nav_code,componentName:componentInfo.component_name,navHeight: componentInfo.component_height};
                                let navCode = { parentObjID: util.getUUID() + 'div', type: 'nav', code: code }
                                pageData['componentInfo']=componentInfo
                                pageData['navCode']=navCode
                                let thisNav = new nav(pageData);
                                thisNav.render();
                                fullMap.push(thisNav.objID, thisNav);
                            }

                        }
                        if(!util.isNull(response.data.data.js_file)&&!util.isNull(response.data.data['page_render_after'])){
                            let jsonConfig={objID:'home',button_method:response.data.data['page_render_after']}
                            util.import2023(response.data.data.js_file,jsonConfig);
                        }
                    });
                })
            }
            that.menuObj.setActiveMenuByCode(pageCode,false)
            resolve();
        })
    }
    refreshMenuByType(menuShouType){
        let that=this;
        if(util.isNull(menuShouType)){
            menuShouType="1";//默认类型1，展示icon(图标)+菜单名称
        }
        that.headerObj.menuShowByType(menuShouType);
    }
    queryComponentInfo(componentArray){
        let that=this;
        return new Promise((resolve, reject) => {
            if(componentArray.length==0){
                resolve()
                return ;
            }
            let queryCount=0;//设置
            let parentPageDivId=that.getParentPageDivId();
            for (let i = 0; i < componentArray.length; i++) {
                let componentInfo = componentArray[i];
                let noGetMetaTypeArr=['charts','simpleCard','iframe','htmlView','openLink','nav']
                if(!noGetMetaTypeArr.includes(componentInfo.component_type)){
                    let code={ version: '1.0.0', dsCode: componentInfo.ds_code, formCode: componentInfo.form_code,queryCode: componentInfo.query_code };
                    let formCode = { parentObjID: util.getUUID() + 'div', type: 'form', code: code }
                    let queryCode = { parentObjID: util.getUUID() + 'div', type: 'query', code: code };
                    let formPageData = { parentObjID: that.pageCode };
                    formPageData['pageCode'] = that.pageCode;
                    formPageData['formCode'] = formCode;
                    formPageData['queryCode'] = queryCode;
                    let obj={url:config.getConfigJson().metaUrl,params:code,isClientCache:true}//isClientCache：true 将查询结果存到临时缓存
                    httpUtil.post(obj,(response)=>{
                        //成功后什么也不操作，这是将所有的组件信息查询出来，然后放临时缓存。
                    }).then(()=>{
                        queryCount=queryCount+1;//查询成功加1
                        if(queryCount==componentArray.length) resolve(parentPageDivId);
                    })
                }else{
                    queryCount=queryCount+1;//图表不查询，但也需要+1
                    if(queryCount==componentArray.length) resolve(parentPageDivId);
                }
            }
        })
    }
    refreshSimpleCardValue(){
        let that=this;
        let componentArray=that.componentArray;
        for (let i = 0; i < componentArray.length; i++) {
            let componentInfo = componentArray[i];
            if(componentInfo.component_type=='simpleCard'){
                that[componentInfo['simple_card_code']].refreshSimpleCardValue(0);
            }
        }
    }

}
export { home };