diff --git a/entry/src/main/ets/Components/BottomView.ets b/entry/src/main/ets/Components/BottomView.ets new file mode 100644 index 0000000000000000000000000000000000000000..59fb92df2d557acf7ceea5bcaa0d9210393411a7 --- /dev/null +++ b/entry/src/main/ets/Components/BottomView.ets @@ -0,0 +1,47 @@ + +@Component +export default struct BottomView { + private mClickListener + private mClickEmptyListener + private isShow + private buttonList + private isCopying + + build() { + Stack({ alignContent: Alignment.BottomEnd }) { + Flex({ wrap: FlexWrap.NoWrap }) { + } + .width('100%') + .height('100%') + .backgroundColor(0x29000000) + .onClick(()=>{ + console.log('hans --->aaaaa') + this.mClickEmptyListener() + }).visibility(this.isCopying == true ? Visibility.None:Visibility.Visible) + + Flex({ wrap: FlexWrap.NoWrap }) { + ForEach(this.buttonList,(item,index)=>{ + Text(item).width('100%').fontSize(16) + .fontColor('#333333') + .fontWeight(FontWeight.Regular).backgroundColor(0xffffff).textAlign(TextAlign.Center).margin({top:10}).padding({top:15,bottom:10}).onClick(()=>{ + this.mClickListener(item,index) + console.log('hans --->2222') + }) + }) + } + .width('100%') + .height(80) + .backgroundColor(0xffffff) + .gesture( + LongPressGesture({ repeat: false, duration: 500 })//拦截长按 + .onAction((event: GestureEvent) => { + + }) + ) + } + .height(this.isCopying == true ?80:'100%') + .width('100%') + .visibility(this.isShow == false ? Visibility.Hidden:Visibility.Visible) + + } +} \ No newline at end of file diff --git a/entry/src/main/ets/Components/USBDrive.ets b/entry/src/main/ets/Components/USBDrive.ets new file mode 100644 index 0000000000000000000000000000000000000000..a2beedb3e8898ccbd1d13e5412dc47411d4881ef --- /dev/null +++ b/entry/src/main/ets/Components/USBDrive.ets @@ -0,0 +1,140 @@ + +import volumeManager from '@ohos.volumeManager'; +import storagestatistics from "@ohos.storageStatistics"; +import router from '@system.router' + +export interface Volume { + id: string; + uuid: string; + description: string; + removable: boolean; + state: number; + path: string; + totalSize: number; + freeSize: number; +} + +@Entry +@Component +export struct USBDrive { + + scroller: Scroller = new Scroller() + @State arr: Volume[] = [] + + build() { + Stack({ alignContent: Alignment.TopStart }) { + Scroll(this.scroller) { + Column() { + ForEach(this.arr, (vol:Volume) => { + Column() { + Column() { + Row(){ + Text(`名字:${vol.description} 地址:${vol.path}`) + .fontSize(16) + .fontColor('#888888') + .fontWeight(FontWeight.Regular) + .width('20%') + .textAlign(TextAlign.End) + .textAlign(TextAlign.Start) + .padding({left:25}) + .width('50%') + + Text(`可用:${Math.floor((vol.totalSize-vol.freeSize)/1024/1024/1024)}GB | 共${Math.floor(vol.totalSize/1024/1024/1024)}GB`) + .fontSize(16) + .fontColor('#888888') + .fontWeight(FontWeight.Regular) + .width('20%') + .textAlign(TextAlign.End) + .textAlign(TextAlign.End) + .padding({right:25}) + .width('50%') + + }.height(60) + .width('100%') + .margin({top:5}) + Stack(){ + Progress({ value: 10, total: 100, type: ProgressType.Linear }) + .color('#0fa4c1') + .value(this.getPercentage(Math.floor(vol.freeSize/1024/1024/1024), Math.floor(vol.totalSize/1024/1024/1024))) + .width('100%').padding({left:25,right:140}) + Text(`已用:${this.getPercentage(Math.floor(vol.freeSize/1024/1024/1024), Math.floor(vol.totalSize/1024/1024/1024))}%`) + .fontSize(16) + .fontColor('#888888') + .fontWeight(FontWeight.Regular) + .width('20%') + .textAlign(TextAlign.End) + .textAlign(TextAlign.End) + .padding({right:25}) + .width('100%') + + }.height(30) + .width('100%') + } + .onClick(()=>{ // + + router.push({ + uri: "pages/USBShowList", + params: { foodData: vol } + }) + }) + .width('90%') + .height(130) + .backgroundColor(0xFbFbFb) + .borderRadius(15) + .margin({ top: 30 ,bottom:15}) + } + .height(150) + + }) + }.width('100%') + } + .scrollable(ScrollDirection.Vertical) + .scrollBar(BarState.On) + .scrollBarColor(Color.Gray) + .scrollBarWidth(30) + .onScroll((xOffset: number, yOffset: number) => { + console.info(xOffset + ' ' + yOffset) + }) + .onScrollEdge((side: Edge) => { + console.info('hans To the edge') + }) + .onScrollEnd(() => { + console.info('hans Scroll Stop') + }) + }.width('100%').height('100%').backgroundColor(0xffffff) + } + + getList(){ + + volumeManager.getAllVolumes(async (error, volumes)=>{ + + console.info("hans getAllVolumes volumes:"+ JSON.stringify(volumes)); + + for(let i = 0;i < volumes.length ; i++){ + var vol:Volume = { + id : volumes[i].id, + uuid : volumes[i].uuid, + description : volumes[i].description, + removable : volumes[i].removable, + state : volumes[i].state, + path : volumes[i].path, + totalSize : await storagestatistics.getTotalSizeOfVolume(volumes[i].uuid), + freeSize :await storagestatistics.getFreeSizeOfVolume(volumes[i].uuid) + } + this.arr.push(vol) + } + }); + } + + //获取使用内存比例 + getPercentage(num:number, total:number) { + if (num == 0 || total == 0) { + return 0 + } + return Number(Number((num / total)*100).toFixed(2)) + } + + aboutToAppear(){ + this.getList() + } +}