优化
This commit is contained in:
@@ -68,7 +68,7 @@
|
|||||||
import API from '@api'
|
import API from '@api'
|
||||||
import { CircleCheckFilled, Edit } from '@element-plus/icons-vue'
|
import { CircleCheckFilled, Edit } from '@element-plus/icons-vue'
|
||||||
import hotkeys from 'hotkeys-js'
|
import hotkeys from 'hotkeys-js'
|
||||||
import { getSourceName, isInvaildSource } from '../utils/souce'
|
import { getSourceName, isInvaildSource, normalizeSource } from '../utils/souce'
|
||||||
|
|
||||||
const store = useSourceStore()
|
const store = useSourceStore()
|
||||||
const pull = () => {
|
const pull = () => {
|
||||||
@@ -168,6 +168,7 @@ const redo = () => {
|
|||||||
const saveSource = () => {
|
const saveSource = () => {
|
||||||
const source = store.currentSource
|
const source = store.currentSource
|
||||||
if (isInvaildSource(source)) {
|
if (isInvaildSource(source)) {
|
||||||
|
normalizeSource(source)
|
||||||
API.saveSource(source).then(({ data }) => {
|
API.saveSource(source).then(({ data }) => {
|
||||||
const sourceName = getSourceName(source)
|
const sourceName = getSourceName(source)
|
||||||
if (data.isSuccess) {
|
if (data.isSuccess) {
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ const emptySource = isBookSource ? emptyBookSource : emptyRssSource
|
|||||||
export const useSourceStore = defineStore('source', {
|
export const useSourceStore = defineStore('source', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
bookSources: [] as BookSoure[], // 临时存放所有书源,
|
bookSources: shallowRef([] as BookSoure[]), // 临时存放所有书源,
|
||||||
rssSources: [] as RssSource[], // 临时存放所有订阅源
|
rssSources: shallowRef([] as RssSource[]), // 临时存放所有订阅源
|
||||||
savedSources: [] as Source[], // 批量保存到阅读app成功的源
|
savedSources: [] as Source[], // 批量保存到阅读app成功的源
|
||||||
currentSource: JSON.parse(JSON.stringify(emptySource)) as Source, // 当前编辑的源
|
currentSource: JSON.parse(JSON.stringify(emptySource)) as Source, // 当前编辑的源
|
||||||
currentTab: localStorage.getItem('tabName') || 'editTab',
|
currentTab: localStorage.getItem('tabName') || 'editTab',
|
||||||
@@ -51,9 +51,9 @@ export const useSourceStore = defineStore('source', {
|
|||||||
//拉取源后保存
|
//拉取源后保存
|
||||||
saveSources(data: Source[]) {
|
saveSources(data: Source[]) {
|
||||||
if (isBookSource) {
|
if (isBookSource) {
|
||||||
this.bookSources = data as BookSoure[]
|
this.bookSources = markRaw(data) as BookSoure[]
|
||||||
} else {
|
} else {
|
||||||
this.rssSources = data as RssSource[]
|
this.rssSources = markRaw(data) as RssSource[]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//批量推送
|
//批量推送
|
||||||
|
|||||||
@@ -49,12 +49,27 @@ export const convertSourcesToMap = (sources: Source[]): Map<string, Source> => {
|
|||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const normalizeSource = (source: any) => {
|
||||||
|
for (const key in source) {
|
||||||
|
const value = source[key]
|
||||||
|
if (
|
||||||
|
value === '' ||
|
||||||
|
value === null ||
|
||||||
|
(typeof value === 'string' && !value.trim())
|
||||||
|
) {
|
||||||
|
delete source[key]
|
||||||
|
} else if (value instanceof Object) {
|
||||||
|
normalizeSource(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const emptyBookSource = {
|
export const emptyBookSource = {
|
||||||
ruleSearch: {},
|
ruleSearch: {},
|
||||||
ruleBookInfo: {},
|
ruleBookInfo: {},
|
||||||
ruleToc: {},
|
ruleToc: {},
|
||||||
ruleContent: {},
|
ruleContent: {},
|
||||||
ruleReview: {},
|
// ruleReview: {},
|
||||||
ruleExplore: {},
|
ruleExplore: {},
|
||||||
} as BookSoure
|
} as BookSoure
|
||||||
export const emptyRssSource = {} as RssSource
|
export const emptyRssSource = {} as RssSource
|
||||||
|
|||||||
Reference in New Issue
Block a user