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

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博客

http://www.xdnf.cn/news/13371.html

相关文章:

  • 3 Studying《深入理解Android卷(邓凡平)》2
  • python基础面试练习题
  • Spring Boot 3 集成 MyBatis 连接 MySQL 数据库
  • TrOCR模型微调
  • 手机连接windows遇到的问题及解决方法
  • 40道Bash Shell高频题整理(附答案背诵版)
  • day 50
  • 【记录头条】头条内容合规快速自查清单
  • C++与C有什么不同
  • 【案例实战】轻创业技术手册:如何用最小MVP模型验证市场需求?低成本创业可以做什么?低成本创业项目排行榜前十名!轻资产创业项目做什么比较好?格行代理怎么样?
  • 统计学习—有监督part
  • tcp综述
  • Windows网络配置避坑指南
  • pikachu靶场通关笔记24 SQL注入07-http header注入
  • HTTP 响应状态码
  • 25/6/11 <算法笔记>RL基础算法讲解
  • Kotlin基础语法三
  • 遗传算法详解:从自然选择到代码实战
  • 【斤斤计较的小Z——KMP / hash】
  • 网传西门子12亿美元收购云原生工业软件,云化PLM系统转机在协同
  • C#高级:利用反射让字符串决定调用哪个方法
  • Leetcode20 (有效的括号)
  • Windows笔记之Win11让非焦点窗口程序也能获得流畅性能的方法
  • [论文阅读] 算法 | 布谷鸟算法在声源定位中的应用研究
  • 三星手机Galaxy S24 Ultra使用adb工具关闭和开启系统更新
  • 达梦数据库 单机部署dmhs同步复制(DM8—>DM8)
  • 基于matlab/Simulink的三相四线逆变器并联系统仿真
  • SAP学习笔记 - 开发32 - 前端Fiori开发 Content Density(内容密度)
  • 代码随想录算法训练营day1
  • 【Django】性能优化-普通版