This commit is contained in:
chiayin
2023-10-16 18:38:20 +08:00
parent e751aed3eb
commit 946fabfa93
6 changed files with 68 additions and 204 deletions

View File

@@ -1,17 +1,8 @@
import { defineStore } from "pinia";
import loadingStore from "./loading";
import pinia from '@/stores/main.js';
import {useToast} from 'vue-toast-notification';
import 'vue-toast-notification/dist/theme-sugar.css';
import moment from "moment";
import { Decimal } from 'decimal.js';
import abbreviateNumber from '@/module/abbreviateNumber.js';
const loading = loadingStore(pinia);
const $toast = useToast();
// Delay loading and toast 待模組化
let delay = (s = 0) => new Promise((resolve, reject) => setTimeout(resolve, s));
import apiError from '@/module/apiError.js';
export default defineStore('conformanceStore', {
state: () => ({
@@ -199,12 +190,7 @@ export default defineStore('conformanceStore', {
this.allWaitingTime = response.data.waiting_time;
this.allCycleTime = response.data.cycle_time;
} catch(error) {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to load the Conformance Parameters.',{position: 'bottom'});
apiError(error, 'Failed to load the Conformance Parameters.');
}
},
/**
@@ -218,12 +204,7 @@ export default defineStore('conformanceStore', {
const response = await this.$axios.post(api, data);
this.conformanceTempCheckId = response.data.id;
} catch(error) {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to add the Temporary Check for a log.',{position: 'bottom'});
apiError(error, 'Failed to add the Temporary Check for a log.');
}
},
/**
@@ -237,13 +218,7 @@ export default defineStore('conformanceStore', {
const response = await this.$axios.get(api);
this.allConformanceTempReportData = response.data;
} catch(error) {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to Get the Temporary Log Conformance Report.',{position: 'bottom'});
apiError(error, 'Failed to Get the Temporary Log Conformance Report.');
}
},
/**
@@ -257,12 +232,7 @@ export default defineStore('conformanceStore', {
const response = await this.$axios.get(api);
this.allIssueTraces = response.data.traces;
} catch(error) {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to Get the detail of a temporary log conformance issue.',{position: 'bottom'});
apiError(error, 'Failed to Get the detail of a temporary log conformance issue.');
};
},
/**
@@ -279,14 +249,7 @@ export default defineStore('conformanceStore', {
return response.data.cases;
} catch(error) {
if(error.response.status === 404) this.infinite404 = 404;
else {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to Get the detail of a temporary log conformance issue.',{position: 'bottom'});
};
apiError(error, 'Failed to Get the detail of a temporary log conformance issue.');
};
},
/**
@@ -300,12 +263,7 @@ export default defineStore('conformanceStore', {
const response = await this.$axios.get(api);
this.allLoopTraces = response.data.traces;
} catch(error) {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to Get the detail of a temporary log conformance loop.',{position: 'bottom'});
apiError(error, 'Failed to Get the detail of a temporary log conformance loop.');
};
},
/**
@@ -322,14 +280,7 @@ export default defineStore('conformanceStore', {
return response.data.cases;
} catch(error) {
if(error.response.status === 404) this.infinite404 = 404;
else {
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to Get the detail of a temporary log conformance loop.',{position: 'bottom'});
};
apiError(error, 'Failed to Get the detail of a temporary log conformance loop.');
};
},
},