<template>
|
<view>
|
<view class="list">
|
<view class="list-call">
|
<u-icon class="u-icon" size="40" name="account"></u-icon>
|
<input
|
class="u-input"
|
type="text"
|
v-model="userInfo.username"
|
maxlength="32"
|
:placeholder="$t('login.placeholderAccount')"
|
/>
|
</view>
|
<view class="list-call">
|
<u-icon class="u-icon" size="40" name="lock"></u-icon>
|
<input
|
class="u-input"
|
type="text"
|
v-model="userInfo.password"
|
maxlength="32"
|
:placeholder="$t('login.placeholderPassword')"
|
:password="!showPassword"
|
/>
|
<image
|
class="u-icon-right"
|
:src="
|
'/static/custom/login/eye_' +
|
(showPassword ? 'open' : 'close') +
|
'.png'
|
"
|
@click="showPass()"
|
></image>
|
</view>
|
<u-radio-group v-model="remember" style="margin-top: 30rpx;" @change="checkboxChange">
|
<u-radio shape="square" name="1" :checked="1" >记住密码</u-radio>
|
</u-radio-group>
|
</view>
|
<view class="button custom-botton" hover-class="button-hover" @click="submit()">
|
<text>{{ $t("login.loginButton") }}</text>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import { encryption } from "@/utils";
|
|
export default {
|
name: "userPassword",
|
data() {
|
return {
|
userInfo: {
|
username: "",
|
password: ""
|
},
|
showPassword: false,
|
remember: '',
|
baseUrl: "",
|
};
|
},
|
created() {
|
if (process.env.NODE_ENV == 'development') {
|
// this.userInfo = {
|
// username: "admin",
|
// password: "zttZTT123!"
|
// }
|
}
|
this.remember = uni.getStorageSync('remember');
|
// 检查本地存储中是否有记住的用户名和密码
|
const savedUsername = uni.getStorageSync('username');
|
const savedPassword = uni.getStorageSync('password');
|
if (savedUsername && savedPassword) {
|
this.userInfo.username = savedUsername;
|
this.userInfo.password = savedPassword;
|
}
|
},
|
methods: {
|
showPass() {
|
this.showPassword = !this.showPassword;
|
},
|
//登录
|
submit() {
|
//表单校验
|
if (this.userInfo.username.length === 0) {
|
this.$u.toast("请输入账号");
|
return;
|
}
|
if (this.userInfo.password.length === 0) {
|
this.$u.toast("请输入密码");
|
return;
|
}
|
|
//构造登录参数
|
const user = encryption({
|
data: this.userInfo,
|
key: "pigxpigxpigxpigx",
|
param: ["password"],
|
});
|
|
let grant_type = "password";
|
//登录接口
|
this.$u.api
|
.login(
|
{
|
randomStr: 'blockPuzzle',
|
code: '',
|
grant_type
|
},
|
{
|
username: user.username,
|
password: user.password
|
},
|
{
|
Authorization: "Basic cGlnOnBpZw==",
|
"content-type": "application/x-www-form-urlencoded",
|
isToken: false,
|
"TENANT-ID": "1",
|
}
|
)
|
.then((res) => {
|
//提示
|
this.$u.toast("恭喜您,登录成功!");
|
if (this.remember == 1) {
|
uni.setStorageSync('username', this.userInfo.username);
|
uni.setStorageSync('password', this.userInfo.password);
|
uni.setStorageSync('remember', this.remember);
|
} else {
|
// 如果用户未勾选“记住我”,清除本地存储中的用户名和密码
|
uni.removeStorageSync('username');
|
uni.removeStorageSync('password');
|
uni.removeStorageSync('remember');
|
}
|
console.log('dadasd', res)
|
// 登陆成功,存储相关信息
|
this.$u.vuex("vuex_token", res.access_token);
|
this.$u.vuex("vuex_refresh_token", res.refresh_token);
|
this.$u.vuex("vuex_username", res.user_info.staffName);
|
this.$u.vuex("vuex_userId", res.user_info.id);
|
//this.$u.vuex("vuex_client_id", res.client_id);
|
this.$u.vuex("vuex_user", res.user_info);
|
|
//查询用户详细信息并储存
|
/*this.$u.api.user.getUserInfo().then((res) => {
|
console.log("获取用户信息:", res);
|
this.$u.vuex("vuex_user", res.data.sysUser);
|
});*/
|
|
//跳转页面
|
setTimeout(() => {
|
uni.reLaunch({
|
url: "/pages/sys/home/index",
|
});
|
}, 500);
|
})
|
.catch((e) => {
|
this.$u.toast(e);
|
});
|
},
|
checkboxChange(e) {
|
console.log('e---', e)
|
this.remember = e
|
console.log('this.remember222---', this.remember)
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
@import "index.scss";
|
|
.custom-botton{
|
height: 96rpx;
|
background: #214DED;
|
box-shadow: 0rpx 6rpx 8rpx 0rpx rgba(4,49,212,0.3);
|
border-radius: 16rpx;
|
line-height: 96rpx;
|
}
|
</style>
|