Discover: fix fetch api on once. And switch Navbar done.
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
import { defineStore } from "pinia";
|
||||
import loadingStore from './loading.js';
|
||||
import pinia from '@/stores/main.js'
|
||||
import {useToast} from 'vue-toast-notification';
|
||||
import 'vue-toast-notification/dist/theme-sugar.css';
|
||||
|
||||
const loading = loadingStore(pinia);
|
||||
const $toast = useToast();
|
||||
// Delay loading and toast 待模組化
|
||||
let delay = s => new Promise((resolve, reject) => setTimeout(resolve, s));
|
||||
|
||||
export default defineStore('allMapDataStore', {
|
||||
state: () => ({
|
||||
logId: null,
|
||||
processMap: {},
|
||||
bpmn: {},
|
||||
allProcessMap: {},
|
||||
allBpmn: {},
|
||||
httpStatus: 200,
|
||||
}),
|
||||
getters: {
|
||||
processMap: state => {
|
||||
return state.allProcessMap;
|
||||
},
|
||||
bpmn: state => {
|
||||
return state.allBpmn;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
@@ -18,9 +34,21 @@ export default defineStore('allMapDataStore', {
|
||||
|
||||
try {
|
||||
const response = await this.$axios.get(api);
|
||||
this.processMap = response.data.process_map;
|
||||
this.bpmn = response.data.bpmn;
|
||||
this.allProcessMap = response.data.process_map;
|
||||
this.allBpmn = response.data.bpmn;
|
||||
|
||||
if(this.httpStatus < 300) loading.isLoading = false;
|
||||
} catch(error) {
|
||||
this.httpStatus = error.request.status;
|
||||
delay().then(() =>{
|
||||
loading.isLoading = true;
|
||||
return delay(1000);
|
||||
}).then(()=>{
|
||||
loading.isLoading = false;
|
||||
return delay(500);
|
||||
}).then(() => {
|
||||
$toast.default('Failed to load the discover.');
|
||||
})
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user