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: {
async initData() {
const json = await this.$fetch(`traffic/${this.proxyName}`)
if (!json) return
const res = await this.$fetch(`traffic/${this.proxyName}`)
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)
}

View File

@ -15,9 +15,13 @@ const mutations = {
const actions = {
async fetchServerInfo({ commit }) {
const json = await fetch('serverinfo')
commit('SET_SERVER_INFO', json || null)
return json
const res = await fetch('serverinfo')
if (!res.ok) {
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'
export default function(api, init = {}) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
fetch(`/api/${api}`, Object.assign({ credentials: 'include' }, init))
.then(res => {
if (res.status < 200 || res.status >= 300) {
Message.warning('Get server info from frps failed!')
resolve()
return
}
resolve(res ? res.json() : undefined)
resolve(res)
})
.catch(err => {
this.$message.error(err.message)
resolve()
Message.error(err.message)
reject()
})
})
}

View File

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

View File

@ -95,7 +95,12 @@ export default {
this.subdomain_host = this.serverInfo.subdomain_host
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
this.proxies = []

View File

@ -90,7 +90,12 @@ export default {
this.subdomain_host = this.serverInfo.subdomain_host
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
this.proxies = []

View File

@ -71,7 +71,12 @@ export default {
return Humanize.fileSize(row.traffic_out)
},
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
this.proxies = []

View File

@ -75,7 +75,12 @@ export default {
return Humanize.fileSize(row.traffic_out)
},
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
this.proxies = []

View File

@ -73,7 +73,12 @@ export default {
return Humanize.fileSize(row.traffic_out)
},
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
this.proxies = []