frp/web/src/store/modules/server.js

33 lines
580 B
JavaScript
Raw Normal View History

2020-12-04 01:08:40 +08:00
import fetch from '@/utils/fetch'
2020-12-09 22:11:22 +08:00
import { Message } from 'element-ui'
2020-12-04 01:08:40 +08:00
const state = {
serverInfo: null
}
const mutations = {
SET_SERVER_INFO(state, serverInfo) {
state.serverInfo = serverInfo
}
}
const actions = {
async fetchServerInfo({ commit }) {
2020-12-04 01:19:56 +08:00
const res = await fetch('serverinfo')
if (!res.ok) {
2020-12-09 22:11:22 +08:00
Message.warning('Get server info from frps failed!')
2020-12-04 01:19:56 +08:00
commit('SET_SERVER_INFO', null)
2020-12-09 22:11:22 +08:00
return
2020-12-04 01:19:56 +08:00
}
commit('SET_SERVER_INFO', (await res.json()) || null)
2020-12-04 01:08:40 +08:00
}
}
export default {
namespaced: true,
state,
mutations,
actions
}