diff --git a/entry/src/main/ets/database/AppDatabase/index.ets b/entry/src/main/ets/database/AppDatabase/index.ets index 0ae4c8fe..b4598c13 100644 --- a/entry/src/main/ets/database/AppDatabase/index.ets +++ b/entry/src/main/ets/database/AppDatabase/index.ets @@ -209,7 +209,7 @@ export default { { "fieldPath": "isTop", "columnName": "isTop", - "affinity": "isTop", + "affinity": "INTEGER", "boolean": true, "notNull": true, "defaultValue": "1" @@ -2369,6 +2369,54 @@ export default { }, "indices": [], "foreignKeys": [] + }, + { + "tableName":"rss_source_group", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`rssGroupId` INTEGER NOT NULL, `rssGroupName` TEXT NOT NULL , `isTop` INTEGER NOT NULL DEFAULT 0 , `groupSort` INTEGER , `isDelete` INTEGER NOT NULL DEFAULT 1 , PRIMARY KEY(`rssGroupId`))", + "fields": [ + { + "fieldPath": "rssGroupId", + "columnName": "rssGroupId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "rssGroupName", + "columnName": "rssGroupName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "groupSort", + "columnName": "groupSort", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "isTop", + "columnName": "isTop", + "affinity": "INTEGER", + "boolean": true, + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "isDelete", + "columnName": "isDelete", + "affinity": "INTEGER", + "boolean": true, + "notNull": false, + "defaultValue": "1" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "rssGroupId" + ] + }, + "indices": [], + "foreignKeys": [] } ], "views": [], diff --git a/entry/src/main/ets/database/dao/rssSourceGroupDao.ets b/entry/src/main/ets/database/dao/rssSourceGroupDao.ets new file mode 100644 index 00000000..67d2d38d --- /dev/null +++ b/entry/src/main/ets/database/dao/rssSourceGroupDao.ets @@ -0,0 +1,111 @@ +import { ColumnInfo } from '../types/ColumnInfo'; +import AppDatabaseUtil from '../AppDatabaseUtil' +import { JSON } from '@kit.ArkTS'; +import DbUtil from '../../common/utils/DbUtil'; +import { RssSourceGroup } from '../entities/RssSourceGroup'; + +class RssSourceGroupDao { + TABLE_NAME: string = 'rss_source_group' + + // rss_source_group + async initBookSourceGroupTable() { + try { + const createSql = AppDatabaseUtil.getCreateSql(this.TABLE_NAME); + if (!createSql) { + return + } + await DbUtil.createTable(createSql); + await AppDatabaseUtil.existsTable(this.TABLE_NAME) + this.initGroupData() + return + } catch (err) { + console.info('TagInfo', JSON.stringify(err)) + } + } + + + async search(){ + try { + const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); + let sql = `SELECT * FROM ${this.TABLE_NAME}`; + // sql += `ORDER BY isTop DESC, groupSort ASC`; + const groupDbList = await DbUtil.querySqlForList(sql, column); + console.log("TagInfo", '书籍:' + groupDbList.length) + return groupDbList + } catch (err) { + console.log("TagInfo", JSON.stringify(err)) + return [] + } + } + + + //系统初始订阅源分组数据 + async initGroupData() { + let initGroup = ['小说','漫画','影视','资讯','收藏'] + try { + const groupList = await this.search() + if (groupList.length > 0) { + return + } + for (let index = 0; index < initGroup.length; index++) { + let group = new RssSourceGroup() + // group.rssGroupId = index + group.rssGroupName = initGroup[index] + group.groupSort = index + group.isTop = false + group.isDelete = false + await this.insert(group) + } + }catch (e){ + console.log('TagInfo, Error, ', JSON.stringify(e)) + } + } + + async insert(rssGroup: RssSourceGroup) { + try { + const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); + if (rssGroup.rssGroupId) { + const predicates = DbUtil.getPredicates(this.TABLE_NAME); + predicates.equalTo('rssGroupId', rssGroup.rssGroupId) + const count = await DbUtil.queryForCount(predicates, column) + if (count > 0) { + this.update(rssGroup) + return true + } + } + await DbUtil.insert(this.TABLE_NAME, rssGroup, column) + console.log('TagInfo', '创建成功') + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + } + + async update(rssGroup: RssSourceGroup) { + try { + const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); + const predicates = DbUtil.getPredicates(this.TABLE_NAME); + predicates.equalTo('rssGroupId', rssGroup.rssGroupId) + const count = await DbUtil.queryForCount(predicates, column) + if (count === 0 && rssGroup instanceof RssSourceGroup) { + this.insert(rssGroup) + return true + } + + await DbUtil.update(predicates, rssGroup, column) + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + } + + + + +} + +const rssSourceGroupDao = new RssSourceGroupDao() + +export default rssSourceGroupDao as RssSourceGroupDao \ No newline at end of file diff --git a/entry/src/main/ets/database/entities/RssSourceGroup.ets b/entry/src/main/ets/database/entities/RssSourceGroup.ets new file mode 100644 index 00000000..8007a5c2 --- /dev/null +++ b/entry/src/main/ets/database/entities/RssSourceGroup.ets @@ -0,0 +1,18 @@ +/** + * @author 2008 + * @datetime 2024/12/6 23:31 + * @className: rssSourceGroup + * 订阅源分组 + */ +@Observed +export class RssSourceGroup{ + rssGroupId?:number; + //分组名称 + rssGroupName:string = ""; + //排序 + groupSort:number = 0; + //是否置顶 + isTop:boolean = false; + //是否允许删除 + isDelete:boolean = true; +} \ No newline at end of file diff --git a/entry/src/main/ets/database/index.ets b/entry/src/main/ets/database/index.ets index 9429c738..bfbffe60 100644 --- a/entry/src/main/ets/database/index.ets +++ b/entry/src/main/ets/database/index.ets @@ -2,6 +2,7 @@ import BookGroupsDao from './dao/BookGroupsDao' import bookHistoryDao from './dao/BookHistoryDao' import BooksDao from './dao/BooksDao' import BookSourceDao from './dao/BookSourceDao' +import rssSourceGroupDao from './dao/rssSourceGroupDao' import rssSourcesHistoryDao from './dao/RssSourcesHistoryDao' import SubscriptionDao from './dao/SubscriptionDao' import worksListsDao from './dao/WorksListsDao' @@ -15,6 +16,7 @@ class DataBase { await BookGroupsDao.initGroupTable() await worksListsDao.initWorksListsTable() await bookHistoryDao.initBookHistoryTable() + await rssSourceGroupDao.initBookSourceGroupTable() } } 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 d9f12a10..b048b735 100644 --- a/entry/src/main/ets/pages/view/Subscription/RssSources/newSources.ets +++ b/entry/src/main/ets/pages/view/Subscription/RssSources/newSources.ets @@ -11,6 +11,7 @@ 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 rssSourceGroupDao from '../../../../database/dao/rssSourceGroupDao' import SubscriptionDao from '../../../../database/dao/SubscriptionDao' import { rssSources, SUBSCRIPTION_GROUP_TYPE } from '../../../../database/entities/rssSources' import { rssListRule } from '../../../../database/entities/rule/rssListRule' @@ -221,15 +222,23 @@ export default struct newSources{ rssWebViewRule: new rssWebViewRule(), } + // @State sourceGroupList:SelectOption[] = [] @State sourceGroupList:SelectOption[] = [] - getRssSourceList() { - let list = programDataPreferences.getRssSourcesListData() - //将list存放到sourceGroupList - list.forEach((item) => { + + async getRssSourceList() { + let group = await rssSourceGroupDao.search(); + group.forEach(item=>{ this.sourceGroupList.push({ - value: item + value: item.rssGroupName }) }) + // let list = programDataPreferences.getRssSourcesListData() + // //将list存放到sourceGroupList + // list.forEach((item) => { + // this.sourceGroupList.push({ + // value: item + // }) + // }) } aboutToAppear(): void { this.getRssSourceList() diff --git a/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets b/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets index ba29f35a..a50fea86 100644 --- a/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets +++ b/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets @@ -45,7 +45,7 @@ export default struct SubscriptionContent{ build() { Column(){ Column({ - space:20 + space:16 }){ Flex({ justifyContent:FlexAlign.SpaceBetween,