Skip to content

Commit

Permalink
Merge pull request #212 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
订阅源资源导入
  • Loading branch information
MaoXiaoone authored Jul 20, 2024
2 parents 29280bf + ae7bb22 commit bca8381
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import CommonConstants from '../../../../common/constants/CommonConstants'
import FontConstants from '../../../../common/constants/FontConstants'
import { showMessage } from '../../../../componets/common/promptShow'

@Component
export default struct PreviewEffectImage{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ export default struct SubscriptionContent{
showMessage('置顶')
break
case 2:
showMessage('移动至')
this.isShowGroup = true
break
case 3:
showMessage('删除')
SubscriptionDao.deleteRssSourcesList(this.contentList)
setTimeout(()=>{
this.refresh()
},200)
showMessage('删除成功')
break
}
}),
Expand Down Expand Up @@ -290,7 +294,7 @@ export default struct SubscriptionContent{
this.moveGroup = ''
showMessage('移动成功')
this.refresh()
},500)
},200)
} else {
showMessage('移动失败')
}
Expand Down
101 changes: 98 additions & 3 deletions entry/src/main/ets/pages/view/Subscription/rssWebView.ets
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { webview } from '@kit.ArkWeb';
import { router } from '@kit.ArkUI';
import { showMessage } from '../../../componets/common/promptShow';
import { loginComponentManager } from '@kit.AccountKit';
import ImportCommon from '../../../componets/import/ImportCommon';
import { BookSource } from '../../../database/entities/BookSource';
import { getPasteDataSync, isNetworkUrl, sleep } from '../../../common/utils/utils';
import axios, { AxiosResponse } from '@ohos/axios';
import SubscriptionImport from '../../../componets/import/SubscriptionImport';
import { rssListRule } from '../../../database/entities/rule/rssListRule';
import { rssSources } from '../../../database/entities/rssSources';

interface RouteParams {
url: string,
Expand All @@ -13,6 +21,8 @@ struct RssWebView {
@StorageLink('topRectHeight') topRectHeight: number = 0
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
webviewController: webview.WebviewController = new webview.WebviewController();
regex:string = `/booksource/importonline\\?src=(http[s]?://[^/]+/[^\"']+)`;
regexRss:string = `/rsssource/importonline\\?src=(http[s]?://[^/]+/[^\"']+)`;
aboutToAppear(): void {
const params = router.getParams() as RouteParams;
this.sourcesUrl = params.url
Expand All @@ -33,12 +43,97 @@ struct RssWebView {
.width("100%")
Column(){
Web({ src: this.sourcesUrl, controller: this.webviewController })
.onPageBegin(()=>{
showMessage(this.webviewController.getUserAgent())
.onLoadIntercept((event) => {
let url = event.data.getRequestUrl()
const match = url.match(this.regex);
if (match && match[1]) {
this.pasteAnalyzeBookSource(match[1])
this.webviewController.loadUrl(this.sourcesUrl)
}
const matchRss = url.match(this.regexRss);
if (matchRss && matchRss[1]) {
this.pasteAnalyzeRssSource(matchRss[1])
this.webviewController.loadUrl(this.sourcesUrl)
}
return false
})
}
Flex()
.bindSheet($$this.isShowImportBookSource, this.dialogImportBookFunction(), {
detents: [SheetSize.FIT_CONTENT, SheetSize.LARGE, 200],
dragBar: true,
showClose: false,
onDisappear: () => {
this.isShowImportBookSource = false
}
})

Flex()
.bindSheet($$this.isShowImportRssSources, this.dialogImportRssFunction(), {
detents: [SheetSize.FIT_CONTENT, SheetSize.LARGE, 200],
dragBar: true,
showClose: false,
onDisappear: () => {
this.isShowImportRssSources = false
}
})
}
.padding({ top: this.topRectHeight, bottom: this.bottomRectHeight + 20 })
}
@State isShowImportBookSource: boolean = false
@State sourceList: BookSource[] = []
@Builder
dialogImportBookFunction() {
Flex() {
ImportCommon({ sourceList: this.sourceList, show: this.isShowImportBookSource })
}
}
@State subscriptionList:rssSources[] = []
@State isShowImportRssSources:boolean = false
@Builder dialogImportRssFunction() {
Flex() {
SubscriptionImport({ subscriptionList:this.subscriptionList,show: this.isShowImportRssSources})
}
}
// 发现
async pasteAnalyzeBookSource(url:string) {
try {
if (!url) {
showMessage('未获取到相关Url,请求默认数据')
url = 'https://node.wisdoms.xin/static/file/20240704/sy.json'
await sleep()
}
if (!isNetworkUrl(url ?? '')) {
showMessage('链接不正确')
return
}
const res: AxiosResponse = await axios
.get(url ?? 'https://node.wisdoms.xin/static/file/20240704/sy.json');
this.sourceList = res.data;
this.isShowImportBookSource = true;
} catch (err) {
console.error('错误 ' + err);
}
}
// 订阅
async pasteAnalyzeRssSource(url:string) {
try {
if (!url) {
showMessage('未获取到相关Url,请求默认数据')
url = 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json'
await sleep()
}
if (!isNetworkUrl(url ?? '')) {
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;
this.isShowImportRssSources = true;
} catch (err) {
console.error('错误 ' + err);
}
.padding({top:this.topRectHeight, bottom:this.bottomRectHeight + 20})
}
}

0 comments on commit bca8381

Please sign in to comment.