46 Star 758 Fork 245

桃花镇童长老/harmony-utils

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CacheUtilPage.ets 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
桃花镇童长老 提交于 2026-04-21 23:17 +08:00 . 代码优化。
import { router } from '@kit.ArkUI';
import { MockSetup } from '@ohos/hamock';
import { CacheUtil, ToastUtil } from '@pura/harmony-utils';
import { TitleBarView } from '../../component/TitleBarView';
import { DescribeBean } from '../../model/DescribeBean';
/**
* "缓存工具类
*/
@Entry
@Component
struct Index {
private scroller: Scroller = new Scroller();
@State describe: DescribeBean = router.getParams() as DescribeBean;
@MockSetup
mock() {
this.describe = new DescribeBean("CacheUtil", "缓存工具类");
}
build() {
Column() {
TitleBarView({ describe: this.describe })
Divider()
Scroll(this.scroller) {
Column() {
Button("put()")
.btnStyle()
.onClick(() => {
CacheUtil.put("pwd", "ABCD@12345");
ToastUtil.showToast("缓存密码成功");
})
Button("get()")
.btnStyle()
.onClick(() => {
let pwd = CacheUtil.get<string>("pwd");
ToastUtil.showToast(`取值:${pwd}`);
})
Button("has()")
.btnStyle()
.onClick(() => {
let pwd = CacheUtil.has("pwd");
ToastUtil.showToast(`缓存是否存在:${pwd}`);
})
Button("remove()")
.btnStyle()
.onClick(() => {
CacheUtil.remove("pwd");
ToastUtil.showToast(`缓存移除成功!`);
})
Button("isEmpty()")
.btnStyle()
.onClick(() => {
let blEmpty = CacheUtil.isEmpty();
ToastUtil.showToast(`缓存是否为空:${blEmpty}`);
})
Button("clear()")
.btnStyle()
.onClick(() => {
CacheUtil.clear();
ToastUtil.showToast(`清除缓存数据成功`);
})
Blank().layoutWeight(1)
}
.margin({ top: 5, bottom: 5 })
}
.layoutWeight(1)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Start)
.backgroundColor($r('app.color.main_background'))
}
}
@Styles
function btnStyle() {
.width('90%')
.margin({ top: 10, bottom: 2 })
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tongyuyan/harmony-utils.git
git@gitee.com:tongyuyan/harmony-utils.git
tongyuyan
harmony-utils
harmony-utils
master

搜索帮助