接口格式
This commit is contained in:
5
src/assets/js/getData1.js
Normal file
5
src/assets/js/getData1.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import {post} from '@js/http.js'
|
||||
|
||||
export const workScreen = (wflag) => post('api/bigScreenScreen/workScreen', {
|
||||
web_flag: wflag
|
||||
})
|
||||
10
src/assets/js/getData2.js
Normal file
10
src/assets/js/getData2.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import {post} from '@js/http.js'
|
||||
|
||||
export const screenZK = (id, cid) => post('api/bigScreenScreen/zk', {
|
||||
accountId: id,
|
||||
center_id: cid
|
||||
})
|
||||
export const query3Dcartoon = (id, cid) => post('api/bigScreenScreen/query3Dcartoon', {
|
||||
accountId: id,
|
||||
center_id: cid
|
||||
})
|
||||
78
src/assets/js/http.js
Normal file
78
src/assets/js/http.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import axios from 'axios'
|
||||
import { Dialog, toast } from './mUtils.js'
|
||||
import store from '../../vuex/store'
|
||||
import router from '@/router'
|
||||
|
||||
axios.defaults.timeout = 50000
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
|
||||
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
if (config.method === 'post') {
|
||||
if (!config.data.flag) {
|
||||
config.data = config.data
|
||||
} else {
|
||||
config.data = config.data.formData
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
Dialog('错误的传参')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
if (response.status === 200) {
|
||||
return Promise.resolve(response)
|
||||
} else {
|
||||
return Promise.reject(response)
|
||||
}
|
||||
},
|
||||
error => {
|
||||
if (error && error.response) {
|
||||
switch (error.response.status) {
|
||||
case 401:
|
||||
toast(error.response.data.message)
|
||||
store.dispatch('setSignOut')
|
||||
router.push('/login')
|
||||
break
|
||||
}
|
||||
return Promise.reject(error.response.data)
|
||||
} else {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const post = (sevmethod, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(`${store.getters.baseUrl}/` + sevmethod, params)
|
||||
.then(response => {
|
||||
resolve(response.data)
|
||||
}, error => {
|
||||
Dialog(error.message)
|
||||
reject(error.message)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const post1 = (sevmethod, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(sevmethod, params)
|
||||
.then(response => {
|
||||
resolve(response.data)
|
||||
}, error => {
|
||||
Dialog(error.message)
|
||||
reject(error.message)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user