mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
perf(web): 使用map查找推送失败的源
This commit is contained in:
parent
d65d9429d7
commit
ee70523026
@ -4,7 +4,7 @@
|
|||||||
border
|
border
|
||||||
:label="sourceUrl"
|
:label="sourceUrl"
|
||||||
:class="{
|
:class="{
|
||||||
error: errorPushSources.includes(source),
|
error: isSaveError,
|
||||||
edit: sourceUrl == currentSourceUrl,
|
edit: sourceUrl == currentSourceUrl,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
@ -17,12 +17,16 @@
|
|||||||
import { Edit } from "@element-plus/icons-vue";
|
import { Edit } from "@element-plus/icons-vue";
|
||||||
|
|
||||||
const props = defineProps(["source"]);
|
const props = defineProps(["source"]);
|
||||||
const sourceUrl = props.source.bookSourceUrl || props.source.sourceUrl;
|
|
||||||
const store = useSourceStore();
|
const store = useSourceStore();
|
||||||
const { errorPushSources, currentSourceUrl } = storeToRefs(store);
|
const { savedSourcesMap, currentSourceUrl, sourceUrlKey } = storeToRefs(store);
|
||||||
|
const sourceUrl = computed(() => props.source[sourceUrlKey.value]);
|
||||||
const handleSourceClick = (source) => {
|
const handleSourceClick = (source) => {
|
||||||
store.changeCurrentSource(source);
|
store.changeCurrentSource(source);
|
||||||
};
|
};
|
||||||
|
const isSaveError = computed(() => {
|
||||||
|
if (savedSourcesMap.value.size == 0) return false;
|
||||||
|
return !savedSourcesMap.value.has(sourceUrl.value);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
:deep(.el-checkbox__label) {
|
:deep(.el-checkbox__label) {
|
||||||
|
@ -50,14 +50,15 @@ import SourceItem from "./SourceItem.vue";
|
|||||||
const store = useSourceStore();
|
const store = useSourceStore();
|
||||||
const sourceUrlSelect = ref([]);
|
const sourceUrlSelect = ref([]);
|
||||||
const searchKey = ref("");
|
const searchKey = ref("");
|
||||||
const { sources, sourcesMap, sourceUrlKey } = storeToRefs(store);
|
const { sources, sourcesMap } = storeToRefs(store);
|
||||||
const isBookSource = computed(() => {
|
const isBookSource = computed(() => {
|
||||||
return /bookSource/.test(window.location.href);
|
return /bookSource/.test(window.location.href);
|
||||||
});
|
});
|
||||||
const sourceSelect = computed(() => {
|
const sourceSelect = computed(() => {
|
||||||
if (sourceUrlSelect.value.length == 0) return [];
|
if (sourceUrlSelect.value.length == 0) return [];
|
||||||
let searchKey = sourceUrlKey.value;
|
return sourceUrlSelect.value.map(
|
||||||
return sourceUrlSelect.value.map(sourceUrl => sourcesMap.value.get(sourceUrl));
|
(sourceUrl) => sourcesMap.value.get(sourceUrl) ?? {}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
const deleteSelectSources = () => {
|
const deleteSelectSources = () => {
|
||||||
API.deleteSource(sourceSelect.value).then(({ data }) => {
|
API.deleteSource(sourceSelect.value).then(({ data }) => {
|
||||||
|
@ -11,7 +11,8 @@ export const useSourceStore = defineStore("source", {
|
|||||||
bookSources: [], // 临时存放所有书源,
|
bookSources: [], // 临时存放所有书源,
|
||||||
/** @type {import("@/source").RssSource[]} */
|
/** @type {import("@/source").RssSource[]} */
|
||||||
rssSources: [], // 临时存放所有订阅源
|
rssSources: [], // 临时存放所有订阅源
|
||||||
errorPushSources: [], // 保存到阅读app出错的源
|
/** @type {import("@/source").Source[]} */
|
||||||
|
savedSources: [], // 批量保存到阅读app成功的源
|
||||||
/** @type {import("@/source").Source} */
|
/** @type {import("@/source").Source} */
|
||||||
currentSource: emptySource, // 当前编辑的源
|
currentSource: emptySource, // 当前编辑的源
|
||||||
currentTab: localStorage.getItem("tabName") || "editTab",
|
currentTab: localStorage.getItem("tabName") || "editTab",
|
||||||
@ -21,11 +22,16 @@ export const useSourceStore = defineStore("source", {
|
|||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
sources: (state) => (isBookSource ? state.bookSources : state.rssSources),
|
sources: (state) => (isBookSource ? state.bookSources : state.rssSources),
|
||||||
sourceUrlKey: (state) => isBookSource ? "bookSourceUrl" : "sourceUrl",
|
sourceUrlKey: () => isBookSource ? "bookSourceUrl" : "sourceUrl",
|
||||||
sourcesMap: (state) => {
|
sourcesMap: (state) => {
|
||||||
let map = new Map();
|
let map = new Map();
|
||||||
state.sources.forEach(source => map.set(source[state.sourceUrlKey], source));
|
state.sources.forEach(source => map.set(source[state.sourceUrlKey], source));
|
||||||
return map;
|
return map;
|
||||||
|
},
|
||||||
|
savedSourcesMap: (state) => {
|
||||||
|
let map = new Map();
|
||||||
|
state.savedSources.forEach(source => map.set(source[state.sourceUrlKey], source));
|
||||||
|
return map;
|
||||||
},
|
},
|
||||||
currentSourceUrl: (state) =>
|
currentSourceUrl: (state) =>
|
||||||
isBookSource
|
isBookSource
|
||||||
@ -53,6 +59,10 @@ export const useSourceStore = defineStore("source", {
|
|||||||
this.rssSources = data;
|
this.rssSources = data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
//批量推送
|
||||||
|
setPushReturnSources(returnSoures) {
|
||||||
|
this.savedSources = returnSoures;
|
||||||
|
},
|
||||||
//删除源
|
//删除源
|
||||||
deleteSources(data) {
|
deleteSources(data) {
|
||||||
let sources = isBookSource ? this.bookSources : this.rssSources;
|
let sources = isBookSource ? this.bookSources : this.rssSources;
|
||||||
@ -71,21 +81,6 @@ export const useSourceStore = defineStore("source", {
|
|||||||
changeCurrentSource(source) {
|
changeCurrentSource(source) {
|
||||||
this.currentSource = JSON.parse(JSON.stringify((source)));
|
this.currentSource = JSON.parse(JSON.stringify((source)));
|
||||||
},
|
},
|
||||||
async setPushReturnSources(returnSoures) {
|
|
||||||
if (isBookSource) {
|
|
||||||
// @ts-ignore
|
|
||||||
this.errorPushSources = this.sources.filter((source) =>
|
|
||||||
returnSoures.every(
|
|
||||||
(item) => item.bookSourceUrl !== source.bookSourceUrl
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// @ts-ignore
|
|
||||||
this.errorPushSources = this.sources.filter((source) =>
|
|
||||||
returnSoures.every((item) => item.sourceUrl !== source.sourceUrl)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// update editTab tabName and editTab info
|
// update editTab tabName and editTab info
|
||||||
changeTabName(tabName) {
|
changeTabName(tabName) {
|
||||||
this.currentTab = tabName;
|
this.currentTab = tabName;
|
||||||
@ -133,6 +128,7 @@ export const useSourceStore = defineStore("source", {
|
|||||||
clearAllSource() {
|
clearAllSource() {
|
||||||
this.bookSources = [];
|
this.bookSources = [];
|
||||||
this.rssSources = [];
|
this.rssSources = [];
|
||||||
|
this.savedSources = [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user