Delay loading and toast 待æDone

This commit is contained in:
chiayin
2023-02-16 15:00:16 +08:00
parent 819199864d
commit a20c22dcae
7 changed files with 89 additions and 25 deletions

View File

@@ -3,8 +3,13 @@ import loadingStore from './loading.js';
import pinia from '@/stores/main.js'
import axios from "axios";
import moment from 'moment';
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('filesStore', {
state: () => ({
@@ -67,8 +72,16 @@ export default defineStore('filesStore', {
})
if(this.httpStatus < 300) loading.isLoading = false;
} catch(error) {
loading.isLoading = true;
this.httpStatus = error.request.status;
delay().then(() =>{
loading.isLoading = true;
return delay(1000);
}).then(()=>{
loading.isLoading = false;
return delay(500);
}).then(() => {
$toast.default('Import Filter files error.');
})
};
},
/**
@@ -88,8 +101,16 @@ export default defineStore('filesStore', {
});
if(this.httpStatus < 300) loading.isLoading = false;
} catch(error) {
loading.isLoading = true;
this.httpStatus = error.request.status;
delay().then(() =>{
loading.isLoading = true;
return delay(1000);
}).then(()=>{
loading.isLoading = false;
return delay(500);
}).then(() => {
$toast.default('Import Filter files error.');
})
};
},
}

View File

@@ -1,3 +1,5 @@
import { createPinia } from 'pinia';
const pinia = createPinia();
export default pinia;