|
@@ -5,180 +5,109 @@ import { user } from '@/stores/user'
|
|
|
const { token } = user
|
|
|
|
|
|
const service = axios.create({
|
|
|
- baseURL: window.globalVariables.api,
|
|
|
- method: 'post',
|
|
|
- timeout: 60000,
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- },
|
|
|
+ baseURL: window.globalVariables.api,
|
|
|
+ method: 'post',
|
|
|
+ timeout: 60000,
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
service.interceptors.request.use(
|
|
|
- (config) => {
|
|
|
- // do something before request is sent
|
|
|
+ (config) => {
|
|
|
+ // do something before request is sent
|
|
|
|
|
|
- config.data = Object.assign(
|
|
|
- {
|
|
|
- token,
|
|
|
- site: 'jnmf',
|
|
|
- client: 'web',
|
|
|
- api: 'json',
|
|
|
- // from: 'backend',
|
|
|
- issubmit: (config.url.endsWith('add') || config.url.endsWith('edit')) ? 1 : undefined
|
|
|
- },
|
|
|
- config.data || {}
|
|
|
- )
|
|
|
- if (config.method === 'get') {
|
|
|
- config.params = Object.assign(
|
|
|
- {
|
|
|
- token,
|
|
|
- },
|
|
|
- config.params || {}
|
|
|
- )
|
|
|
- } else {
|
|
|
- if (config.data instanceof FormData) {
|
|
|
- //
|
|
|
- } else {
|
|
|
config.data = Object.assign(
|
|
|
- {
|
|
|
- token,
|
|
|
- client: 'web',
|
|
|
- api: 'json',
|
|
|
- admin: '1',
|
|
|
- issubmit: (config.url?.endsWith('/add') || config.url?.endsWith('/edit')) ? '1' : undefined,
|
|
|
- },
|
|
|
- config.data ?? {}
|
|
|
- )
|
|
|
- if (config.method === 'get') {
|
|
|
- config.params = Object.assign(
|
|
|
{
|
|
|
- token,
|
|
|
+ token,
|
|
|
+ site: 'jnmf',
|
|
|
+ client: 'web',
|
|
|
+ api: 'json',
|
|
|
+ // from: 'backend',
|
|
|
+ issubmit: (config.url.endsWith('add') || config.url.endsWith('edit')) ? 1 : undefined
|
|
|
},
|
|
|
- config.params || {}
|
|
|
- )
|
|
|
+ config.data || {}
|
|
|
+ )
|
|
|
+ if (config.method === 'get') {
|
|
|
+ config.params = Object.assign(
|
|
|
+ {
|
|
|
+ token,
|
|
|
+ },
|
|
|
+ config.params || {}
|
|
|
+ )
|
|
|
}
|
|
|
// 短时间多个请求会冲突
|
|
|
// console.groupCollapsed('axios: ' + config.url)
|
|
|
// console.log('request', config.data)
|
|
|
return config
|
|
|
- }
|
|
|
- (error) => {
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
// do something with request error
|
|
|
console.log(error) // for debug
|
|
|
return Promise.reject(error)
|
|
|
- }
|
|
|
- if (config.$type === 'import') {
|
|
|
- config.timeout = 1000 * 60 * 20
|
|
|
- config.transformRequest = [function (data, headers) {
|
|
|
- const formData = new FormData()
|
|
|
- Object.keys(data).forEach(key => formData.append(key, data[key]))
|
|
|
- return formData;
|
|
|
- }]
|
|
|
- }
|
|
|
- if (config.$type === 'upload') {
|
|
|
- config.timeout = 1000 * 60 * 2
|
|
|
- config.transformRequest = [function (data, headers) {
|
|
|
- const formData = new FormData()
|
|
|
- Object.keys(data).forEach(key => formData.append(key, data[key]))
|
|
|
- return formData;
|
|
|
- }]
|
|
|
- }
|
|
|
- // 短时间多个请求会冲突
|
|
|
- // console.groupCollapsed('axios: ' + config.url)
|
|
|
- // console.log('request', config.data)
|
|
|
- return config
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- // do something with request error
|
|
|
- console.log(error) // for debug
|
|
|
- return Promise.reject(error)
|
|
|
}
|
|
|
)
|
|
|
|
|
|
// response interceptor
|
|
|
let isRelogin = false
|
|
|
service.interceptors.response.use(
|
|
|
- // <<<<<<< HEAD
|
|
|
- // (response, c) => {
|
|
|
- // const { code, msg } = response.data
|
|
|
- // if (code !== '1' && code !== 1) {
|
|
|
- // Message.error(msg)
|
|
|
- // =======
|
|
|
- (response, c) => {
|
|
|
- const { code, msg, data } = response.data
|
|
|
- if (code === '10001') {
|
|
|
- if (!isRelogin) {
|
|
|
- isRelogin = true
|
|
|
- Message.error(msg)
|
|
|
- request({
|
|
|
- url: '/user/main/login',
|
|
|
- data: {
|
|
|
- token: data.token
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 1) {
|
|
|
- localStorage.setItem('userInfo', JSON.stringify(res.data));
|
|
|
- isRelogin = false
|
|
|
- // 视情况打开
|
|
|
- location.reload()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ (response, c) => {
|
|
|
+ const { code, msg, data } = response.data
|
|
|
+ if (code === '10001') {
|
|
|
+ if (!isRelogin) {
|
|
|
+ isRelogin = true
|
|
|
+ Message.error(msg)
|
|
|
+ request({
|
|
|
+ url: '/user/main/login',
|
|
|
+ data: {
|
|
|
+ token: data.token
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code == 1) {
|
|
|
+ localStorage.setItem('userInfo', JSON.stringify(res.data));
|
|
|
+ isRelogin = false
|
|
|
+ // 视情况打开
|
|
|
+ location.reload()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- } else if (code !== '1') {
|
|
|
- Message.error(msg)
|
|
|
+ } else if (code !== '1') {
|
|
|
+ Message.error(msg)
|
|
|
+ }
|
|
|
+ // console.log('response', response.data)
|
|
|
+ // console.groupEnd()
|
|
|
+ return response.data
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.error('err' + error) // for debug
|
|
|
+ return Promise.reject(error)
|
|
|
}
|
|
|
- // console.log('response', response.data)
|
|
|
- // console.groupEnd()
|
|
|
- return response.data
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- console.error('err' + error) // for debug
|
|
|
- return Promise.reject(error)
|
|
|
->>>>>>> master
|
|
|
- }
|
|
|
- // console.log('response', response.data)
|
|
|
- // console.groupEnd()
|
|
|
- return response.data
|
|
|
- },
|
|
|
-(error) => {
|
|
|
- console.error('err' + error) // for debug
|
|
|
- return Promise.reject(error)
|
|
|
-}
|
|
|
)
|
|
|
|
|
|
// 上传
|
|
|
export const request = axios.create({
|
|
|
- baseURL: window.globalVariables.api,
|
|
|
- method: 'post',
|
|
|
- timeout: 5000,
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- },
|
|
|
+ baseURL: window.globalVariables.api,
|
|
|
+ method: 'post',
|
|
|
+ timeout: 5000,
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ },
|
|
|
})
|
|
|
request.interceptors.response.use(
|
|
|
- (response) => {
|
|
|
- const { code, msg } = response.data
|
|
|
- if (code !== '1') {
|
|
|
- Message.error(msg)
|
|
|
+ (response) => {
|
|
|
+ const { code, msg } = response.data
|
|
|
+ if (code !== '1') {
|
|
|
+ Message.error(msg)
|
|
|
+ }
|
|
|
+ return response.data
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.log('err' + error) // for debug
|
|
|
+ return Promise.reject(error)
|
|
|
}
|
|
|
- return response.data
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- console.log('err' + error) // for debug
|
|
|
- return Promise.reject(error)
|
|
|
- }
|
|
|
)
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
-export function download(url, data) {
|
|
|
- const params = Object.assign({ token, limit: 10000, page: 1, api: 'xls' }, data)
|
|
|
- const paramsStr = Object.entries(params).map(([k, v]) => `${k}=${v}`).join('&')
|
|
|
- const el = document.createElement('a')
|
|
|
- const href = `${window.globalVariables.api}${url}?${paramsStr}`
|
|
|
- el.setAttribute('href', href)
|
|
|
- el.click()
|
|
|
-=======
|
|
|
export function download(url, data, name) {
|
|
|
const params = Object.assign({ token, limit: 10000, page: 1, api: 'xls' }, data)
|
|
|
const paramsStr = Object.entries(params).map(([k, v]) => `${k}=${v}`).join('&')
|
|
@@ -187,20 +116,19 @@ export function download(url, data, name) {
|
|
|
el.setAttribute('href', href)
|
|
|
name && el.setAttribute('download', name)
|
|
|
el.click()
|
|
|
->>>>>>> master
|
|
|
}
|
|
|
|
|
|
export function download2(url, data, name) {
|
|
|
- const el = document.createElement('a')
|
|
|
- const href = `${window.globalVariables.api}/openapi/download.php?path=${url}&name=${name}`
|
|
|
- el.setAttribute('href', href)
|
|
|
- name && el.setAttribute('download', name)
|
|
|
- el.click()
|
|
|
+ const el = document.createElement('a')
|
|
|
+ const href = `${window.globalVariables.api}/openapi/download.php?path=${url}&name=${name}`
|
|
|
+ el.setAttribute('href', href)
|
|
|
+ name && el.setAttribute('download', name)
|
|
|
+ el.click()
|
|
|
}
|
|
|
|
|
|
export default (...args) => {
|
|
|
- if (!isRelogin)
|
|
|
- return service(...args)
|
|
|
- else
|
|
|
- return Promise.reject({})
|
|
|
+ if (!isRelogin)
|
|
|
+ return service(...args)
|
|
|
+ else
|
|
|
+ return Promise.reject({})
|
|
|
}
|