123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import axios from 'axios'
- import { MessageBox, Message } from 'element-ui'
- import store from '@/store'
- import { geteSessionStorage } from '@/utils/auth'
- import qs from 'qs'
- import router from '@/router'
- import { pipeConfigInfo } from 'staticPub/config'
- let tempIP = "";
- if (pipeConfigInfo.currentType == pipeConfigInfo.type.company) {
- tempIP = 'http://221.182.8.141:7077';
- } else {
- tempIP = 'http://172.16.0.4:10077';
-
- }
- export const IP = tempIP;
- const service = axios.create({
-
-
- withCredentials: true,
- timeout: 60000
- })
- let requestTimes = 0
- service.interceptors.request.use(
- config => {
- if (config.method === 'post' && config.url === '/auth/oauth/login') {
- config.data = qs.stringify(config.data)
- config.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
- } else if (config.method === 'put' && config.url === '/dc/interfacemanage/updateByStatus') {
- config.data = qs.stringify(config.data)
- config.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
- } else {
- config.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
- }
- if (config.file) {
- config.headers.post['Content-Type'] = 'multipart/form-data'
- }
- if (config.url === '/dc/interfacemanage/callInterface') {
- const formData = new FormData()
- formData.append('code', config.data.code)
- const parmasType = Object.prototype.toString.call(config.data.parameter)
- if (parmasType == '[object FormData]') {
- const paramsAry = {};
- const isAppend = [];
- for (var key of config.data.parameter.keys()) {
- const formDataType = Object.prototype.toString.call(config.data.parameter.get(key))
- if (formDataType == '[object File]') {
- if (isAppend.findIndex(e => { return e == key }) == -1) {
- isAppend.push(key)
- config.data.parameter.getAll(key).forEach(item => {
- formData.append(key, item)
- })
- }
- } else {
- paramsAry[key] = config.data.parameter.get(key)
- }
- }
- formData.append('parameter', JSON.stringify(paramsAry))
- } else {
- formData.append('parameter', JSON.stringify(config.data.parameter))
- }
-
-
-
- config.data = formData
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
- if (store.getters.token && config.url.indexOf('mbData') == "-1") {
- config.headers['Authorization'] = 'bearer ' + geteSessionStorage('token')
- }
- return config
- },
- error => {
-
- console.log(error)
- return Promise.reject(error)
- }
- )
- service.interceptors.response.use(
-
-
- response => {
- const res = response.data
-
- if (typeof res === 'string') return res
-
- if (res instanceof ArrayBuffer) return res
-
- if (res instanceof Blob) return res
-
- if (response.config.url.includes('/dc/interfacemanage/callInterface')) {
-
- if (res.code === -1) {
- if (!res.message || res.message.length < 100) {
- Message({
- message: res.message || 'Error',
- type: 'error',
- duration: 2 * 1000
- })
- } else {
- Message({
- message: '系统错误',
- type: 'error',
- duration: 2 * 1000
- })
- }
- } else if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
-
- MessageBox.confirm('您已注销,您可以取消以停留在此页,或重新登录', '确认注销', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- store.dispatch('user/resetToken').then(() => {
- location.reload()
- })
- })
- } else if (res.code === 1) {
- requestTimes = 0
- return res.result
- } else {
- Message({
- message: res.message || 'Error',
- type: 'error',
- duration: 2 * 1000
- })
- }
- return Promise.reject(new Error(res.message || 'Error')).catch(err => { console.log(err) })
- } else {
-
- if (res.code === -1) {
- if (!res.message || res.message.length < 100) {
- Message({
- message: res.message || 'Error',
- type: 'error',
- duration: 2 * 1000
- })
- } else {
- Message({
- message: '系统错误',
- type: 'error',
- duration: 2 * 1000
- })
- }
- } else if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
-
- MessageBox.confirm('您已注销,您可以取消以停留在此页,或重新登录', '确认注销', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- store.dispatch('user/resetToken').then(() => {
- location.reload()
- })
- })
- } else if (res.code === 1 || res.Code === 200) {
- requestTimes = 0;
-
-
-
-
- return res
- } else {
- Message({
- message: res.message || 'Error',
- type: 'error',
- duration: 2 * 1000
- })
- }
- return Promise.reject(new Error(res.message || 'Error')).catch(err => { console.log(err) })
- }
- },
- error => {
- function clearSession() {
- return new Promise(resolve => {
- sessionStorage.clear()
- resolve(1)
- })
- }
- if (error && error.response && error.response.data && error.response.data.code === 401) {
- if (requestTimes === 0) {
- requestTimes = 1
- MessageBox.confirm('登录失效,请重新登录!', '提示', {
- confirmButtonText: '确定',
- showCancelButton: false,
- showClose: false,
- closeOnPressEscape: false,
- closeOnClickModal: false
- }).then(async () => {
- const result = await clearSession()
- if (result === 1) {
- requestTimes = 0
- router.replace('/login')
- }
- })
- }
- } else {
- Message({
- message: error.message,
- type: 'error',
- duration: 5 * 1000
- })
- }
- }
- )
- export function getSXJList(data) {
- return service({
- url: '/gis/sxjDocking/send',
- method: 'post',
- data
- })
- }
- export default service
|