Skip to content

Commit 24c766d

Browse files
authored
Merge pull request #74 from YiQingZi/main
添加 我的 --> // 书架/更多/书籍导入/网盘导入/文件列表
2 parents 968ad7a + 3fa84b8 commit 24c766d

File tree

9 files changed

+317
-1
lines changed

9 files changed

+317
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @author 惟草木之零落兮
3+
* @date 2024/5/22 20:10
4+
*/
5+
6+
export default class BasicDataSource implements IDataSource {
7+
private listeners: DataChangeListener[] = [];
8+
private originDataArray: Array<ESObject> = [];
9+
10+
public totalCount(): number {
11+
return 0;
12+
}
13+
14+
public getData(index: number): ESObject {
15+
return this.originDataArray[index];
16+
}
17+
18+
// 该方法为框架侧调用,为LazyForEach组件向其数据源处添加listener监听
19+
registerDataChangeListener(listener: DataChangeListener): void {
20+
if (this.listeners.indexOf(listener) < 0) {
21+
console.info('add listener');
22+
this.listeners.push(listener);
23+
}
24+
}
25+
26+
// 该方法为框架侧调用,为对应的LazyForEach组件在数据源处去除listener监听
27+
unregisterDataChangeListener(listener: DataChangeListener): void {
28+
const pos = this.listeners.indexOf(listener);
29+
if (pos >= 0) {
30+
console.info('remove listener');
31+
this.listeners.splice(pos, 1);
32+
}
33+
}
34+
35+
// 通知LazyForEach组件需要重载所有子组件
36+
notifyDataReload(): void {
37+
this.listeners.forEach(listener => {
38+
listener.onDataReloaded();
39+
})
40+
}
41+
42+
// 通知LazyForEach组件需要在index对应索引处添加子组件
43+
notifyDataAdd(index: number): void {
44+
this.listeners.forEach(listener => {
45+
listener.onDataAdd(index);
46+
})
47+
}
48+
49+
// 通知LazyForEach组件在index对应索引处数据有变化,需要重建该子组件
50+
notifyDataChange(index: number): void {
51+
this.listeners.forEach(listener => {
52+
listener.onDataChange(index);
53+
})
54+
}
55+
56+
// 通知LazyForEach组件需要在index对应索引处删除该子组件
57+
notifyDataDelete(index: number): void {
58+
this.listeners.forEach(listener => {
59+
listener.onDataDelete(index);
60+
})
61+
}
62+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @author 惟草木之零落兮
3+
* @date 2024/5/22 20:17
4+
*/
5+
import BasicDataSource from './BasicDataSource';
6+
import FolderAndFileItem from '../../componets/dataList/FolderAndFileItem';
7+
8+
/**
9+
* 文件夹 文件列表 数据懒加载对象
10+
* */
11+
export default class FolderFileDataSource extends BasicDataSource {
12+
private dataArray: FolderAndFileItem[] = [];
13+
14+
public totalCount(): number {
15+
return this.dataArray.length;
16+
}
17+
18+
public getData(index: number): FolderAndFileItem{
19+
return this.dataArray[index];
20+
}
21+
22+
public addData(index: number, data: FolderAndFileItem): void {
23+
this.dataArray.splice(index, 0, data);
24+
this.notifyDataAdd(index);
25+
}
26+
27+
public pushData(data: FolderAndFileItem): void {
28+
this.dataArray.push(data);
29+
this.notifyDataAdd(this.dataArray.length - 1);
30+
}
31+
32+
public pushAllData(data: FolderAndFileItem[]): void {
33+
for (const d of data) {
34+
this.dataArray.push(d);
35+
this.notifyDataAdd(this.dataArray.length - 1);
36+
}
37+
}
38+
39+
// 重新加载
40+
public reloadNewData(data: FolderAndFileItem[]): void {
41+
this.dataArray = []
42+
for (const d of data) {
43+
this.dataArray.push(d);
44+
this.notifyDataAdd(this.dataArray.length - 1);
45+
}
46+
this.notifyDataReload()
47+
}
48+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @author 惟草木之零落兮
3+
* @date 2024/5/22 20:21
4+
*/
5+
// 网盘 本地目录 文件夹 文件信息
6+
export default interface FolderAndFileItem {
7+
title: string, // 文件夹文件标题
8+
icon: PixelMap | ResourceStr | DrawableDescriptor, // 文件夹文件图标
9+
size: string, // 文件夹里文件数量,或者文件的大小
10+
date: string, // 最后修改日期
11+
isFolder: boolean // 是否为文件夹,用于排序,文件夹在最上面
12+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @author 惟草木之零落兮
3+
* @date 2024/5/22 20:51
4+
*/
5+
import CommonConstants from '../../common/constants/CommonConstants'
6+
import FolderAndFileItem from '../dataList/FolderAndFileItem'
7+
8+
@Preview
9+
@Component
10+
export default struct FolderFileListItem{
11+
data: FolderAndFileItem = {
12+
title: "MATE 40 PRO 备份",
13+
icon: $r("app.media.ic_folder"),
14+
size: "12项",
15+
date: "2021/8/13",
16+
isFolder: true
17+
}
18+
19+
build() {
20+
Row(){
21+
// 文件夹、 文件图标
22+
Image(this.data.icon)
23+
.size({width: 40,height: 40})
24+
.margin({right: 12})
25+
26+
Column(){
27+
// 标题,名称
28+
Text(this.data.title)
29+
.height(22)
30+
.width("100%")
31+
.maxLines(1)
32+
.fontSize(14)
33+
.fontWeight(500)
34+
.textAlign(TextAlign.Start)
35+
.fontColor("rgba(0, 0, 0, 0.88)")
36+
37+
// 大小,数量、最后修改事件
38+
Text(`${this.data.size} ${this.data.date}`)
39+
.height(18)
40+
.width("100%")
41+
.maxLines(1)
42+
.fontSize(10)
43+
.fontWeight(500)
44+
.textAlign(TextAlign.Start)
45+
.fontColor("rgba(0, 0, 0, 0.45)")
46+
}
47+
.height(40)
48+
.layoutWeight(1) // 占满剩余空间
49+
}
50+
.height(40)
51+
.width("100%")
52+
}
53+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @author 惟草木之零落兮
3+
* @date 2024/5/22 15:05
4+
*/
5+
6+
@Preview
7+
@Component
8+
export default struct MyCenterFileSearch{
9+
10+
11+
@State @Watch("searchEvent") searchValue: string = ''
12+
13+
// 回调函数,回调搜索框输入的值
14+
onResultCallBack?: (searchValue: string)=> void
15+
16+
controller: SearchController = new SearchController()
17+
18+
build() {
19+
Row(){
20+
Search({ value: this.searchValue, placeholder: '搜索', controller: this.controller })
21+
.width('100%')
22+
.height(34)
23+
.placeholderColor("rgba(0, 0, 0, 0.45)")
24+
.placeholderFont({ size: 14, weight: 400 })
25+
.textFont({ size: 14, weight: 400 })
26+
.onSubmit((value: string) => {
27+
this.searchValue = value
28+
})
29+
.onChange((value: string) => {
30+
this.searchValue = value
31+
})
32+
.padding({left: 16, right: 16, top: 6, bottom: 6})
33+
.backgroundColor("rgba(0, 0, 0, 0.04)")
34+
}
35+
.margin({top: 8, bottom: 8})
36+
.width("100%")
37+
.height(34)
38+
}
39+
40+
// 搜索框值发生变化触发该函数
41+
searchEvent(){
42+
if (this.onResultCallBack) this.onResultCallBack(this.searchValue)
43+
}
44+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { MyCenterTitle } from '../../../componets/myCenter/MyCenterTitle';
2+
import MyCenterFileSearch from '../../../componets/myCenter/MyCenterFileSearch';
3+
import FolderFileDataSource from '../../../common/LazyIDataSource/FileListDataSource';
4+
import FolderFileListItem from '../../../componets/myCenter/FolderFileListItem';
5+
import FolderAndFileItem from '../../../componets/dataList/FolderAndFileItem';
6+
7+
/**
8+
* @author 惟草木之零落兮
9+
* @date 2024/5/22 14:33
10+
*/
11+
12+
// 书架/更多/书籍导入/网盘导入/文件列表/开源阅读
13+
@Entry
14+
@Component
15+
struct FileManagement {
16+
@State title: string = '坚果云';
17+
18+
@State fileList: FolderFileDataSource = new FolderFileDataSource()
19+
20+
aboutToAppear(): void {
21+
for (let i=0; i < 20; i++){
22+
this.fileList.pushData({
23+
title: i < 3 ? `文件夹 ${i}` : `文件 ${i}`,
24+
icon: i < 3 ? $r("app.media.ic_folder") : $r("app.media.ic_zip") ,
25+
size: i < 3 ? "12项" : "30M",
26+
date: "2021/8/13",
27+
isFolder: i < 3 ? true: false
28+
})
29+
}
30+
}
31+
32+
build() {
33+
Column(){
34+
35+
// 标题栏
36+
MyCenterTitle({
37+
title: this.title,
38+
isShowEdit: true,
39+
isShowMore: true,
40+
onEditClickEvent: ()=>{
41+
42+
},
43+
onMoreClickEvent: ()=>{
44+
45+
}
46+
})
47+
48+
// 搜索栏
49+
MyCenterFileSearch({
50+
onResultCallBack: (value: string)=>{
51+
// value 搜索框值发生变化和提交搜索会触发
52+
// TODO 执行搜索,此处应做防抖处理
53+
}
54+
})
55+
56+
// 目录层级栏
57+
Row(){
58+
Text("TODO 目录层级") //TODO 目录层级
59+
}
60+
.margin({top: 12, bottom: 12})
61+
62+
// 文件+文件夹列表
63+
Column(){
64+
List({space: 20}){
65+
LazyForEach(this.fileList, (item: FolderAndFileItem, index: number)=>{
66+
ListItem(){
67+
FolderFileListItem({
68+
data: item
69+
})
70+
}
71+
})
72+
}
73+
.width("100%")
74+
.height("100%")
75+
}
76+
.width("100%")
77+
.layoutWeight(1) // 占满屏幕剩余空间
78+
}
79+
.padding({left: 20, right: 20})
80+
}
81+
}
Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

entry/src/main/resources/base/profile/main_pages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"pages/view/myCenter/aboutUs/OpenSourceLicensePage",
1717
"pages/view/myCenter/aboutUs/DisclaimerPage",
1818
"pages/view/myCenter/helpCenterPage",
19-
"pages/view/myCenter/readStatistics"
19+
"pages/view/myCenter/readStatistics",
20+
"pages/view/myCenter/FileManagement"
2021
]
2122
}

0 commit comments

Comments
 (0)