Showing
7 changed files
with
28 additions
and
52 deletions
| 1 | import request from '@/utils/request' | 1 | import request from '@/utils/request' |
| 2 | 2 | ||
| 3 | // 登录方法 | 3 | // 登录方法 |
| 4 | -export function login(username, password, code, uuid) { | 4 | +export function login(username, password, rememberMe) { |
| 5 | const data = { | 5 | const data = { |
| 6 | username, | 6 | username, |
| 7 | password, | 7 | password, |
| 8 | - code, | 8 | + rememberMe |
| 9 | - uuid | ||
| 10 | } | 9 | } |
| 11 | return request({ | 10 | return request({ |
| 12 | - url: '/login', | 11 | + url: '/hello', |
| 13 | method: 'post', | 12 | method: 'post', |
| 14 | data: data | 13 | data: data |
| 15 | }) | 14 | }) |
| ... | @@ -18,23 +17,15 @@ export function login(username, password, code, uuid) { | ... | @@ -18,23 +17,15 @@ export function login(username, password, code, uuid) { |
| 18 | // 获取用户详细信息 | 17 | // 获取用户详细信息 |
| 19 | export function getInfo() { | 18 | export function getInfo() { |
| 20 | return request({ | 19 | return request({ |
| 21 | - url: '/getInfo', | 20 | + url: '/auth/getInfo', |
| 22 | - method: 'get' | 21 | + method: 'post' |
| 23 | }) | 22 | }) |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | // 退出方法 | 25 | // 退出方法 |
| 27 | export function logout() { | 26 | export function logout() { |
| 28 | return request({ | 27 | return request({ |
| 29 | - url: '/logout', | 28 | + url: '/auth/logout', |
| 30 | method: 'post' | 29 | method: 'post' |
| 31 | }) | 30 | }) |
| 32 | } | 31 | } |
| 33 | - | ||
| 34 | -// 获取验证码 | ||
| 35 | -export function getCodeImg() { | ||
| 36 | - return request({ | ||
| 37 | - url: '/captchaImage', | ||
| 38 | - method: 'get' | ||
| 39 | - }) | ||
| 40 | -} | ... | ... |
| ... | @@ -3,7 +3,7 @@ import request from '@/utils/request' | ... | @@ -3,7 +3,7 @@ import request from '@/utils/request' |
| 3 | // 获取路由 | 3 | // 获取路由 |
| 4 | export const getRouters = () => { | 4 | export const getRouters = () => { |
| 5 | return request({ | 5 | return request({ |
| 6 | - url: '/getRouters', | 6 | + url: '/auth/getRouters', |
| 7 | - method: 'get' | 7 | + method: 'post' |
| 8 | }) | 8 | }) |
| 9 | } | 9 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -38,6 +38,7 @@ export default { | ... | @@ -38,6 +38,7 @@ export default { |
| 38 | matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched) | 38 | matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched) |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | + | ||
| 41 | this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false) | 42 | this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false) |
| 42 | }, | 43 | }, |
| 43 | isDashboard(route) { | 44 | isDashboard(route) { | ... | ... |
| ... | @@ -33,10 +33,10 @@ const user = { | ... | @@ -33,10 +33,10 @@ const user = { |
| 33 | Login({ commit }, userInfo) { | 33 | Login({ commit }, userInfo) { |
| 34 | const username = userInfo.username.trim() | 34 | const username = userInfo.username.trim() |
| 35 | const password = userInfo.password | 35 | const password = userInfo.password |
| 36 | - const code = userInfo.code | 36 | + const rememberMe = userInfo.rememberMe |
| 37 | - const uuid = userInfo.uuid | 37 | + |
| 38 | return new Promise((resolve, reject) => { | 38 | return new Promise((resolve, reject) => { |
| 39 | - login(username, password, code, uuid).then(res => { | 39 | + login(username, password,rememberMe).then(res => { |
| 40 | setToken(res.data.token) | 40 | setToken(res.data.token) |
| 41 | commit('SET_TOKEN', res.data.token) | 41 | commit('SET_TOKEN', res.data.token) |
| 42 | resolve() | 42 | resolve() |
| ... | @@ -71,6 +71,7 @@ const user = { | ... | @@ -71,6 +71,7 @@ const user = { |
| 71 | LogOut({ commit, state }) { | 71 | LogOut({ commit, state }) { |
| 72 | return new Promise((resolve, reject) => { | 72 | return new Promise((resolve, reject) => { |
| 73 | logout(state.token).then(() => { | 73 | logout(state.token).then(() => { |
| 74 | + | ||
| 74 | commit('SET_TOKEN', '') | 75 | commit('SET_TOKEN', '') |
| 75 | commit('SET_ROLES', []) | 76 | commit('SET_ROLES', []) |
| 76 | commit('SET_PERMISSIONS', []) | 77 | commit('SET_PERMISSIONS', []) | ... | ... |
| ... | @@ -8,7 +8,8 @@ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' | ... | @@ -8,7 +8,8 @@ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' |
| 8 | // 创建axios实例 | 8 | // 创建axios实例 |
| 9 | const service = axios.create({ | 9 | const service = axios.create({ |
| 10 | // axios中请求配置有baseURL选项,表示请求URL公共部分 | 10 | // axios中请求配置有baseURL选项,表示请求URL公共部分 |
| 11 | - baseURL: process.env.VUE_APP_BASE_API, | 11 | + //baseURL: process.env.VUE_APP_BASE_API, |
| 12 | + baseURL: 'http://192.168.1.45:8080', | ||
| 12 | // 超时 | 13 | // 超时 |
| 13 | timeout: 10000 | 14 | timeout: 10000 |
| 14 | }) | 15 | }) |
| ... | @@ -64,7 +65,9 @@ service.interceptors.response.use(res => { | ... | @@ -64,7 +65,9 @@ service.interceptors.response.use(res => { |
| 64 | location.href = '/index'; | 65 | location.href = '/index'; |
| 65 | }) | 66 | }) |
| 66 | }) | 67 | }) |
| 67 | - } else if (code === 500) { | 68 | + } else if (code === 403) { |
| 69 | + location.href = '/401'; | ||
| 70 | + }else if (code === 500) { | ||
| 68 | Message({ | 71 | Message({ |
| 69 | message: msg, | 72 | message: msg, |
| 70 | type: 'error' | 73 | type: 'error' | ... | ... |
| ... | @@ -18,20 +18,7 @@ | ... | @@ -18,20 +18,7 @@ |
| 18 | <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> | 18 | <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> |
| 19 | </el-input> | 19 | </el-input> |
| 20 | </el-form-item> | 20 | </el-form-item> |
| 21 | - <el-form-item prop="code"> | 21 | + |
| 22 | - <el-input | ||
| 23 | - v-model="loginForm.code" | ||
| 24 | - auto-complete="off" | ||
| 25 | - placeholder="验证码" | ||
| 26 | - style="width: 63%" | ||
| 27 | - @keyup.enter.native="handleLogin" | ||
| 28 | - > | ||
| 29 | - <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> | ||
| 30 | - </el-input> | ||
| 31 | - <div class="login-code"> | ||
| 32 | - <img :src="codeUrl" @click="getCode" class="login-code-img"/> | ||
| 33 | - </div> | ||
| 34 | - </el-form-item> | ||
| 35 | <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> | 22 | <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> |
| 36 | <el-form-item style="width:100%;"> | 23 | <el-form-item style="width:100%;"> |
| 37 | <el-button | 24 | <el-button |
| ... | @@ -56,7 +43,7 @@ | ... | @@ -56,7 +43,7 @@ |
| 56 | <script> | 43 | <script> |
| 57 | import { getCodeImg } from "@/api/login"; | 44 | import { getCodeImg } from "@/api/login"; |
| 58 | //import Cookies from "js-cookie"; | 45 | //import Cookies from "js-cookie"; |
| 59 | -import { encrypt, decrypt } from '@/utils/jsencrypt' | 46 | +import { encrypt, } from '@/utils/jsencrypt' |
| 60 | 47 | ||
| 61 | export default { | 48 | export default { |
| 62 | name: "Login", | 49 | name: "Login", |
| ... | @@ -67,9 +54,7 @@ export default { | ... | @@ -67,9 +54,7 @@ export default { |
| 67 | loginForm: { | 54 | loginForm: { |
| 68 | username: "admin", | 55 | username: "admin", |
| 69 | password: "admin123", | 56 | password: "admin123", |
| 70 | - rememberMe: false, | 57 | + rememberMe: false |
| 71 | - code: "", | ||
| 72 | - uuid: "" | ||
| 73 | }, | 58 | }, |
| 74 | loginRules: { | 59 | loginRules: { |
| 75 | username: [ | 60 | username: [ |
| ... | @@ -77,8 +62,7 @@ export default { | ... | @@ -77,8 +62,7 @@ export default { |
| 77 | ], | 62 | ], |
| 78 | password: [ | 63 | password: [ |
| 79 | { required: true, trigger: "blur", message: "密码不能为空" } | 64 | { required: true, trigger: "blur", message: "密码不能为空" } |
| 80 | - ], | 65 | + ] |
| 81 | - code: [{ required: true, trigger: "change", message: "验证码不能为空" }] | ||
| 82 | }, | 66 | }, |
| 83 | loading: false, | 67 | loading: false, |
| 84 | redirect: undefined | 68 | redirect: undefined |
| ... | @@ -93,23 +77,18 @@ export default { | ... | @@ -93,23 +77,18 @@ export default { |
| 93 | } | 77 | } |
| 94 | }, | 78 | }, |
| 95 | created() { | 79 | created() { |
| 96 | - //this.getCode(); | 80 | + |
| 97 | this.getCookie(); | 81 | this.getCookie(); |
| 98 | }, | 82 | }, |
| 99 | methods: { | 83 | methods: { |
| 100 | - getCode() { | 84 | + |
| 101 | - getCodeImg().then(res => { | ||
| 102 | - this.codeUrl = "data:image/gif;base64," + res.img; | ||
| 103 | - this.loginForm.uuid = res.uuid; | ||
| 104 | - }); | ||
| 105 | - }, | ||
| 106 | getCookie() { | 85 | getCookie() { |
| 107 | const username = localStorage.getItem("username"); | 86 | const username = localStorage.getItem("username"); |
| 108 | const password = localStorage.getItem("password"); | 87 | const password = localStorage.getItem("password"); |
| 109 | const rememberMe = localStorage.getItem('rememberMe') | 88 | const rememberMe = localStorage.getItem('rememberMe') |
| 110 | this.loginForm = { | 89 | this.loginForm = { |
| 111 | username: username === undefined ? this.loginForm.username : username, | 90 | username: username === undefined ? this.loginForm.username : username, |
| 112 | - password: password === undefined ? this.loginForm.password : decrypt(password), | 91 | + password: password === undefined ? this.loginForm.password : password, |
| 113 | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe) | 92 | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe) |
| 114 | }; | 93 | }; |
| 115 | }, | 94 | }, |
| ... | @@ -119,7 +98,7 @@ export default { | ... | @@ -119,7 +98,7 @@ export default { |
| 119 | this.loading = true; | 98 | this.loading = true; |
| 120 | if (this.loginForm.rememberMe) { | 99 | if (this.loginForm.rememberMe) { |
| 121 | localStorage.setItem("username", this.loginForm.username, { expires: 30 }); | 100 | localStorage.setItem("username", this.loginForm.username, { expires: 30 }); |
| 122 | - localStorage.setItem("password", encrypt(this.loginForm.password), { expires: 30 }); | 101 | + localStorage.setItem("password", this.loginForm.password, { expires: 30 }); |
| 123 | localStorage.setItem('rememberMe', this.loginForm.rememberMe, { expires: 30 }); | 102 | localStorage.setItem('rememberMe', this.loginForm.rememberMe, { expires: 30 }); |
| 124 | } else { | 103 | } else { |
| 125 | localStorage.removeItem("username"); | 104 | localStorage.removeItem("username"); | ... | ... |
| ... | @@ -34,7 +34,8 @@ module.exports = { | ... | @@ -34,7 +34,8 @@ module.exports = { |
| 34 | proxy: { | 34 | proxy: { |
| 35 | // detail: https://cli.vuejs.org/config/#devserver-proxy | 35 | // detail: https://cli.vuejs.org/config/#devserver-proxy |
| 36 | [process.env.VUE_APP_BASE_API]: { | 36 | [process.env.VUE_APP_BASE_API]: { |
| 37 | - target: `http://localhost:8080`, | 37 | + // target: `http://localhost:8080`, |
| 38 | + target: `http://192.168.1.45:8080`, | ||
| 38 | changeOrigin: true, | 39 | changeOrigin: true, |
| 39 | pathRewrite: { | 40 | pathRewrite: { |
| 40 | ['^' + process.env.VUE_APP_BASE_API]: '' | 41 | ['^' + process.env.VUE_APP_BASE_API]: '' | ... | ... |
-
Please register or login to post a comment