<template>
|
<view class="login_index">
|
<view class="login_header">
|
<view class="login_header_title">
|
<!-- 登录 -->
|
</view>
|
<view class="login_header_icon">
|
<u-image src="@/static/login-icon.png" width="70px" height="70px"></u-image>
|
</view>
|
</view>
|
<view class="login_content">
|
<view class="login_content_title">
|
管片数字工厂
|
</view>
|
<view class="login_content_form">
|
<u-form
|
ref="form"
|
:model="formLogin"
|
:rules="rulesLogin">
|
<u-form-item prop="username" borderBottom>
|
<u-input
|
v-model="formLogin.username"
|
border="none"
|
placeholder="请输入手机号码"
|
clearable>
|
<template slot="prefix">
|
<u-icon name="account" label="|" labelColor="#EDEDED" labelSize="12px"></u-icon>
|
</template>
|
</u-input>
|
</u-form-item>
|
<u-form-item prop="password" borderBottom>
|
<u-input
|
v-model="formLogin.password"
|
border="none"
|
clearable
|
placeholder="请输入密码"
|
type="password">
|
<template slot="prefix">
|
<u-icon name="lock" label="|" labelColor="#EDEDED" labelSize="12px"></u-icon>
|
</template>
|
</u-input>
|
</u-form-item>
|
<u-text type="primary" text="立即注册" @click="navGotoRegister()"></u-text>
|
<view class="login_content_button">
|
<u-button
|
type="primary"
|
:color="colorStyle"
|
@click="submitForm()">登录
|
</u-button>
|
</view>
|
</u-form>
|
<view class="login_content_info">
|
<!-- 登录代表你已同意<span>《用户协议》</span>和<span>《隐私政策》</span> -->
|
</view>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import { throttle } from '../../plugins/public';
|
export default {
|
data() {
|
return {
|
formLogin: {
|
username: '',
|
// username: '14798989898',
|
password: ''
|
},
|
rulesLogin: {
|
username: [{
|
required: true,
|
message: '请输入手机号码',
|
trigger: 'blur',
|
},
|
{
|
// 自定义验证函数,见上说明
|
validator: (rule, value, callback) => {
|
return uni.$u.test.mobile(value);
|
},
|
message: '请输入正确的手机号码',
|
trigger: 'blur',
|
}],
|
password: [{
|
required: true,
|
message: '请输入密码',
|
trigger: 'blur',
|
}]
|
},
|
colorStyle: 'linear-gradient(to right, rgb(79, 142, 244), rgb(85, 109, 254))'
|
}
|
},
|
onShow() {
|
const that = this;
|
uni.clearStorage();
|
uni.clearStorageSync();
|
wx.getSetting({
|
complete: (info) => {
|
if(!info.authSetting['scope.userInfo']) {
|
uni.showModal({
|
title: '提示',
|
content: '是否授权获取您的信息,该信息仅用于确认身份信息',
|
success: function (res) {
|
if (res.confirm) {
|
wx.login({
|
success(res) {
|
uni.$u.toast('授权成功!');
|
that.$api.system.getUserInfo(res.code).then((res) => {
|
if(res.success) {
|
uni.setStorageSync('openId', res.data.openid);
|
that.$api.system.changeWChartUser({
|
openId: res.data.openid
|
}).then((reslut) => {
|
console.log(reslut);
|
that.switchUserInfo(reslut.data.regstatus, reslut.data.reginfo);
|
})
|
} else {
|
uni.$u.toast(res.statusMsg);
|
}
|
})
|
},
|
fail: (err) => {
|
console.log(err,'---');
|
}
|
})
|
} else if (res.cancel) {
|
wx.exitMiniProgram({
|
success: (res) => {
|
console.log(res,'--');
|
}
|
})
|
}
|
}
|
});
|
} else {
|
wx.login({
|
success(res) {
|
that.$api.system.getUserInfo(res.code).then((res) => {
|
if(res.success) {
|
uni.setStorageSync('openId', res.data.openid);
|
that.$api.system.changeWChartUser({
|
openId: res.data.openid
|
}).then((reslut) => {
|
that.switchUserInfo(reslut.data.regstatus, reslut.data.reginfo);
|
})
|
} else {
|
uni.$u.toast(res.statusMsg);
|
}
|
})
|
},
|
fail: (err) => {
|
console.log(err,'---');
|
}
|
})
|
}
|
}
|
})
|
},
|
onReady() {
|
this.$refs.form.setRules(this.rulesLogin);
|
},
|
methods: {
|
// 立即注册
|
navGotoRegister: throttle(function() {
|
uni.navigateTo({
|
url: '../registerIndex/index'
|
})
|
}, 3000),
|
// 检查用户信息
|
switchUserInfo(status, data) {
|
switch(status) {
|
// case 0:
|
// uni.$u.toast('当前用户未注册');
|
// break;
|
// case 2:
|
// uni.$u.toast('您的信息暂未审核,请联系您的管理人员');
|
// break;
|
case 3:
|
uni.$u.toast('您的审核未通过, 请检查注册信息后重新提交!');
|
setTimeout(() => {
|
uni.navigateTo({
|
url: '../registerIndex/index?data=' + JSON.stringify(data)
|
})
|
}, 2000)
|
break;
|
}
|
},
|
// 提交登录信息
|
submitForm: throttle(function() {
|
this.$refs.form.validate().then((valid) => {
|
console.log(valid);
|
if(valid) {
|
const params = Object.assign({}, this.formLogin);
|
this.$api.system.userLogin(params).then((res) => {
|
console.log(res.data, '----');
|
if(res.success) {
|
uni.$u.toast('登录成功!');
|
uni.setStorageSync('realName', res.data.realName);
|
uni.setStorageSync('telphone', res.data.telphone);
|
uni.setStorageSync('userType', res.data.userType);
|
uni.setStorageSync('menus', res.data.menus);
|
uni.setStorageSync('userToken', res.data.token);
|
if(res.data.userType === 1){
|
uni.navigateTo({
|
url: '../robeHome/index',
|
fail(err) {
|
console.log(err,'???');
|
}
|
})
|
}else{
|
uni.navigateTo({
|
url: '../labourHome/index',
|
fail(err) {
|
console.log(err,'???');
|
}
|
})
|
}
|
} else {
|
uni.$u.toast(res.statusMsg);
|
}
|
}).catch((err) => {
|
uni.$u.toast('请检查网络服务!')
|
})
|
}
|
})
|
}, 3000),
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.login_index {
|
position: relative;
|
width: 100vw;
|
height: 100vh;
|
background: #F6F6F6;
|
|
.login_header {
|
position: relative;
|
width: 100%;
|
height: 50%;
|
// background: #556DFE;
|
background: url('http://filemanage.thhy-tj.com:8888/group1/M00/00/04/bx5d1GR1awaAOSrGAADytgHWrpk815.png') no-repeat;
|
background-size: 100% 100%;
|
border-radius: 0 0 20px 20px;
|
|
.login_header_title {
|
padding: 40px 0 0;
|
color: #fff;
|
font-size: 20px;
|
text-align: center;
|
}
|
|
.login_header_icon {
|
position: absolute;
|
top: 50%;
|
left: 50%;
|
transform: translateX(-50%) translateY(-45%);
|
padding: 15px;
|
border-radius: 15px;
|
background: #FFFFFF;
|
}
|
}
|
|
.login_content {
|
position: absolute;
|
top: 50%;
|
left: 50%;
|
transform: translateX(-50%) translateY(-30%);
|
padding: 20px;
|
width: calc(90% - 40px);
|
border-radius: 15px;
|
box-shadow: 0 2px 12px 0 rgba(120, 83, 251, 0.3);
|
background: #fff;
|
|
.login_content_title {
|
padding: 10px 0;
|
font-size: 24px;
|
text-align: center;
|
}
|
|
.login_content_form {
|
padding: 20px 0 0;
|
}
|
.login_content_button {
|
margin-top: 40px;
|
}
|
|
.login_content_info {
|
padding: 20px 0 0;
|
font-size: 12px;
|
text-align: center;
|
|
& span {
|
color: #556DFE;
|
}
|
}
|
}
|
}
|
|
::v-deep .u-form-item__body__right__message {
|
margin-left: 0 !important;
|
}
|
::v-deep .u-form-item {
|
margin-bottom: 10px;
|
}
|
::v-deep .u-text {
|
justify-content: flex-end !important;
|
}
|
</style>
|