前言
  • BasicLibrary是一个基于API 11封装的基本库
  • 未来的计划是将其打造成一个通用的UI组件+基本工具组件,目前只做了部分基本工具组件,大家如果组件有什么需求,可以尽管提哦
简介

鸿蒙基本库封装,提升鸿蒙开发效率

安装

ohpm install @peakmain/library

一、ResourceManager资源管理类

导入依赖

import { ResourceManager } from '@peakmain/library'

1. 资源新增透明度

static resourceAddAlpha(sourceResource: ResourceColor, alpha: number=0.6):string

参数

 示例代码

ResourceManager.resourceAddAlpha(Color.White)

二、StringBuilder字符串拼接

导入依赖

import { StringBuilder } from '@peakmain/library'

1. 拼接单个参数

append(str: string | number | boolean | null): StringBuilder

参数

返回值

2. 拼接数组参数并且对数据进行base64加密

appendArray(str:string[]):void

参数

返回值

3. toString,将存储的对象转成string

toString(): string

参数

三、StringUtils 字符串相关工具类

导入依赖

import { StringUtils } from '@peakmain/library'

1. 判断是否字符

static isCharacter(str: string):string

参数

返回值

2. 判断是否是数字

static isNumeric(str: string):boolean

参数

返回值

3. 当前字符是否为空

static isEmpty(str: string | null | undefined): boolean

参数

返回值

4. 隐藏手机号码

static replacePhone(num: string): string

参数

返回值

5. 获取字符串的长度

static getLength(str: string | null):number

参数

返回值

6. 首字母大写

static capitalizeFirstLetter(str: string): string

参数

返回值

7. 字符串str1是否包含某个字符str2

static isContain(str1: string, str2: string):boolean

参数

返回值

8. 判断两个字符串是否相等(忽略大小写)

equalsIgnoreCase(str1: string, str2: string): boolean

参数

返回值

四、ClickUtils 点击事件

导入依赖

import { ClickUtils } from '@peakmain/library'

1. 设置事件防抖

static setOnDoubleClick(onClick?: () => void)

参数

 示例

ClickUtils.setOnDoubleClick(() => {
    JumpUtils.jumpToH5(H5EnvironmentConstant.SPEND_POINT);
});
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