回复
[中工开发者] 线上商城开发zut 原创
wx674999ce964a1
发布于 2024-12-5 16:36
浏览
0收藏
介绍
本应用是一款线上商城的的制作。
本学期学习了鸿蒙开发课程,想通过一个小项目检验一下自己所学,下面把该项目总结一下,希望对学习鸿蒙开发的小伙伴提供一些参考。
项目结构
![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/8661a8c9538d4d32de55341d5e5762a15faa57.png?x-oss-process=image/resize,w_433,h_578)
项目展示
线上商城app展示
登录界面
包括验证输入是否为空
多个登录方式![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/46a64ec5176b85521c11755bf621ee49199383.png?x-oss-process=image/resize,w_480,h_1026)
首页
import router from '@ohos.router';
import Home from '../view/HomePage'
import Mine from '../view/MinePage'
import Choice from '../view/ChoicePage'
interface GeneratedTypeLiteralInterface_1 {
title: string;
}
interface GeneratedTypeLiteralInterface_2 {
title: string;
}
@Entry
@Component
struct Main {
@State message: string = '首页';
private controller: TabsController = new TabsController();
private items: Array<GeneratedTypeLiteralInterface_1> = [
{ title: '首页' },
{ title: '精选' },
{ title: '我的' },
]
build() {
Row() {
Tabs({ barPosition: BarPosition.End }) {
ForEach(this.items, (item: GeneratedTypeLiteralInterface_2 ,index:number) => {
TabContent() {
Column(){
Text(item.title)
if(index===0){
Home()
}else if(index===1){
Choice()
}else {
Mine()
}
}
}.tabBar(item.title)
})
}
.vertical(false)
.barWidth('100%')
.barHeight('70vp')
.animationDuration(400)
// Column(){
// Text(this.message)
// .fontSize(50)
// .fontWeight(FontWeight.Bold)
// Button('返回登录',{type:ButtonType.Capsule,stateEffect:true})
// .width('90%')
// .margin('20vp')
// .onClick(()=>{
// //
// router.pushUrl({
// url :'pages/LoginPage'
//
// }).catch((error:Error)=>{
//
// })
// })
// }
}
.height('100%')
.width('100%')
}
}
轮播图
使用swiper组件(“https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/arkts-rendering-control-foreach-V13”)
![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/04351c4855356f75681504a44a2f837615136e.png?x-oss-process=image/resize,w_459,h_281)
代码展示
@Component
export default struct SwiperExample{
@State swiperData:Array<Resource> =[
$r('app.media.img_4'),
$r('app.media.img_5'),
$r('app.media.img_6')
]
build() {
Column(){
Swiper(){
ForEach(this.swiperData,(item:Resource)=>{
Image(item)
.width('95%')
.height('160vp')
})
}
.index(0)//初始化索引值
.autoPlay(true)//自动播放
.interval(3000)//时间间隔
.loop(true)
.duration(1000)//
.itemSpace(10)
.indicator(true)//是否启用导航点治时期
}
.width('100%')
.margin({top:'5vp'})
}
}
个人主页
使用了按钮和Text组件
通过foreach循环渲染(“https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V13/arkts-rendering-control-foreach-V13”)
![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/e41a69e07d9d0277dc9275c0b58a0a0276295f.png?x-oss-process=image/resize,w_460,h_1002)
项目解析
首页MainPage
![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/833678246970dac8d8c007ba3700222515462f.png?x-oss-process=image/resize,w_820,h_1301)
import router from '@ohos.router';
import MineUser from './components/MineUser'
import MineList from './components/MineList'
@Component
export default struct Mince {
@State message:string='我的';
build() {
Row(){
Column(){
Text(this.message)
.fontSize('16vp')
.alignSelf(ItemAlign.Start)
MineUser()
MineList()
Button('退出登录')
.width('90%')
.height('40vp')
.fontSize('16fp')
.backgroundColor('#e5e8ea')
.fontColor(Color.Red)
.margin({
top:'30vp'
})
.onClick(()=>{
router.pushUrl({
url:'pages/LoginPage'
}).catch((error:Error)=>{
})
})
}
.width('95%')
.height('100%')
.margin('10vp')
}
.backgroundColor('#f1f3f5')
}
}
登录界面LoginPage
![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/e5406d358b02380aff79169d89407913f2302e.png?x-oss-process=image/resize,w_820,h_1292)
个人主页MinePage
![[中工开发者] 线上商城开发zut-鸿蒙开发者社区 [中工开发者] 线上商城开发zut-鸿蒙开发者社区](https://dl-harmonyos.51cto.com/images/202412/c117c1824a617d8efd391482cd4b12b42a2cc9.png?x-oss-process=image/resize,w_820,h_1283)
总结
本项目只是对本学期知识的总结和运用.
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
已于2024-12-13 16:40:12修改
赞
收藏
回复
相关推荐




















