/
itp_practice
/
itp_frontend
Обзор
Документация
Войти
/
itp_practice
/
itp_frontend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
src/stores/processManager.js
194 строки
6 KB
vivanenko
taps manager
27 май 2025, 23:38
27 май 2025, 23:38
c9f977f
Код
Авторство
О чём код?
import { defineStore } from 'pinia'; import axios from 'axios'; import { getApiUrl } from '@/config'; export const useProcessManagerStore = defineStore('processManager', { state: () => ({ tapProcesses: [], allProcesses: [], loading: false, error: null, currentTapLogs: null, loadingLogs: false }), actions: { async fetchTapProcesses() { this.loading = true; this.error = null; try { const token = localStorage.getItem('token'); const response = await axios.get(`${getApiUrl()}/admin/process-manager/taps`, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } }); this.tapProcesses = response.data.data; } catch (error) { this.error = error.response?.data?.message || 'Failed to fetch tap processes'; console.error('Error fetching tap processes:', error); } finally { this.loading = false; } }, async fetchAllProcesses() { this.loading = true; this.error = null; try { const token = localStorage.getItem('token'); const response = await axios.get(`${getApiUrl()}/admin/process-manager/processes`, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } }); this.allProcesses = response.data.data; } catch (error) { this.error = error.response?.data?.message || 'Failed to fetch processes'; console.error('Error fetching processes:', error); } finally { this.loading = false; } }, async startTapProcess(tapId) { try { const token = localStorage.getItem('token'); const response = await axios.post(`${getApiUrl()}/admin/process-manager/taps/start`, { tap_id: tapId }, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json', 'Content-Type': 'application/json' } } ); if (response.data.success) { await this.fetchTapProcesses(); return { success: true, message: response.data.message }; } return { success: false, message: response.data.message }; } catch (error) { console.error('Error starting tap process:', error); return { success: false, message: error.response?.data?.message || 'Failed to start tap process' }; } }, async stopTapProcess(tapId) { try { const token = localStorage.getItem('token'); const response = await axios.post(`${getApiUrl()}/admin/process-manager/taps/stop`, { tap_id: tapId }, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json', 'Content-Type': 'application/json' } } ); if (response.data.success) { await this.fetchTapProcesses(); return { success: true, message: response.data.message }; } return { success: false, message: response.data.message }; } catch (error) { console.error('Error stopping tap process:', error); return { success: false, message: error.response?.data?.message || 'Failed to stop tap process' }; } }, async restartTapProcess(tapId) { try { const token = localStorage.getItem('token'); const response = await axios.post(`${getApiUrl()}/admin/process-manager/taps/restart`, { tap_id: tapId }, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json', 'Content-Type': 'application/json' } } ); if (response.data.success) { await this.fetchTapProcesses(); return { success: true, message: response.data.message }; } return { success: false, message: response.data.message }; } catch (error) { console.error('Error restarting tap process:', error); return { success: false, message: error.response?.data?.message || 'Failed to restart tap process' }; } }, async fetchTapLogs(tapId, offset = 0, length = 1000) { this.loadingLogs = true; try { const token = localStorage.getItem('token'); const response = await axios.get( `${getApiUrl()}/admin/process-manager/taps/${tapId}/logs`, { params: { offset, length }, headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } } ); this.currentTapLogs = response.data.data; return response.data.data; } catch (error) { console.error('Error fetching tap logs:', error); return null; } finally { this.loadingLogs = false; } }, async reloadConfig() { try { const token = localStorage.getItem('token'); const response = await axios.post(`${getApiUrl()}/admin/process-manager/reload`, {}, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } }); if (response.data.success) { await this.fetchAllProcesses(); return { success: true, message: response.data.message }; } return { success: false, message: response.data.message }; } catch (error) { console.error('Error reloading config:', error); return { success: false, message: error.response?.data?.message || 'Failed to reload configuration' }; } } } });