当前位置: 首页 > news >正文

SAP学习笔记 - 开发31 - 前端Fiori开发 Device Adaptation(设备自适应)

上一章讲了Fiori开发中的 Responsiveness(响应式设计)。

SAP学习笔记 - 开发30 - 前端Fiori开发 Responsiveness(响应式设计)-CSDN博客

本章继续学习Fiori 开发中的知识。

目录

1,Device Adaptation(设备自适应)

1),HelloPanel.view.xml

2),Component.js

3),运行看效果

4),Detail.view.xml

5),Detail.controller.js 

6),运行看效果


下面是详细内容。

1,Device Adaptation(设备自适应)

SAPUI5 SDK - Demo Kit

先来看一下具体改了什么文件,达到了什么效果。 

简单来说就是实现折叠一部分组件,以节约空间。

1),HelloPanel.view.xml

<mvc:ViewcontrollerName="ui5.walkthrough.controller.HelloPanel"xmlns="sap.m"xmlns:mvc="sap.ui.core.mvc"><PanelheaderText="{i18n>helloPanelTitle}"class="sapUiResponsiveMargin"width="auto"expandable="{device>/system/phone}"expanded="{= !${device>/system/phone} }"><content><Buttonid="helloDialogButton"icon="sap-icon://world"text="{i18n>openDialogButtonText}"press=".onOpenDialog"class="sapUiSmallMarginEnd sapUiVisibleOnlyOnDesktop"/><Buttontext="{i18n>showHelloButtonText}"press=".onShowHello"class="myCustomButton"/><Inputvalue="{/recipient/name}"valueLiveUpdate="true"width="60%"/><FormattedTexthtmlText="Hello {/recipient/name}"class="sapUiSmallMargin sapThemeHighlight-asColor myCustomText"/></content></Panel>
</mvc:View>

在Panel 组件里面,用下面属性来启动自适应:

- expandable="{device>/system/phone}" =》在设备为 phone 的时候,会启用折叠
- expanded="{= !${device>/system/phone} }"> =》该状态指明该部分是否已经处于折叠状态

- sapUiVisibleOnlyOnDesktop =》该CSS 样式用于只显示于Desktop 模式下

2),Component.js

sap.ui.define(["sap/ui/core/UIComponent","sap/ui/model/json/JSONModel","sap/ui/Device"
], (UIComponent, JSONModel, Device) => {"use strict";return UIComponent.extend("ui5.walkthrough.Component", {metadata: {interfaces: ["sap.ui.core.IAsyncContentCreation"],manifest: "json"},init() {// call the init function of the parentUIComponent.prototype.init.apply(this, arguments);// set data modelconst oData = {recipient: {name: "World"}};const oModel = new JSONModel(oData);this.setModel(oModel);// set device modelconst oDeviceModel = new JSONModel(Device);oDeviceModel.setDefaultBindingMode("OneWay");this.setModel(oDeviceModel, "device");// create the views based on the url/hashthis.getRouter().initialize();}});
});

- 指定Device Model为单向模式(默认是双向绑定) 

const oDeviceModel = new JSONModel(Device);
oDeviceModel.setDefaultBindingMode("OneWay");
this.setModel(oDeviceModel, "device");

3),运行看效果

其实就是指定一部分对象作为折叠对象,然后引入Device模块,之后SAP Fiori就全帮你干了。

好像没啥变化哈~

因为这是Desktop 中显示,咱们给调成 phone 模式显示

按 F12,然后调成 phone 模式

这样就会显示折叠

点一下可以展开折叠或再次折叠 

上面在列表上搞了个折叠,当是phone模式的时候,会自适应为折叠。

下面看看在明细画面也做下优化。

4),Detail.view.xml

<mvc:ViewcontrollerName="ui5.walkthrough.controller.Detail"xmlns="sap.m"xmlns:core="sap.ui.core"xmlns:mvc="sap.ui.core.mvc"xmlns:wt="ui5.walkthrough.control"><Pagetitle="{i18n>detailPageTitle}"showNavButton="true"navButtonPress=".onNavBack"><ObjectHeadercore:require="{Date: 'sap/ui/model/type/Date',Currency: 'sap/ui/model/type/Currency'}"responsive="true"fullScreenOptimized="true"number="{parts: ['invoice>ExtendedPrice','view>/currency'],type: 'Currency',formatOptions: {showMeasure: false}}"numberUnit="{view>/currency}"intro="{invoice>ShipperName}"title="{invoice>ProductName}"><attributes><ObjectAttributetitle="{i18n>quantityTitle}"text="{invoice>Quantity}"/><ObjectAttributetitle="{i18n>dateTitle}"text="{path: 'invoice>ShippedDate',type: 'Date',formatOptions: {style: 'long',source: {pattern: 'yyyy-MM-ddTHH:mm:ss'}}}"/></attributes></ObjectHeader><wt:ProductRatingid="rating"class="sapUiSmallMarginBeginEnd"change=".onRatingChange"/></Page>
</mvc:View>

- 通过两句就是启动 ObjectHeader 组件的自适应模式

responsive="true"
fullScreenOptimized="true"

- 那么自适应对象是谁呢?就是这个 <attributes> 部分。

  和上面在 HelloPanel.view.xml 作用在 panel 组件上,用的是不同的属性。

<attributes>
    <ObjectAttribute
        title="{i18n>quantityTitle}"
        text="{invoice>Quantity}"/>
    <ObjectAttribute
        title="{i18n>dateTitle}"
        text="{
            path: 'invoice>ShippedDate',
            type: 'Date',
            formatOptions: {
                style: 'long',
                source: {
                    pattern: 'yyyy-MM-ddTHH:mm:ss'
                }
            }
        }"/>
