2024-03-12 09:27:48 +08:00
|
|
|
|
<template>
|
2024-04-18 08:26:16 +08:00
|
|
|
|
<view class="common-container">
|
|
|
|
|
|
<!-- 登录图片 -->
|
|
|
|
|
|
<view class="login-banner-box">
|
|
|
|
|
|
<u--image :showLoading="true" src="/static/images/ui/login.png" width="360px" height="240px"></u--image>
|
2024-03-12 10:02:38 +08:00
|
|
|
|
</view>
|
2024-04-18 08:26:16 +08:00
|
|
|
|
<!-- 登录框 -->
|
|
|
|
|
|
<view class="login-form-box">
|
|
|
|
|
|
<!-- 登录表单 -->
|
|
|
|
|
|
<u--form labelPosition="left" :model="loginForm" ref="uForm">
|
|
|
|
|
|
<u-form-item prop="username" borderBottom>
|
2024-07-15 15:29:29 +08:00
|
|
|
|
<u--input v-model="loginForm.username" border="none" placeholder="账号" prefixIcon="account"
|
|
|
|
|
|
prefixIconStyle="font-size: 22px;color: #909399"></u--input>
|
2024-04-18 08:26:16 +08:00
|
|
|
|
</u-form-item>
|
|
|
|
|
|
<u-form-item prop="password" borderBottom>
|
2024-07-15 15:29:29 +08:00
|
|
|
|
<u--input v-model="loginForm.password" border="none" placeholder="密码" prefixIcon="lock"
|
|
|
|
|
|
prefixIconStyle="font-size: 22px;color: #909399"></u--input>
|
2024-04-18 08:26:16 +08:00
|
|
|
|
</u-form-item>
|
|
|
|
|
|
<u-form-item prop="BaseUrl" borderBottom>
|
2024-07-15 15:29:29 +08:00
|
|
|
|
<u-input v-model="BaseUrl" border="none" placeholder="连接地址,例:127.0.0.1:8888" prefixIcon="ie"
|
|
|
|
|
|
prefixIconStyle="font-size: 22px;color: #909399">
|
2024-04-18 08:26:16 +08:00
|
|
|
|
<template slot="suffix">
|
2024-07-15 15:29:29 +08:00
|
|
|
|
<u-button type="primary" size="mini" text="修改地址" @click="handlerBaseUrlConfirm"
|
|
|
|
|
|
shape="circle"></u-button>
|
2024-04-18 08:26:16 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</u-input>
|
|
|
|
|
|
</u-form-item>
|
2024-05-15 14:52:20 +08:00
|
|
|
|
<u-form-item prop="button" style="margin-top: 60px">
|
2024-07-15 15:29:29 +08:00
|
|
|
|
<u-button @click="handleLogin" type="primary" :color="buttonColor" text="登录"
|
|
|
|
|
|
shape="circle"></u-button>
|
2024-04-18 08:26:16 +08:00
|
|
|
|
</u-form-item>
|
|
|
|
|
|
</u--form>
|
2024-03-12 10:02:38 +08:00
|
|
|
|
</view>
|
2024-05-15 14:52:20 +08:00
|
|
|
|
|
2024-04-18 08:26:16 +08:00
|
|
|
|
<!-- 无网络处理 -->
|
|
|
|
|
|
<u-no-network></u-no-network>
|
2024-05-15 14:52:20 +08:00
|
|
|
|
<view class="bangben">版本号:{{ version }}</view>
|
2024-03-12 10:02:38 +08:00
|
|
|
|
</view>
|
2024-03-12 09:27:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-07-15 15:29:29 +08:00
|
|
|
|
import {
|
|
|
|
|
|
getCodeImg
|
|
|
|
|
|
} from '@/api/login';
|
|
|
|
|
|
import {
|
|
|
|
|
|
getToken,
|
|
|
|
|
|
setToken,
|
|
|
|
|
|
removeToken
|
|
|
|
|
|
} from '@/utils/auth';
|
|
|
|
|
|
import {
|
|
|
|
|
|
getBaseUrl,
|
|
|
|
|
|
setBaseUrl,
|
|
|
|
|
|
removeBaseUrl
|
|
|
|
|
|
} from '@/utils/baseUrl';
|
|
|
|
|
|
import {
|
|
|
|
|
|
getLoginInfo,
|
|
|
|
|
|
setLoginInfo,
|
|
|
|
|
|
removeLoginInfo
|
|
|
|
|
|
} from '@/utils/loginInfo';
|
|
|
|
|
|
import config from '@/config';
|
|
|
|
|
|
export default {
|
|
|
|
|
|
onLoad() {
|
|
|
|
|
|
const systemInfo = uni.getSystemInfoSync();
|
|
|
|
|
|
this.version = systemInfo.appVersion;
|
2024-03-12 10:02:38 +08:00
|
|
|
|
},
|
2024-07-15 15:29:29 +08:00
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
version: '',
|
|
|
|
|
|
codeUrl: '',
|
|
|
|
|
|
captchaEnabled: false,
|
|
|
|
|
|
// 用户注册开关
|
|
|
|
|
|
register: false,
|
|
|
|
|
|
globalConfig: getApp().globalData.config,
|
|
|
|
|
|
BaseUrl: '127.0.0.1:8888',
|
|
|
|
|
|
buttonColor: 'linear-gradient(to right, #3296F9, #235FF5)',
|
|
|
|
|
|
loginForm: {
|
|
|
|
|
|
username: '',
|
|
|
|
|
|
password: '',
|
|
|
|
|
|
code: '',
|
|
|
|
|
|
uuid: ''
|
2024-03-12 10:02:38 +08:00
|
|
|
|
}
|
2024-07-15 15:29:29 +08:00
|
|
|
|
};
|
2024-05-15 14:52:20 +08:00
|
|
|
|
},
|
2024-07-15 15:29:29 +08:00
|
|
|
|
created() {
|
|
|
|
|
|
this.init();
|
|
|
|
|
|
// this.getCode();
|
2024-05-15 14:52:20 +08:00
|
|
|
|
},
|
2024-07-15 15:29:29 +08:00
|
|
|
|
methods: {
|
|
|
|
|
|
init() {
|
|
|
|
|
|
// 初始化链接地址设计
|
|
|
|
|
|
let baseUrl = getBaseUrl();
|
|
|
|
|
|
if (!baseUrl) {
|
|
|
|
|
|
baseUrl = '192.168.60.251:8888';
|
|
|
|
|
|
setBaseUrl(baseUrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.BaseUrl = baseUrl;
|
|
|
|
|
|
// 初始化用户登录存储
|
|
|
|
|
|
try {
|
|
|
|
|
|
let loginInfoStr = getLoginInfo();
|
|
|
|
|
|
let loginInfo = JSON.parse(loginInfoStr);
|
|
|
|
|
|
if (loginInfo) {
|
|
|
|
|
|
this.loginForm.username = loginInfo.username;
|
|
|
|
|
|
this.loginForm.password = loginInfo.password;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// console.log(e);
|
|
|
|
|
|
//TODO handle the exception
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
// 获取图形验证码
|
|
|
|
|
|
getCode() {
|
|
|
|
|
|
getCodeImg().then((res) => {
|
|
|
|
|
|
if (res.code !== 200) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '获取验证码失败!请检查网络!',
|
|
|
|
|
|
icon: 'error'
|
|
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const result = res.data;
|
|
|
|
|
|
if (result.captchaOff === 'off') {
|
|
|
|
|
|
this.captchaEnabled = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.captchaEnabled = true;
|
2024-05-15 14:52:20 +08:00
|
|
|
|
}
|
2024-07-15 15:29:29 +08:00
|
|
|
|
this.codeUrl = 'data:image/gif;base64,' + result.img;
|
|
|
|
|
|
this.loginForm.uuid = result.uuid;
|
2024-05-15 14:52:20 +08:00
|
|
|
|
});
|
2024-07-15 15:29:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 登录方法
|
|
|
|
|
|
async handleLogin() {
|
|
|
|
|
|
// debug快速登录
|
|
|
|
|
|
if (this.loginForm.username === 'debug') {
|
|
|
|
|
|
setToken('123');
|
|
|
|
|
|
this.$tab.reLaunch('/pages/index/index');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.loginForm.username === '') {
|
|
|
|
|
|
this.$modal.msgError('请输入您的账号');
|
|
|
|
|
|
} else if (this.loginForm.password === '') {
|
|
|
|
|
|
this.$modal.msgError('请输入您的密码');
|
|
|
|
|
|
} else if (this.loginForm.code === '' && this.captchaEnabled) {
|
|
|
|
|
|
this.$modal.msgError('请输入验证码');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$modal.loading('登录中,请耐心等待...');
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.$modal.closeLoading();
|
|
|
|
|
|
}, 30000);
|
|
|
|
|
|
this.pwdLogin();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 密码登录
|
|
|
|
|
|
async pwdLogin() {
|
|
|
|
|
|
this.$store
|
|
|
|
|
|
.dispatch('Login', this.loginForm)
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const loginInfo = {
|
|
|
|
|
|
username: this.loginForm.username,
|
|
|
|
|
|
password: this.loginForm.password
|
|
|
|
|
|
}
|
|
|
|
|
|
const loginInfoStr = JSON.stringify(loginInfo);
|
|
|
|
|
|
setLoginInfo(loginInfoStr);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$modal.closeLoading();
|
|
|
|
|
|
this.loginSuccess();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
this.$modal.closeLoading();
|
|
|
|
|
|
if (this.captchaEnabled) {
|
|
|
|
|
|
this.getCode();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
// 登录成功后,处理函数
|
|
|
|
|
|
loginSuccess(result) {
|
|
|
|
|
|
// 获取户信息
|
|
|
|
|
|
this.$store.dispatch('GetInfo').then((res) => {
|
|
|
|
|
|
this.$tab.reLaunch('/pages/index/index');
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
// 确认修改链接地址
|
|
|
|
|
|
handlerBaseUrlConfirm() {
|
|
|
|
|
|
const baseUrl = this.BaseUrl;
|
|
|
|
|
|
// console.log('changeBaseUrl', baseUrl);
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '链接地址已修改:' + baseUrl,
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
|
|
|
|
|
setBaseUrl(baseUrl);
|
|
|
|
|
|
}
|
2024-03-12 10:02:38 +08:00
|
|
|
|
}
|
2024-07-15 15:29:29 +08:00
|
|
|
|
};
|
2024-03-12 09:27:48 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2024-07-15 15:29:29 +08:00
|
|
|
|
.bangben {
|
|
|
|
|
|
margin-top: 110px;
|
|
|
|
|
|
margin-left: 35%;
|
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@import url('login.scss');
|
|
|
|
|
|
</style>
|