refactor(modules/web): arrange storeToRefs destruct
This commit is contained in:
@@ -23,6 +23,7 @@ const isSelected = (idx) => {
|
|||||||
return idx == props.currentChapterIndex;
|
return idx == props.currentChapterIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// PC端 一个虚拟列表中有两个章节
|
||||||
const catas = computed(() => {
|
const catas = computed(() => {
|
||||||
return props.source?.catas ?? [props.source];
|
return props.source?.catas ?? [props.source];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,23 +27,21 @@ import CatalogItem from "./CatalogItem.vue";
|
|||||||
|
|
||||||
const store = useBookStore();
|
const store = useBookStore();
|
||||||
|
|
||||||
const isNight = computed(() => theme.value == 6);
|
const {
|
||||||
const { catalog, popCataVisible, miniInterface } = storeToRefs(store);
|
catalog,
|
||||||
|
popCataVisible, miniInterface
|
||||||
|
} = storeToRefs(store);
|
||||||
|
|
||||||
const theme = computed(() => {
|
//主题
|
||||||
return store.config.theme;
|
const isNight = computed(() => store.theme);
|
||||||
});
|
const theme = computed(() => store.theme);
|
||||||
const popupTheme = computed(() => {
|
const popupTheme = computed(() => {
|
||||||
return {
|
return {
|
||||||
background: settings.themes[theme.value].popup,
|
background: settings.themes[theme.value].popup,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentChapterIndex = computed({
|
//虚拟列表 数据源
|
||||||
get: () => store.readingBook.index,
|
|
||||||
set: (value) => (store.readingBook.index = value),
|
|
||||||
});
|
|
||||||
|
|
||||||
const virtualListdata = computed(() => {
|
const virtualListdata = computed(() => {
|
||||||
let catalogValue = catalog.value;
|
let catalogValue = catalog.value;
|
||||||
if (miniInterface.value) return catalogValue;
|
if (miniInterface.value) return catalogValue;
|
||||||
@@ -63,6 +61,25 @@ const virtualListdata = computed(() => {
|
|||||||
return virtualListDataSource;
|
return virtualListDataSource;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//打开目录 计算当前章节对应的虚拟列表位置
|
||||||
|
const virtualListRef = ref();
|
||||||
|
const currentChapterIndex = computed({
|
||||||
|
get: () => store.readingBook.index,
|
||||||
|
set: (value) => (store.readingBook.index = value),
|
||||||
|
});
|
||||||
|
const virtualListIndex = computed(() => {
|
||||||
|
let index = currentChapterIndex.value;
|
||||||
|
if (miniInterface.value) return index;
|
||||||
|
// pc端 virtualListIitem有2个章节
|
||||||
|
return Math.floor(index / 2);
|
||||||
|
});
|
||||||
|
onUpdated(() => {
|
||||||
|
// dom更新触发ResizeObserver,更新虚拟列表内部的sizes Map
|
||||||
|
if (!popCataVisible.value) return;
|
||||||
|
virtualListRef.value.scrollToIndex(virtualListIndex.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 点击加载对应章节内容
|
||||||
const emit = defineEmits(["getContent"]);
|
const emit = defineEmits(["getContent"]);
|
||||||
const gotoChapter = (note) => {
|
const gotoChapter = (note) => {
|
||||||
const chapterIndex = catalog.value.indexOf(note);
|
const chapterIndex = catalog.value.indexOf(note);
|
||||||
@@ -73,18 +90,6 @@ const gotoChapter = (note) => {
|
|||||||
emit("getContent", chapterIndex);
|
emit("getContent", chapterIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
const virtualListRef = ref();
|
|
||||||
const virtualListIndex = computed(() => {
|
|
||||||
let index = currentChapterIndex.value;
|
|
||||||
if (miniInterface.value) return index;
|
|
||||||
return Math.floor(index / 2);
|
|
||||||
});
|
|
||||||
|
|
||||||
onUpdated(() => {
|
|
||||||
// dom更新触发ResizeObserver,更新虚拟列表内部的sizes Map
|
|
||||||
if (!popCataVisible.value) return;
|
|
||||||
virtualListRef.value.scrollToIndex(virtualListIndex.value);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ watch(
|
|||||||
|
|
||||||
//主题颜色
|
//主题颜色
|
||||||
const theme = computed(() => store.theme);
|
const theme = computed(() => store.theme);
|
||||||
const isNight = computed(() => store.isDark);
|
const isNight = computed(() => store.isNight);
|
||||||
const moonIcon = computed(() => theme.value == 6 ? "" : "");
|
const moonIcon = computed(() => theme.value == 6 ? "" : "");
|
||||||
const themeColors = [
|
const themeColors = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,14 +18,17 @@ import { Edit } from "@element-plus/icons-vue";
|
|||||||
import { getSourceUniqueKey } from "@/utils/souce";
|
import { getSourceUniqueKey } from "@/utils/souce";
|
||||||
|
|
||||||
const props = defineProps(["source"]);
|
const props = defineProps(["source"]);
|
||||||
|
|
||||||
const store = useSourceStore();
|
const store = useSourceStore();
|
||||||
const { savedSourcesMap, currentSourceUrl } = storeToRefs(store);
|
|
||||||
|
const currentSourceUrl = computed(() => store.currentSourceUrl);
|
||||||
const sourceUrl = computed(() => getSourceUniqueKey(props.source));
|
const sourceUrl = computed(() => getSourceUniqueKey(props.source));
|
||||||
|
|
||||||
const handleSourceClick = (source) => {
|
const handleSourceClick = (source) => {
|
||||||
store.changeCurrentSource(source);
|
store.changeCurrentSource(source);
|
||||||
};
|
};
|
||||||
const isSaveError = computed(() => {
|
const isSaveError = computed(() => {
|
||||||
const map = savedSourcesMap.value;
|
const map = store.savedSourcesMap;
|
||||||
if (map.size == 0) return false;
|
if (map.size == 0) return false;
|
||||||
return !map.has(sourceUrl.value);
|
return !map.has(sourceUrl.value);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ 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 } = storeToRefs(store);
|
const sources = computed(() => store.sources);
|
||||||
|
|
||||||
// 筛选源
|
// 筛选源
|
||||||
/** @type Ref<import('@/source').Source[]> */
|
/** @type Ref<import('@/source').Source[]> */
|
||||||
@@ -74,7 +74,7 @@ const sourceSelect = computed(() => {
|
|||||||
if (urls.length == 0) return [];
|
if (urls.length == 0) return [];
|
||||||
const sourcesFilteredMap =
|
const sourcesFilteredMap =
|
||||||
searchKey.value == ""
|
searchKey.value == ""
|
||||||
? sourcesMap.value
|
? store.sourcesMap
|
||||||
: convertSourcesToMap(sourcesFiltered.value);
|
: convertSourcesToMap(sourcesFiltered.value);
|
||||||
return urls.reduce((sources, sourceUrl) => {
|
return urls.reduce((sources, sourceUrl) => {
|
||||||
const source = sourcesFilteredMap.get(sourceUrl);
|
const source = sourcesFilteredMap.get(sourceUrl);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
const store = useSourceStore();
|
const store = useSourceStore();
|
||||||
defineProps(["config"]);
|
defineProps(["config"]);
|
||||||
const { currentSource } = storeToRefs(store);
|
const currentSource = store.currentSource;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { useSourceStore } from "@/store";
|
|||||||
|
|
||||||
const store = useSourceStore();
|
const store = useSourceStore();
|
||||||
|
|
||||||
const { currentTab: current_tab } = storeToRefs(store);
|
const current_tab = store.currentTab;
|
||||||
|
|
||||||
const tabData = ref([
|
const tabData = ref([
|
||||||
["editTab", "编辑源"],
|
["editTab", "编辑源"],
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export const useBookStore = defineStore("book", {
|
|||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
connectStatus: "正在连接后端服务器……",
|
connectStatus: "正在连接后端服务器……",
|
||||||
|
/**@type {"primary" | "success" |"danger"} */
|
||||||
connectType: "primary",
|
connectType: "primary",
|
||||||
newConnect: true,
|
newConnect: true,
|
||||||
/**@type {Array<{respondTime:number}>} */
|
/**@type {Array<{respondTime:number}>} */
|
||||||
@@ -53,7 +54,7 @@ export const useBookStore = defineStore("book", {
|
|||||||
theme: (state) => {
|
theme: (state) => {
|
||||||
return state.config.theme
|
return state.config.theme
|
||||||
},
|
},
|
||||||
isDark: (state) => state.config.theme == 6,
|
isNight: (state) => state.config.theme == 6,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setConnectStatus(connectStatus) {
|
setConnectStatus(connectStatus) {
|
||||||
|
|||||||
@@ -132,21 +132,21 @@ const {
|
|||||||
readSettingsVisible,
|
readSettingsVisible,
|
||||||
miniInterface,
|
miniInterface,
|
||||||
showContent,
|
showContent,
|
||||||
config,
|
|
||||||
readingBook,
|
|
||||||
bookProgress,
|
bookProgress,
|
||||||
|
theme,
|
||||||
|
isNight,
|
||||||
} = storeToRefs(store);
|
} = storeToRefs(store);
|
||||||
|
|
||||||
const chapterPos = computed({
|
const chapterPos = computed({
|
||||||
get: () => readingBook.value.chapterPos,
|
get: () => store.readingBook.chapterPos,
|
||||||
set: (value) => (readingBook.value.chapterPos = value),
|
set: (value) => (store.readingBook.chapterPos = value),
|
||||||
});
|
});
|
||||||
const chapterIndex = computed({
|
const chapterIndex = computed({
|
||||||
get: () => readingBook.value.index,
|
get: () => store.readingBook.index,
|
||||||
set: (value) => (readingBook.value.index = value),
|
set: (value) => (store.readingBook.index = value),
|
||||||
});
|
});
|
||||||
|
|
||||||
const theme = computed(() => config.value.theme);
|
const infiniteLoading = computed(() => store.config.infiniteLoading);
|
||||||
const infiniteLoading = computed(() => config.value.infiniteLoading);
|
|
||||||
|
|
||||||
// 字体
|
// 字体
|
||||||
const fontFamily = computed(() => {
|
const fontFamily = computed(() => {
|
||||||
@@ -208,7 +208,6 @@ const rightBarTheme = computed(() => {
|
|||||||
display: miniInterface.value && !showToolBar.value ? "none" : "block",
|
display: miniInterface.value && !showToolBar.value ? "none" : "block",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const isNight = computed(() => theme.value == 6);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pc移动端判断 最大阅读宽度修正
|
* pc移动端判断 最大阅读宽度修正
|
||||||
|
|||||||
@@ -84,9 +84,7 @@ import { Search } from "@element-plus/icons-vue";
|
|||||||
import API from "@api";
|
import API from "@api";
|
||||||
|
|
||||||
const store = useBookStore();
|
const store = useBookStore();
|
||||||
const { connectStatus, connectType, newConnect, shelf, isDark } = storeToRefs(store);
|
const isNight = computed(() => store.isNight);
|
||||||
|
|
||||||
const isNight = computed(() => isDark.value);
|
|
||||||
|
|
||||||
const readingRecent = ref({
|
const readingRecent = ref({
|
||||||
name: "尚无阅读记录",
|
name: "尚无阅读记录",
|
||||||
@@ -101,8 +99,9 @@ const { showLoading, closeLoading, loadingWrapper, isLoading } = useLoading(
|
|||||||
"正在获取书籍信息"
|
"正在获取书籍信息"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 书架书籍和在线书籍搜索
|
||||||
const books = shallowRef([]);
|
const books = shallowRef([]);
|
||||||
|
const shelf = computed(() => store.shelf);
|
||||||
const search = ref("");
|
const search = ref("");
|
||||||
const isSearching = ref(false);
|
const isSearching = ref(false);
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
@@ -119,7 +118,7 @@ watchEffect(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
//搜索在线书籍
|
||||||
const searchBook = () => {
|
const searchBook = () => {
|
||||||
if (search.value == "") return;
|
if (search.value == "") return;
|
||||||
books.value = [];
|
books.value = [];
|
||||||
@@ -150,6 +149,10 @@ const searchBook = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//连接状态
|
||||||
|
const connectStatus = computed(() => store.connectStatus);
|
||||||
|
const connectType = computed(() => store.connectType);
|
||||||
|
const newConnect = computed(() => store.newConnect);
|
||||||
const setIP = () => {
|
const setIP = () => {
|
||||||
ElMessageBox.prompt(
|
ElMessageBox.prompt(
|
||||||
"请输入 IP 和端口 ( 如:127.0.0.1:9527 或者通过内网穿透的地址)",
|
"请输入 IP 和端口 ( 如:127.0.0.1:9527 或者通过内网穿透的地址)",
|
||||||
|
|||||||
Reference in New Issue
Block a user