|
@@ -1,53 +0,0 @@
|
|
|
-import { useMarkStore } from "@/store";
|
|
|
-import { getSetting, updateUISetting } from "@/api/markPage";
|
|
|
-import { debounce, isEmpty } from "lodash-es";
|
|
|
-import { watch } from "vue";
|
|
|
-
|
|
|
-export default function useSetting() {
|
|
|
- const markStore = useMarkStore();
|
|
|
-
|
|
|
- async function updateSetting() {
|
|
|
- const settingRes = await getSetting();
|
|
|
- if (isEmpty(settingRes.data.uiSetting)) {
|
|
|
- settingRes.data.uiSetting = {
|
|
|
- "answer.paper.scale": 1,
|
|
|
- "score.board.collapse": false,
|
|
|
- "normal.mode": "keyboard",
|
|
|
- "score.fontSize.scale": 1,
|
|
|
- "paper.modal": false,
|
|
|
- "answer.modal": false,
|
|
|
- "minimap.modal": false,
|
|
|
- "specialTag.modal": false,
|
|
|
- "shortCut.modal": false,
|
|
|
- };
|
|
|
- } else {
|
|
|
- settingRes.data.uiSetting = JSON.parse(settingRes.data.uiSetting);
|
|
|
- }
|
|
|
- settingRes.data.sheetConfig = settingRes.data.sheetConfig
|
|
|
- ? JSON.parse(settingRes.data.sheetConfig)
|
|
|
- : [];
|
|
|
- settingRes.data.doubleTrack = true;
|
|
|
- markStore.setting = settingRes.data;
|
|
|
- }
|
|
|
-
|
|
|
- const debouncedUpdateUISetting = debounce(() => {
|
|
|
- updateUISetting(
|
|
|
- markStore.setting.mode,
|
|
|
- markStore.setting.uiSetting,
|
|
|
- markStore.setting.questionModel
|
|
|
- ).catch((e) => console.log("保存设置出错", e));
|
|
|
- }, 3000);
|
|
|
-
|
|
|
- watch(
|
|
|
- () => [markStore.setting.uiSetting, markStore.setting.mode],
|
|
|
- () => {
|
|
|
- debouncedUpdateUISetting();
|
|
|
- },
|
|
|
- { deep: true }
|
|
|
- );
|
|
|
-
|
|
|
- return {
|
|
|
- updateSetting,
|
|
|
- debouncedUpdateUISetting,
|
|
|
- };
|
|
|
-}
|