Skip to content

Commit

Permalink
fix: 首次加载问题部分解决
Browse files Browse the repository at this point in the history
  • Loading branch information
simply-none committed Jan 7, 2024
1 parent 8a3877b commit 94bdbdd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/hooks/useVoca.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function isRequiredField(obj) {
}
const required = ["currentBook", "currentRange", "studyMode", "studyCount"];
return required.every((field) => {
console.log(obj[field], '真')
return obj[field];
});
}
Expand Down Expand Up @@ -61,7 +62,7 @@ export function useVoca() {

let isMorethanTodayPlan = ref(false)

let { basicData } = storeToRefs(useBook);
let { basicData, basicDataOrigin } = storeToRefs(useBook);

const drawer = ref(false);

Expand All @@ -71,6 +72,13 @@ export function useVoca() {

let isWordNotInDict = ref(false)

watchEffect(() => {
if (JSON.stringify(basicData.value) === JSON.stringify(basicDataOrigin.value)) {
console.log('初始化')
initDataInFirstLoad()
}
})

watch(
[() => basicData.value.currentBook, () => basicData.value.currentRange, () => basicData.value.studyMode, () => basicData.value.studyCount],
() => {
Expand Down Expand Up @@ -140,6 +148,7 @@ export function useVoca() {
async function initDataInFirstLoad() {
// fullscreenLoading.value = true;
let isRequired = isRequiredField(basicData);
console.log(isRequired, 'sfs')

if (!isRequired) {
setNotify("请完成基础设置后再试");
Expand Down
10 changes: 10 additions & 0 deletions src/stores/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export const useBookStore = defineStore("book", () => {
showVocabularyItem: [],
});

let basicDataOrigin = reactive({
currentBook: "",
currentRange: "",
studyMode: "",
studyCount: 0,
showMode: '',
showVocabularyItem: [],
});

let useDB = useDBStore();
let { schema, dbChanged } = storeToRefs(useDB);
let { getTable } = useDB;
Expand Down Expand Up @@ -65,6 +74,7 @@ export const useBookStore = defineStore("book", () => {

return {
basicData,
basicDataOrigin,
updateBasicInfo,
};
});
2 changes: 1 addition & 1 deletion src/views/wordMainPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let {
let router = useRouter()
if (router.currentRoute.value.query && router.currentRoute.value.query.reload) {
if (router && router.currentRoute.value.query && router.currentRoute.value.query.reload) {
location.href = './'
}
Expand Down

0 comments on commit 94bdbdd

Please sign in to comment.