From 4d845e0377fab2470c115524330b354fb8c3e20f Mon Sep 17 00:00:00 2001 From: 2008 <59199830@qq.com> Date: Sun, 21 Jul 2024 22:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=BA=90Web=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=AF=BC=E5=85=A5URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 订阅源Web读取导入URL --- .../componets/import/SubscriptionImport.ets | 5 ++ .../main/ets/database/entities/rssSources.ets | 2 +- .../components/SubscriptionSearch.ets | 1 - .../pages/view/Subscription/rssWebView.ets | 47 +++++++++++++------ .../preferences/programDataPreferences.ets | 2 +- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/entry/src/main/ets/componets/import/SubscriptionImport.ets b/entry/src/main/ets/componets/import/SubscriptionImport.ets index 5cd17792..e29a00b7 100644 --- a/entry/src/main/ets/componets/import/SubscriptionImport.ets +++ b/entry/src/main/ets/componets/import/SubscriptionImport.ets @@ -59,6 +59,11 @@ export default struct SubscriptionImport { } // 向当前group的list中添加BookSource对象 groupMap[title].list.push(item); + } else { + if (!groupMap['其他']) { + groupMap['其他'] = { title: '其他', list: [] }; + } + groupMap['其他'].list.push(item); } for (let i = 0; i < this.localSourceList.length; i++) { const localItem = this.localSourceList[i]; diff --git a/entry/src/main/ets/database/entities/rssSources.ets b/entry/src/main/ets/database/entities/rssSources.ets index a8cb97f0..27dbb9cb 100644 --- a/entry/src/main/ets/database/entities/rssSources.ets +++ b/entry/src/main/ets/database/entities/rssSources.ets @@ -112,7 +112,7 @@ export const SUBSCRIPTION_GROUP_TYPE: Record ={ 0: '小说', 1: '漫画', 2: '影视', - 3: '咨询', + 3: '资讯', 4: '收藏夹' } diff --git a/entry/src/main/ets/pages/view/Subscription/components/SubscriptionSearch.ets b/entry/src/main/ets/pages/view/Subscription/components/SubscriptionSearch.ets index 80c19cb2..b6da7649 100644 --- a/entry/src/main/ets/pages/view/Subscription/components/SubscriptionSearch.ets +++ b/entry/src/main/ets/pages/view/Subscription/components/SubscriptionSearch.ets @@ -3,7 +3,6 @@ * @datetime 2024/7/13 23:33 * @className: SubscriptionSearch * 订阅搜索页面 - * TODO 测试页面后续调整改为DB数据查询和数据读取 */ import CommonConstants from '../../../../common/constants/CommonConstants'; import FontConstants from '../../../../common/constants/FontConstants'; diff --git a/entry/src/main/ets/pages/view/Subscription/rssWebView.ets b/entry/src/main/ets/pages/view/Subscription/rssWebView.ets index 49138ab8..490e03ce 100644 --- a/entry/src/main/ets/pages/view/Subscription/rssWebView.ets +++ b/entry/src/main/ets/pages/view/Subscription/rssWebView.ets @@ -1,13 +1,11 @@ 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 { 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 { @@ -23,6 +21,7 @@ struct RssWebView { webviewController: webview.WebviewController = new webview.WebviewController(); regex:string = `/booksource/importonline\\?src=(http[s]?://[^/]+/[^\"']+)`; regexRss:string = `/rsssource/importonline\\?src=(http[s]?://[^/]+/[^\"']+)`; + legadoRegex:string = `/import/auto\\?src=(http[s]?://[^/]+/[^\"']+)` aboutToAppear(): void { const params = router.getParams() as RouteParams; this.sourcesUrl = params.url @@ -44,15 +43,23 @@ struct RssWebView { Column(){ Web({ src: this.sourcesUrl, controller: this.webviewController }) .onLoadIntercept((event) => { - let url = event.data.getRequestUrl() + let url = decodeURIComponent(event.data.getRequestUrl()); const match = url.match(this.regex); if (match && match[1]) { - this.pasteAnalyzeBookSource(match[1]) + let urlBook = decodeURIComponent(match[1]); + this.pasteAnalyzeBookSource(urlBook) this.webviewController.loadUrl(this.sourcesUrl) } const matchRss = url.match(this.regexRss); if (matchRss && matchRss[1]) { - this.pasteAnalyzeRssSource(matchRss[1]) + let urlRss = decodeURIComponent(matchRss[1]); + this.pasteAnalyzeRssSource(urlRss) + this.webviewController.loadUrl(this.sourcesUrl) + } + const legadoMatch = url.match(this.legadoRegex); + if (legadoMatch && legadoMatch[1]) { + let urlLegado= decodeURIComponent(legadoMatch[1]); + showMessage(urlLegado) //todo 替换规则导入 this.webviewController.loadUrl(this.sourcesUrl) } return false @@ -107,11 +114,16 @@ struct RssWebView { 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; + const res: AxiosResponse = await axios.get(url ?? 'https://node.wisdoms.xin/static/file/20240704/sy.json'); + if (res) { + console.log('res', JSON.stringify(res)) + this.sourceList = res.data; + this.isShowImportBookSource = true; + } else { + showMessage('订阅源解析失败') + } } catch (err) { + showMessage('订阅源解析失败') console.error('错误 ' + err); } } @@ -127,12 +139,17 @@ struct RssWebView { 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; + const res: AxiosResponse = await axios.get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json'); + if (res) { + console.log('res', JSON.stringify(res)) + this.subscriptionList = res.data; + this.isShowImportRssSources = true; + } else { + showMessage('订阅源解析失败') + } + } catch (err) { + showMessage('订阅源解析失败') console.error('错误 ' + err); } } diff --git a/entry/src/main/ets/preferences/programDataPreferences.ets b/entry/src/main/ets/preferences/programDataPreferences.ets index 5f2bf536..40dcfd95 100644 --- a/entry/src/main/ets/preferences/programDataPreferences.ets +++ b/entry/src/main/ets/preferences/programDataPreferences.ets @@ -8,7 +8,7 @@ import CommonConstants from '../common/constants/CommonConstants' import bookDataPreferences from '../common/utils/DataPreferencesUtils' export class programDataPreferences { - readonly rssSourcesGroup: string[] = ['小说', '漫画', '影视', '咨询', '收藏夹'] + readonly rssSourcesGroup: string[] = ['小说', '漫画', '影视', '资讯', '收藏夹'] initProgramDataPreferences = () => { //内容数据持久化 //订阅源分组数据