123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- const httpRequest = axios.create({
- baseURL: 'http://192.168.2.144:8080',
- timeout: 3 * 60 * 1000,
- withCredentials: true,
- })
- httpRequest.interceptors.request.use(
- function (config) {
- if(config.data.access_token){
- config.headers['accessToken'] = config.data.access_token
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return config
- },
- function (error) {
- return Promise.reject(error)
- }
- )
- httpRequest.interceptors.response.use(
- function (response) {
- const res = response.data
-
-
-
-
-
-
-
-
-
- return response
- },
- function (error) {
- this.ELEMENT.Message.error(error.message)
- return Promise.reject(error)
- }
- )
- function get(url, params) {
- return new Promise((resolve, reject) => {
- httpRequest
- .get(url, { params: params })
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err.data)
- })
- })
- }
- function post(url, data, config) {
- return new Promise((resolve, reject) => {
- httpRequest
- .post(url, data, config)
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err)
- })
- })
- }
- function postFile(url, blob) {
- return new Promise((resolve, reject) => {
- let formdata = new FormData()
- formdata.append('multipartFile', blob)
- httpRequest
- .post(url, formdata)
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err)
- })
- })
- }
- function localEnvLogin() {
- post(
- '/apiSys/login',
- {
- username: 'admin',
- password: '1q2w3e4r5t',
- },
- {
- transformRequest: [
- function (data, headers) {
-
- headers['Content-Type'] = 'application/x-www-form-urlencoded'
- return stringify(data)
- },
- ],
- }
- ).then(res => {
- localStorage.setItem('token', res.data.token || getQueryVariable('token'))
- })
- }
- function stringify(data) {
- let ret = ''
- for (const it in data) {
- ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
- }
- ret = ret.substring(0, ret.lastIndexOf('&'))
- return ret
- }
- function formatDate(time) {
- let date = time ? new Date(Number(time)) : new Date();
- let Y = date.getFullYear() + '-';
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
- let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
- let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
- let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
- return Y + M + D + h + m + s;
- }
|