Skip to content

Commit

Permalink
feat: 增加错误复制功能
Browse files Browse the repository at this point in the history
  • Loading branch information
simply-none committed Jan 20, 2024
1 parent 71c5c5f commit 5ca9119
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/components/errorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ console.log(isPC(), 'isPCccc')
let useError = useErrorStore()
let { errorList } = storeToRefs(useError)
let { clearError } = useError
let { clearError, copyError } = useError
let visible = computed(() => !!errorList.value)
Expand All @@ -57,6 +57,7 @@ watch(errorList, (n, o) => {
})
function copyErrorInfo() {
copyError()
console.log('复制成功')
}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useWordItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function useWordItem() {

watch(isMorethanTodayPlan, (n, o) => {
if (n) {
console.log(n, o, 'hhhhh')
setNotify(
"今日单词计划已完成,已备份数据到本地,将开启今日学习复习模式!",
"success",
Expand Down
20 changes: 16 additions & 4 deletions src/stores/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from "vue";
import { defineStore, storeToRefs } from "pinia";

import { writeTextToClipboard } from '../utils/clipboard'

// 本store,用处在于获取、设置基础信息数据
export const useErrorStore = defineStore("error", () => {
let errorList = ref();
Expand All @@ -21,23 +23,32 @@ export const useErrorStore = defineStore("error", () => {
// 此处弹出错误弹框
})

function addError(err) {
async function addError(err) {
// 防止卡死,限制数量
if (errorList.value && errorList.value.length >= 50) {
return false
}
if (errLastTime.value && Math.abs(errLastTime.value - Date.now()) < 3000) {
return false
}
err = {
msg: err.message,
stack: err.stack.toString()

let { message } = err
err = message ? {
msg: err.message,
stack: err.stack?.toString()
} : {
msg: err.reason?.message,
stack: err.reason?.stack?.toString()
}

errorList.value = (errorList.value || []).concat(err);
errorListCache.value = errorListCache.value.concat(err);
}

function copyError () {
writeTextToClipboard(errorList.value)
}

function clearError() {
errorList.value = null;
console.log(errorList.value)
Expand All @@ -49,6 +60,7 @@ export const useErrorStore = defineStore("error", () => {
errorList,
errorListCache,
addError,
copyError,
clearError,
};
});
11 changes: 8 additions & 3 deletions src/stores/words.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export const useWordStore = defineStore("word", () => {
let notStudyWords = ref();

let isMorethanTodayPlan = computed(() => {
console.log("ismore");
console.log("ismore", todayWords.value?.length , basicData.value?.studyCount);
if (!basicData.value?.studyCount) {
return false
}

return todayWords.value?.length >= basicData.value?.studyCount;
});

Expand Down Expand Up @@ -76,8 +80,6 @@ export const useWordStore = defineStore("word", () => {
}
);

console.log(stopInitWatch, "111千万");

watch(willStudyWords, (n, o) => {
if (n) {
console.log(willStudyWords.value?.length, 'hhhhhhhhh')
Expand Down Expand Up @@ -239,6 +241,9 @@ export const useWordStore = defineStore("word", () => {
// 获取获取database table对象 数据集合 数组
function getDataFromDB(tableRef, dataRef) {
let table = unref(tableRef);
if (!table) {
return false
}
table
.orderBy("n")
.keys()
Expand Down
4 changes: 2 additions & 2 deletions utils/clipboard.js → src/utils/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 写入剪切板
function writeTextToClipboard (val) {
export function writeTextToClipboard(val) {
if (navigator.clipboard) {
navigator.clipboard.writeText(JSON.stringify(val));
}
}
}

0 comments on commit 5ca9119

Please sign in to comment.