Skip to content

Commit

Permalink
test (#222)
Browse files Browse the repository at this point in the history
* git-test

* 订阅源-本地导入1
  • Loading branch information
yindushenwen authored Jul 23, 2024
1 parent 63847fa commit 24501f2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 63 deletions.
15 changes: 12 additions & 3 deletions entry/src/main/ets/common/utils/FileHandler.ets
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { BusinessError } from '@ohos.base';
import fs, { Options, WriteOptions } from '@ohos.file.fs';
import fs, { Options } from '@ohos.file.fs';
import { common, Context } from '@kit.AbilityKit';
import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem';
import { BookList } from '../../componets/dataList/bookList';
import { addShelfBook } from '../../storage/bookListData';
import { showMessage } from '../../componets/common/promptShow';
import { fileIo, picker } from '@kit.CoreFileKit';
import { picker } from '@kit.CoreFileKit';
import { util } from '@kit.ArkTS';
import { buffer } from '@kit.ArkTS'

let context = getContext(this) as common.UIAbilityContext;
let filePath = context.filesDir;
Expand All @@ -32,6 +33,14 @@ export class FileHandler {
});
}

static async ReadJSONFile(srcUrl: string) {
let file = fs.openSync(srcUrl, fs.OpenMode.READ_WRITE);
let arrayBuffer = new ArrayBuffer(40960);
let readLen: number = await fs.read(file.fd, arrayBuffer)
let JSONString = buffer.from(arrayBuffer, 0, readLen).toString();
return JSONString
}

