Files
lucia-frontend/src/stores/performance.js

69 lines
1.6 KiB
JavaScript

import { defineStore } from "pinia";
import apiClient from "@/api/client.js";
import apiError from '@/module/apiError.js';
export default defineStore('performanceStore', {
state: () => ({
allPerformanceData: null,
freqChartData: null,
freqChartOptions: null,
freqChartXData: {
minX: null,
maxX: null,
xData: null,
content: null,
}
}),
getters: {
performanceData: state => {
return state.allPerformanceData;
},
},
actions: {
/**
* Get Performance
* @param {string} type 'log' | 'filter',可傳入以上任一。
* @param {*} id 檔案 ID
*/
async getPerformance(type, id) {
let api = '';
switch (type) {
case 'log':
api = `/api/logs/${id}/performance`;
break;
case 'filter':
api = `/api/filters/${id}/performance`;
break;
}
try {
const response = await apiClient.get(api);
this.allPerformanceData = response.data;
} catch(error) {
apiError(error, 'Failed to load the Performance.');
}
},
/**
* In PrimeVue format
* @param {object} freqChartData
*/
setFreqChartData(freqChartData){
this.freqChartData = freqChartData;
},
/**
* In PrimeVue format
* @param {object} freqChartOptions
*/
setFreqChartOptions(freqChartOptions){
this.freqChartOptions = freqChartOptions;
},
/**
*
* @param {object} freqChartXData
*/
setFreqChartXData(freqChartXData) {
this.freqChartXData = freqChartXData;
}
},
})