From 374b5ee6dccb60acac391006b6563a4cb184ae1e Mon Sep 17 00:00:00 2001 From: 2008 <59199830@qq.com> Date: Mon, 22 Jul 2024 15:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=BA=90=E9=A1=B5=E9=9D=A2de?= =?UTF-8?q?bug=E3=80=81=E6=9B=B4=E5=A4=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 订阅源页面debug、更多功能 --- .../main/resources/base/media/icon_dubug.svg | 9 + entry/src/main/ets/componets/dialog/help.ets | 28 ++- .../main/ets/database/AppDatabase/index.ets | 10 +- .../main/ets/database/entities/rssSources.ets | 2 +- .../main/ets/entryability/EntryAbility.ets | 2 + entry/src/main/ets/pages/Index.ets | 1 + .../Subscription/RssSources/newSources.ets | 218 ++++++++++++++++-- .../RssSources/newSourcesNetWork.ets | 7 +- .../components/PreviewEffectImage.ets | 2 + .../components/rssSourcesHelp.ets | 115 +++++++++ .../pages/view/Subscription/rssWebView.ets | 69 ++++-- 11 files changed, 408 insertions(+), 55 deletions(-) create mode 100644 commons/colorLibrary/src/main/resources/base/media/icon_dubug.svg create mode 100644 entry/src/main/ets/pages/view/Subscription/components/rssSourcesHelp.ets diff --git a/commons/colorLibrary/src/main/resources/base/media/icon_dubug.svg b/commons/colorLibrary/src/main/resources/base/media/icon_dubug.svg new file mode 100644 index 00000000..5131d5b7 --- /dev/null +++ b/commons/colorLibrary/src/main/resources/base/media/icon_dubug.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/entry/src/main/ets/componets/dialog/help.ets b/entry/src/main/ets/componets/dialog/help.ets index 03142cc6..5af0d81a 100644 --- a/entry/src/main/ets/componets/dialog/help.ets +++ b/entry/src/main/ets/componets/dialog/help.ets @@ -11,8 +11,11 @@ export default struct Help { btnText: string = '' btnClick: Function = () => { } + @Builder contentBuilders() {} + // 自定义左侧区域 + @BuilderParam contentBuilder: () => void = this.contentBuilders @StorageLink('bottomRectHeight') bottomRectHeight: number = 0 - + isShowContent:boolean = true build() { Flex({ direction: FlexDirection.Column, @@ -31,13 +34,24 @@ export default struct Help { .padding({ bottom: PaddingConstants.PADDING_12 }) + if (this.contentBuilders !== this.contentBuilder) { + Column(){ + this.contentBuilder() + } + .padding({ + top: PaddingConstants.PADDING_12, + bottom: PaddingConstants.PADDING_12 + }) + } + if (this.isShowContent){ + Flex() { + Text(!this.context ? HelpInfo.HELP_INFO_MESSAGE : this.context) + }.padding({ + top: PaddingConstants.PADDING_12, + bottom: PaddingConstants.PADDING_12 + }) + } - Flex() { - Text(!this.context ? HelpInfo.HELP_INFO_MESSAGE : this.context) - }.padding({ - top: PaddingConstants.PADDING_12, - bottom: PaddingConstants.PADDING_12 - }) } Button(!this.btnText ? $r('app.string.i_know') : this.btnText) diff --git a/entry/src/main/ets/database/AppDatabase/index.ets b/entry/src/main/ets/database/AppDatabase/index.ets index 7dc1e883..dc17a4c7 100644 --- a/entry/src/main/ets/database/AppDatabase/index.ets +++ b/entry/src/main/ets/database/AppDatabase/index.ets @@ -1291,6 +1291,14 @@ export default { "affinity": "TEXT", "notNull": false }, + { + "fieldPath": "autoComplete", + "columnName": "autoComplete", + "affinity": "INTEGER", + "boolean": true, + "notNull": true, + "defaultValue": "0" + }, ], "primaryKey": { "autoGenerate": false, @@ -1979,7 +1987,7 @@ export default { }, { "tableName": "rss_sources_history", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourceType` INTEGER NOT NULL ,`sourceGroup` TEXT,`sourceUrl` TEXT NOT NULL, `sourceName` TEXT NOT NULL, `sourceIcon` TEXT NOT NULL,`lastUpdateTime` INTEGER NOT NULL DEFAULT 0,`sourceIconIsUrl` INTEGER ,`showRecentIcon` INTEGER NOT NULL DEFAULT 1,`customizeTitle` TEXT, PRIMARY KEY(`sourceUrl`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourceType` INTEGER NOT NULL ,`sourceGroup` TEXT,`sourceUrl` TEXT NOT NULL, `sourceName` TEXT NOT NULL, `sourceIcon` TEXT NOT NULL,`lastUpdateTime` INTEGER NOT NULL DEFAULT 0,`sourceIconIsUrl` INTEGER ,`showRecentIcon` INTEGER NOT NULL DEFAULT 1 ,`autoComplete` INTEGER NOT NULL DEFAULT 0,`customizeTitle` TEXT, PRIMARY KEY(`sourceUrl`))", "fields": [ { "fieldPath": "sourceType", diff --git a/entry/src/main/ets/database/entities/rssSources.ets b/entry/src/main/ets/database/entities/rssSources.ets index 27dbb9cb..6f849568 100644 --- a/entry/src/main/ets/database/entities/rssSources.ets +++ b/entry/src/main/ets/database/entities/rssSources.ets @@ -21,7 +21,7 @@ export class rssSources{ // 图标是否使用链接 sourceIconIsUrl:boolean = false // 分组 - sourceGroup:string = SUBSCRIPTION_GROUP_TYPE[0] + sourceGroup:string = SUBSCRIPTION_GROUP_TYPE[4] //源注解 sourceComment?:string //是否启用 diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 900947fc..19bccca7 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -6,6 +6,7 @@ import { AbilityConstant, Want } from '@kit.AbilityKit'; import display from '@ohos.display'; import DbUtil from '../common/utils/DbUtil'; import DataBase from '../database' +import { webview } from '@kit.ArkWeb'; export default class EntryAbility extends UIAbility { @@ -33,6 +34,7 @@ export default class EntryAbility extends UIAbility { } onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + webview.WebviewController.initializeWebEngine()//初始化web控件 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 848108a5..ee13e50d 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -38,6 +38,7 @@ struct Main { justifyContent:FlexAlign.Center }){ Image(this.currentTabIndex === index?icon_select:unselected).height(25) + .draggable(false) Text(name).fontSize(11).margin(5).fontColor(this.currentTabIndex === index ?'rgb(255,119, 50)' : '#000000') } }.gesture( diff --git a/entry/src/main/ets/pages/view/Subscription/RssSources/newSources.ets b/entry/src/main/ets/pages/view/Subscription/RssSources/newSources.ets index 90237f0e..75928e15 100644 --- a/entry/src/main/ets/pages/view/Subscription/RssSources/newSources.ets +++ b/entry/src/main/ets/pages/view/Subscription/RssSources/newSources.ets @@ -1,47 +1,109 @@ -/** - * @author 2008 - * @datetime 2024/7/16 18:13 - * @className: newSources - * 新建/修改订阅源 - */ import CommonConstants from '../../../../common/constants/CommonConstants' import FontConstants from '../../../../common/constants/FontConstants' +import ImageConstants from '../../../../common/constants/ImageConstants' import PaddingConstants from '../../../../common/constants/PaddingConstants' +import TextConstants from '../../../../common/constants/TextConstants' import { isNetworkUrl } from '../../../../common/utils/utils' import buttonCommon from '../../../../componets/common/buttonCommon' +import dialogTitleFuction from '../../../../componets/common/dialogTitleFuction' import { showMessage } from '../../../../componets/common/promptShow' +import Help from '../../../../componets/dialog/help' import FormItem from '../../../../componets/Form/FormItem' import SubscriptionDao from '../../../../database/dao/SubscriptionDao' import { rssSources, SUBSCRIPTION_GROUP_TYPE } from '../../../../database/entities/rssSources' import { rssListRule } from '../../../../database/entities/rule/rssListRule' import { rssWebViewRule } from '../../../../database/entities/rule/rssWebViewRule' import programDataPreferences from '../../../../preferences/programDataPreferences' +import SourceDebug from '../../Find/BookSource/components/SourceDebug' import PreviewEffectImage from '../components/PreviewEffectImage' import RssSourceCheckImage from '../components/RssSourceCheckImage' +import rssSourcesHelp from '../components/rssSourcesHelp' @Component export default struct newSources{ + @State isShowHelp: boolean = false + @State isShowMenu: boolean = false hideNewSources:Function = ()=>{} @State currentIndex: number = 0 @Prop isEdit:boolean = false private controller: TabsController = new TabsController() private headController: TabsController = new TabsController() - @State @Watch('onReadChange') readIndex: number = 0 - onReadChange() { - console.log(this.readIndex + '') - this.headController.changeIndex(this.readIndex) - } + @State readIndex: number = 0 build() { Column(){ Column(){ - Text(`${this.isEdit?'编辑':'新建'}订阅源`) - .fontSize(FontConstants.FONT_SIZE_16) - .fontWeight(FontConstants.FONT_WEIGHT_500) - .lineHeight(24) - .fontColor($r('app.string.color_black_88')) - .textAlign(TextAlign.Center) + Flex({ + justifyContent:FlexAlign.SpaceBetween, + alignItems:ItemAlign.Center + }){ + if (this.readIndex===1){ + Image($r('app.media.return_left')) + .width(25) + .height(25) + .onClick(()=>{ + this.headController.changeIndex(0) + }) + } + Text(this.readIndex===0?`${this.isEdit?'编辑':'新建'}订阅源`:'调试源') + .fontSize(FontConstants.FONT_SIZE_18) + .fontWeight(FontConstants.FONT_WEIGHT_500) + .lineHeight(26) + .fontColor($r('app.string.color_black_88')) + .textAlign(TextAlign.Center) + + Row({ + space:20 + }){ + Row({ + space: 4 + }){ + if (this.readIndex === 0){ + Image($r('app.media.icon_dubug')) + .fillColor($r('app.string.color_black_88')) + .width(ImageConstants.IMG_WIDTH_20) + .height(ImageConstants.IMG_HEIGHT_20) + Text('调试') + .font({ + size: FontConstants.FONT_SIZE_14, + weight: FontConstants.FONT_WEIGHT_400, + family: CommonConstants.FAMILY_PingFANG + }) + .fontColor($r('app.string.color_black_88')) + .lineHeight(22) + } + } + .onClick(()=>{ + this.headController.changeIndex(1) + }) + Image(this.readIndex === 0?$r('app.media.more'):$r('app.media.more_translate')) + .fillColor($r('app.string.color_black_88')) + .width(ImageConstants.IMG_WIDTH_24) + .height(ImageConstants.IMG_HEIGHT_24) + .bindPopup( + this.isShowMenu,{ + builder: this.rightMoreDialogBuilder(),//todo dubug弹窗菜单不一样 + placement: Placement.Bottom, + radius:10, + enableArrow: false, + popupColor:Color.Transparent, + onStateChange: (e) => { + if (!e.isVisible) { + this.isShowMenu = false; + } + }, + transition:!this.isShowMenu?TransitionEffect.asymmetric( + TransitionEffect.OPACITY.animation({ duration: 1000, curve: Curve.Ease }).combine( + TransitionEffect.translate({ x: 0, y: 1 })), TransitionEffect.IDENTITY) + :TransitionEffect.scale({ x: 1, y: 0 }).animation({ duration: 500, curve: Curve.Ease }) + } + ) + .onClick(() => { + this.isShowMenu = !this.isShowMenu + }) + } + } Tabs({ barPosition: BarPosition.Start, index: this.readIndex, controller: this.headController }) { TabContent() { Column() { @@ -72,7 +134,7 @@ export default struct newSources{ }.layoutWeight(1) TabContent() { - // SourceDebug() + SourceDebug() //todo 需要写一个订阅源页面 }.layoutWeight(1) } .barWidth(0) @@ -126,6 +188,15 @@ export default struct newSources{ this.isShowPresetIcon = false } }) + Flex() + .bindSheet($$this.isShowHelp, this.dialogHelpFuction(), { + height: '65%', + showClose: false, + dragBar: false, + onDisappear: () => { + this.isShowHelp = false + } + }) } } private scroller: Scroller = new Scroller() @@ -139,7 +210,7 @@ export default struct newSources{ lastUpdateTime: new Date().getTime(), customOrder: 0, autoComplete: false, - sourceGroup: SUBSCRIPTION_GROUP_TYPE[0], + sourceGroup: SUBSCRIPTION_GROUP_TYPE[4], enabled: true, singleUrl: true, showRecentIcon: true, @@ -166,6 +237,7 @@ export default struct newSources{ if (!this.formModel.rssWebViewRule) { this.formModel.rssWebViewRule = new rssWebViewRule() } + this.readIndex = 0 } @Builder @@ -215,7 +287,10 @@ export default struct newSources{ Row() { Select(this.sourceGroupList) - .value(this.formModel.sourceGroup.length === 0?SUBSCRIPTION_GROUP_TYPE[0]:this.formModel.sourceGroup) + .selected(this.sourceGroupList.findIndex((item) => { + return item.value === this.formModel.sourceGroup + })) + .value(this.formModel.sourceGroup?this.formModel.sourceGroup:SUBSCRIPTION_GROUP_TYPE[4]) .borderRadius(4) .fontColor(this.formModel.sourceGroup !== undefined ? '#E0000000' : '#73000000') .onSelect((index: number, text?: string | undefined) => { @@ -615,4 +690,105 @@ export default struct newSources{ } } } -} \ No newline at end of file + + Item_Right_MORE_Dialog_Data: string[] = ['清除Cookie','自动补全','拷贝源','粘贴源','设置原变量','字符串分享','帮助'] + dialogMoreRightChange(index:number){ + switch (index) { + case 0: + showMessage('清除Cookie') + break + case 2: + showMessage('拷贝源') + break + case 3: + showMessage('粘贴源') + break + case 4: + showMessage('设置原变量') + break + case 5: + showMessage('字符串分享') + break + case 6: + this.isShowHelp = true + showMessage('帮助') + break + } + } + @Builder + rightMoreDialogBuilder() { + Column(){ + ForEach(this.Item_Right_MORE_Dialog_Data, (item: string, index) => { + if (index === 1) { + this.toggleBuilder(item) + } else { + dialogTitleFuction({ + title: item, + isBorder: this.Item_Right_MORE_Dialog_Data.length !== index + 1 + }) + .onClick(() => { + this.dialogMoreRightChange(index) + }) + } + }) + } + .alignItems(HorizontalAlign.Start) + } + @Builder + toggleBuilder(title:string) { + Column() { + Row({ + space:5 + }){ + Text(title) + .font({ + size:FontConstants.FONT_SIZE_14, + weight:FontConstants.FONT_WEIGHT_400, + family:CommonConstants.FAMILY_PingFANG + }) + .fontColor($r('app.string.color_black_88')) + .lineHeight(TextConstants.TEXT_LINE_HEIGHT_22) + Toggle({ type: ToggleType.Switch, isOn: this.formModel.autoComplete}) + .selectedColor(0xff6600) + .margin({ left: 8 }) + .onChange((val: boolean) => { + this.formModel.autoComplete = val + }) + } + .border({ + style: BorderStyle.Solid, + width: 1, + color: '#f5f5f5' + }) + .padding({ + top:PaddingConstants.PADDING_12, + bottom:PaddingConstants.PADDING_12}) + .alignItems(VerticalAlign.Center) + .justifyContent(FlexAlign.Center) + } + .padding({ + left:PaddingConstants.PADDING_20, + right:PaddingConstants.PADDING_20,}) + } + + + @Builder + dialogHelpFuction() { + Column() { + Help({ + title:'源规则帮助', + btnClick:()=>{ + this.isShowHelp = false + }, + contentBuilder:this.helpContent, + isShowContent:false + }) + } + } + @Builder + helpContent(){ + Column(){ + rssSourcesHelp() + } + } +} diff --git a/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets b/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets index 368684cf..6565ad25 100644 --- a/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets +++ b/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets @@ -83,7 +83,7 @@ export default struct newSourcesNetWork{ lastUpdateTime: new Date().getTime(), customOrder: 0, autoComplete: false, - sourceGroup: SUBSCRIPTION_GROUP_TYPE[0], + sourceGroup: SUBSCRIPTION_GROUP_TYPE[4], enabled: true, singleUrl: true, showRecentIcon: true, @@ -142,7 +142,10 @@ export default struct newSourcesNetWork{ Row() { Select(this.sourceGroupList) - .value(this.formModel.sourceGroup.length === 0?SUBSCRIPTION_GROUP_TYPE[0]:this.formModel.sourceGroup) + .selected(this.sourceGroupList.findIndex((item) => { + return item.value === this.formModel.sourceGroup + })) + .value(this.formModel.sourceGroup?this.formModel.sourceGroup:SUBSCRIPTION_GROUP_TYPE[4]) .borderRadius(4) .fontColor(this.formModel.sourceGroup !== undefined ? '#E0000000' : '#73000000') .onSelect((index: number, text?: string | undefined) => { diff --git a/entry/src/main/ets/pages/view/Subscription/components/PreviewEffectImage.ets b/entry/src/main/ets/pages/view/Subscription/components/PreviewEffectImage.ets index b38e6699..ab6b9ed4 100644 --- a/entry/src/main/ets/pages/view/Subscription/components/PreviewEffectImage.ets +++ b/entry/src/main/ets/pages/view/Subscription/components/PreviewEffectImage.ets @@ -66,6 +66,7 @@ export default struct PreviewEffectImage{ .animation(({ duration:1000 })) + .draggable(false) .borderRadius(this.ImageRadius) } else { Image(this.sourceIcon.indexOf('app.media.')>-1?$r(this.sourceIcon):this.sourceIcon) @@ -74,6 +75,7 @@ export default struct PreviewEffectImage{ .animation(({ duration:1000 })) + .draggable(false) .borderRadius(this.ImageRadius) .onError(()=>{ this.isError = true diff --git a/entry/src/main/ets/pages/view/Subscription/components/rssSourcesHelp.ets b/entry/src/main/ets/pages/view/Subscription/components/rssSourcesHelp.ets new file mode 100644 index 00000000..cddf84c7 --- /dev/null +++ b/entry/src/main/ets/pages/view/Subscription/components/rssSourcesHelp.ets @@ -0,0 +1,115 @@ +/** + * @author 2008 + * @datetime 2024/7/22 13:40 + * @className: rssSourcesHelp + */ +import CommonConstants from '../../../../common/constants/CommonConstants' +import FontConstants from '../../../../common/constants/FontConstants' +import TextConstants from '../../../../common/constants/TextConstants' + +@Component +export default struct rssSourcesHelp { + build() { + Column({ + space:5 + }) { + Row({ + space:8 + }){ + Row() + .width(5) + .height(5) + .borderRadius(5) + .backgroundColor('#188BFF') + Text('书源帮助文档') + .font({ + size:FontConstants.FONT_SIZE_14, + weight:FontConstants.FONT_WEIGHT_400, + family:CommonConstants.FAMILY_PingFANG + }) + .lineHeight(TextConstants.TEXT_LINE_HEIGHT_22) + .fontColor('#188BFF') + .decoration({ type: TextDecorationType.Underline, color: '#188BFF' }) + } + + Row({ + space:8 + }){ + Row() + .width(5) + .height(5) + .borderRadius(5) + .backgroundColor('#188BFF') + Text('订阅源帮助文档') + .font({ + size:FontConstants.FONT_SIZE_14, + weight:FontConstants.FONT_WEIGHT_400, + family:CommonConstants.FAMILY_PingFANG + }) + .lineHeight(TextConstants.TEXT_LINE_HEIGHT_22) + .fontColor('#188BFF') + .decoration({ type: TextDecorationType.Underline, color: '#188BFF' }) + } + + Row({ + space:8 + }){ + Row() + .width(5) + .height(5) + .borderRadius(5) + .backgroundColor('#188BFF') + Text('辅助键盘❓中可插入URL参数模板,打开帮助,js教程,正则教程,选择文件') + .font({ + size:FontConstants.FONT_SIZE_14, + weight:FontConstants.FONT_WEIGHT_400, + family:CommonConstants.FAMILY_PingFANG + }) + .lineHeight(TextConstants.TEXT_LINE_HEIGHT_22) + .fontColor('#188BFF') + .decoration({ type: TextDecorationType.Underline, color: '#188BFF' }) + } + + Row({ + space:8 + }){ + Row() + .width(5) + .height(5) + .borderRadius(5) + .backgroundColor('#188BFF') + Text('规则标志, {{......}}内使用规则必须有明显的规则标志,没有规则标志当作js执行') + .font({ + size:FontConstants.FONT_SIZE_14, + weight:FontConstants.FONT_WEIGHT_400, + family:CommonConstants.FAMILY_PingFANG + }) + .lineHeight(TextConstants.TEXT_LINE_HEIGHT_22) + .fontColor('#188BFF') + .decoration({ type: TextDecorationType.Underline, color: '#188BFF' }) + } + Column(){ + Text('@@ 默认规则,直接写时可以省略@@\n' + + '@XPath: xpath规则,直接写时以//开头可省略@XPath\n' + + '@Json: json规则,直接写时以$.开头可省略@Json\n' + + ': regex规则,不可省略,只可以用在书籍列表和目录列表') + .font({ + size:FontConstants.FONT_SIZE_14, + weight:FontConstants.FONT_WEIGHT_400, + family:CommonConstants.FAMILY_PingFANG + }) + .lineHeight(TextConstants.TEXT_LINE_HEIGHT_22) + .fontColor($r('app.string.color_black_88')) + .margin({ + top:12, + bottom:12, + left:16, + right:16 + }) + } + .alignItems(HorizontalAlign.Start) + .width('100%') + .backgroundColor($r('app.string.color_black_6')) + }.alignItems(HorizontalAlign.Start) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/Subscription/rssWebView.ets b/entry/src/main/ets/pages/view/Subscription/rssWebView.ets index 490e03ce..fc658812 100644 --- a/entry/src/main/ets/pages/view/Subscription/rssWebView.ets +++ b/entry/src/main/ets/pages/view/Subscription/rssWebView.ets @@ -14,11 +14,12 @@ interface RouteParams { @Entry @Component +@Preview struct RssWebView { @State sourcesUrl:string = '' @StorageLink('topRectHeight') topRectHeight: number = 0 @StorageLink('bottomRectHeight') bottomRectHeight: number = 0 - webviewController: webview.WebviewController = new webview.WebviewController(); + controller: 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]?://[^/]+/[^\"']+)` @@ -41,28 +42,20 @@ struct RssWebView { .margin({left:5}) .width("100%") Column(){ - Web({ src: this.sourcesUrl, controller: this.webviewController }) - .onLoadIntercept((event) => { - let url = decodeURIComponent(event.data.getRequestUrl()); - const match = url.match(this.regex); - if (match && 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]) { - 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 + Web({ src: this.sourcesUrl||'www.baidu.com', controller: this.controller }) + .onPageBegin((event) => { + //设置setCustomUserAgent为手机 + this.controller.setCustomUserAgent('Mozilla/5.0 (Linux; Android 13; M2007J3SC Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.101 Mobile Safari/537.36') + }) + .layoutWeight(1) + .onPageEnd((event) => { + this.getOnclickUrl(event.url) + }) + .onScroll((event) => { + showMessage("x = " + event.xOffset) + showMessage("y = " + event.yOffset) + console.info("x = " + event.xOffset); + console.info("y = " + event.yOffset); }) } Flex() @@ -102,6 +95,36 @@ struct RssWebView { SubscriptionImport({ subscriptionList:this.subscriptionList,show: this.isShowImportRssSources}) } } + getOnclickUrl(postUrl:string) { + let url = decodeURIComponent(postUrl); + //如果url存在匹配返回false + // if (url.match(this.regex) || url.match(this.regexRss) || url.match(this.legadoRegex)) { + // return false + // } + const match = url.match(this.regex); + if (match && match[1]) { + let urlBook = decodeURIComponent(match[1]); + this.pasteAnalyzeBookSource(urlBook) + this.controller.backward() + this.controller.scrollTo(0, 0) + return false + } + const matchRss = url.match(this.regexRss); + if (matchRss && matchRss[1]) { + let urlRss = decodeURIComponent(matchRss[1]); + this.pasteAnalyzeRssSource(urlRss) + this.controller.backward() + return false + } + const legadoMatch = url.match(this.legadoRegex); + if (legadoMatch && legadoMatch[1]) { + let urlLegado= decodeURIComponent(legadoMatch[1]); + showMessage(urlLegado) //todo 替换规则导入 + this.controller.backward() + return false + } + return true + } // 发现 async pasteAnalyzeBookSource(url:string) { try {