Fix module-level store init in files.js, apiError.js, cytoscapeMap.js and add files store tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 07:59:30 +08:00
parent 5be29ddd51
commit 9eb8881c57
4 changed files with 207 additions and 9 deletions

View File

@@ -1,13 +1,10 @@
import router from "@/router/index.ts";
import loadingStore from '@/stores/loading.js';
import pinia from '@/stores/main.ts';
import {useToast} from 'vue-toast-notification';
import 'vue-toast-notification/dist/theme-sugar.css';
import axios from "axios";
import { deleteCookie } from "@/utils/cookieUtil.js";
const loading = loadingStore(pinia);
const $toast = useToast();
// Delay loading and toast
const delay = (s = 0) => new Promise((resolve, reject) => setTimeout(resolve, s));
@@ -23,6 +20,8 @@ export default async function apiError(error, toastMessage) {
deleteCookie("luciaToken");
return router.push('/login');
}
const loading = loadingStore();
const $toast = useToast();
await delay();
loading.isLoading = true;
await delay(1000);

View File

@@ -10,7 +10,6 @@ import { getTimeLabel } from '@/module/timeLabel.js'; // 時間格式轉換器
import CytoscapeStore from '@/stores/cytoscapeStore';
import { SAVE_KEY_NAME } from '@/constants/constants.js';
const mapPathStore = MapPathStore();
const composeFreqTypeText = (baseText, dataLayerOption, optionValue) => { //sonar-qube
let text = baseText;
const textInt = dataLayerOption === 'rel_freq' ? baseText + optionValue * 100 + "%" : baseText + optionValue;
@@ -233,12 +232,12 @@ export default function cytoscapeMap(mapData, dataLayerType, dataLayerOption, cu
// 按下節點光暈效果與鄰邊光暈效果
cy.on('tap, mousedown', 'node', function (event) {
mapPathStore.onNodeClickHighlightEdges(event.target);
MapPathStore().onNodeClickHighlightEdges(event.target);
});
// 按下線段光暈效果與兩端點光暈效果
cy.on('tap, mousedown', 'edge', function (event) {
mapPathStore.onEdgeClickHighlightNodes(event.target);
MapPathStore().onEdgeClickHighlightNodes(event.target);
});
// creat tippy.js

View File

@@ -4,11 +4,8 @@ import moment from 'moment';
import apiError from '@/module/apiError.js';
import Swal from 'sweetalert2';
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess, deleteSuccess } from '@/module/alertModal.js';
import pinia from '@/stores/main.ts';
import loadingStore from '@/stores/loading.js';
const loading = loadingStore(pinia);
export default defineStore('filesStore', {
state: () => ({
allEventFiles: [
@@ -261,6 +258,7 @@ export default defineStore('filesStore', {
if(id == null || isNaN(id)) {
return $toast.default('Delete File API Error.', {position: 'bottom'});
};
const loading = loadingStore();
loading.isLoading = true;
switch (type) {
case 'log':
@@ -294,6 +292,7 @@ export default defineStore('filesStore', {
async deletionRecord(id) {
let api = '';
const loading = loadingStore();
loading.isLoading = true;
api = `/api/deletion/${id}`;
try {