[UI5 常用控件] 03.Icon, Avatar,Image

文章目录

  • 前言
  • 1. Icon
  • 2. Avatar
    • 2.1 displayShape
    • 2.2 initials
    • 2.3 backgroundColor
    • 2.4 Size
    • 2.5 fallbackIcon
    • 2.6 badgeIcon
    • 2.7 badgeValueState
    • 2.8 active
  • 3. Image


前言

本章节记录常用控件Title,Link,Label。
其路径分别是:

  • sap.m.Icon
  • sap.m.Avatar
  • sap.m.Image

1. Icon

  • 常用属性有src, class, color, press等
    在这里插入图片描述
  • View
<Panel
   headerText="Icon"
    class="sapUiLargeMargin"
>
    <HBox width="50%">
        <core:Icon
            src="sap-icon://syringe"
            class="size1"
            color="#031E48"
        >
            <core:layoutData>
                <FlexItemData growFactor="1" />
            </core:layoutData>
        </core:Icon>
        <core:Icon
            src="sap-icon://pharmacy"
            class="size2"
            color="#64E4CE"
        >
            <core:layoutData>
                <FlexItemData growFactor="2" />
            </core:layoutData>
        </core:Icon>
        <core:Icon
            src="sap-icon://electrocardiogram"
            class="size3"
            color="#E69A17"
        >
            <core:layoutData>
                <FlexItemData growFactor="3" />
            </core:layoutData>
        </core:Icon>
        <core:Icon
            src="sap-icon://doctor"
            class="size4"
            color="#1C4C98"
        >
            <core:layoutData>
                <FlexItemData growFactor="4" />
            </core:layoutData>
        </core:Icon>
        <core:Icon
            src="sap-icon://stethoscope"
            class="size5"
            color="#8875E7"
            press="handleStethoscopePress"
        >
            <core:layoutData>
                <FlexItemData growFactor="5" />
            </core:layoutData>
        </core:Icon>
    </HBox>
</Panel>

2. Avatar

2.1 displayShape

  • 显示形状(方形,圆形)
    在这里插入图片描述
  • View
<Panel
   headerText="displayShape"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox alignItems="Center">
            <Avatar
                src="img/1.webp"
                displaySize="XL"
                displayShape="Square"
                showBorder="true"
                press="onPress"
            />
            <Text text="Square" />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                src="img/1.webp"
                displaySize="XL"
                showBorder="true"
                press="onPress"
            />
            <Text text="默认或者Circle" />
        </VBox>
    </HBox>
</Panel>

2.2 initials

  • 显示initials文字
    在这里插入图片描述
  • View
<Panel
    headerText="显示initials: IS"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox alignItems="Center">
            <Avatar
                initials="IS"
                displaySize="XL"
                displayShape="Square"
                press="onPress"
            />
            <Text text="两个字母" />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                enabled="false"
                initials="PI"
                displaySize="XL"
                press="onPress"
            />
            <Text text="虚化:enabled=false" />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="XL"
                press="onPress"
                initials="ABC"
            />
            <Text text="三个字母" />
        </VBox>
    </HBox>
</Panel>

2.3 backgroundColor

  • 背景色(Transparent,TileIcon, Placeholder, Random)
  • Random会在每次渲染时随机分配颜色
    在这里插入图片描述
  • View
<Panel
   headerText="背景色: backgroundColor"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="XL"
                backgroundColor="Transparent"
                press="onPress"
            />
            <Text text="Transparent" />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                initials="IS"
                displaySize="XL"
                backgroundColor="TileIcon"
                press="onPress"
            />
            <Text text="TileIcon" />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="XL"
                backgroundColor="Placeholder"
                displayShape="Square"
                press="onPress"
            />
            <Text text="Placeholder" />
        </VBox>
    </HBox>
</Panel>

2.4 Size

  • 指定大小(XL,L,M,S,XS,Custom)
    在这里插入图片描述
  • View
