/**
 * config.js
 *
 * 说明：
 * 该文件包含应用的敏感配置信息，需要登录后才能访问。配置项包括但不限于：
 * - API 密钥
 * - 数据库连接字符串
 * - 权限设置
 *
 * 登录用户才能访问本文件中的配置，确保了敏感信息的安全性。
 *
 * 注意：
 * 如果用户未登录，将只能访问 nosession_config.js 文件，该文件包含
 * 公共配置，不包含敏感信息。
 *
 * 使用场景：
 * 本文件主要用于存储应用内部的敏感配置，如认证信息、API 密钥等，
 * 这些配置项对于已登录的用户才有意义。
 */
"use strict";
import { util } from './util/util.js'
import {menuSettingsConfig} from "./component/menu/menuSettingsConfig.js";
class config{
    //获取env来确认环境（ prd：生产环境 test：测试环境， dev：开发环境）
    static getEnv(){
        let env='dev';
        return env;
    }
    static getConfigJson(){
        if(!util.isNull(this.configJson)){
            return this.configJson;
        }
        this.configJson={}
        let protocol = window.location.protocol;
        let ws = protocol.includes('s') ? 'wss:' : 'ws:';
        this.configJson.contextPath = '/gd-api';//后端的别名
        this.configJson.contextFrontPath = '/sys';//前端别名
        this.configJson.homePageCode='page_home';//默认加载页面编码
        this.configJson.inedxHtmlFilePath='/khc/index.html';//index页面路径
        this.configJson.autocompleteLoginUsername='';//自动填充用户名（此配置适用于演示，其他阶段为空即可）
        this.configJson.autocompleteLoginPassword='';//自动填充密码（此配置适用于演示，其他阶段为空即可）
        if(this.getEnv()=='dev'){
            this.configJson.serverUrl='http://127.0.0.1:8066';//后端地址
            this.configJson.minioUrl='http://192.168.1.185:9000';//MinIO地址
            this.configJson.awsUrl='http://192.168.1.185:8888/unsafe';//thumbor图片裁剪服务地址
            this.configJson.websocketUrl='ws://127.0.0.1:8066'+this.configJson.contextPath+'/ws/websocket';//WebSocket地址
            this.configJson.baseURL='/api';//代理URL gulp环境使用
        }
        if(this.getEnv()=='test'){
            this.configJson.host='example.com';
            this.configJson.serverUrl=protocol+'//'+this.configJson.host;
            this.configJson.minioUrl=protocol+'//'+this.configJson.host;
            this.configJson.awsUrl=protocol+'//'+this.configJson.host+'/unsafe';
            this.configJson.websocketUrl=ws+'//'+this.configJson.host+this.configJson.contextPath+'/ws/websocket';
            this.configJson.baseURL='';//使用Nginx 无需代理，为空即可。
        }
        if(this.getEnv()=='prd'){
            this.configJson.host='example.com';
            this.configJson.serverUrl=protocol+'//'+this.configJson.host;
            this.configJson.minioUrl=protocol+'//'+this.configJson.host;
            this.configJson.awsUrl=protocol+'//'+this.configJson.host+'/unsafe';
            this.configJson.websocketUrl=ws+'//'+this.configJson.host+this.configJson.contextPath+'/ws/websocket';
            this.configJson.baseURL='';//使用Nginx 无需代理，为空即可。
        }
        this.configJson.pubKey='04707EB84B010E5F25F37B047F37DACA389AB7F912B9B4E26041EB79EE40C9AF8196DC06C717182DADB8076CB69741E5E8D0672B01D6DC7712A08D589442E25E50';
        this.configJson.systemFullName='CCUI 2.0';//系统全称
        this.configJson.systemShortName='CCUI 2.0';//系统简称
        this.configJson.iconPath='../css/img/favicon.ico';//icon路径
        this.configJson.logoPath='../css/img/logo.png';//logo路径
        this.configJson.defaultColorJson={
            "蓝色":"#4c84ff","灰色":"#8897AA","绿色":"#02BC77",
            "黄色":"#F59A23","浅蓝":"#28c3d7","红色":"#d9534f","黑色":"#2f3237"}
        this.configJson.defaultColorClassJson={
            "蓝色":{"bfColor":"khc-theme-status-primary-bf-color","color":"khc-theme-status-primary-color"},
            "灰色":{"bfColor":"khc-theme-status-secondary-bf-color","color":"khc-theme-status-secondary-color"},
            "绿色":{"bfColor":"khc-theme-status-success-bf-color","color":"khc-theme-status-success-color"},
            "黄色":{"bfColor":"khc-theme-status-warning-bf-color","color":"khc-theme-status-warning-color"},
            "浅蓝":{"bfColor":"khc-theme-status-info-bf-color","color":"khc-theme-status-info-color"},
            "红色":{"bfColor":"khc-theme-status-danger-bf-color","color":"khc-theme-status-danger-color"},
            "黑色":{"bfColor":"khc-theme-status-dark-bf-color","color":"khc-theme-status-dark-color"}}
        this.configJson.defaultFontSizeJson={//注：5级-卡片文字标题，6级-Tab标签 列表标题二级标题，7级-默认文本和内容字段，8级-辅助说明和提示文本
            "1":"40px;","2":"32px;","3":"28px;","4":"24px;",
            "5":"20px;","6":"16px;","7":"14px;","8":"12px;"}
        this.configJson.themeColor='#325396';//主题色
        this.configJson.defaultTableColorJson={
            "tableThBackgroundColor":"#cccccc",
            "tableTdMouseoverBackgroundColor":"#a0c5e8",
            "tableTDMouseoutEvenBackgroundColor":"#eaeaea",
            "tableTDMouseoutOddBackgroundColor":"#fafafa",
        }
        this.configJson.defaultTableColorClassJson={
            "tableThBackgroundColor":"khc-theme-table-th-color",
            "tableTdMouseoverBackgroundColor":"khc-theme-table-td-mouseover-color",
            "tableTDMouseoutEvenBackgroundColor":"khc-theme-table-mouseout-even-color",
            "tableTDMouseoutOddBackgroundColor":"khc-theme-table-mouseout-odd-color",
        }
        this.configJson.tableManagingName='管理';//管理列标题名称
        this.configJson.tableSelectButtonLabel='更多操作';//table下拉按钮名称
        this.configJson.rowSelectButtonLabel='更多操作';//row下拉按钮名称
        this.configJson.navbarFixed='true'//默认固定导航栏
        this.configJson.sidenavFixed='true'//默认固定菜单栏
        this.configJson.navbarTheme='white'//默认导航栏主题
        this.configJson.sidenavTheme='white'//默认菜单栏主题
        this.configJson.defaultMenuSettings='false'//默认是否显示主题设置
        this.configJson.loadOutDescription=''//加载页面输出的描述
        this.configJson.loadOutLink=''//加载页面输出的链接
        this.configJson.showMenuStyleConfig1=`default-style ${menuSettingsConfig.getMenuSettingsConfigJson().navbarFixed=='true'?'layout-fixed':''} ${menuSettingsConfig.getMenuSettingsConfigJson().sidenavFixed=='true'?'layout-navbar-fixed':''}`;//全部展示(展示icon图标+菜单名称)
        this.configJson.showMenuStyleConfig2=`default-style ${menuSettingsConfig.getMenuSettingsConfigJson().navbarFixed=='true'?'layout-fixed':''} ${menuSettingsConfig.getMenuSettingsConfigJson().sidenavFixed=='true'?'layout-navbar-fixed':''} layout-collapsed`;//左侧菜单为简易(只展示icon图标)
        this.configJson.showMenuStyleConfig3='default-style layout-offcanvas layout-expanded'//分辨率小于991.11，不展示左侧菜单
        this.configJson.logLevel='';//默认为空，可配置 debug 为调试
        //====url====
        this.configJson.queryUrl = this.configJson.contextPath+'/api/data/showAll';
        this.configJson.queryOneUrl = this.configJson.contextPath+'/api/data/findOne';
        this.configJson.queryTreeUrl = this.configJson.contextPath+'/api/data/showAllForTree';
        this.configJson.saveUrl = this.configJson.contextPath+'/api/data/save';
        this.configJson.insertOneUrl = this.configJson.contextPath+'/api/data/insertOne';//插入一条空的数据
        this.configJson.delUrl = this.configJson.contextPath+'/api/data/del';
        this.configJson.metaUrl = this.configJson.contextPath+'/api/data/list';
        this.configJson.pageInfoUrl=this.configJson.contextPath+'/api/data/page';
        this.configJson.myActionUrl=this.configJson.contextPath+'/api/data/myAction';
        this.configJson.importExcelData=this.configJson.contextPath+'/api/data/importExcelData';//上传附件并解析数据入库（一次请求）
        this.configJson.importExcelDataNew=this.configJson.contextPath+'/api/data/importExcelDataNew';//先上传附件（upFileUrl）拿到返回的文件信息再请求此接口解析数据入库（两次请求）
        this.configJson.importJsonData=this.configJson.contextPath+'/api/data/importJsonData';
        this.configJson.updateJsonData=this.configJson.contextPath+'/api/data/updateJsonData';
        this.configJson.exportWordDataUrl=this.configJson.contextPath+'/api/data/exportWordData';
        this.configJson.exportExcelOneData=this.configJson.contextPath+'/api/data/exportExcelOneData';
        this.configJson.exportExcelDataUrl=this.configJson.contextPath+'/api/data/exportExcelData';
        this.configJson.exportExcelTemplate=this.configJson.contextPath+'/api/data/exportExcelTemplate';
        this.configJson.downFileUrl=this.configJson.contextPath+'/api/file/downFile';
        this.configJson.createOnePdfURL=this.configJson.contextPath+'/api/data/createOnePdf'
        this.configJson.upFileUrl=this.configJson.contextPath+'/api/file/upload';
        this.configJson.nosessionActionUrl=this.configJson.contextPath+'/nosession/data/myAction';
        //====actionJsPath====
        this.configJson.tableActionPath='../component/page/query/table/tableAction.js';
        this.configJson.formActionPath='../component/page/form/formAction.js';
        this.configJson.queryActionPath='../component/page/query/queryAction.js';
        this.configJson.modalAreaID = 'formDetailModalArea'
        return this.configJson;
    }
    //获取默认展示的页面编码
    static getHomePageCode(){
        return this.getConfigJson().homePageCode;
    }
    //获取默认的请求头
    static getRequestConfig(){
        let token=config.getToken()
        let requestConfig={
            headers:{
                Authorization:'Bearer '+token
            }
        }
        return requestConfig;
    }
    static setToken(token){
        util.setCookie('token',token);
    }
    //获取默认的请求头
    static getToken(){
        let token=util.getCookie('token');
        if(util.isNull(token)){
            util.toLogin();
        }else{
            return token;
        }
    }
    static removeToken(){
        util.removeCookie('token')
    }
    //获取 SM2 公钥
    static getSM2PubKey(){
        return this.getConfigJson().pubKey;
    }
    //获取 pageCode
    static getPageCode(){
        let pageCode='';
        let urlHash = window.location.hash;
        if (!util.isNull(urlHash)) {
            pageCode = urlHash.substring(1, urlHash.length);
        }
        let urlPageCode=util.getUrlParam('pageCode');
        if(!util.isNull(urlPageCode))return urlPageCode;
        // 去掉查询字符串部分，保留基础 URL
        pageCode = pageCode.split('?')[0];
        return pageCode;
    }
    //获取 后台地址，跳转activiti用到
    static getSystemUrl(){
        return this.getConfigJson().serverUrl;
    }
    //获取 minio地址，
    static getMinioUrl(){
        return this.getConfigJson().minioUrl;
    }
    //获取 aws地址,配合minio缩放原图使用，
    static getAwsUrl(){
        return this.getConfigJson().awsUrl;
    }
    //获取 websocket地址
    static getWebsocketUrl(){
        return this.getConfigJson().websocketUrl;
    }
    //获取 index url
    static getIndexUrl(){
        return window.location.origin+this.getConfigJson().contextFrontPath+this.getConfigJson().inedxHtmlFilePath;
    }
}
export {config};