海信交通一体化小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

191 lines
5.1 KiB

<template>
<view class="page" style="background: #2D8CF0 url(../../static/image/loginBg.png) center top no-repeat;background-size: 750rpx 482rpx;">
<view class="login_form_warp">
<view class="login_title">登录</view>
<view class="login_form_item">
<uni-easyinput placeholderStyle="color:#c8c8c8;font-size:24rpx;" prefixIcon="person" v-model="form.username" placeholder="请输入账号" maxlength="20"></uni-easyinput>
</view>
<view class="login_form_item">
<uni-easyinput placeholderStyle="color:#c8c8c8;font-size:24rpx;" prefixIcon="locked" type="password" v-model="form.password" placeholder="请输入密码" maxlength="20"></uni-easyinput>
</view>
<view class="login_form_item" style="background-color: #f6f6f6;border-radius: 10rpx;padding:0 10rpx;">
<view class="vercode_label">验证码:</view>
<uni-easyinput placeholderStyle="color:#c8c8c8;font-size:24rpx;" v-model="form.verCode" placeholder="请输入图形验证码" maxlength="20"></uni-easyinput>
<image :src="codeImg" @click="getVerCode" style="width: 180rpx; height:59rpx;"></image>
</view>
<view class="login_btn" @click="doLogin">登录</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
form: {
username: '',
password: '',
verCode: '',
vercodeType: 5
}, //登录form
codeImg: '', //图形验证码
}
},
onLoad() {
this.getVerCode();
},
methods: {
//获取图形验证码
getVerCode() {
this.$request1(getApp().globalData.baseUrl + '/api/common/captchaBase64?type=5&_t=' + Date.parse(new Date()), {}, 'GET').then(res => {
if(res.code == 200) {
this.codeImg = res.data.img;
}
}).catch(() => {
console.log('vercode err')
})
},
//登录
doLogin() {
console.log('login',this.form)
if(this.form.username == '' || this.form.password == '') {
uni.showToast({
title: '用户名密码不能为空',
icon: 'none'
})
return;
} else if(this.form.verCode == '') {
uni.showToast({
title: '验证码不能为空',
icon: 'none'
})
return;
}
uni.showLoading({
title: '登录中...',
mask: true
})
this.$request1(getApp().globalData.baseUrl + '/api/login/auth', this.form, 'POST').then(res => {
uni.hideLoading();
if(res.code == 200) {
uni.setStorageSync('satoken', res.data.satoken);
this.getUserInfo();
this.getDeptName();
this.getRouters();
}
}).catch((err) => {
console.log(err)
uni.hideLoading();
uni.showToast({
title: err.data.msg ? err.data.msg : '登录失败',
icon: 'none'
})
this.getVerCode();//重新获取验证码
})
},
//拉取用户信息
getUserInfo() {
this.$request(getApp().globalData.baseUrl + '/api/login/info', {}, 'POST').then(res => {
if(res.code == 200) {
uni.setStorageSync('userInfo', res.data);
}
}).catch(() => {
})
},
//拉取所属单位
getDeptName() {
this.$request(getApp().globalData.baseUrl + '/api/user/getDeptName', {}, 'GET').then(res => {
if(res.code == 200) {
uni.setStorageSync('deptName', res.data);
}
}).catch(() => {
})
},
//拉取权限路由
getRouters() {
this.$request(getApp().globalData.baseUrl + '/api/login/getRouters', {}, 'GET').then(res => {
if(res.code == 200 && res.data.length == 1) {
uni.redirectTo({
url: '/pages/home/index?routers=' + JSON.stringify(res.data[0])
})
}else{
uni.redirectTo({
url: '/pages/home/home'
})
}
}).catch(() => {
})
},
}
}
</script>
<style lang="scss" scoped>
.page{
position: relative;
height: 100vh;
overflow: hidden;
}
.login_form_warp{
position: absolute;
left: 0;
right:0;
bottom:0;
background-color: #fff;
box-shadow: 0rpx -25rpx 46rpx 1rpx rgba(0,0,0,0.13);
border-radius: 40rpx 40rpx 0rpx 0rpx;
padding: 50rpx;
.login_title{
color: #333;
line-height: 59rpx;
font-size: 42rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
margin-bottom: 60rpx;
}
.sub_title{
color: #666;
line-height: 33rpx;
font-size: 24rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
margin: 10rpx 0 60rpx;
}
.login_form_item {
display: flex;
align-items: center;
background: #F6F6F6;
margin-bottom: 50rpx;
.vercode_label{
width: 96rpx;
color: #333;
line-height: 59rpx;
font-size: 24rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
}
::v-deep .content-clear-icon{
padding:0 10rpx;
}
::v-deep .is-input-border{
border: 0 !important;
background-color: #f6f6f6 !important;
border-radius: 10rpx !important;
}
::v-deep .uni-easyinput__content-input{
height: 90rpx !important;
border: 0;
background-color: #f6f6f6 !important;
}
}
}
.login_btn {
background-color: #2D8CF0;
color: #ffffff;
font-size: 28rpx;
line-height: 90rpx;
font-family: PingFang SC-Regular, PingFang SC;
border-radius: 100rpx;
text-align: center;
margin: 70rpx auto 50rpx;
}
</style>