static async readFile(readFileUrl: string) {
let chapterNumber = 0
const chapters: chaptersItem[] = [];
Expand Down Expand Up @@ -66,7 +75,7 @@ export class FileHandler {
return chapters
}

static async documentPickerFile(maxSelectNumber:number,fileSuffixFilters:Array<string>) {
static async documentPickerFile(maxSelectNumber: number, fileSuffixFilters: Array<string>) {
// 尝试写一个通用的picker
try {
const documentSelectOptions = new picker.DocumentSelectOptions();
Expand Down
128 changes: 68 additions & 60 deletions entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { FileHandler } from 'ets/common/utils/FileHandler'
@Component
export default struct SubscriptionIndex {
@State isShowImport: boolean = false
@State isShowNewSources:boolean = false
@Prop @Watch('currentTabIndexChange')currentTabIndex: number
@State isShowNewSources: boolean = false
@Prop @Watch('currentTabIndexChange') currentTabIndex: number
@StorageLink('topRectHeight') topRectHeight: number = 0
@State
moreList: IconTitleVo[] = [
Expand All @@ -36,25 +36,22 @@ export default struct SubscriptionIndex {
new IconTitleVo($r('app.media.icon_rule_batch'), '批量管理'),
]
@State RecentlyUsed: rssSourcesHistory[] = []

@State loading: boolean = false
@State subscriptionList: rssSources[] = []
@State rssSourcesList: rssSources[] = []
@State groupList: rssGroupList[] = []
//刷新
refresh = ()=>{
refresh = () => {
this.resetState()
this.getList()
setTimeout(()=>{
rssSourcesHistoryDao.search().then((rssSourcesHistoryList:rssSourcesHistory[])=>{
setTimeout(() => {
rssSourcesHistoryDao.search().then((rssSourcesHistoryList: rssSourcesHistory[]) => {
this.RecentlyUsed = rssSourcesHistoryList
})
},100)
}, 100)
}

@State subscriptionList:rssSources[]=[]


@State rssSourcesList:rssSources[] = []
@State groupList: rssGroupList[] =[]
currentTabIndexChange(){
currentTabIndexChange() {
this.refresh()
}

Expand Down Expand Up @@ -96,41 +93,46 @@ export default struct SubscriptionIndex {
this.groupList = Object.values(groupMap)
}



build() {
Column(){
Column() {
//搜索Start
Flex(
{
direction:FlexDirection.Row,
direction: FlexDirection.Row,
alignItems: ItemAlign.Center,
justifyContent: FlexAlign.SpaceBetween
}
) {
Row({
space:CommonConstants.SPACE_20
space: CommonConstants.SPACE_20
}) {
Image($r('app.media.icon_subscription_index')).width(CommonConstants.COMMON_WIDTH_45_36).height(CommonConstants.COMMON_HEIGHT_21_6)
Image($r('app.media.icon_subscription_index'))
.width(CommonConstants.COMMON_WIDTH_45_36)
.height(CommonConstants.COMMON_HEIGHT_21_6)
Search({ placeholder: '搜索订阅', icon: "/common/images/search.svg" })
.layoutWeight(1)
.height(CommonConstants.COMMON_HEIGHT_40)
.backgroundColor(Color.White)
.onClick(()=>{
.onClick(() => {
router.pushUrl({
url: 'pages/view/Subscription/components/SubscriptionSearch'
})
})
.focusOnTouch(false) //不可获取焦点
}
.padding({right: PaddingConstants.PADDING_16})
Image($r('app.media.addSubscription')).width(ImageConstants.IMG_WIDTH_24).height(ImageConstants.IMG_HEIGHT_24).bindMenu(this.MenuBuilder)
.padding({ right: PaddingConstants.PADDING_16 })

Image($r('app.media.addSubscription'))
.width(ImageConstants.IMG_WIDTH_24)
.height(ImageConstants.IMG_HEIGHT_24)
.bindMenu(this.MenuBuilder)
}
.height('8%')

//搜索End
//最近使用Start
RssSourcesHistory({
RecentlyUsed:this.RecentlyUsed
RecentlyUsed: this.RecentlyUsed
})
if (this.loading) {
Column() {
Expand All @@ -144,45 +146,45 @@ export default struct SubscriptionIndex {
} else if (!this.groupList.length) {
SubscriptionContent({
subscriptionTitle: '收藏',
showAddDialog:()=>{
showAddDialog: () => {
this.isShowNewSources = true
}
})
} else {
Scroll(){
Column(){
ForEach(this.groupList,(item:rssGroupList)=>{
Scroll() {
Column() {
ForEach(this.groupList, (item: rssGroupList) => {
SubscriptionContent({
subscriptionTitle: item.title,
contentList: item.list,
refresh:this.refresh
refresh: this.refresh
})
})
}
}
.align(Alignment.Top)
.padding({bottom:20})
.padding({ bottom: 20 })
.layoutWeight(1)
.scrollBar(BarState.Off)
.scrollable(ScrollDirection.Vertical)
}

Flex()
.bindSheet($$this.isShowImport,this.dialogImportFunction(),{
.bindSheet($$this.isShowImport, this.dialogImportFunction(), {
detents: [SheetSize.FIT_CONTENT, SheetSize.LARGE, 200],
dragBar: true,
showClose:false,
onDisappear:()=>{
showClose: false,
onDisappear: () => {
this.isShowImport = false
}
})

Flex()
.bindSheet($$this.isShowNewSources,this.dialogNewSourcesFunction(),{
.bindSheet($$this.isShowNewSources, this.dialogNewSourcesFunction(), {
height: 200,
dragBar: true,
showClose:false,
onDisappear:()=>{
showClose: false,
onDisappear: () => {
this.isShowNewSources = false
}
})
Expand All @@ -200,24 +202,26 @@ export default struct SubscriptionIndex {
.height('100%')
}

@Builder dialogImportFunction() {
@Builder
dialogImportFunction() {
Flex() {
SubscriptionImport({
subscriptionList:this.subscriptionList
,show: this.isShowImport
}).onDisAppear(()=>{
subscriptionList: this.subscriptionList
, show: this.isShowImport
}).onDisAppear(() => {
this.refresh()
})
}
}

@Builder dialogNewSourcesFunction() {
Column(){
@Builder
dialogNewSourcesFunction() {
Column() {
dialogNewSources({
btnClick:()=>{
btnClick: () => {
this.isShowNewSources = false
}
}).onDisAppear(()=>{
}).onDisAppear(() => {
this.refresh()
})

Expand Down Expand Up @@ -245,7 +249,7 @@ export default struct SubscriptionIndex {
this.MenuOnclick(index)
})

if(index !== 5){
if (index !== 5) {
Divider()
}
}
Expand All @@ -257,31 +261,27 @@ export default struct SubscriptionIndex {
.width(100)
}



async MenuOnclick(value:number|string){
switch (value){
async MenuOnclick(value: number | string) {
switch (value) {
case 0:
this.pasteAnalyze();
// 粘贴导入
this.pasteAnalyze(0);
break;
case 1:
//todo:本地导入
let result = await FileHandler.documentPickerFile(1, ['.json'])
showMessage('订阅源本地导入成功')
// 本地导入
this.pasteAnalyze(1);
break
case 2:
this.isShowNewSources =true
this.isShowNewSources = true
break;
case 3:
break
case 4:

break

}
}

async pasteAnalyze() {
async pasteAnalyze(value: number) {
try {
const url = getPasteDataSync()
if (!url) {
Expand All @@ -294,10 +294,18 @@ export default struct SubscriptionIndex {
// showMessage('复制的链接不正确')
// return
// }
const res: AxiosResponse = await axios
.get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json');
console.log('res', JSON.stringify(res))
this.subscriptionList = res.data;
if (value === 1) {
let FileResult = await FileHandler.documentPickerFile(1, ['.json'])
FileHandler.ReadJSONFile(FileResult[0]).then(result => {
// console.log('result:' + result)
this.subscriptionList = JSON.parse(result) as rssSources[]
})
} else if (value === 0) {
const res: AxiosResponse = await axios
.get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json');
console.log('res', JSON.stringify(res))
this.subscriptionList = res.data;
}
this.isShowImport = true;
} catch (err) {
console.error('错误 ' + err);
Expand Down

0 comments on commit 24501f2

Please sign in to comment.