刘翔宇-旅管家 3 years ago
parent 133c6a2c16
commit a406e0b3ba

@ -2,8 +2,8 @@
ENV = 'development'
# base api
VUE_APP_DOMIAN=http://192.168.60.99:9003/
#VUE_APP_DOMIAN=http://hdcontract.ali251.langye.net/
V#UE_APP_DOMIAN=http://192.168.60.99:9003/
VUE_APP_DOMIAN=http://hdcontract.ali251.langye.net/
VUE_APP_BASE_API = ''

@ -12,7 +12,8 @@ export function loginOss(data) {
return request({
url: '/api/admin/auth/oss-login',
method: 'post',
data
data,
noloading:true
})
}

@ -1,95 +1,108 @@
import axios from 'axios'
import { MessageBox, Message,Loading } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'
let loading;
// create an axios instance
const service = axios.create({
baseURL: process.env.VUE_APP_DOMIAN, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 5000 // request timeout
})
// request interceptor
service.interceptors.request.use(
config => {
// do something before request is sent
loading = Loading.service({
lock:true,
background:"rgba(0,0,0,0.4)",
text:"正在加载中..."
})
if (store.getters.token) {
// let each request carry token
// ['X-Token'] is a custom headers key
// please modify it according to the actual situation
//config.headers['X-Token'] = getToken();
config.headers['Authorization'] ="Bearer "+getToken()
}
return config
},
error => {
// do something with request error
console.log(error) // for debug
return Promise.reject(error)
}
)
// response interceptor
service.interceptors.response.use(
/**
* If you want to get http information such as headers or status
* Please return response => response
*/
/**
* Determine the request status by custom code
* Here is just an example
* You can also judge the status by HTTP Status Code
*/
response => {
loading.close()
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.errcode) {
Message({
message: res.errmsg || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.errcode === 50008 || res.errcode === 50012 || res.errcode === 50014) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.errmsg || 'Error'))
} else {
return res
}
},
error => {
loading.close()
console.log('err' + error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)
import axios from 'axios'
import {
MessageBox,
Message,
Loading
} from 'element-ui'
import store from '@/store'
import {
getToken
} from '@/utils/auth'
let loading;
// create an axios instance
const service = axios.create({
baseURL: process.env.VUE_APP_DOMIAN, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 500000 // request timeout
})
// request interceptor
service.interceptors.request.use(
config => {
if (!config.noloading) {
// do something before request is sent
loading = Loading.service({
lock: true,
background: "rgba(0,0,0,0.4)",
text: "正在加载中..."
})
}
if (store.getters.token) {
// let each request carry token
// ['X-Token'] is a custom headers key
// please modify it according to the actual situation
//config.headers['X-Token'] = getToken();
config.headers['Authorization'] = "Bearer " + getToken()
}
return config
},
error => {
// do something with request error
console.log(error) // for debug
return Promise.reject(error)
}
)
// response interceptor
service.interceptors.response.use(
/**
* If you want to get http information such as headers or status
* Please return response => response
*/
/**
* Determine the request status by custom code
* Here is just an example
* You can also judge the status by HTTP Status Code
*/
response => {
if (loading) {
loading.close()
}
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.errcode) {
Message({
message: res.errmsg || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.errcode === 50008 || res.errcode === 50012 || res.errcode === 50014) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again',
'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.errmsg || 'Error'))
} else {
return res
}
},
error => {
if (loading) {
loading.close()
}
console.log('err' + error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)
export default service

@ -1,5 +1,5 @@
<template>
<div class="login-container">
<div class="login-container" v-if="showLogin">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on"
label-position="left">
@ -12,7 +12,7 @@
<svg-icon icon-class="user" />
</span>
<el-input ref="username" v-model="loginForm.username" placeholder="请输入账号" name="username" type="text"
tabindex="1" auto-complete="on" />
tabindex="1" auto-complete="off" />
</el-form-item>
<el-form-item prop="password">
@ -20,8 +20,8 @@
<svg-icon icon-class="password" />
</span>
<el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType"
placeholder="请输入密码" name="password" tabindex="2" auto-complete="on" @keyup.enter.native="handleLogin" />
<!-- <span class="show-pwd" @click="showPwd">
placeholder="请输入密码" name="password" tabindex="2" auto-complete="off" @keyup.enter.native="handleLogin" />
<!-- <span class="show-pwd" @click="showPwd">
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
</span> -->
</el-form-item>
@ -31,6 +31,7 @@
</el-form>
</div>
<div v-else class="login-container-w"></div>
</template>
<script>
@ -56,6 +57,7 @@
}
}
return {
showLogin: false,
loginForm: {
username: '',
password: ''
@ -77,20 +79,18 @@
redirect: undefined
}
},
watch: {
$route: {
handler: function(route) {
this.redirect = route.query && route.query.redirect
},
immediate: true
}
beforeCreate() {
},
created() {
var query = this.$route.query;
var query = this.$route.query;
if (query.tp) {
this.showLogin = false;
} else {
this.showLogin = true;
}
if (query.token && query.userid && query.tp) {
this.loading = true
console.log(query.token)
//this.$store.dispatch('user/logout')
this.loading = true
this.$store.dispatch('user/loginskip', {
token: query.token,
tp: query.tp
@ -105,6 +105,14 @@
})
}
},
watch: {
$route: {
handler: function(route) {
this.redirect = route.query && route.query.redirect
},
immediate: true
}
},
methods: {
showPwd() {
if (this.passwordType === 'password') {
@ -119,11 +127,11 @@
handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true;
this.loading = true
this.$store.dispatch('user/login', this.loginForm).then(() => {
console.log(this.redirect)
this.$router.push({
path: '/'
path: this.redirect || '/'
})
this.loading = false
}).catch(() => {
@ -191,6 +199,13 @@
$dark_gray:#889aa4;
$light_gray:#eee;
.login-container-w {
min-height: 100%;
width: 100%;
background-color: #ffffff;
overflow: hidden;
}
.login-container {
min-height: 100%;
width: 100%;

Loading…
Cancel
Save