Compare commits
16 Commits
Author | SHA1 | Date |
---|---|---|
yujialong | f46b80d2c6 | 1 month ago |
yujialong | 77f2e9eeb8 | 1 month ago |
yujialong | 8d95350531 | 2 months ago |
yujialong | 999066b59b | 3 months ago |
yujialong | 1c3297c0c0 | 4 months ago |
yujialong | a7a04ff314 | 4 months ago |
yujialong | 9f816354a2 | 5 months ago |
yujialong | 190bfe4fb8 | 5 months ago |
yujialong | 9f37d8be0a | 5 months ago |
yujialong | 93987d0e74 | 5 months ago |
yujialong | 13c75433ec | 5 months ago |
yujialong | d90fcd1df0 | 5 months ago |
yujialong | 05fd504802 | 6 months ago |
yujialong | ac88afa39b | 6 months ago |
yujialong | ac1914bf1d | 7 months ago |
yujialong | e0f0ed0092 | 7 months ago |
16 changed files with 1200 additions and 1231 deletions
@ -1,108 +1,121 @@ |
|||||||
import axios from 'axios'; |
import axios from 'axios'; |
||||||
import { |
import { |
||||||
Message |
Message |
||||||
} from 'element-ui' |
} from 'element-ui' |
||||||
import router from '../router/index' |
import router from '../router/index' |
||||||
import Cookie from 'js-cookie' |
import Cookie from 'js-cookie' |
||||||
import config from '@/config' |
import config from '@/config' |
||||||
|
import Util from '@/util' |
||||||
|
|
||||||
const service = axios.create({ |
const service = axios.create({ |
||||||
baseURL: config.host, |
baseURL: config.host, |
||||||
timeout: 10000000 |
timeout: 10000000 |
||||||
}) |
}) |
||||||
|
|
||||||
// post请求头
|
// post请求头
|
||||||
service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; |
service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; |
||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
service.interceptors.request.use(config => { |
service.interceptors.request.use(config => { |
||||||
const token = Cookie.get('admin-token') |
const token = Cookie.get('admin-token') |
||||||
if (token) { |
if (token) { |
||||||
config.headers.token = token |
config.headers.token = token |
||||||
|
} |
||||||
|
return config; |
||||||
|
}, err => { |
||||||
|
Message.error({ |
||||||
|
message: '退出登陆', |
||||||
|
onClose: function () { |
||||||
|
router.push({ name: 'login' }); |
||||||
} |
} |
||||||
return config; |
}) |
||||||
}, err => { |
return Promise.reject(err); |
||||||
Message.error({ |
|
||||||
message: '退出登陆', |
|
||||||
onClose: function () { |
|
||||||
router.push({name: 'login'}); |
|
||||||
} |
|
||||||
}) |
|
||||||
return Promise.reject(err); |
|
||||||
}) |
}) |
||||||
|
|
||||||
|
let logouted = 0; |
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
service.interceptors.response.use( |
service.interceptors.response.use( |
||||||
response => { |
response => { |
||||||
const res = response.data; |
const res = response.data; |
||||||
if (res.status == 200 || res.status == 10000 || res.status == 30001) { |
if (res.status == 200 || res.status == 10000 || res.status == 30001) { |
||||||
return Promise.resolve(res).catch(e => {}); |
return Promise.resolve(res).catch(e => { }); |
||||||
} else if (!res.status) { |
} else if (res.code === 401) { |
||||||
return Promise.resolve(res).catch(e => {}); |
// 账号互踢
|
||||||
} else { |
if (!logouted) { |
||||||
Message.error(res.message) |
Message.error(res.msg.includes('顶') ? '您的账号已在其他设备登录,您已被迫下线!' : '登录过期,请重新登录!') |
||||||
return Promise.reject(res) |
setTimeout(() => { |
||||||
} |
Util.exit() |
||||||
}, |
}, 1500) |
||||||
// 服务器状态码不是200的情况
|
logouted = 1 |
||||||
error => { |
} |
||||||
if (error.response.status) { |
} else if (!res.status) { |
||||||
switch (error.response.status) { |
return Promise.resolve(res).catch(e => { }); |
||||||
// 401: 未登录
|
} else { |
||||||
case 401: |
Message.error(res.message) |
||||||
Message.error('登录过期,请重新登录') |
return Promise.reject(res) |
||||||
setTimeout(() => { |
} |
||||||
history.back() |
}, |
||||||
}, 1500) |
// 服务器状态码不是200的情况
|
||||||
break; |
error => { |
||||||
default: |
if (error.response.status) { |
||||||
// Message.error(error.response.data.message)
|
switch (error.response.status) { |
||||||
Promise.reject(error.response); |
// 401: 未登录
|
||||||
} |
case 401: |
||||||
return Promise.reject(error.response); |
if (!logouted) { |
||||||
} |
Message.error('登录过期,请重新登录') |
||||||
|
setTimeout(() => { |
||||||
|
history.back() |
||||||
|
}, 1500) |
||||||
|
logouted = 1 |
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
Promise.reject(error.response); |
||||||
|
} |
||||||
|
return Promise.reject(error.response); |
||||||
} |
} |
||||||
|
} |
||||||
); |
); |
||||||
|
|
||||||
function get(url, params) { |
function get (url, params) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
service.get(url, { params: params }).then(res => { |
service.get(url, { params: params }).then(res => { |
||||||
resolve(res); |
resolve(res); |
||||||
}).catch(err => { |
}).catch(err => { |
||||||
reject(err); |
reject(err); |
||||||
}); |
|
||||||
}); |
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
function post(url, params) { |
function post (url, params) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
service.post(url, params).then(res => { |
service.post(url, params).then(res => { |
||||||
resolve(res); |
resolve(res); |
||||||
}).catch(err => { |
}).catch(err => { |
||||||
reject(err.data); |
reject(err.data); |
||||||
}); |
|
||||||
}); |
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
function del(url, params) { |
function del (url, params) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
service.delete(url, { |
service.delete(url, { |
||||||
params |
params |
||||||
}).then(res => { |
}).then(res => { |
||||||
resolve(res); |
resolve(res); |
||||||
}).catch(err => { |
}).catch(err => { |
||||||
reject(err.data); |
reject(err.data); |
||||||
}); |
|
||||||
}); |
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
function put(url, params) { |
function put (url, params) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
service.put(url, params).then(res => { |
service.put(url, params).then(res => { |
||||||
resolve(res); |
resolve(res); |
||||||
}).catch(err => { |
}).catch(err => { |
||||||
reject(err.data); |
reject(err.data); |
||||||
}); |
|
||||||
}); |
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
export { get, post, del, put } |
export { get, post, del, put } |
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,41 @@ |
|||||||
/** |
/** |
||||||
* 阿里云oss配置 |
* 阿里云oss配置 |
||||||
* */ |
* */ |
||||||
|
import { get } from '@/api/http' |
||||||
|
import api from '@/api' |
||||||
|
import CryptoJS from 'crypto-js' |
||||||
|
import JSEncrypt from 'jsencrypt' |
||||||
|
|
||||||
export default { |
const A = (key, encryptedData) => { |
||||||
// oss账号信息
|
const keyHex = CryptoJS.enc.Base64.parse(key) |
||||||
config: { |
const decrypted = CryptoJS.AES.decrypt(encryptedData, keyHex, { |
||||||
region: 'oss-cn-shenzhen', |
mode: CryptoJS.mode.ECB, |
||||||
accessKeyId: 'LTAI4FzqQHnk4rozqLZ8jCNj', |
padding: CryptoJS.pad.Pkcs7 |
||||||
accessKeySecret: 'mveW7B1OyFoKUkHm8WsxmrjHmkJWHq', |
}) |
||||||
bucket: 'huoran' |
return decrypted.toString(CryptoJS.enc.Utf8) |
||||||
}, |
} |
||||||
// 上传成功url前置部分(成功回调没有返回url)
|
|
||||||
preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/' |
const R = (encryptedKey, privateKey) => { |
||||||
|
const decrypt = new JSEncrypt() |
||||||
|
decrypt.setPrivateKey(privateKey) |
||||||
|
const decryptedKey = decrypt.decrypt(encryptedKey) |
||||||
|
return decryptedKey |
||||||
|
} |
||||||
|
|
||||||
|
export default async function () { |
||||||
|
try { |
||||||
|
const res = await get(api.encrypt) |
||||||
|
const RE = A(R(res.encryptedKey, res.privateKey), res.encryptedData).split('/') |
||||||
|
return { |
||||||
|
// oss账号信息
|
||||||
|
config: { |
||||||
|
region: 'oss-cn-shenzhen', |
||||||
|
accessKeyId: RE[0], |
||||||
|
accessKeySecret: RE[1], |
||||||
|
bucket: 'huoran' |
||||||
|
}, |
||||||
|
// 上传成功url前置部分(成功回调没有返回url)
|
||||||
|
preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/' |
||||||
|
} |
||||||
|
} catch (e) { } |
||||||
} |
} |
Loading…
Reference in new issue