登录接口调试,项目正常运行,基础管理菜单基本分配
This commit is contained in:
parent
e23954a9de
commit
eb4e8c8c13
|
|
@ -5,11 +5,11 @@ import request from '@/utils/request'
|
||||||
|
|
||||||
/** 新增工程 */
|
/** 新增工程 */
|
||||||
export const addProjectApi = (data) => {
|
export const addProjectApi = (data) => {
|
||||||
return request.post('/xxx/xx', data)
|
return request.post('/base/project/add', data)
|
||||||
}
|
}
|
||||||
/** 删除工程 */
|
/** 删除工程 */
|
||||||
export const deleteProjectApi = (id) => {
|
export const deleteProjectApi = (id) => {
|
||||||
return request.delete('/xxx/xx', id)
|
return request.delete('/base/project/deleteProById', id)
|
||||||
}
|
}
|
||||||
/** 修改工程 */
|
/** 修改工程 */
|
||||||
export const editProjectApi = (data) => {
|
export const editProjectApi = (data) => {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export const deleteUnitTypeApi = (id) => {
|
||||||
}
|
}
|
||||||
/** 修改单位类型*/
|
/** 修改单位类型*/
|
||||||
export const editUnitTypeApi = (data) => {
|
export const editUnitTypeApi = (data) => {
|
||||||
return request.post('/xxx/xx', data)
|
return request.post('/base/unittype/update', data)
|
||||||
}
|
}
|
||||||
/** 单位类型列表查询 */
|
/** 单位类型列表查询 */
|
||||||
export const queryUnitTypeListApi = (data) => {
|
export const queryUnitTypeListApi = (data) => {
|
||||||
|
|
|
||||||
|
|
@ -12,47 +12,46 @@ const whiteList = ['/login', '/register']
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
NProgress.start()
|
NProgress.start()
|
||||||
|
if (getToken()) {
|
||||||
|
console.log(getToken())
|
||||||
|
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
|
||||||
|
/* has token*/
|
||||||
|
if (to.path === '/login') {
|
||||||
|
next({ path: '/' })
|
||||||
|
NProgress.done()
|
||||||
|
} else if (whiteList.indexOf(to.path) !== -1) {
|
||||||
next()
|
next()
|
||||||
// if (getToken()) {
|
} else {
|
||||||
// console.log(getToken())
|
if (store.getters.roles.length === 0) {
|
||||||
// to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
|
isRelogin.show = true
|
||||||
// /* has token*/
|
// 判断当前用户是否已拉取完user_info信息
|
||||||
// if (to.path === '/login') {
|
store.dispatch('GetInfo').then(() => {
|
||||||
// next({ path: '/' })
|
isRelogin.show = false
|
||||||
// NProgress.done()
|
store.dispatch('GenerateRoutes').then(accessRoutes => {
|
||||||
// } else if (whiteList.indexOf(to.path) !== -1) {
|
// 根据roles权限生成可访问的路由表
|
||||||
// next()
|
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
||||||
// } else {
|
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
||||||
// if (store.getters.roles.length === 0) {
|
})
|
||||||
// isRelogin.show = true
|
}).catch(err => {
|
||||||
// // 判断当前用户是否已拉取完user_info信息
|
store.dispatch('LogOut').then(() => {
|
||||||
// store.dispatch('GetInfo').then(() => {
|
Message.error(err)
|
||||||
// isRelogin.show = false
|
next({ path: '/' })
|
||||||
// store.dispatch('GenerateRoutes').then(accessRoutes => {
|
})
|
||||||
// // 根据roles权限生成可访问的路由表
|
})
|
||||||
// router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
} else {
|
||||||
// next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
next()
|
||||||
// })
|
}
|
||||||
// }).catch(err => {
|
}
|
||||||
// store.dispatch('LogOut').then(() => {
|
} else {
|
||||||
// Message.error(err)
|
// 没有token
|
||||||
// next({ path: '/' })
|
if (whiteList.indexOf(to.path) !== -1) {
|
||||||
// })
|
// 在免登录白名单,直接进入
|
||||||
// })
|
next()
|
||||||
// } else {
|
} else {
|
||||||
// next()
|
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页
|
||||||
// }
|
NProgress.done()
|
||||||
// }
|
}
|
||||||
// } else {
|
}
|
||||||
// // 没有token
|
|
||||||
// if (whiteList.indexOf(to.path) !== -1) {
|
|
||||||
// // 在免登录白名单,直接进入
|
|
||||||
// next()
|
|
||||||
// } else {
|
|
||||||
// next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页
|
|
||||||
// NProgress.done()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.afterEach(() => {
|
router.afterEach(() => {
|
||||||
|
|
|
||||||
|
|
@ -72,30 +72,30 @@ export const constantRoutes = [
|
||||||
name: 'Index',
|
name: 'Index',
|
||||||
meta: { title: '首页', icon: 'dashboard', affix: true }
|
meta: { title: '首页', icon: 'dashboard', affix: true }
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
path: 'ProjectManage',
|
// path: 'ProjectManage',
|
||||||
component: () => import('@/views/base/project'),
|
// component: () => import('@/views/base/project'),
|
||||||
name: 'ProjectManage',
|
// name: 'ProjectManage',
|
||||||
meta: { title: '工程管理', icon: 'dashboard', affix: true }
|
// meta: { title: '工程管理', icon: 'dashboard', affix: true }
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
path: 'ContactUnits',
|
// path: 'ContactUnits',
|
||||||
component: () => import('@/views/base/contun'),
|
// component: () => import('@/views/base/contun'),
|
||||||
name: 'ContactUnits',
|
// name: 'ContactUnits',
|
||||||
meta: { title: '往来单位', icon: 'dashboard', affix: true }
|
// meta: { title: '往来单位', icon: 'dashboard', affix: true }
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
path: 'UnitType',
|
// path: 'UnitType',
|
||||||
component: () => import('@/views/base/unitType'),
|
// component: () => import('@/views/base/unitType'),
|
||||||
name: 'UnitType',
|
// name: 'UnitType',
|
||||||
meta: { title: '单位类型', icon: 'dashboard', affix: true }
|
// meta: { title: '单位类型', icon: 'dashboard', affix: true }
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
path: 'ProtocolManage',
|
// path: 'ProtocolManage',
|
||||||
component: () => import('@/views/base/agreement'),
|
// component: () => import('@/views/base/agreement'),
|
||||||
name: 'ProtocolManage',
|
// name: 'ProtocolManage',
|
||||||
meta: { title: '协议管理', icon: 'dashboard', affix: true }
|
// meta: { title: '协议管理', icon: 'dashboard', affix: true }
|
||||||
}
|
// }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ const user = {
|
||||||
commit('SET_TOKEN', data.access_token)
|
commit('SET_TOKEN', data.access_token)
|
||||||
setExpiresIn(data.expires_in)
|
setExpiresIn(data.expires_in)
|
||||||
commit('SET_EXPIRES_IN', data.expires_in)
|
commit('SET_EXPIRES_IN', data.expires_in)
|
||||||
|
|
||||||
|
console.log(res, '登录成功')
|
||||||
resolve()
|
resolve()
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@
|
||||||
>
|
>
|
||||||
<el-row type="flex" justify="space-between" :gutter="24">
|
<el-row type="flex" justify="space-between" :gutter="24">
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item label="工程名称" prop="scrapNum">
|
<el-form-item label="工程名称" prop="projectName">
|
||||||
<el-input v-model="projectParams.scrapNum" />
|
<el-input v-model="projectParams.projectName" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item label="工程编号" prop="pro_code">
|
<el-form-item label="工程编号" prop="pcNo">
|
||||||
<el-input v-model="projectParams.pro_code" />
|
<el-input v-model="projectParams.pcNo" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
@ -110,6 +110,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { addProjectApi } from '@/api/base/project.js'
|
||||||
export default {
|
export default {
|
||||||
name: 'FormProject',
|
name: 'FormProject',
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -126,8 +127,8 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
projectParams: {
|
projectParams: {
|
||||||
scrapNum: '',
|
projectName: '', // 工程名称
|
||||||
pro_code: '',
|
pcNo: '', // 工程编号
|
||||||
pro_unit: '',
|
pro_unit: '',
|
||||||
pro_type_of: '',
|
pro_type_of: '',
|
||||||
pro_type: '',
|
pro_type: '',
|
||||||
|
|
@ -137,7 +138,7 @@ export default {
|
||||||
},
|
},
|
||||||
// 校验规则
|
// 校验规则
|
||||||
projectParamsRules: {
|
projectParamsRules: {
|
||||||
scrapNum: [
|
projectName: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入工程名称',
|
message: '请输入工程名称',
|
||||||
|
|
@ -178,7 +179,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
/** 确认按钮 */
|
/** 确认按钮 */
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.$refs.projectParamsRef.validate((valid) => {
|
this.$refs.projectParamsRef.validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
console.log('校验通过')
|
console.log('校验通过')
|
||||||
// 1. 表单校验通过后调后台 Api
|
// 1. 表单校验通过后调后台 Api
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="login">
|
<div class="login">
|
||||||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
<el-form
|
||||||
|
ref="loginForm"
|
||||||
|
:model="loginForm"
|
||||||
|
:rules="loginRules"
|
||||||
|
class="login-form"
|
||||||
|
>
|
||||||
<h3 class="title">博诺思后台管理系统</h3>
|
<h3 class="title">博诺思后台管理系统</h3>
|
||||||
<el-form-item prop="username">
|
<el-form-item prop="username">
|
||||||
<el-input
|
<el-input
|
||||||
|
|
@ -9,7 +14,11 @@
|
||||||
auto-complete="off"
|
auto-complete="off"
|
||||||
placeholder="账号"
|
placeholder="账号"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="user"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="password">
|
<el-form-item prop="password">
|
||||||
|
|
@ -20,7 +29,11 @@
|
||||||
placeholder="密码"
|
placeholder="密码"
|
||||||
@keyup.enter.native="handleLogin"
|
@keyup.enter.native="handleLogin"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="password"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="code" v-if="captchaEnabled">
|
<el-form-item prop="code" v-if="captchaEnabled">
|
||||||
|
|
@ -31,26 +44,40 @@
|
||||||
style="width: 63%"
|
style="width: 63%"
|
||||||
@keyup.enter.native="handleLogin"
|
@keyup.enter.native="handleLogin"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="validCode"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
<div class="login-code">
|
<div class="login-code">
|
||||||
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
<img
|
||||||
|
:src="codeUrl"
|
||||||
|
@click="getCode"
|
||||||
|
class="login-code-img"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
|
<el-checkbox
|
||||||
<el-form-item style="width:100%;">
|
v-model="loginForm.rememberMe"
|
||||||
|
style="margin: 0px 0px 25px 0px"
|
||||||
|
>记住密码</el-checkbox
|
||||||
|
>
|
||||||
|
<el-form-item style="width: 100%">
|
||||||
<el-button
|
<el-button
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
size="medium"
|
size="medium"
|
||||||
type="primary"
|
type="primary"
|
||||||
style="width:100%;"
|
style="width: 100%"
|
||||||
@click.native.prevent="handleLogin"
|
@click.native.prevent="handleLogin"
|
||||||
>
|
>
|
||||||
<span v-if="!loading">登 录</span>
|
<span v-if="!loading">登 录</span>
|
||||||
<span v-else>登 录 中...</span>
|
<span v-else>登 录 中...</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
<div style="float: right;" v-if="register">
|
<div style="float: right" v-if="register">
|
||||||
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
<router-link class="link-type" :to="'/register'"
|
||||||
|
>立即注册</router-link
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
@ -62,97 +89,130 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from "@/api/login";
|
import { getCodeImg } from '@/api/login'
|
||||||
import Cookies from "js-cookie";
|
import Cookies from 'js-cookie'
|
||||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: 'Login',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
codeUrl: "",
|
codeUrl: '',
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: "admin",
|
username: 'admin',
|
||||||
password: "admin123",
|
password: 'admin123',
|
||||||
rememberMe: false,
|
rememberMe: false,
|
||||||
code: "",
|
code: '',
|
||||||
uuid: ""
|
uuid: '',
|
||||||
},
|
},
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [
|
username: [
|
||||||
{ required: true, trigger: "blur", message: "请输入您的账号" }
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
message: '请输入您的账号',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, trigger: "blur", message: "请输入您的密码" }
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
message: '请输入您的密码',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
code: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'change',
|
||||||
|
message: '请输入验证码',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
// 验证码开关
|
// 验证码开关
|
||||||
captchaEnabled: true,
|
captchaEnabled: true,
|
||||||
// 注册开关
|
// 注册开关
|
||||||
register: false,
|
register: false,
|
||||||
redirect: undefined
|
redirect: undefined,
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
$route: {
|
$route: {
|
||||||
handler: function(route) {
|
handler: function (route) {
|
||||||
this.redirect = route.query && route.query.redirect;
|
this.redirect = route.query && route.query.redirect
|
||||||
|
},
|
||||||
|
immediate: true,
|
||||||
},
|
},
|
||||||
immediate: true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getCode();
|
this.getCode()
|
||||||
this.getCookie();
|
this.getCookie()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
getCode() {
|
||||||
getCodeImg().then(res => {
|
getCodeImg().then(res => {
|
||||||
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
this.captchaEnabled =
|
||||||
|
res.captchaEnabled === undefined ? true : res.captchaEnabled
|
||||||
if (this.captchaEnabled) {
|
if (this.captchaEnabled) {
|
||||||
this.codeUrl = "data:image/gif;base64," + res.img;
|
this.codeUrl = 'data:image/gif;base64,' + res.img
|
||||||
this.loginForm.uuid = res.uuid;
|
this.loginForm.uuid = res.uuid
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
getCookie() {
|
getCookie() {
|
||||||
const username = Cookies.get("username");
|
const username = Cookies.get('username')
|
||||||
const password = Cookies.get("password");
|
const password = Cookies.get('password')
|
||||||
const rememberMe = Cookies.get('rememberMe')
|
const rememberMe = Cookies.get('rememberMe')
|
||||||
this.loginForm = {
|
this.loginForm = {
|
||||||
username: username === undefined ? this.loginForm.username : username,
|
username:
|
||||||
password: password === undefined ? this.loginForm.password : decrypt(password),
|
username === undefined ? this.loginForm.username : username,
|
||||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
password:
|
||||||
};
|
password === undefined
|
||||||
|
? this.loginForm.password
|
||||||
|
: decrypt(password),
|
||||||
|
rememberMe:
|
||||||
|
rememberMe === undefined ? false : Boolean(rememberMe),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
handleLogin() {
|
handleLogin() {
|
||||||
this.$refs.loginForm.validate(valid => {
|
this.$refs.loginForm.validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true;
|
this.loading = true
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
Cookies.set('username', this.loginForm.username, {
|
||||||
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
expires: 30,
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
})
|
||||||
|
Cookies.set(
|
||||||
|
'password',
|
||||||
|
encrypt(this.loginForm.password),
|
||||||
|
{ expires: 30 },
|
||||||
|
)
|
||||||
|
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
||||||
|
expires: 30,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove("username");
|
Cookies.remove('username')
|
||||||
Cookies.remove("password");
|
Cookies.remove('password')
|
||||||
Cookies.remove('rememberMe');
|
Cookies.remove('rememberMe')
|
||||||
}
|
}
|
||||||
this.$store.dispatch("Login", this.loginForm).then(() => {
|
this.$store
|
||||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
.dispatch('Login', this.loginForm)
|
||||||
}).catch(() => {
|
.then(() => {
|
||||||
this.loading = false;
|
this.$router
|
||||||
|
.push({ path: this.redirect || '/' })
|
||||||
|
.catch(() => {})
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.loading = false
|
||||||
if (this.captchaEnabled) {
|
if (this.captchaEnabled) {
|
||||||
this.getCode();
|
this.getCode()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style rel="stylesheet/scss" lang="scss">
|
<style rel="stylesheet/scss" lang="scss">
|
||||||
|
|
@ -161,7 +221,7 @@ export default {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-image: url("../assets/images/login-background.jpg");
|
background-image: url('../assets/images/login-background.jpg');
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
.title {
|
.title {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="login">
|
<div class="login">
|
||||||
<div class="login-form">
|
<div class="login-form">
|
||||||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
<el-form
|
||||||
|
ref="loginForm"
|
||||||
|
:model="loginForm"
|
||||||
|
:rules="loginRules"
|
||||||
|
class="login-form"
|
||||||
|
>
|
||||||
<h3 class="title">博诺思后台管理系统</h3>
|
<h3 class="title">博诺思后台管理系统</h3>
|
||||||
<template v-if="loginMethod === 'password'">
|
<template v-if="loginMethod === 'password'">
|
||||||
<el-form-item prop="username">
|
<el-form-item prop="username">
|
||||||
|
|
@ -12,7 +17,11 @@
|
||||||
auto-complete="off"
|
auto-complete="off"
|
||||||
placeholder="手机号/用户名/邮箱"
|
placeholder="手机号/用户名/邮箱"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="user"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="password">
|
<el-form-item prop="password">
|
||||||
|
|
@ -23,7 +32,11 @@
|
||||||
placeholder="密码"
|
placeholder="密码"
|
||||||
@keyup.enter.native="handleLogin"
|
@keyup.enter.native="handleLogin"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="password"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="code" v-if="captchaEnabled">
|
<el-form-item prop="code" v-if="captchaEnabled">
|
||||||
|
|
@ -34,10 +47,18 @@
|
||||||
style="width: 63%"
|
style="width: 63%"
|
||||||
@keyup.enter.native="handleLogin"
|
@keyup.enter.native="handleLogin"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="validCode"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
<div class="login-code">
|
<div class="login-code">
|
||||||
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
<img
|
||||||
|
:src="codeUrl"
|
||||||
|
@click="getCode"
|
||||||
|
class="login-code-img"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -49,7 +70,11 @@
|
||||||
auto-complete="off"
|
auto-complete="off"
|
||||||
placeholder="手机号/邮箱"
|
placeholder="手机号/邮箱"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="user"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="code" v-if="captchaEnabled">
|
<el-form-item prop="code" v-if="captchaEnabled">
|
||||||
|
|
@ -60,42 +85,67 @@
|
||||||
style="width: 63%"
|
style="width: 63%"
|
||||||
@keyup.enter.native="handleLogin"
|
@keyup.enter.native="handleLogin"
|
||||||
>
|
>
|
||||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="validCode"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
<div class="login-code">
|
<div class="login-code">
|
||||||
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
<img
|
||||||
|
:src="codeUrl"
|
||||||
|
@click="getCode"
|
||||||
|
class="login-code-img"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="verificationCode">
|
<el-form-item prop="verificationCode">
|
||||||
<el-input v-model="loginForm.verificationCode" placeholder="请输入验证码">
|
<el-input
|
||||||
|
v-model="loginForm.verificationCode"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
>
|
||||||
<template slot="append">
|
<template slot="append">
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="sendCode"
|
@click="sendCode"
|
||||||
:disabled="isSendingCode || !loginForm.code"
|
:disabled="
|
||||||
|
isSendingCode || !loginForm.code
|
||||||
|
"
|
||||||
class="send-code-button"
|
class="send-code-button"
|
||||||
>
|
>
|
||||||
{{ countdown === 0 ? '获取验证码' : `${countdown}s` }}
|
{{
|
||||||
|
countdown === 0
|
||||||
|
? '获取验证码'
|
||||||
|
: `${countdown}s`
|
||||||
|
}}
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
<svg-icon slot="prefix" icon-class="message" class="el-input__icon input-icon"/>
|
<svg-icon
|
||||||
|
slot="prefix"
|
||||||
|
icon-class="message"
|
||||||
|
class="el-input__icon input-icon"
|
||||||
|
/>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
<div class="login-form-center">
|
<div class="login-form-center">
|
||||||
<el-link @click="toggleLoginMethod">{{ loginMethod === 'password' ? '短信登录' : '密码登录' }}</el-link>
|
<el-link @click="toggleLoginMethod">{{
|
||||||
|
loginMethod === 'password' ? '短信登录' : '密码登录'
|
||||||
|
}}</el-link>
|
||||||
<router-link to="/register">
|
<router-link to="/register">
|
||||||
<el-link>注册账号</el-link>
|
<el-link>注册账号</el-link>
|
||||||
</router-link>
|
</router-link>
|
||||||
<el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
|
<el-checkbox v-model="loginForm.rememberMe"
|
||||||
|
>记住密码</el-checkbox
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<el-form-item style="width: 100%;">
|
<el-form-item style="width: 100%">
|
||||||
<el-button
|
<el-button
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
size="medium"
|
size="medium"
|
||||||
type="primary"
|
type="primary"
|
||||||
style="width: 100%;"
|
style="width: 100%"
|
||||||
@click.native.prevent="isLogin"
|
@click.native.prevent="handleLogin"
|
||||||
>
|
>
|
||||||
<span v-if="!loading">登 录</span>
|
<span v-if="!loading">登 录</span>
|
||||||
<span v-else>登 录 中...</span>
|
<span v-else>登 录 中...</span>
|
||||||
|
|
@ -105,13 +155,13 @@
|
||||||
<div class="login-divider">第三方登录</div>
|
<div class="login-divider">第三方登录</div>
|
||||||
<div class="login-icons">
|
<div class="login-icons">
|
||||||
<div class="login-icon">
|
<div class="login-icon">
|
||||||
<img :src="dingding" alt="Weibo">
|
<img :src="dingding" alt="Weibo" />
|
||||||
</div>
|
</div>
|
||||||
<div class="login-icon">
|
<div class="login-icon">
|
||||||
<img :src="wx" alt="WeChat">
|
<img :src="wx" alt="WeChat" />
|
||||||
</div>
|
</div>
|
||||||
<div class="login-icon">
|
<div class="login-icon">
|
||||||
<img :src="qq" alt="QQ">
|
<img :src="qq" alt="QQ" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -146,16 +196,46 @@ export default {
|
||||||
verificationCode: '',
|
verificationCode: '',
|
||||||
uuid: '',
|
uuid: '',
|
||||||
loginType: '',
|
loginType: '',
|
||||||
mobileCodeType: 'login'
|
mobileCodeType: 'login',
|
||||||
},
|
},
|
||||||
passwordLoginRules: {
|
passwordLoginRules: {
|
||||||
username: [{ required: true, trigger: 'blur', message: '请输入您的账号' }],
|
username: [
|
||||||
password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }],
|
{
|
||||||
code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
message: '请输入您的账号',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
password: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
message: '请输入您的密码',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
code: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'change',
|
||||||
|
message: '请输入验证码',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
mobileLoginRules: {
|
mobileLoginRules: {
|
||||||
mobile: [{ required: true, trigger: 'blur', message: '请输入您的手机号' }],
|
mobile: [
|
||||||
verificationCode: [{ required: true, trigger: 'blur', message: '请输入验证码' }]
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
message: '请输入您的手机号',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
verificationCode: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
trigger: 'blur',
|
||||||
|
message: '请输入验证码',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
captchaEnabled: true,
|
captchaEnabled: true,
|
||||||
|
|
@ -164,21 +244,23 @@ export default {
|
||||||
countdown: 0,
|
countdown: 0,
|
||||||
loginMethod: 'password', // 'password' or 'mobile'
|
loginMethod: 'password', // 'password' or 'mobile'
|
||||||
supportsPhoneLogin: false,
|
supportsPhoneLogin: false,
|
||||||
supportsEmailLogin: false
|
supportsEmailLogin: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
loginRules() {
|
loginRules() {
|
||||||
return this.loginMethod === 'password' ? this.passwordLoginRules : this.mobileLoginRules
|
return this.loginMethod === 'password'
|
||||||
}
|
? this.passwordLoginRules
|
||||||
|
: this.mobileLoginRules
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
$route: {
|
$route: {
|
||||||
handler(route) {
|
handler(route) {
|
||||||
this.redirect = route.query && route.query.redirect
|
this.redirect = route.query && route.query.redirect
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getCode()
|
this.getCode()
|
||||||
|
|
@ -187,7 +269,8 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
getCode() {
|
||||||
getCodeImg().then(res => {
|
getCodeImg().then(res => {
|
||||||
this.captchaEnabled = res.captchaEnabled !== undefined ? res.captchaEnabled : true
|
this.captchaEnabled =
|
||||||
|
res.captchaEnabled !== undefined ? res.captchaEnabled : true
|
||||||
if (this.captchaEnabled) {
|
if (this.captchaEnabled) {
|
||||||
this.codeUrl = 'data:image/gif;base64,' + res.img
|
this.codeUrl = 'data:image/gif;base64,' + res.img
|
||||||
this.loginForm.uuid = res.uuid
|
this.loginForm.uuid = res.uuid
|
||||||
|
|
@ -207,17 +290,30 @@ export default {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set('username', this.loginForm.username, { expires: 30 })
|
Cookies.set('username', this.loginForm.username, {
|
||||||
Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 })
|
expires: 30,
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
|
})
|
||||||
|
Cookies.set(
|
||||||
|
'password',
|
||||||
|
encrypt(this.loginForm.password),
|
||||||
|
{ expires: 30 },
|
||||||
|
)
|
||||||
|
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
||||||
|
expires: 30,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove('username')
|
Cookies.remove('username')
|
||||||
Cookies.remove('password')
|
Cookies.remove('password')
|
||||||
Cookies.remove('rememberMe')
|
Cookies.remove('rememberMe')
|
||||||
}
|
}
|
||||||
this.loginForm.loginType = this.loginMethod
|
this.loginForm.loginType = this.loginMethod
|
||||||
this.$store.dispatch('Login', this.loginForm)
|
|
||||||
.then(() => this.$router.push({ path: this.redirect || '/' }))
|
this.$store
|
||||||
|
.dispatch('Login', this.loginForm)
|
||||||
|
.then(() => {
|
||||||
|
console.log(this.redirect, '重定向的地址')
|
||||||
|
this.$router.push({ path: this.redirect || '/' })
|
||||||
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
if (this.captchaEnabled) this.getCode()
|
if (this.captchaEnabled) this.getCode()
|
||||||
|
|
@ -230,9 +326,17 @@ export default {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set('username', this.loginForm.username, { expires: 30 })
|
Cookies.set('username', this.loginForm.username, {
|
||||||
Cookies.set('password', encrypt(this.loginForm.password), { expires: 30 })
|
expires: 30,
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
|
})
|
||||||
|
Cookies.set(
|
||||||
|
'password',
|
||||||
|
encrypt(this.loginForm.password),
|
||||||
|
{ expires: 30 },
|
||||||
|
)
|
||||||
|
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
||||||
|
expires: 30,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove('username')
|
Cookies.remove('username')
|
||||||
Cookies.remove('password')
|
Cookies.remove('password')
|
||||||
|
|
@ -240,15 +344,22 @@ export default {
|
||||||
}
|
}
|
||||||
let that = this
|
let that = this
|
||||||
this.loginForm.loginType = this.loginMethod
|
this.loginForm.loginType = this.loginMethod
|
||||||
this.$store.dispatch('IsLogin', this.loginForm)
|
this.$store
|
||||||
|
.dispatch('Login', this.loginForm)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
this.$modal.confirm('账号已在其他地方登录是否继续登录!!!!').then(function() {
|
this.$modal
|
||||||
|
.confirm(
|
||||||
|
'账号已在其他地方登录是否继续登录!!!!',
|
||||||
|
)
|
||||||
|
.then(function () {
|
||||||
return that.handleLogin()
|
return that.handleLogin()
|
||||||
}).then(() => {
|
})
|
||||||
this.loading = false;
|
.then(() => {
|
||||||
}).catch(() => {
|
this.loading = false
|
||||||
this.loading = false;
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.loading = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
that.handleLogin()
|
that.handleLogin()
|
||||||
|
|
@ -271,7 +382,8 @@ export default {
|
||||||
this.$message.error('请先填写手机号')
|
this.$message.error('请先填写手机号')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.$store.dispatch('GetPhoneCode', this.loginForm)
|
this.$store
|
||||||
|
.dispatch('GetPhoneCode', this.loginForm)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.isSendingCode = true
|
this.isSendingCode = true
|
||||||
this.countdown = 60
|
this.countdown = 60
|
||||||
|
|
@ -293,18 +405,18 @@ export default {
|
||||||
this.isSendingCode = false
|
this.isSendingCode = false
|
||||||
this.countdown = 0
|
this.countdown = 0
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
,
|
|
||||||
toggleLoginMethod() {
|
toggleLoginMethod() {
|
||||||
this.loginMethod = this.loginMethod === 'password' ? 'mobile' : 'password'
|
this.loginMethod =
|
||||||
|
this.loginMethod === 'password' ? 'mobile' : 'password'
|
||||||
this.loginForm.username = ''
|
this.loginForm.username = ''
|
||||||
this.loginForm.password = ''
|
this.loginForm.password = ''
|
||||||
this.loginForm.code = ''
|
this.loginForm.code = ''
|
||||||
this.loginForm.verificationCode = ''
|
this.loginForm.verificationCode = ''
|
||||||
this.loginForm.loginMethod = ''
|
this.loginForm.loginMethod = ''
|
||||||
this.getCode()
|
this.getCode()
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -314,7 +426,7 @@ export default {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-image: url("../assets/images/bg.png");
|
background-image: url('../assets/images/bg.png');
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,11 +526,11 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-divider:not(:empty)::before {
|
.login-divider:not(:empty)::before {
|
||||||
margin-right: .25em;
|
margin-right: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-divider:not(:empty)::after {
|
.login-divider:not(:empty)::after {
|
||||||
margin-left: .25em;
|
margin-left: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-icons {
|
.login-icons {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ module.exports = {
|
||||||
proxy: {
|
proxy: {
|
||||||
// detail: https://cli.vuejs.org/config/#devserver-proxy
|
// detail: https://cli.vuejs.org/config/#devserver-proxy
|
||||||
[process.env.VUE_APP_BASE_API]: {
|
[process.env.VUE_APP_BASE_API]: {
|
||||||
target: `http://192.168.2.130:18080`,
|
target: `http://192.168.2.39:18080`,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: {
|
pathRewrite: {
|
||||||
['^' + process.env.VUE_APP_BASE_API]: ''
|
['^' + process.env.VUE_APP_BASE_API]: ''
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue