diff --git a/entry/src/main/ets/common/utils/AnalysisRules.ts b/entry/src/main/ets/common/utils/AnalysisRules.ts new file mode 100644 index 00000000..802e1c6c --- /dev/null +++ b/entry/src/main/ets/common/utils/AnalysisRules.ts @@ -0,0 +1,67 @@ +function parseData(data) { + const lines = data.split('\n'); + const result = []; + + lines.forEach((line) => { + const parts = line.split('::'); + if (parts.length === 2) { + const title = parts[0]; + const api = parts[1].replace(/{{String$new Date$$$.replace$'$GMT\+08:00$','$中国标准时间$'$}}/g, new Date().toString()); + + result.push({ + title: title, + api: { + url: api, + body: {}, + header: {} + } + }); + } + }); + + return result; +} +function parseDataWithMethod(data) { + const lines = data.split('\n'); + const result = []; + + lines.forEach((line) => { + const parts = line.split('::'); + if (parts.length === 2) { + const title = parts[0]; + const apiData = parts[1].split(','); + if (apiData.length === 2) { + const url = apiData[0]; + const apiInfo = apiData[1]; + + let parsedInfo = apiInfo.replace(/'/g, '"'); + parsedInfo = JSON.parse(parsedInfo); + const { method, body } = parsedInfo; + + result.push({ + title: title, + api: { + url: url.trim(), + method: method.trim(), + body: body.trim(), + header: {} + } + }); + } + } + }); + + return result; +} + +export const autoParseData = (data) => { + if (data.includes('method')) { + return parseDataWithMethod(data); + } else { + return parseData(data); + } +} + +export const AnalysisRules = (data) => { + return autoParseData(data) +} \ No newline at end of file diff --git a/entry/src/main/ets/componets/import/ImportCommon.ets b/entry/src/main/ets/componets/import/ImportCommon.ets index b706e9a7..64e6abe3 100644 --- a/entry/src/main/ets/componets/import/ImportCommon.ets +++ b/entry/src/main/ets/componets/import/ImportCommon.ets @@ -9,7 +9,8 @@ import { showMessage } from '../common/promptShow'; import Score from '../common/Score'; import Tag from '../common/Tag'; import BookSourceDao from '../../database/dao/BookSourceDao'; -import { BookSource, GroupList } from '../../database/entities/BookSource'; +import { BookSource, GroupList, SOURCE_GROUP_MAP } from '../../database/entities/BookSource'; +import SourceGroup from '../ui/sourceGroup'; @Component export default struct ImportCommon { @@ -25,6 +26,9 @@ export default struct ImportCommon { @State fullActive: boolean = false @State waringActive: boolean = false @StorageLink('refreshCount') refreshCount: number = 0 + @State isShowGroup: boolean = false + @State groupName: string = '' + @State groupIndex: number = 0 private scroll: Scroller = new Scroller() private secondScroll = new Scroller() @@ -88,6 +92,10 @@ export default struct ImportCommon { this.currentIndex = 0 } + getSourceGroupAll () { + return Object.values(SOURCE_GROUP_MAP).flat() + } + build() { Column() { Row({ space: 12 }) { @@ -104,7 +112,7 @@ export default struct ImportCommon { List({ scroller: this.secondScroll }) { ForEach(this.groupList, (item: GroupList, index: number) => { ListItemGroup({ - header: this.classifyHeader(`${item.title} (${item.list.length})`, index), + header: this.classifyHeader(`${item.title}`, ` (${item.list.length})` , index, item.list[0].bookSourceType || 0), space: 0 }) { ForEach(item.list, (bookSource: BookSource, j: number) => { @@ -201,15 +209,26 @@ export default struct ImportCommon { top: 12, bottom: 12 }) + + //分组 + Flex() + .bindSheet($$this.isShowGroup, this.showCheckGroup(), { + height: 320, + dragBar: true, + showClose: false, + onDisappear: () => { + this.isShowGroup = false + } + }) } .padding({ top: 12, bottom: 12 }) .backgroundColor(0xF5F5F5) } @Builder - classifyHeader(title: string, index: number) { + classifyHeader(title: string, num: string, index: number, groupIndex: number) { Row() { - Text(title) + Text(title + num) .textAlign(TextAlign.Start) .height(48) .fontSize(16) @@ -218,10 +237,32 @@ export default struct ImportCommon { .textOverflow({ overflow: TextOverflow.Ellipsis }) + + Blank() + + if (!this.getSourceGroupAll().includes(title)) { + Row() { + Text(SOURCE_GROUP_MAP[groupIndex][0]) + .fontSize(14) + .lineHeight(22) + .fontColor('#FF6600') + Image($r('app.media.f60_right')) + .width(16) + } + .alignItems(VerticalAlign.Center) + .padding({ right: 6 }) + .onClick(() => { + this.groupName = title + this.groupIndex = groupIndex + this.isShowGroup = true + }) + } + CheckboxGroup({ group: 'checkboxGroup' + index }) .checkboxShape(CheckBoxShape.CIRCLE) .selectedColor(0xff6600) } + .alignItems(VerticalAlign.Center) .padding({ right: 16 }) .backgroundColor('#f5f5f5') } @@ -278,5 +319,30 @@ export default struct ImportCommon { }) .backgroundColor(Color.White) } + + //移动分组 + @Builder + showCheckGroup() { + Flex() { + SourceGroup({ + title: '导入至', + groupList: SOURCE_GROUP_MAP[this.groupIndex], + confirm: async (groupName) => { + const sourceList = this.sourceList.map(item => { + if (item.bookSourceGroup === this.groupName) { + item.bookSourceGroup = groupName + } + return item + }) + this.sourceList = sourceList + this.getGroupList() + this.isShowGroup = false + }, + cancel: () => { + this.isShowGroup = false + } + }) + } + } } diff --git a/entry/src/main/ets/componets/ui/sourceGroup.ets b/entry/src/main/ets/componets/ui/sourceGroup.ets new file mode 100644 index 00000000..d9dc9d4f --- /dev/null +++ b/entry/src/main/ets/componets/ui/sourceGroup.ets @@ -0,0 +1,102 @@ +/** + * @author andy + * @datetime 2024/7/27 01:02 + * @className: BookSourceGroup + * 通用分组选择弹窗 + */ +import CommonConstants from '../../common/constants/CommonConstants' +import PaddingConstants from '../../common/constants/PaddingConstants' + +@Component +export default struct SourceGroup { + @Prop groupList: string[] = [] + @Prop currentName: string + title: string = '移动至' + confirm: (groupName: string) => void = (_groupName) => { + } + cancel: () => void = () => { + } + + build() { + Column() { + Column() { + Text(this.title) + .fontSize(16) + .fontWeight(700) + .lineHeight(24) + } + .padding({ + right: 20, + left: 20, + top: 12, + bottom: 12 + }) + + Divider() + Scroll() { + Grid() { + ForEach(this.groupList, (item: string, index: number) => { + GridItem() { + this.titleBuilder(item) + } + .onClick(() => { + this.confirm(item) + }) + }) + } + .columnsTemplate('1fr 1fr 1fr') + .columnsGap(16) + .rowsGap(16) + } + .padding(PaddingConstants.PADDING_20) + .align(Alignment.Top) + .layoutWeight(1) + .scrollBar(BarState.Off) + + Column() { + Divider().strokeWidth(0.5) + + Button('取消') + .padding({ + left: 32, + right: 32, + top: 8, + bottom: 8 + }) + .width('100%') + .height(56) + .type(ButtonType.Normal) + .stateEffect(false) + .buttonStyle(ButtonStyleMode.TEXTUAL) + .fontColor('#E0000000') + .onClick(() => { + this.cancel() + }) + } + } + .width(CommonConstants.FULL_WIDTH) + .height(CommonConstants.FULL_HEIGHT) + } + + @Builder + titleBuilder(title: string) { + Column() { + Text(title) + .fontSize(14) + .textOverflow({ + overflow: TextOverflow.Ellipsis + }) + .lineHeight(20) + .maxLines(1) + } + .width(96) + .borderRadius(4) + .backgroundColor($r('app.string.color_black_6')) + .padding({ + left: 16, + right: 16, + top: 8, + bottom: 8 + }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets b/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets index c2a617ed..a996664b 100644 --- a/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets +++ b/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets @@ -9,9 +9,10 @@ import Tag from '../../../../../componets/common/Tag' import { IconTitleVo } from '../../../../../componetsmodel/IconTitleVo' import { CustomContentDialog, router } from '@kit.ArkUI' import BookSourceDao from '../../../../../database/dao/BookSourceDao' -import { GroupPartList } from '../../../../../database/entities/BookSource' +import { GroupPartList, SOURCE_GROUP_MAP } from '../../../../../database/entities/BookSource' import { BookSourcePart } from '../../../../../database/entities/BookSourcePart' import { JSON } from '@kit.ArkTS' +import SourceGroup from '../../../../../componets/ui/sourceGroup' @Component export default struct SourceView { @@ -40,6 +41,7 @@ export default struct SourceView { private secondScroll = new Scroller() @State dialogItem: Partial = {} @StorageLink('refreshCount') refreshCount: number = 0 + @State isShowGroup: boolean = false private dialogController: CustomDialogController = new CustomDialogController({ builder: CustomContentDialog({ primaryTitle: '书源评分', @@ -373,7 +375,15 @@ export default struct SourceView { this.rightDialogBuilder(this.More_Right_Dialog_Data, async (index: number) => { switch (index) { case 0: + if (!Object.values(this.activeNameMap).filter(o => o).length) { + showMessage('请至少选择一个') + return + } + this.isShowGroup = true; + break; case 1: + this.dialogController.open() + break; case 2: showMessage(this.More_Right_Dialog_Data[index].title) break; @@ -424,6 +434,17 @@ export default struct SourceView { .animation({ duration: 300 }) + + //分组 + Flex() + .bindSheet($$this.isShowGroup, this.showCheckGroup(), { + height: 320, + dragBar: true, + showClose: false, + onDisappear: () => { + this.isShowGroup = false + } + }) } .alignContent(Alignment.Top) } @@ -771,4 +792,30 @@ export default struct SourceView { }) } } + + //移动分组 + @Builder + showCheckGroup() { + Flex() { + SourceGroup({ + groupList: SOURCE_GROUP_MAP[[0, 2, 1][this.index]], + confirm: async (groupName) => { + this.sourceList.forEach((item, i) => { + if (this.activeNameMap[item.bookSourceUrl]) { + item.bookSourceGroup = groupName + this.sourceList[i] = item + } + }) + await BookSourceDao.batchUpdateFlow(this.sourceList) + this.getList() + this.activeNameMap = {} + this.isShowGroup = false + }, + cancel: () => { + this.isShowGroup = false + } + }) + } + .padding({ bottom: this.bottomRectHeight }) + } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/Find/components/BodyContent.ets b/entry/src/main/ets/pages/view/Find/components/BodyContent.ets index 71d571ff..24aa5ee2 100644 --- a/entry/src/main/ets/pages/view/Find/components/BodyContent.ets +++ b/entry/src/main/ets/pages/view/Find/components/BodyContent.ets @@ -35,7 +35,8 @@ export default struct BodyContent { BookSourceDao.search({ type: [0, 2, 1][this.currentIndex], enabled: true, - hasExploreUrl: this.hasExploreUrl + hasExploreUrl: this.hasExploreUrl, + showExplore: true }).then(bookSources => { console.info('TagInfo', JSON.stringify(bookSources.slice(0, 3))) this.sourceList = bookSources diff --git a/entry/src/main/ets/pages/view/Subscription/rssWebView.ets b/entry/src/main/ets/pages/view/Subscription/rssWebView.ets index fc658812..048bbbfc 100644 --- a/entry/src/main/ets/pages/view/Subscription/rssWebView.ets +++ b/entry/src/main/ets/pages/view/Subscription/rssWebView.ets @@ -49,7 +49,7 @@ struct RssWebView { }) .layoutWeight(1) .onPageEnd((event) => { - this.getOnclickUrl(event.url) + this.getOnclickUrl(event?.url || '') }) .onScroll((event) => { showMessage("x = " + event.xOffset) diff --git a/entry/src/main/resources/base/media/f60_right.svg b/entry/src/main/resources/base/media/f60_right.svg new file mode 100644 index 00000000..ec6413ab --- /dev/null +++ b/entry/src/main/resources/base/media/f60_right.svg @@ -0,0 +1,5 @@ + + + + +