<Panel
  headerText="Size"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox
            alignItems="Center"
            class="sapUiSmallMarginEnd"
        >
            <Avatar
                src="sap-icon://lab"
                displaySize="XL"
                backgroundColor="Accent6"
            />
            <Text
                text="XL"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiSmallMarginEnd"
        >
            <Avatar
                src="sap-icon://lab"
                displaySize="L"
                backgroundColor="Accent7"
            />
            <Text
                text="L"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiSmallMarginEnd"
        >
            <Avatar
                src="sap-icon://lab"
                displaySize="M"
                backgroundColor="Accent8"
            />
            <Text
                text="M"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiSmallMarginEnd"
        >
            <Avatar
                src="sap-icon://lab"
                displaySize="S"
                backgroundColor="Accent9"
            />
            <Text
                text="S"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiSmallMarginEnd"
        >
            <Avatar
                src="sap-icon://lab"
                displaySize="XS"
                backgroundColor="Accent10"
            />
            <Text
                text="XS"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox alignItems="Center">
            <Avatar
                src="img/lamp.png"
                displaySize="Custom"
                customDisplaySize="200px"
                displayShape="Circle"
            />
            <Text
                text="displaySize=Custom, customDisplaySize=200px"
                class="sapUiSmallMarginTop"
            />
        </VBox>
    </HBox>
</Panel>

2.5 fallbackIcon

  • Avatar会根据displayShape属性有默认图标,也可以指定图标。 如果指定路径有问题将会显示initials
    在这里插入图片描述
  • View
<Panel
   headerText="图标"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginEnd"
        >
            <Avatar
                displaySize="L"
                displayShape="Square"
                backgroundColor="Random"
            />
            <Text
                text="Square默认图标"
                class="sapUiSmallMarginTop"
            />
        </VBox>

        <VBox
            alignItems="Center"
            class="sapUiLargeMarginEnd"
        >
            <Avatar
                displaySize="L"
                displayShape="Circle"
                backgroundColor="Random"
            />
            <Text
                text="Circle默认图标"
                class="sapUiSmallMarginTop"
            />
        </VBox>

        <VBox
            alignItems="Center"
            class="sapUiLargeMarginEnd"
        >
            <Avatar
                displaySize="L"
                displayShape="Square"
                fallbackIcon="sap-icon://accelerated"
                backgroundColor="Random"
            />
            <Text
                text="指定图标fallbackIcon"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginEnd"
        >
            <Avatar
                displaySize="L"
                initials="PB"
                src="{/test}"
                backgroundColor="Random"
            />
            <Text
                text="错误的图片路径将显示initials"
                class="sapUiSmallMarginTop"
                textAlign="Center"
            />
        </VBox>
    </HBox>
</Panel>

2.6 badgeIcon

  • badgeIcon只能在激活press属性并且在控制器里有对应function时激活
    在这里插入图片描述

  • View

<Panel
   headerText="badgeIcon"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox alignItems="Center">
            <Avatar
                displaySize="M"
                backgroundColor="Accent3"
                press="onPress"
                badgeIcon="sap-icon://edit"
            />
            <Text
                textAlign="Center"
                text="edit"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="XL"
                press="onPress"
                badgeIcon="sap-icon://camera"
                badgeTooltip="Sabine Mayer"
            />
            <Text
                textAlign="Center"
                text="camera"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="XL"
                backgroundColor="Accent5"
                src="sap-icon://soccer"
                displayShape="Square"
                press="onPress"
                badgeIcon="sap-icon://edit"
            />
            <Text
                textAlign="Center"
                text="add"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                src="img/lamp.png"
                displaySize="L"
                displayShape="Circle"
            >
                <detailBox>
                    <LightBox>
                        <LightBoxItem
                            imageSrc="img/lamp.png"
                            alt="灯泡"
                            title="这是灯泡"
                            subtitle="闪闪发光"
                        />
                    </LightBox>
                </detailBox>
            </Avatar>
            <Text
                textAlign="Center"
                text="LightBox事件"
                class="sapUiSmallMarginTop"
            />
        </VBox>
    </HBox>
</Panel>

2.7 badgeValueState

  • 会给badgeIcon上颜色
    在这里插入图片描述
  • View
<Panel
   headerText="badgeValueState"
    class="sapUiLargeMarginBottom"
