edit fetch

This commit is contained in:
hubery.wang 2020-12-04 01:19:56 +08:00
parent 54673e972b
commit 519b62d43f
9 changed files with 48 additions and 20 deletions

View File

@ -16,8 +16,12 @@ export default {
}, },
methods: { methods: {
async initData() { async initData() {
const json = await this.$fetch(`traffic/${this.proxyName}`) const res = await this.$fetch(`traffic/${this.proxyName}`)
if (!json) return if (!res.ok) {
this.$message.warning('Get traffic info from frps failed!')
return
}
const json = await res.json()
DrawProxyTrafficChart(this.proxyName, json.traffic_in, json.traffic_out) DrawProxyTrafficChart(this.proxyName, json.traffic_in, json.traffic_out)
} }

View File

@ -15,9 +15,13 @@ const mutations = {
const actions = { const actions = {
async fetchServerInfo({ commit }) { async fetchServerInfo({ commit }) {
const json = await fetch('serverinfo') const res = await fetch('serverinfo')
commit('SET_SERVER_INFO', json || null) if (!res.ok) {
return json this.$message.warning('Get server info from frps failed!')
commit('SET_SERVER_INFO', null)
}
commit('SET_SERVER_INFO', (await res.json()) || null)
} }
} }

View File

@ -1,20 +1,14 @@
import { Message } from 'element-ui' import { Message } from 'element-ui'
export default function(api, init = {}) { export default function(api, init = {}) {
return new Promise(resolve => { return new Promise((resolve, reject) => {
fetch(`/api/${api}`, Object.assign({ credentials: 'include' }, init)) fetch(`/api/${api}`, Object.assign({ credentials: 'include' }, init))
.then(res => { .then(res => {
if (res.status < 200 || res.status >= 300) { resolve(res)
Message.warning('Get server info from frps failed!')
resolve()
return
}
resolve(res ? res.json() : undefined)
}) })
.catch(err => { .catch(err => {
this.$message.error(err.message) Message.error(err.message)
resolve() reject()
}) })
}) })
} }

View File

@ -82,6 +82,7 @@ export default {
methods: { methods: {
initData() { initData() {
if (!this.serverInfo) return if (!this.serverInfo) return
console.log('serverInfo', this.serverInfo)
this.version = this.serverInfo.version this.version = this.serverInfo.version
this.bind_port = this.serverInfo.bind_port this.bind_port = this.serverInfo.bind_port

View File

@ -95,7 +95,12 @@ export default {
this.subdomain_host = this.serverInfo.subdomain_host this.subdomain_host = this.serverInfo.subdomain_host
if (this.vhost_http_port == null || this.vhost_http_port === 0) return if (this.vhost_http_port == null || this.vhost_http_port === 0) return
const json = await this.$fetch('proxy/http') const res = await this.$fetch('proxy/http')
if (!res.ok) {
this.$message.warning('Get proxy info from frps failed!')
return
}
const json = await res.json()
if (!json) return if (!json) return
this.proxies = [] this.proxies = []

View File

@ -90,7 +90,12 @@ export default {
this.subdomain_host = this.serverInfo.subdomain_host this.subdomain_host = this.serverInfo.subdomain_host
if (this.vhost_https_port == null || this.vhost_https_port === 0) return if (this.vhost_https_port == null || this.vhost_https_port === 0) return
const json = await this.$fetch('proxy/https') const res = await this.$fetch('proxy/https')
if (!res.ok) {
this.$message.warning('Get proxy info from frps failed!')
return
}
const json = await res.json()
if (!json) return if (!json) return
this.proxies = [] this.proxies = []

View File

@ -71,7 +71,12 @@ export default {
return Humanize.fileSize(row.traffic_out) return Humanize.fileSize(row.traffic_out)
}, },
async initData() { async initData() {
const json = await this.$fetch('proxy/stcp') const res = await this.$fetch('proxy/stcp')
if (!res.ok) {
this.$message.warning('Get proxy info from frps failed!')
return
}
const json = await res.json()
if (!json) return if (!json) return
this.proxies = [] this.proxies = []

View File

@ -75,7 +75,12 @@ export default {
return Humanize.fileSize(row.traffic_out) return Humanize.fileSize(row.traffic_out)
}, },
async initData() { async initData() {
const json = await this.$fetch('proxy/tcp') const res = await this.$fetch('proxy/tcp')
if (!res.ok) {
this.$message.warning('Get proxy info from frps failed!')
return
}
const json = await res.json()
if (!json) return if (!json) return
this.proxies = [] this.proxies = []

View File

@ -73,7 +73,12 @@ export default {
return Humanize.fileSize(row.traffic_out) return Humanize.fileSize(row.traffic_out)
}, },
async initData() { async initData() {
const json = await this.$fetch('proxy/udp') const res = await this.$fetch('proxy/udp')
if (!res.ok) {
this.$message.warning('Get proxy info from frps failed!')
return
}
const json = await res.json()
if (!json) return if (!json) return
this.proxies = [] this.proxies = []