/**
 * 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(forceRefresh=false){
        if(!forceRefresh && !util.isNull(this.configJson)){
            return this.configJson;
        }
        this.configJson={}
        let protocol = window.location.protocol;
        let ws = protocol.includes('s') ? 'wss:' : 'ws:';
        this.configJson.contextBasePath = '';//基础路径前缀
        this.configJson.contextPath = this.configJson.contextBasePath+'/gd-api';//后端的别名
        this.configJson.contextFrontPath = this.configJson.contextBasePath+'/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.seaweedfsUrl='http://192.168.1.162:8333';//SeaweedFS S3地址
            this.configJson.seaweedfsAwsUrl='http://192.168.1.162:28888/unsafe';//thumbor图片裁剪服务地址
            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.contextBasePath;
            this.configJson.seaweedfsUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath;
            this.configJson.seaweedfsAwsUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath+'/seaweedfs-aws/unsafe';
            this.configJson.minioUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath;
            this.configJson.awsUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath+'/minio-aws/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.contextBasePath;
            this.configJson.seaweedfsUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath;
            this.configJson.seaweedfsAwsUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath+'/seaweedfs-aws/unsafe';
            this.configJson.minioUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath;
            this.configJson.awsUrl=protocol+'//'+this.configJson.host+this.configJson.contextBasePath+'/minio-aws/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.isShowWaterMark='true';//是否展示全局水印
        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.inputBgColor = '#ffffff'; // 控件背景色
        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.tableLrBordered='true'//表格竖线分割
        this.configJson.tableThAlign='center'//表头对齐方式   居左：left   居中：center
        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 为调试
        this.initApiUrls();
        //====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 initApiUrls(){
        this.configJson.apiPrefix = this.configJson.loginType == 'session' ? '/session' : '/api';
        this.configJson.queryUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/showAll';
        this.configJson.queryOneUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/findOne';
        this.configJson.queryTreeUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/showAllForTree';
        this.configJson.saveUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/save';
        this.configJson.insertOneUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/insertOne';
        this.configJson.delUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/del';
        this.configJson.metaUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/list';
        this.configJson.pageInfoUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/page';
        this.configJson.myActionUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/myAction';
        this.configJson.importExcelData = this.configJson.contextPath + this.configJson.apiPrefix + '/data/importExcelData';
        this.configJson.importExcelDataNew = this.configJson.contextPath + this.configJson.apiPrefix + '/data/importExcelDataNew';
        this.configJson.importJsonData = this.configJson.contextPath + this.configJson.apiPrefix + '/data/importJsonData';
        this.configJson.updateJsonData = this.configJson.contextPath + this.configJson.apiPrefix + '/data/updateJsonData';
        this.configJson.exportWordDataUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/exportWordData';
        this.configJson.exportExcelOneData = this.configJson.contextPath + this.configJson.apiPrefix + '/data/exportExcelOneData';
        this.configJson.exportExcelDataUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/data/exportExcelData';
        this.configJson.exportExcelTemplate = this.configJson.contextPath + this.configJson.apiPrefix + '/data/exportExcelTemplate';
        this.configJson.downFileUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/file/downFile';
        this.configJson.createOnePdfURL = this.configJson.contextPath + this.configJson.apiPrefix + '/data/createOnePdf';
        this.configJson.upFileUrl = this.configJson.contextPath + this.configJson.apiPrefix + '/file/upload';
        this.configJson.nosessionActionUrl = this.configJson.contextPath + '/nosession/data/myAction';
    }

    //获取默认展示的页面编码
    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(){
        if(this.getConfigJson().loginType=='session'){
            return "";
        }
        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;
    }
    //获取 seaweedfs地址，
    static getSeaweedfsUrl(){
        return this.getConfigJson().seaweedfsUrl;
    }
    //获取 aws地址,配合seaweedfs缩放原图使用，
    static getSeaweedfsAwsUrlUrl(){
        return this.getConfigJson().seaweedfsAwsUrl;
    }
    //获取 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(){
        if(this.getConfigJson().loginType=='session'){
            return window.location.origin+this.getConfigJson().contextPath+'/session/';
        }else{
            return window.location.origin+this.getConfigJson().contextFrontPath+this.getConfigJson().inedxHtmlFilePath;
        }
    }
}
export {config};