>
    <HBox>
        <VBox
            alignItems="Center"
            class=""
        >
            <Avatar
                displaySize="M"
                imageFitType="Cover"
                badgeValueState="Warning"
                press="onPress"
                badgeIcon="sap-icon://alert"
                badgeTooltip="Sabine Mayer"
            />
            <Text
                textAlign="Center"
                text="Warning"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="M"
                imageFitType="Cover"
                badgeValueState="Information"
                press="onPress"
                badgeIcon="sap-icon://information"
                badgeTooltip="Sabine Mayer"
            />
            <Text
                textAlign="Center"
                text="information"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="M"
                imageFitType="Cover"
                badgeValueState="Success"
                press="onPress"
                badgeIcon="sap-icon://message-success"
                badgeTooltip="Sabine Mayer"
            />
            <Text
                textAlign="Center"
                text="Success"
                class="sapUiSmallMarginTop"
            />
        </VBox>
        <VBox
            alignItems="Center"
            class="sapUiLargeMarginBegin"
        >
            <Avatar
                displaySize="M"
                imageFitType="Cover"
                badgeValueState="Error"
                press="onPress"
                badgeIcon="sap-icon://message-error"
                badgeTooltip="Sabine Mayer"
            />
            <Text
                textAlign="Center"
                text="Error"
                class="sapUiSmallMarginTop"
            />
        </VBox>
    </HBox>
</Panel>

2.8 active

  • 只有绑定press事件时才能激活该属性
  • Active背景颜色和Non-Active背景颜色有差异
    在这里插入图片描述
    在这里插入图片描述
  • View
<Panel
    headerText="Active - Popover menu"
    class="sapUiLargeMarginBottom"
>
    <VBox>
        <MessageStrip
            text="Active state of Avatar is set, when the user clicks on the Avatar and the Popover menu is opened. When the menu is closed, Active state is removed."
            showIcon="false"
            showCloseButton="false"
            class="sapUiTinyMargin"
        />
        <HBox>
            
            <Avatar
                id="myAvatar"
                active="false"
                displaySize="L"
                showBorder="true"
                class="sapUiTinyMargin"
                press="onPressPopover"
            />
        </HBox>
    </VBox>
</Panel>
  • 点击事件
onPressPopover: function (oEvent) {
    var oEventSource = oEvent.getSource(),
        bActive = this.oMyAvatar.getActive();

    this.oMyAvatar.setActive(!bActive);

    if (bActive) {
        this._oPopover.close();
    } else {
        this._oPopover.openBy(oEventSource);
    }

}

3. Image

  • Image可以显示主流图片文件,也可以显示BASE64图片文件
    在这里插入图片描述
  • View
<Panel
   headerText="Image"
   class="sapUiLargeMargin"
>
   <HBox width="50%">
       <VBox
           alignItems="Center"
           class="sapUiLargeMarginBegin"
       >
           <Image
               src="img/lamp.png"
               width="150px"
           />
           <Text
               text="PNG格式"
               class="sapUiSmallMarginBottom"
           />
       </VBox>
       <VBox
           alignItems="Center"
           class="sapUiLargeMarginBegin"
       >
           <Image
               src="img/1.webp"
               width="150px"
           />
           <Text
               text="webp格式"
               class="sapUiSmallMarginBottom"
           />
       </VBox>
       <VBox
           alignItems="Center"
           class="sapUiLargeMarginBegin"
       >
           <Image src="img/sap-logo.svg" />
           <Text
               text="svg格式"
               class="sapUiSmallMarginBottom"
           />
       </VBox>
       <VBox
           alignItems="Center"
           class="sapUiLargeMarginBegin"
       >
           <Image src="{/imgurl}" />
           <Text
               text="BASE64值"
               class="sapUiSmallMarginBottom"
           />
       </VBox>
   </HBox>
</Panel>
  • 读取本地图片并转成base64
_convertImageToBase64: function (filePath) {
   return new Promise(function (resolve, reject) {
       // 创建一个XMLHttpRequest对象
       var xhr = new XMLHttpRequest();

       // 配置请求,使用GET方法获取文件
       xhr.open("GET", filePath, true);

       // 设置响应类型为blob(二进制数据)
       xhr.responseType = "blob";

       // 注册加载完成的回调函数
       xhr.onload = function () {
           if (xhr.status === 200) {
               // 读取到的文件数据
               var blob = xhr.response;

               // 创建一个FileReader对象
               var reader = new FileReader();

               // 注册读取完成的回调函数
               reader.onloadend = function () {
                   // 获取Base64编码的文件内容
                   var base64Data = reader.result;
                   resolve(base64Data);
               };

               // 读取blob数据为Base64编码
               reader.readAsDataURL(blob);
           } else {
               reject(new Error("Failed to load the image."));
           }
       };

       // 注册错误回调函数
       xhr.onerror = function () {
           reject(new Error("Failed to make the request."));
       };

       // 发送请求
       xhr.send();
   });
}
  • onInit中调用
