且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过 url 参数 parameters 和 script tag 属性来配置 SAP UI5 运行时

更新时间:2022-08-26 17:59:21

Configuration of the SAPUI5 Runtime using URL parameters


新建一个 SAP UI5 应用,index.html 实现如下图所示:


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />

<script
    src="resources/sap-ui-core.js" 
    id="sap-ui-bootstrap"
    data-sap-ui-libs="sap.m">   
</script>

<script>
    // Set the log level to INFO
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.INFO);

    // Get reference the Core object
    var oCore = sap.ui.getCore();

    // Read Core
    var oLibMap = oCore.getLoadedLibraries();
    for (key in oLibMap) {
        jQuery.sap.log.info("Loaded Library name", key);
    }
    jQuery.sap.log.info("Has model?", oCore.hasModel().toString());
    jQuery.sap.log.info("Is mobile?", oCore.isMobile().toString());

    // Read Configuration object from the Core
    var oConfig = oCore.getConfiguration();
    jQuery.sap.log.info("Accessibility", oConfig.getAccessibility().toString());
    jQuery.sap.log.info("Debug", oConfig.getDebug().toString());
    jQuery.sap.log.info("Language", oConfig.getLanguage());
    jQuery.sap.log.info("Locale", oConfig.getLocale());
    jQuery.sap.log.info("Version of SAPUI5 Framework", oConfig.getVersion());
    jQuery.sap.log.info("Theme", oConfig.getTheme());
    jQuery.sap.log.info("User agent", navigator.userAgent);

    // Reset the log level to default of ERROR 
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.ERROR);
</script>

</head>
<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>
</html>

使用如下的 url 进行测试:


http://localhost:8080/sapui5.configurl.demo?sap-ui-accessibility=false&sap-ui-debug=false&sap-ui-language=de&sap-ui-theme=sap_bluecrystal&data-sap-ui-xx-fakeOS=ios


请根据您的服务器配置使用端口号。 加载 index.html 将在开发者工具控制台中打印日志。 该 URL 包含多个配置参数(格式为 sap-ui-PARAMETER-NAME = ”value”),由第二个脚本区域中的代码读取。 日志级别从默认的 ERROR 更改为 INFO 并返回以打印 jQuery.sap.log.info () 语句。


通过 url 参数 parameters 和 script tag 属性来配置 SAP UI5 运行时


Configuration of the SAPUI5 Runtime using script tag attributes

index.html:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />

<script
    src="resources/sap-ui-core.js" 
    id="sap-ui-bootstrap"
    data-sap-ui-libs="sap.m" 
    data-sap-ui-accessibility="false"
    data-sap-ui-debug="false"
    data-sap-ui-language="de"
    data-sap-ui-theme="sap_bluecrystal" 
    data-sap-ui-xx-fakeOS="ios">    
</script>

<script>
    // Set the log level to INFO
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.INFO);

    // Get reference the Core object
    var oCore = sap.ui.getCore();

    // Read Core
    var oLibMap = oCore.getLoadedLibraries();
    for (key in oLibMap) {
        jQuery.sap.log.info("Loaded Library name", key);
    }
    jQuery.sap.log.info("Has model?", oCore.hasModel().toString());
    jQuery.sap.log.info("Is mobile?", oCore.isMobile().toString());

    // Read Configuration object from the Core
    var oConfig = oCore.getConfiguration();
    jQuery.sap.log.info("Accessibility", oConfig.getAccessibility().toString());
    jQuery.sap.log.info("Debug", oConfig.getDebug().toString());
    jQuery.sap.log.info("Language", oConfig.getLanguage());
    jQuery.sap.log.info("Locale", oConfig.getLocale());
    jQuery.sap.log.info("Version of SAPUI5 Framework", oConfig.getVersion());
    jQuery.sap.log.info("Theme", oConfig.getTheme());
    jQuery.sap.log.info("User agent", navigator.userAgent);

    // Reset the log level to default of ERROR 
    jQuery.sap.log.setLevel(jQuery.sap.log.Level.ERROR);
</script>

</head>
<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>
</html>

在浏览器中打开如下网址 http://localhost:8080/sapui5.config.demo/

请根据您的服务器配置使用端口号。 加载 index.html 将在开发者工具控制台中打印日志。 第一个脚本区域(也称为 Bootstrap)中的代码包含多个配置参数(格式为 data-sap-ui-PARAMETER-NAME = ”value”),由第二个脚本区域中的代码读取。 日志级别从默认的 ERROR 更改为 INFO 并返回以打印 jQuery.sap.log.info () 语句。