IT评测·应用市场-qidao123.com技术社区
标题:
【中工开发者】鸿蒙——仿当当网计划
[打印本页]
作者:
立山
时间:
2025-4-7 09:53
标题:
【中工开发者】鸿蒙——仿当当网计划
1. 先容
本学期学习了鸿蒙开发课程,想通过一个小项目检验一下本身所学,下面把该项目总结一下,希望对学习鸿蒙开发的小伙伴提供一些参考。
本次项目《当当网》是一款基于ohm模型的UIAbility OpenHarmony应用开发的册本商城在线购物应用。界面简单直观,让您可以轻松直观地探求您需要的各类册本进行购物。
2. 环境搭建
起首需要完成HarmonyOS开发环境搭建,可参照如下步调进行。
2.1 软件要求
DevEco Studio版本:DevEco Studio 3.1 Release。
HarmonyOS SDK版本:API version 9。
2.2 硬件要求
设备类型:华为手机或运行在DevEco Studio上的华为手机设备模拟器。
HarmonyOS体系:3.1.0 Developer Release。
2.3 环境搭建
安装DevEco Studio。
设置DevEco Studio开发环境,下载HarmonyOS SDK。
3. 项目布局
4. 项目展示
点击应用图标,进入应用界面。
当前处于登录页面,由于还没有账号,无法登录,点击“注册账号”进行账号注册。
注册成功后,利用刚才注册的账号,点击“登录”,进入应用首页。
进入应用后,主页界面可以上下滑动,查看各种册本干系概况。点击底部状态栏“分类”,进入册本分类页面,可以根据个人差别爱好挑选各类册本,例如:计算机、文学、励志和艺术,任意选取一本册本,可进入详情页面,查看商品先容。
挑选完成感爱好的册本后,可以进入底部状态栏的“购物车”页面,就各个商品进行挑选和结算。
结算完成后界面如下:
最后,可以点击底部状态栏进入“我的”页面,进行个人信息管理和账号退出。
至此,《当当网》APP所有功能展示完毕,接下来开始对源代码进行解析。
5. 项目解析
本项目主要布局如下:
5.1 注册登录计划
1. 页面布局与UI组件
在 Index.ets 中,整个登录页面的布局是通过 Column 组件来构建的,利用了一些常见的UI组件,如 Text, TextInput, Button, Image 等,来构造用户输入框、按钮等界面元素。
Column() {
Image($r('app.media.systemLogo')) // Logo图片
.width(100) // Logo宽度
.height(100) // Logo高度
.borderRadius(10) // 圆角效果
.margin({ top: '100vp', bottom: '8vp' }) // Logo边距
Text('当当网') // 登录页面标题
.margin({ top: 10 })
.fontSize('44fp') // 标题字体大小
.fontWeight(FontWeight.Medium) // 标题字体粗细
.fontColor('#182431') // 标题字体颜色
}
复制代码
2. 账号与暗码输入框
账号和暗码输入框利用了自定义的 TextInput 组件,并通过 .inputStyle() 来应用样式,onChange 变乱用于更新状态变量(account 和 password)。
TextInput({ text: this.account, placeholder: '请输入手机号' })
.maxLength(11) // 最大长度
.type(InputType.Number) // 输入类型为数字
.inputStyle() // 应用自定义样式
.onChange((value: string) => {
this.account = value; // 更新账号状态
})
复制代码
TextInput 组件用来接收用户输入,maxLength(11) 限制了账号的最大长度为 11 个字符。
通过 onChange 变乱,每次输入厘革时更新 account 状态。
同理,暗码输入框也利用了类似的处理方式,区别在于暗码框的 InputType.Password 类型,确保暗码以潜伏的情势显示。
3. 登录逻辑
登录操作在 login() 方法中实现,起首验证用户输入的账号和暗码是否为空,假如不为空,则进行账号和暗码的验证。
login(): void {
if (this.account == '') {
myTools.alertMsg('账号不能为空!')
return;
}
if (this.password == '') {
myTools.alertMsg('密码不能为空!')
return;
}
if(!AppStorage.get(this.account)){
myTools.alertMsg('该账号不存在!')
return;
}
if(AppStorage.get(this.account) != this.password){
myTools.alertMsg('密码错误!')
return;
}
this.isShowProgress = true
if (this.timeOutId === -1) {
this.timeOutId = setTimeout(() => {
this.isShowProgress = false
this.timeOutId = -1
router.replaceUrl({
url: "pages/Home"
}, router.RouterMode.Single)
}, 2000)
}
}
复制代码
功能解析
:
起首查抄 account 和 password 是否为空,若为空则弹出提示。
利用 AppStorage.get(this.account) 查抄是否存在该账号并验证暗码是否精确。
登录成功后,显示加载进度指示器,并设置2秒的延时模拟登录过程,登录完成后跳转到首页 (pages/Home)。
4. 跳转与进度指示器
登录成功后,利用 router.replaceUrl() 方法跳转到首页,并显示一个进度指示器(LoadingProgress)来告知用户正在进行登录操作。
if (this.isShowProgress) {
LoadingProgress() // 加载进度组件
.color('#182431') // 颜色
.width('30vp') // 宽度
.height('30vp') // 高度
.margin({ top: '20vp' }) // 上方边距
Text('正在登录中,请稍后...')
}
复制代码
这段代码展示了登录时进度条的实现,并在页面加载中显示文本提示。
5.2 首页代码解析(Home.ets、Page001.ets)
1. Tab栏与页面布局
首页通过 Tabs 组件来实现一个具有选项卡功能的布局。 Tabs 组件中的 TabContent 用来显示差别的页面内容, TabBuilder 用来构建每个选项卡的显示内容。
Tabs({ barPosition: BarPosition.End, controller: this.controller }) {
TabContent() {
Page001();
}.tabBar(this.TabBuilder(0, '主页'))
TabContent() {
Page002();
}.tabBar(this.TabBuilder(1, '分类'))
TabContent() {
Page003();
}.tabBar(this.TabBuilder(2, '购物车'))
TabContent() {
Page004();
}.tabBar(this.TabBuilder(3, '我的'))
}
复制代码
功能解析
:
Tabs 组件创建了四个选项卡:主页、分类、购物车和我的。
每个 TabContent 显示一个页面 (Page001, Page002, Page003, Page004),并通过 tabBar() 方法绑定相应的标签标题。
2. 选项卡切换
onChange 变乱监听选项卡切换时,更新当前选中的索引值 currentIndex,并根据选中的 tab 显示差别的页面内容。
.onChange((index: number) => {
this.currentIndex = index;
})
复制代码
这段代码确保在用户点击差别选项卡时,选中的 tab 索引值会被更新,从而动态修改选项卡内容的显示。
3. 自定义Tab样式
TabBuilder 函数用来天生每个 tab 的外观,动态更新文字颜色、大小和分割线的显示。
Text(name)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize(this.currentIndex === index ? 16 : 15)
.fontWeight(this.currentIndex === index ? 500 : 400)
.lineHeight(22)
.margin({ top: 7, bottom: 9 })
Divider()
.strokeWidth(2)
.color('#007DFF')
.opacity(this.currentIndex === index ? 1 : 0)
复制代码
当选中该 tab 时,文字颜色变为 selectedFontColor,字体加粗,并显示分割线;否则规复为默认样式。
4.热门推荐部分
接下来,通过 Row 和 MyText 显示“热门推荐”标题,下面是利用 Grid 组件展示册本的列表。每本册本都利用了 MyGridItemColumn 来天生图文布局。
Row() {
this.MyText('热门推荐');
}
.height(35)
.width('100%')
// 严选精品(热门推荐)
Grid(this.scroller) {
GridItem() {
this.MyGridItemColumn($r('app.media.book6'), '计算机');
}
GridItem() {
this.MyGridItemColumn($r('app.media.book7'), '文学');
}
// 更多书籍项...
}
.columnsTemplate('1fr 1fr') // 设置每行两列
.rowsGap(5) // 设置行间距
.columnsGap(3) // 设置列间距
.width('99%')
.height(360)
.margin({
top: 10
})
.borderRadius(10)
.padding({ left: 3, right: 3 })
.backgroundColor('#ffffff')
复制代码
5.3 册本分类页计划(Page002.ets)
1.总体架构
页面包括:
标题:“图书分类”。
Tabs:用于显示差别册本分类的标签,点击标签切换差别分类的册本。
商品列表:每个分类下都有对应的商品列表,展示册本封面、书名、店肆、价格等信息。
@Component
export struct Page002 {
@State message: string = '图书分类'
@State fontColor: string = '#182431'
@State selectedFontColor: string = '#007DFF'
@State currentIndex: number = 0
private controller: TabsController = new TabsController()
// 两个书籍分类的数据
@State goodsList1: Array<GoodsModel> = [ ... ]
@State goodsList2: Array<GoodsModel> = [ ... ]
}
复制代码
2.Tab标签页
利用 Tabs 组件来创建四个分类,分别是:“计算机”、“文学”、“励志”和“艺术”。点击差别的标签页可以切换显示差别分类下的册本。
<Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
TabContent() {
this.MyList(this.goodsList1);
}.tabBar(this.TabBuilder(0, '计算机'))
TabContent() {
this.MyList(this.goodsList2);
}.tabBar(this.TabBuilder(1, '文学'))
TabContent() {
this.MyList(this.goodsList1);
}.tabBar(this.TabBuilder(2, '励志'))
TabContent() {
this.MyList(this.goodsList2);
}.tabBar(this.TabBuilder(3, '艺术'))
}
.barMode(BarMode.Fixed)
.barHeight(48)
.animationDuration(200)
.onChange((index: number) => {
this.currentIndex = index
})
复制代码
3.自定义组件:TabBuilder, MyText, MyList
TabBuilder方法用于天生每个标签的外观,Text 控件显示分类名称,点击时标签的字体颜色和大小发生厘革。
@Builder
TabBuilder(index: number, name: string) {
Column() {
Text(name)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize(16)
.fontWeight(this.currentIndex === index ? 500 : 400)
.lineHeight(22)
.margin({ top: 3, bottom: 3 })
Divider()
.strokeWidth(2)
.color('#007DFF')
.opacity(this.currentIndex === index ? 1 : 0)
}.width('100%')
}
复制代码
MyList方法用于渲染商品列表,通过 ForEach 遍历册本数据并显示每本书的封面、名称、价格和店肆信息。
@Builder
MyList(list: Array<GoodsModel>) {
List({ space: 10 }) {
ForEach(list, (item: GoodsModel, index) => {
ListItem() {
Column() {
Row() {
Image(item.goodsImage)
.width(125)
.height(130)
.margin({ left: 5 })
.borderRadius(12)
Column({ space: 14 }) {
Text(item.goodsName).width('60%').fontSize(15).fontWeight(FontWeight.Bold)
Text(item.shopName).fontColor('#787878').fontSize(13)
Text(item.goodsPrice).fontColor('#ffff0000')
}
.alignItems(HorizontalAlign.Start)
.margin({ left: 10 })
}
.width('100%')
.justifyContent(FlexAlign.Start)
}
.borderRadius(8)
.backgroundColor('#ffffffff')
.width('96%')
.height(135)
.justifyContent(FlexAlign.Center)
.onClick(() => {
router.pushUrl({
url: 'pages/GoodsDetails',
params: {
goodsModel: JSON.stringify(item),
},
}, router.RouterMode.Single)
})
}
})
}
.height('100%')
.padding({ top: 5 })
.alignListItem(ListItemAlign.Center)
}
复制代码
4. 页面布局
页面布局中通过 Tabs 和 TabContent 实现了标签切换,每个标签下显示差别的册本分类。标题部分利用了 MyText 来渲染分类标题。
build() {
Column() {
Row() {
this.MyText(this.message);
}
.height(35)
.width('100%')
Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
TabContent() {
this.MyList(this.goodsList1);
}.tabBar(this.TabBuilder(0, '计算机'))
TabContent() {
this.MyList(this.goodsList2);
}.tabBar(this.TabBuilder(1, '文学'))
TabContent() {
this.MyList(this.goodsList1);
}.tabBar(this.TabBuilder(2, '励志'))
TabContent() {
this.MyList(this.goodsList2);
}.tabBar(this.TabBuilder(3, '艺术'))
}
.vertical(false)
.barMode(BarMode.Fixed)
.barWidth('100%')
.barHeight(48)
.animationDuration(200)
.onChange((index: number) => {
this.currentIndex = index
})
.width('100%')
.backgroundColor('#F1F3F5')
}
.backgroundColor('#efefef')
.width('100%')
.height('100%')
}
复制代码
5.4 购物车页(Page003.ets)
CardInfo类:
包含购物车商品的信息,属性包括:id、name、image、price、size、numb。
通过构造函数初始化商品信息,包括商品ID、名称、图片、价格和数量。
class CardInfo {
id: number = 0;
name: string | Resource = '';
image: string | Resource | null = null;
price: number = 0;
size: string | number = '';
numb: number = 0;
constructor(id: number = 0, name: string | Resource = '', image: string | Resource | null = null, price: number, numb: number) {
this.id = id;
this.name = name;
this.image = image;
this.price = price;
this.numb = numb;
}
}
复制代码
Page003布局:
shopCardInfo: 存储购物车商品信息,包括两本册本。
shopNums: 购物车中商品的总数量。
allMoney: 购物车中商品的总价格。
numberCount1, numberCount2: 记录每种商品的数量。
@Component
export struct Page003 {
@State shopCardInfo: Array<CardInfo> = [
new CardInfo(0, 'Python数据结构与算法分析', $r('app.media.book2'), 26.5, 1),
new CardInfo(1, '深度学习入门-基于Python的理论与实现', $r('app.media.book1'), 45.5, 2)
]
@State shopNums: number = 0;
@State allMoney: number = 0;
@State numberCount1: number = 0
@State numberCount2: number = 0
}
复制代码
addShopCardInfo方法:
用于增长商品到购物车,更新商品的总价和数量。
addShopCardInfo(price: number, size: number) {
this.allMoney = this.allMoney + price;
this.shopNums = this.shopNums + size;
}
复制代码
deleteShopCardInfo方法:
用于淘汰商品,从购物车中移除并更新商品的总价和数量。
deleteShopCardInfo(price: number, size: number) {
this.allMoney = (this.allMoney - price) <= 0 ? 0 : (this.allMoney - price);
this.shopNums = (this.shopNums - size) <= 0 ? 0 : (this.shopNums - size);
}
复制代码
购物车展示部分
标题部分:
显示标题“购物车”,字体大小为24px,左边距为12vp。
Column() {
Text('购物车')
.fontWeight(FontWeight.Medium)
.fontSize('24fp')
.margin({ top: '12vp' })
.padding({ left: '12vp' })
}
复制代码
商品列表部分:
利用Flex布局,展示购物车商品信息。
每个商品显示商品图片、名称、价格和数量。
通过Checkbox组件控制商品是否选中,选中时增长商品数量,未选中时淘汰商品数量。
商品数量通过Counter组件进行调整,点击加号或减号时更新购物车信息。
Flex({ direction: FlexDirection.Row }) {
Checkbox({ name: 'checkbox1', group: 'checkboxGroup' })
.selectedColor('#007DFF')
.borderRadius('16vp')
.onChange((value: boolean) => {
if (value) {
this.numberCount1++
this.addShopCardInfo(this.shopCardInfo[0].price, this.shopCardInfo[0].numb);
} else {
this.numberCount1--
this.deleteShopCardInfo(this.shopCardInfo[0].price, this.shopCardInfo[0].numb);
}
})
Image(this.shopCardInfo[0].image)
.objectFit(ImageFit.Cover)
.width(120)
.height(118)
.borderRadius(10)
Column() {
Text(this.shopCardInfo[0].name)
.fontSize('15')
Row() {
Text('¥' + this.shopCardInfo[0].price)
.fontSize(25)
.fontColor(Color.Red)
.margin({ top: 20 })
Counter() {
Text(this.numberCount1.toString())
}
.onInc(() => {
this.numberCount1++
this.addShopCardInfo(this.shopCardInfo[0].price, 1)
})
.onDec(() => {
this.numberCount1 = (this.numberCount1--) <= 0 ? 0 : this.numberCount1
this.deleteShopCardInfo(this.shopCardInfo[0].price, 1)
})
}
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
}
.padding({ left: 10, top: 10, right: 10 })
.alignItems(HorizontalAlign.Start)
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
.height(118)
}
复制代码
结算部分:
显示购物车中已选商品的数量和总价。
提供结算按钮,点击时弹出确认框,展示购物车的总商品数和总金额。
Row() {
Text('已选' + this.shopNums)
Text('总计:¥' + this.allMoney).fontColor(Color.Red).padding({ left: '20vp' })
Button('结算', { type: ButtonType.Normal, stateEffect: true })
.borderRadius(20)
.width('40%')
.height('40vp')
.fontSize('16fp')
.fontColor('#ffffffff')
.fontWeight(FontWeight.Medium)
.margin({ top: 8 })
.backgroundColor('#e8483c')
.onClick(() => {
AlertDialog.show({
title: "购物车结算弹窗",
message: "您一共买了" + this.shopNums + "件商品,总价值:" + this.allMoney + "元。",
confirm: { value: "确定", action: () => {} }
})
})
}
复制代码
5.5 个人信息管理页(Page004.ets)
Page004布局:
页面包含了用户个人信息展示区和常用功能列表。
通过封装的RowItem组件,实现了常用功能项的复用。
RowItem组件:
用于封装每一行的显示内容,包括图标、名称、右侧箭头。
组件接收参数:itemImage、itemName、topValue,用于显示差别功能项。
通过onClick变乱处理点击行为,根据差别的功能项执行相应的操作,如跳转页面或弹出提示。
@Builder
RowItem(
itemImage: Resource,
itemName: string,
topValue: number,
) {
Row() {
Row() {
Image(itemImage)
.height(35)
.width(35)
.margin({ bottom: 10 })
}
Column() {
Row() {
Text(itemName)
.fontWeight(FontWeight.Bold)
.fontSize(17)
.margin({ left: 10 })
Blank()
Image($r('app.media.rightGo'))
.height(30)
.width(40)
}
.width('90%')
.justifyContent(FlexAlign.SpaceBetween)
Divider()
.width('90%')
.margin({ top: 10 })
}
}
.onClick(() => {
if (itemName == '我的消息') {
myTools.alertMsg(CommonConstants.UN_DO_TIPS)
} else if (itemName == '个人中心') {
router.pushUrl({
url: 'pages/MyInfo',
}, router.RouterMode.Single)
} else if (itemName == '客服') {
myTools.alertMsg(CommonConstants.UN_DO_TIPS)
} else if (itemName == '关于我们') {
myTools.alertMsg(CommonConstants.UN_DO_TIPS)
} else if (itemName == '邀请好友') {
myTools.alertMsg(CommonConstants.UN_DO_TIPS)
}
})
.margin({ top: topValue })
.width('90%')
}
复制代码
个人信息展示部分:
显示用户的头像、昵称和邮箱信息。头像利用圆角结果显示。
通过Column布局将昵称和邮箱信息显示在头像旁边。
Column() {
Row() {
Image($r('app.media.touristAvatar'))
.width(80)
.height(80)
.borderRadius(10) // 圆角效果
.margin({ left: 27 }) // 左边距
}
Column() {
Row() {
Text("qq").fontSize(25).fontWeight(90).margin({ left: 10 })
}
Row() {
Text("123456789@qq.com")
.fontSize(14)
.fontColor('#ff565656')
.margin({ left: 10 })
}
.margin({ top: 8 })
}
.alignItems(HorizontalAlign.Start) // 左对齐
.margin({ left: 12 })
}
复制代码
常用功能区:
通过调用RowItem组件渲染常用功能项,如“我的消息”、“个人中心”、“客服”等。
每个功能项点击后执行差别的操作,部分功能项会弹出提示,部分会跳转到对应页面。
this.RowItem($r("app.media.mymsg"), '我的消息', 10)
this.RowItem($r("app.media.gerenxinxi"), '个人中心', 10)
this.RowItem($r("app.media.aboutus"), '关于我们', 10)
this.RowItem($r("app.media.kefu"), '客服', 10)
this.RowItem($r("app.media.yaoqinghaoyou"), '邀请好友', 10)
复制代码
退出登录部分:
提供退出登录的按钮,点击后弹出确认框,扣问用户是否确定退出。
确定退出后跳转到登录页面。
Button('退出登录', { type: ButtonType.Normal, stateEffect: true })
.borderRadius(20)
.width('85%')
.height(40)
.margin({ top: 190 })
.backgroundColor('#e8483c')
.onClick(() => {
AlertDialog.show({
title: "请确认:",
message: '确定退出APP吗?',
autoCancel: false,
alignment: DialogAlignment.Center,
primaryButton: {
value: "确定",
fontColor: Color.Red,
action: () => {
router.replaceUrl({
url: 'pages/Index',
}, router.RouterMode.Single)
}
},
secondaryButton: {
value: "取消",
action: () => {}
}
})
})
复制代码
5.6 页面生命周期管理和数据备份规复
《当当网》应用程序的焦点模块:页面生命周期管理和数据备份规复。
在该项目中,EntryAbility.ets 和 EntryBackupAbility.ets 两个文件负责管理应用程序的页面生命周期以及数据的备份和规复功能。
EntryAbility.ets 文件定义了一个名为 EntryAbility 的类,该类继承自 UIAbility 类,实现了一系列生命周期方法:
// 在页面创建时被调用,可以在此执行一些初始化操作
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
// 在页面窗口创建时被调用,在这里加载页面内容
onWindowStageCreate(windowStage: window.WindowStage): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
复制代码
在 onCreate() 方法中,开发者可以执行一些页面初始化的操作。在 onWindowStageCreate() 方法中,通过调用 windowStage.loadContent() 方法来加载 pages/Index 页面。假如页面加载失败,会记录错误日记。
onDestroy() 方法在页面烧毁时被调用,开发者可以在此释放资源。onWindowStageDestroy() 方法在页面窗口烧毁时被调用。onForeground() 和 onBackground() 方法分别在页面进入前台和后台时被调用。
这些生命周期方法确保了应用程序的页面能够正常加载和烧毁,为用户提供稳定的利用体验。
另一个关键模块 EntryBackupAbility.ets 定义了一个名为 EntryBackupAbility 的类,该类继承自 BackupExtensionAbility 类,实现了数据备份和规复的功能。
// 在需要备份数据时被调用,可以在此实现数据备份逻辑
async onBackup() {
hilog.info(0x0000, 'testTag', 'onBackup ok');
}
// 在需要从备份中恢复数据时被调用,可以在此实现数据恢复逻辑
async onRestore(bundleVersion: BundleVersion) {
hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
}
复制代码
onBackup() 方法在需要备份数据时被调用,开发者可以在此实现数据备份的逻辑。onRestore() 方法在需要从备份中规复数据时被调用,开发者可以在此实现数据规复的逻辑。这两个方法都会记录干系操作的日记信息,方便后续题目排查。
通过这个类,应用程序可以可靠地备份和规复用户数据,提高应用程序的结实性和可靠性。在现实开发中,开发者还可以根据应用程序的具体需求,完善备份和规复的具体实现逻辑。
总的来说,EntryAbility 和 EntryBackupAbility 两个类共同构成了该电子商城购书应用程序的焦点功能模块,分别负责管理页面生命周期和提供数据备份规复功能。这些模块的计划确保了应用程序的稳定运行和数据安全性,为用户提供了良好的利用体验。
5.7 体系功能模块
起首包括通用常量模块 (CommonConstants.ets)
export default class CommonConstants {
/**
* 相关功能
*/
}
复制代码
用于存放应用程序中的通用常量,进行集中管理。
其次是体系工具模块 (MyTools.ets)
import promptAction from '@ohos.promptAction';
/*
* Desc: 系统工具类
*/
export class MyTools {
/**
* 弹框提示
* @param message
*/
alertMsg(message: string) {
promptAction.showToast({
message: message, //message属性用于设置提示信息
duration: 2000, //duration属性用于设置提示信息停留时长,单位为毫秒,取值范围是[1500,10000]
bottom: '360vp' //bottom属性用于设置提示信息到底部的距离
})
}
}
export const myTools = new MyTools();
复制代码
该类提供了一些常用的体系工具方法,调用了 promptAction.showToast() API,向用户屏幕底部显示一个连续2秒的提示信息。这个方法可以方便地在应用程序的任何地方被调用,以向用户提供反馈信息。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/)
Powered by Discuz! X3.4