// 调用函数将文件转换为base64编码
this._convertImageToBase64("img/2.jpg")
     .then(function (base64Data) {
         that.getView().setModel(new JSONModel({ "imgurl": base64Data }))
         
     })
     .catch(function (error) {
         console.error(error);
     });

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/351461.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

C++面试:散列表

目录 1. 散列表的基本概念 散列表的定义 散列函数 哈希冲突 2. 处理冲突的方法 链地址法&#xff08;Separate Chaining&#xff09; 开放地址法 再散列 3. 散列表的性能分析 1. 平均查找长度&#xff08;ASL&#xff09; 2. 负载因子&#xff08;Load Factor&#…

CAD-autolisp(二)——选择集、命令行设置对话框、符号表

目录 一、选择集1.1 选择集的创建1.2 选择集的编辑1.3 操作选择集 二、命令行设置对话框2.1 设置图层2.2 加载线型2.3 设置字体样式2.4 设置标注样式&#xff08;了解即可&#xff09; 三、符号表3.1 简介3.2 符号表查找3.2 符号表删改增 一、选择集 定义&#xff1a;批量选择…

go语言(十八)---- goroutine

一、goroutine package mainimport ("fmt""time" )func main() {//用go创建承载一个形参为空&#xff0c;返回值为空的一个函数go func() {defer fmt.Println("A.defer")func() {defer fmt.Println("B.defer")//退出当前goroutinefmt…

《WebKit 技术内幕》学习之十五(6):Web前端的未来

6 Chromium OS和Chrome的Web应用 6.1 基本原理 HTML5技术已经不仅仅用来编写网页了&#xff0c;也可以用来实现Web应用。传统的操作系统支持本地应用&#xff0c;那么是否可以有专门的操作系统来支持Web应用呢&#xff1f;当然&#xff0c;现在已经有众多基于Web的操作系统&…

跟无神学AI之Prompt

在大模型时代会写prompt变得很重要。 Prompt翻译为中文为提示词&#xff0c;在大模型的特定领域指的是大模型使用者给大模型提交的一种有一定格式的交互命令&#xff0c;让我们看看科大讯飞的大模型给出的答案—— Prompt是一种向人工智能模型提供的输入文本或指令&#xff0…

uv胶UV大灯修复液修复汽车车灯大灯尾灯?

使用UV胶进行汽车大灯修复是一种常见的方法&#xff0c;特别是用于修复裂纹、划痕或氧化的透明塑料表面。以下是使用UV胶修复汽车大灯的一般步骤&#xff1a; 1.准备工作&#xff1a; 确保汽车大灯表面是干净的&#xff0c;没有灰尘、油脂或其他污垢。可以使用清洁剂和软布进行…

Microsoft Remote Desktop for Mac(远程桌面连接)激活版

Microsoft Remote Desktop是一款由微软开发的远程桌面连接工具&#xff0c;它允许用户从另一台计算机或移动设备远程连接到Windows桌面或服务器。 以下是该软件的一些主要特点和功能&#xff1a; 跨平台支持&#xff1a;Microsoft Remote Desktop支持Windows、macOS、iOS和Andr…

leetcode:二叉树的中序遍历(外加先序,后序遍历)

题外&#xff1a;另外三种遍历可以看这&#xff1a; 层序遍历&#xff1a; Leetcode:二分搜索树层次遍历-CSDN博客 先序遍历&#xff1a; 二叉树的先序&#xff0c;中序&#xff0c;后序遍历-CSDN博客 后序遍历&#xff1a; 二叉树的先序&#xff0c;中序&#xff0c;后序…

网络安全全栈培训笔记(58-服务攻防-应用协议设备KibanaZabbix远控向日葵VNCTV)

第58天 服务攻防-应用协议&设备Kibana&Zabbix&远控向日葵&VNC&TV 知识点&#xff1a; 1、远程控制第三方应用安全 2、三方应用-向日葵&VNC&TV 3、设备平台-Zabbix&Kibanai漏洞 章节内容&#xff1a; 常见版务应用的安全测试&#xff1a; 1…

【Web】CTFSHOW SQL注入刷题记录(上)

目录 无过滤注入 web171 web172 web173 web174 web175 时间盲注 写马 过滤注入 web176 web177 web178 web179 web180 web181-182 web183 web184 web185-186 web187 web188 web189 web190 布尔盲注 web191 web192 web193 web194 堆叠注入 web195 …

[C++]使用纯opencv部署yolov8旋转框目标检测

【官方框架地址】 https://github.com/ultralytics/ultralytics 【算法介绍】 YOLOv8是一种先进的对象检测算法&#xff0c;它通过单个神经网络实现了快速的物体检测。其中&#xff0c;旋转框检测是YOLOv8的一项重要特性&#xff0c;它可以有效地检测出不同方向和角度的物体。…

格子表单GRID-FORM | 嵌套子表单与自定义脚本交互

格子表单/GRID-FORM已在Github 开源&#xff0c;如能帮到您麻烦给个星&#x1f91d; GRID-FORM 系列文章 基于 VUE3 可视化低代码表单设计器嵌套表单与自定义脚本交互 新版本功能 &#x1f389; 不觉间&#xff0c;GRID-FORM 已经开源一年&#xff08;2023年1月29日首次提交…

【JaveWeb教程】(28)SpringBootWeb案例之《智能学习辅助系统》的详细实现步骤与代码示例(1)

目录 SpringBootWeb案例011. 准备工作1.1 需求&环境搭建1.1.1 需求说明1.1.2 环境搭建 1.2 开发规范 2. 部门管理 SpringBootWeb案例01 前面我们已经讲解了Web前端开发的基础知识&#xff0c;也讲解了Web后端开发的基础(HTTP协议、请求响应)&#xff0c;并且也讲解了数据库…

QT+VS实现Kmeans聚类算法

1、Kmeans的定义 聚类是一个将数据集中在某些方面相似的数据成员进行分类组织的过程&#xff0c;聚类就是一种发现这种内在结构的技术&#xff0c;聚类技术经常被称为无监督学习。k均值聚类是最著名的划分聚类算法&#xff0c;由于简洁和效率使得他成为所有聚类算法中最广泛使…

Java 基础知识-IO流

大家好我是苏麟 , 今天聊聊IO流 . 资料来源黑马程序员 . IO概述 生活中&#xff0c;你肯定经历过这样的场景。当你编辑一个文本文件&#xff0c;忘记了ctrls &#xff0c;可能文件就白白编辑了。当你电脑上插入一个U盘&#xff0c;可以把一个视频&#xff0c;拷贝到你的电脑硬…

ajax点击搜索返回所需数据

html 中body设置&#xff08;css设置跟进自身需求&#xff09; <p idsearch_head>学生信息查询表</p> <div id"div_1"> <div class"search_div"> <div class"search_div_item"> …

day22 事件委托

目录 事件委托 事件委托 事件委托是利用事件流的特征解决一些开发需求的知识技巧 优点&#xff1a;减少注册次数&#xff0c;提高程序性能原理&#xff1a;事件委托其实是利用事件冒泡的特点 给父元素注册事件&#xff0c;当触发子元素时&#xff0c;会冒泡到父元素上&#x…

automa插件使用的一些实战经验3

1 子流程的变量怎么传回父流程 主流程向子流程传参很容易 在子流程可以看到&#xff0c;父流程定义的表格&#xff0c;在子流程中是看不到的&#xff0c;那么子流程定义的变量如何传回父流程呢&#xff1f;另外在子流程再添加执行工作流&#xff0c;是无法选择父流程本身&…

C++:vector容器(memcpy浅拷贝问题、迭代器失效问题)

文章目录 一. vector 的介绍二. vector 的使用1. string 和 vector<char> 的区别2. 为什么 vector 没有 find() 接口 三. vector 的模拟实现1. vector 的基本框架2. memcpy 和 memmove 的浅拷贝问题3. vector 迭代器失效问题4. 模拟代码 一. vector 的介绍 vector 的文档…

二次元动漫卡通手机APP应用下载页HTML源码

HTML源码&#xff0c;记事本修改里面的内容即可&#xff0c;本地双击index.html即可运行 蓝奏云&#xff1a;https://wfr.lanzout.com/itZRg1mf3b9c