Convert all store files from JavaScript to TypeScript
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
71
src/stores/compare.ts
Normal file
71
src/stores/compare.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { defineStore } from "pinia";
|
||||
import apiClient from "@/api/client.js";
|
||||
import apiError from '@/module/apiError.js';
|
||||
|
||||
export const useCompareStore = defineStore('compareStore', {
|
||||
state: () => ({
|
||||
allCompareDashboardData: null,
|
||||
}),
|
||||
getters: {
|
||||
compareDashboardData: state => {
|
||||
return state.allCompareDashboardData;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* Get Performance
|
||||
* @param { array } queryParams
|
||||
*/
|
||||
async getCompare(queryParams) {
|
||||
// encodeURIComponent 函數用於將字串中的特殊字符進行編碼,以確保 URL 的正確性。
|
||||
const queryString = JSON.stringify(queryParams);
|
||||
const api = `/api/compare?datasets=${encodeURIComponent(queryString)}`;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
this.allCompareDashboardData = response.data;
|
||||
} catch(error) {
|
||||
apiError(error, 'Failed to load the Compare.');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* fetch discover api, get stats.
|
||||
* @param {string} type 'log' | 'filter',可傳入 'log' 或 'filter'
|
||||
* @param {number} id log or filter ID
|
||||
*/
|
||||
async getStateData(type, id) {
|
||||
let api = '';
|
||||
|
||||
switch (type) {
|
||||
case 'log':
|
||||
api = `/api/logs/${id}/discover`;
|
||||
break;
|
||||
case 'filter':
|
||||
api = `/api/filters/${id}/discover`
|
||||
break;
|
||||
}
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
|
||||
return response.data.stats;
|
||||
} catch(error) {
|
||||
apiError(error, "Failed to load the Compare's States.");
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Get file's name
|
||||
* @param {number} id log or filter ID
|
||||
*/
|
||||
async getFileName(id) {
|
||||
id = Number(id)
|
||||
try {
|
||||
const response = await apiClient.get('/api/files');
|
||||
const file = response.data.find(i => i.id === id);
|
||||
|
||||
if(file) return file.name;
|
||||
} catch(error) {
|
||||
apiError(error, "Failed to load the Compare's file name.");
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user