<template>
|
<view class="mainbox">
|
<img src="/static/images/loginbg.png" class="bgbox">
|
<div class="top">
|
<img :src="logoSrc" mode="scaleToFill" alt="" class="logo" @error="handleImageError">
|
</div>
|
<input type="text" class="nickname" placeholder="手机号码" v-model="loginForm.username">
|
<input type="text" class="nickname" placeholder="身份证号" v-model="loginForm.sfzh">
|
<input type="password" class="nickname" placeholder="密码默认为身份证号后6位" v-model="loginForm.password">
|
<div class="btn" @tap="login" :disabled="loading">
|
<div class="txt">{{ loading ? '登录中...' : '登录' }}</div>
|
</div>
|
<div class="btn1" @tap="edit" :disabled="loading">
|
<div class="txt">修改电话</div>
|
</div>
|
</view>
|
</template>
|
<script>
|
import {
|
login1
|
} from '@/api/login'
|
import {
|
getToken,
|
setToken,
|
removeToken
|
} from '@/utils/auth'
|
// import {
|
// encrypt,decrypt
|
// } from '@/utils/crypto.js'
|
export default {
|
name: "Login",
|
data() {
|
return {
|
code: '',
|
userInfo: {},
|
codeUrl: "",
|
val: "",
|
canIUseGetUserProfile: false,
|
globalConfig: getApp().globalData.config,
|
loginForm: {
|
username: "", // 手机号码
|
password: "", // 身份证号后6位
|
mobile: false,
|
sfzh: ""
|
},
|
loading: false,
|
logoSrc: '/static/images/logo.png', // 默认 Logo
|
}
|
},
|
onLoad(options) {
|
// 获取传递的 code 参数并设置 logoSrc
|
|
if (uni.getStorageSync('hospId')) {
|
this.code = uni.getStorageSync('hospId')
|
this.logoSrc = `http://47.109.86.30:5902/img/${this.code}-logo.png`;
|
}
|
uni.showToast({
|
title: '加载中...',
|
icon: 'loading',
|
duration: 500
|
});
|
if (uni.getUserProfile) {
|
this.canIUseGetUserProfile = true;
|
}
|
},
|
onShow() {
|
this.localtoken = uni.getStorageSync('localtoken');
|
console.log('localtoken:', this.localtoken);
|
},
|
methods: {
|
// 处理图片加载失败
|
handleImageError() {
|
this.logoSrc = '/static/images/logo.png'; // 加载失败时使用默认本地 Logo
|
},
|
edit() {
|
uni.navigateTo({
|
url: `/pages/edit` // ?code=${this.code}传递 item.code
|
});
|
},
|
// 登录方法
|
// 登录页面 script
|
login() {
|
// 防止重复点击
|
if (this.loading) return;
|
|
// 校验输入
|
const {
|
username,
|
sfzh,
|
password
|
} = this.loginForm;
|
if (!username || !sfzh || !password) {
|
uni.showToast({
|
title: '请输入完整的账号、身份证号和密码',
|
icon: 'none'
|
});
|
return;
|
}
|
|
this.loading = true;
|
// console.log('loginForm:', this.loginForm);
|
// 加密对象
|
// let data = JSON.stringify(this.loginForm)
|
// const encryptedUserData = encrypt(data);
|
// console.log('加密后的数据:', encryptedUserData);
|
|
// 解密数据
|
// const decryptedUserData = decrypt(encryptedUserData);
|
// console.log('解密后的对象:', decryptedUserData);
|
// 调用登录 API
|
login1(this.loginForm).then((res) => {
|
console.log(res);
|
if (res.code == 200) {
|
// 设置 token
|
setToken(res.token);
|
// 序列化 orderList(如果不存在,传空数组)
|
// const orderList = encodeURIComponent(JSON.stringify(res.orderList || []));
|
// 序列化 sfzh
|
// const sfzh = encodeURIComponent(JSON.stringify(this.loginForm.sfzh));
|
localStorage.setItem('orderList', JSON.stringify(res.orderList));
|
localStorage.setItem('sfzh', JSON.stringify(this.loginForm.sfzh));
|
// 跳转到 friendReport 页面,传递 orderList 和 sfzh
|
uni.reLaunch({
|
// ?orderList=${orderList}&sfzh=${sfzh}
|
url: `/pages/friendReport/friendReport`
|
});
|
} else {
|
uni.showToast({
|
title: '账号或密码错误',
|
icon: 'none'
|
});
|
}
|
}).catch((err) => {
|
console.error('Login error:', err);
|
uni.showToast({
|
title: '登录失败,请稍后重试',
|
icon: 'none'
|
});
|
}).finally(() => {
|
this.loading = false; // 重置 loading 状态
|
});
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.mainbox {
|
display: flex;
|
height: 1624rpx;
|
flex-direction: column;
|
|
.bgbox {
|
width: 750rpx;
|
height: 1624rpx;
|
position: absolute;
|
z-index: -1;
|
}
|
|
.top {
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
width: 100%;
|
margin-top: 200rpx;
|
|
.logo {
|
width: 124rpx;
|
height: 140rpx;
|
margin-bottom: 16rpx;
|
}
|
|
.logotxt {
|
width: 165rpx;
|
height: 62rpx;
|
margin-bottom: 81rpx;
|
}
|
}
|
|
.nickname {
|
width: 540rpx;
|
height: 96rpx;
|
background: #F4F5F8;
|
border-radius: 48rpx;
|
margin: 0 auto 40rpx;
|
padding-left: 50rpx;
|
font-size: 32rpx;
|
color: #9496A2;
|
}
|
|
.btn {
|
width: 540rpx;
|
height: 96rpx;
|
background: #419FFD;
|
border-radius: 48rpx;
|
margin: 25rpx auto 25rpx;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
opacity: 1;
|
|
&[disabled] {
|
opacity: 0.6;
|
}
|
}
|
|
.btn1 {
|
width: 540rpx;
|
height: 96rpx;
|
background: #54adff;
|
border-radius: 48rpx;
|
margin: 25rpx auto 25rpx;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
opacity: 1;
|
|
&[disabled] {
|
opacity: 0.6;
|
}
|
}
|
|
.txt {
|
font-size: 32rpx;
|
color: #FFFFFF;
|
}
|
}
|
</style>
|