mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
优化
This commit is contained in:
parent
7a0df7824e
commit
d4103616d7
@ -72,7 +72,7 @@ export const useSourceStore = defineStore("source", {
|
|||||||
saveCurrentSource() {
|
saveCurrentSource() {
|
||||||
let source = this.currentSource,
|
let source = this.currentSource,
|
||||||
map = this.sourcesMap;
|
map = this.sourcesMap;
|
||||||
map.set(getSourceUniqueKey(source), Object.create(source));
|
map.set(getSourceUniqueKey(source), JSON.parse(JSON.stringify(source)));
|
||||||
this.saveSources(Array.from(map.values()));
|
this.saveSources(Array.from(map.values()));
|
||||||
},
|
},
|
||||||
// 更改当前编辑的源qq
|
// 更改当前编辑的源qq
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
import { Source } from '../source'
|
import { Source } from '../source'
|
||||||
|
|
||||||
|
|
||||||
const isNullOrBlank = (string: string | null | undefined | number) => string == null || (string as string).length === 0 || /^\s+$/.test(string as string)
|
const isNullOrBlank = (string: string | null | undefined | number) => string == null || (string as string).length === 0 || /^\s+$/.test(string as string)
|
||||||
const isBookSource = (source: Source) => "bookSourceName" in source
|
const isBookSource = (source: Source) => "bookSourceName" in source
|
||||||
|
|
||||||
export const isInvaildSource: (source: Source) => boolean = (source) => {
|
export const isInvaildSource: (source: Source) => boolean = (source) => {
|
||||||
if (isBookSource(source)) {
|
if (isBookSource(source)) {
|
||||||
return !isNullOrBlank(source.bookSourceName) &&
|
return !isNullOrBlank(source.bookSourceName) &&
|
||||||
!isNullOrBlank(source.bookSourceUrl) &&
|
!isNullOrBlank(source.bookSourceUrl) &&
|
||||||
!isNullOrBlank(source.bookSourceType)
|
!isNullOrBlank(source.bookSourceType)
|
||||||
}
|
}
|
||||||
return !isNullOrBlank(source.sourceName) &&
|
return !isNullOrBlank(source.sourceName) &&
|
||||||
!isNullOrBlank(source.sourceName)
|
!isNullOrBlank(source.sourceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getSourceUniqueKey = (source: Source) => isBookSource(source) ? source.bookSourceUrl : source.sourceUrl;
|
export const getSourceUniqueKey = (source: Source) => isBookSource(source) ? source.bookSourceUrl : source.sourceUrl;
|
||||||
|
|
||||||
export const isSourceMatches: (source: Source, searchKey: string) => boolean = (source, searchKey) => {
|
export const isSourceMatches: (source: Source, searchKey: string) => boolean = (source, searchKey) => {
|
||||||
// TODO: 正则和普通字符串识别 识别 * . \ [ ] <= <! != = ?: () \d\w\s\...
|
// TODO: 正则和普通字符串识别 识别 * . \ [ ] <= <! != = ?: () \d\w\s\...
|
||||||
if (isBookSource(source)) {
|
if (isBookSource(source)) {
|
||||||
return (source.bookSourceName?.includes(searchKey) ||
|
return (source.bookSourceName?.includes(searchKey) ||
|
||||||
source.bookSourceUrl?.includes(searchKey) ||
|
source.bookSourceUrl?.includes(searchKey) ||
|
||||||
source.bookSourceGroup?.includes(searchKey) ||
|
source.bookSourceGroup?.includes(searchKey) ||
|
||||||
source.bookSourceComment?.includes(searchKey)) ?? false
|
source.bookSourceComment?.includes(searchKey)) ?? false
|
||||||
}
|
}
|
||||||
return (source.sourceName?.includes(searchKey) ||
|
return (source.sourceName?.includes(searchKey) ||
|
||||||
source.sourceUrl?.includes(searchKey) ||
|
source.sourceUrl?.includes(searchKey) ||
|
||||||
source.sourceGroup?.includes(searchKey) ||
|
source.sourceGroup?.includes(searchKey) ||
|
||||||
source.sourceComment?.includes(searchKey)) ?? false
|
source.sourceComment?.includes(searchKey)) ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
export const convertSourcesToMap = (sources: Source[]): Map<string, Source> => {
|
export const convertSourcesToMap = (sources: Source[]): Map<string, Source> => {
|
||||||
const map = new Map();
|
const map = new Map();
|
||||||
sources.forEach((source) =>
|
sources.forEach((source) =>
|
||||||
map.set(getSourceUniqueKey(source), source)
|
map.set(getSourceUniqueKey(source), source)
|
||||||
);
|
);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const emptyBookSource = {
|
export const emptyBookSource = {
|
||||||
ruleSearch: {},
|
ruleSearch: {},
|
||||||
ruleBookInfo: {},
|
ruleBookInfo: {},
|
||||||
ruleToc: {},
|
ruleToc: {},
|
||||||
ruleContent: {},
|
ruleContent: {},
|
||||||
ruleReview: {},
|
ruleReview: {},
|
||||||
ruleExplore: {}
|
ruleExplore: {}
|
||||||
}
|
}
|
||||||
export const emptyRssSource = {}
|
export const emptyRssSource = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user