</attributes>

5),Detail.controller.js 

sap.ui.define(["sap/ui/core/mvc/Controller","sap/ui/core/routing/History","sap/m/MessageToast","sap/ui/model/json/JSONModel"
], (Controller, History, MessageToast, JSONModel) => {"use strict";return Controller.extend("ui5.walkthrough.controller.Detail", {onInit() {const oViewModel = new JSONModel({currency: "EUR"});this.getView().setModel(oViewModel, "view");const oRouter = this.getOwnerComponent().getRouter();oRouter.getRoute("detail").attachPatternMatched(this.onObjectMatched, this);},…});
});

这里没啥,就是为了在详细页面加几个字段,比如这个Currency,所以加的Model而已

6),运行看效果

点任意一条明细,显示下面画面

哦,我这个用的Remote Data,Order Date 在Meta Data 里没暴漏出来。

我再加一个字段,然后再看看。

默认Destop Web 是这样的:有几个字段是靠右的

调成 phone 模式之后,就变成这样的

其实就是适应手机屏幕尺寸,把一些字段给调在下面表示了 

官方资料里提供的是这两种方式,在实际开发当中还是挺常用的。

其他的肯定还有,官方暂时没提供Sample,以后有Sample再说。

以上就是本篇的全部内容。

更多SAP顾问业务知识请点击下面目录链接或东京老树根的博客主页

https://blog.csdn.net/shi_ly/category_12216766.html

东京老树根-CSDN博客

相关文章:

  • 【实战指南】前端项目Nginx配置全流程:从打包部署到解决跨域/路由循环问题
  • 零基础学前端-传统前端开发(第三期-CSS介绍与应用)
  • JavaSE-Java简史
  • HTML5 定位网页元素
  • 火山引擎 veFuser:面向扩散模型的图像与视频生成推理服务框架
  • SQL 注入:iBatis与修复
  • 【python】预测投保人医疗费用,附insurance.csv数据集
  • 如何开始HarmonyOS 5与Godot引擎融合开发?
  • 中兴B860AV1.1_晨星MSO9280芯片_4G和8G闪存_TTL-BIN包刷机固件包
  • 如何“调优”我们自身的人体系统?
  • 嵌入式程序存储结构
  • postman调用接口报错401, Unauthorized, Invalid Token. null解决办法
  • 论文笔记 -《MegaBlocks- Efficient Sparse Training with Mixture-of-Experts》
  • 第27节 Node.js Buffer
  • AI中间件,构建大模型应用的标准化接入枢纽
  • ptyhon 导入本地模块 no module named Python Error几种解决方案
  • Docker安装mysql数据库后显示时间问题
  • 若依微服务Openfeign接口调用超时问题
  • 【网页端数字人开发】基于babylonjs+mediapipe实现视频驱动数字人姿态生成
  • 大型语言模型的中毒攻击的系统评价
  • 做网站用多大的服务器/seo关键词排名优化软件
  • 越秀做网站/厦门seo公司
  • 新网站应该怎么做seo/百度app安装下载免费
  • 自己的博客和自己的网站做友链/识图
  • 个人 网站建设方案书 备案/网页设计排版布局技巧
  • 十八把网站做扇子/赣州网站建设公司