Skip to content

Commit

Permalink
feat: 导入时可进行分组,书院中批量操作分组 (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-boide authored Jul 26, 2024
1 parent 1315163 commit f4a233a
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 7 deletions.
67 changes: 67 additions & 0 deletions entry/src/main/ets/common/utils/AnalysisRules.ts
Original file line number Diff line number Diff line change
@@ -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)
}
74 changes: 70 additions & 4 deletions entry/src/main/ets/componets/import/ImportCommon.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()

Expand Down Expand Up @@ -88,6 +92,10 @@ export default struct ImportCommon {
this.currentIndex = 0
}

getSourceGroupAll () {
return Object.values(SOURCE_GROUP_MAP).flat()
}

build() {
Column() {
Row({ space: 12 }) {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
Expand All @@ -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')
}
Expand Down Expand Up @@ -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
}
})
}
}
}

102 changes: 102 additions & 0 deletions entry/src/main/ets/componets/ui/sourceGroup.ets
Original file line number Diff line number Diff line change
@@ -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
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -40,6 +41,7 @@ export default struct SourceView {
private secondScroll = new Scroller()
@State dialogItem: Partial<BookSourcePart> = {}
@StorageLink('refreshCount') refreshCount: number = 0
@State isShowGroup: boolean = false
private dialogController: CustomDialogController = new CustomDialogController({
builder: CustomContentDialog({
primaryTitle: '书源评分',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 })
}
}
Loading

0 comments on commit f4a233a

Please sign in to comment.