Skip to content

Commit

Permalink
refactor: 重构功能,并微调
Browse files Browse the repository at this point in the history
  • Loading branch information
simply-none committed Jan 19, 2024
1 parent 9783871 commit b10e42b
Show file tree
Hide file tree
Showing 12 changed files with 13,051 additions and 534 deletions.
12,540 changes: 12,540 additions & 0 deletions Untitled-1.js

Large diffs are not rendered by default.

340 changes: 77 additions & 263 deletions src/hooks/useVoca.js

Large diffs are not rendered by default.

43 changes: 24 additions & 19 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import './assets/main.css'
import "./assets/main.css";

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createApp } from "vue";
import { createPinia } from "pinia";

import App from './App.vue'
import router from './router'
import App from "./App.vue";
import router from "./router";

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import { useErrorStore } from "./stores/error";

const app = createApp(App)
const app = createApp(App);

app.use(createPinia())
app.use(router)
app.use(router);

app.use(ElementPlus)
app.use(ElementPlus);

app.use(createPinia());

app.mount("#app");

// store必须写在pinia的最下面
let { addError } = useErrorStore();

// 全局错误处理
app.config.errorHandler = (err, instance, info) => {
alert(info)
console.table([{err, instance, info}])
}
console.table([{ err, instance, info }]);
addError(err);
};

app.config.globalProperties.$globalErrorHandler = (err, instance, info) => {
alert(info)
console.table([{err, instance, info}])
}

app.mount('#app')
addError(err);
console.table([{ err, instance, info }]);
};
6 changes: 3 additions & 3 deletions src/stores/db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ref, computed, watch, reactive, toRaw, unref } from "vue";
import { defineStore, storeToRefs } from "pinia";
import { db } from "../utils/createDB";
import { db, dexieErrorTag } from "../utils/createDB";
import { useBookStore } from "./books";

export default defineStore("DB", () => {
Expand All @@ -25,7 +25,7 @@ export default defineStore("DB", () => {
let schema = {};
// 这段代码的作用是:新增或修改数据库表时,不删除原有的表
db.tables.forEach(function (table) {
console.log(table, "table");
// console.log(table, "table");
let tableSchema = [table.schema.primKey.src];
table.schema.indexes.forEach((index) => {
tableSchema.push(index.src);
Expand All @@ -41,7 +41,7 @@ export default defineStore("DB", () => {
if (!tables.includes(table)) {
return false;
}
console.log(db[table], 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq')
// console.log(db[table], 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq')

return db[table];
}
Expand Down
39 changes: 39 additions & 0 deletions src/stores/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
ref,
computed,
watch,
reactive,
unref,
toRaw,
toRefs,
watchEffect,
} from "vue";
import { defineStore, storeToRefs } from "pinia";

// 本store,用处在于获取、设置基础信息数据
export const useErrorStore = defineStore("error", () => {
let errorList = ref([]);
let errorListCache = ref([]);

watch(() => errorList.value, (n, o) => {
console.log('监听dexie错误', n, o)
// 此处弹出错误弹框
})

function addError(err) {
console.log('hhhhh')
errorList.value = errorList.value.concat(err);
errorListCache.value = errorList.value.concat(err);
}

function clearError() {
errorList.value = [];
}

return {
errorList,
errorListCache,
addError,
clearError,
};
});
Loading

0 comments on commit b10e42b

Please sign in to comment.