Fiori elements 特性全集演示 · 对象页 · 通用特性

项目

内容

官方仓库

SAP-samples/fiori-elements-feature-showcase

业务场景

用一套可运行的应用演示 Fiori elements 的每一种表格、表单与页面特性

技术栈

SAP Fiori elements for OData V4、SAPUI5、注解(annotation)、灵活编程模型

对应课程

UX405、UX406、UX410、UX400

对应路径

第 3 条 开发 SAPUI5 应用

为什么值得做:Fiori elements 的能力边界靠文档很难建立直觉。 这个仓库把特性做成可点开的界面,点一下就知道某个注解会产生什么效果。

动手要点:

  • 把应用跑起来,逐个对照 annotations.cds —— 改一个注解,刷新看变化。

  • 这个「改注解看效果」的循环,是掌握 Fiori elements 最快的路径。

本页内容抓取自官方仓库 SAP-samples/fiori-elements-feature-showcase,共收录 1 篇官方文档(README 与 docs)。原仓库内容版权归 SAP SE,遵循其许可证。

General Features Object Page

数据字段的注解

通信属性

搜索词:#CommunicationFields

要把电子邮件与电话号码显示为链接,需要为它们加上 @Communication.IsEmailAddress 或 @Communication.IsPhoneNumber 注解。

annotate schema.RootEntities with{
    ...
    email                   @title : '{i18n>email}'                          @Communication.IsEmailAddress;
    telephone               @title : '{i18n>telephone}'                      @Communication.IsPhoneNumber;
    ...

时间与日期

搜索词:#TimeAndDate

SAP Fiori elements 开箱即可显示与编辑日期、时间以及时间戳。无需任何注解,只要属性具有对应的数据类型。

aspect rootBasis : {
    ...
    validFrom   : Date;
    validTo     : DateTime;
    time        : Time;
    timeStamp   : Timestamp;
    ...
};

自 UI5 1.129.0 起,可以使用 @UI.DateTimeStyle 修改日期的显示方式。

annotate srv.RootEntities with {
    validTo @UI.DateTimeStyle : 'short'
}

允许的取值为 short、medium、long 与 full。

多行文本

搜索词(以下关键词均可在官方仓库中搜索到示例):#MultiLineText、"formatOptions"

使用 @UI.MultiLineText 注解时,较长的字符串会以多行显示。

annotate schema.RootEntities with{
    ...
    description             @title : '{i18n>description}'                    @UI.MultiLineText;
    ...
};

此外,可以在 manifest.json 中定义最大行数。 带 @UI.MultiLineText 注解的数据字段就是限定名(qualifier)。格式选项 textLinesDisplay 定义只读模式下显示几行,textLinesEdit 相应地定义编辑模式下的行数; textMaxLines 定义最多允许几行——若实际行数更少,则按实际行数显示。 textMaxCharactersDisplay 还可以取 Infinity,以完整显示文本;textExpandBehaviorDisplay 可取 InPlace,在页面上就地展开文本。InPlace 是默认值。

"RootEntityObjectReport": {
    ...
    "options": {
        "settings": {
            ...
            "controlConfiguration": {
                ...
                "@com.sap.vocabularies.UI.v1.FieldGroup#Section": {
                    "fields": {
                        "DataField::description": {
                            "formatOptions": {
                                "textLinesDisplay": 1,
                                "textLinesEdit": 3
                            }
                        },
                        "DataField::description_customGrowing": {
                            "formatOptions": {
                                "textMaxLines": "5",
                                "textMaxCharactersDisplay": 400,
                                "textExpandBehaviorDisplay" : "Popover"
                            }
                        }
                    },
                    ...
                },
                ...
            },
            ...
        }
    }
},

更多信息见 SAP Fiori elements 文档。

占位符值

搜索词:#Placeholder

使用 @UI.Placeholder 可以定义字段处于编辑模式时的占位符值。

annotate schema.RootEntities with {
    ...
    region @title : '{i18n:region}' @UI.Placeholder : 'Select a region';
    ...
};

该值也可以是属性路径。