This commit is contained in:
Paidax
2024-07-24 15:10:07 +08:00
parent e2f6a9f4b1
commit 020b6c48ed
79 changed files with 7733 additions and 3760 deletions
+216 -77
View File
@@ -114,19 +114,19 @@
}
}
.login-code{
.icp {
color: black;
bottom: 33px;
position: absolute;
display: inline-block;
float: right;
width: 38%;
height: 38px;
left: 50%;
transform: translateX(-50%);
}
.login-code img{
vertical-align: middle;
cursor: pointer;
.icp a {
text-decoration: none;
color: black;
}
</style>
</head>
@@ -151,6 +151,7 @@
<div class="login-container">
<div class="login-content">
<div class="mobile-login-img">
<embed src="/m-login.svg" style="width: 100%" type="image/svg+xml"/>
</div>
@@ -160,79 +161,112 @@
${AppName!}系统登录
</h4>
<el-tabs class="login-tabs">
<el-tab-pane label="用户名登录">
<el-form :model="loginForm" :rules="loginRules" auto-complete="on"
class="login-form"
<!--<el-tab-pane label="用户名登录" name="1">
<el-form v-if="activeName == '1'" :model="loginForm" :rules="loginRules" auto-complete="on" class="login-form"
ref="loginForm">
<el-form-item prop="username">
<el-input
placeholder="账号或手机号码"
placeholder="请输入用户名"
prefix-icon="el-icon-user"
type="text"
v-model="loginForm.username"
>
v-model="loginForm.username">
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
@keyup.enter.native="doLogin"
placeholder="密码"
placeholder="请输入密码"
prefix-icon="el-icon-lock"
type="password"
v-model="loginForm.password"
>
v-model="loginForm.password">
</el-input>
</el-form-item>
<el-form-item prop="platformCaptcha">
<el-input
@keyup.enter.native="doLogin"
placeholder="验证码"
prefix-icon="el-icon-lock"
style="width: 60%"
type="password"
v-model="loginForm.platformCaptcha"
>
</el-input>
<div class="login-code">
<img :src="codeUrl" @click="getCode" alt="">
</div>
</el-form-item>
<el-form-item>
<el-button :disabled="disabled"
:loading="loading"
@click.native.prevent="doLogin"
@click.native.prevent="handleLogin"
class="login-button"
type="primary">
<span v-if="!loading">登 录</span>
<span v-else>登录中...</span>
</el-button>
</el-form-item>
</el-form>
</el-tab-pane>-->
<el-tab-pane label="短信快捷登陆">
<el-form :model="loginForm" :rules="loginRules" auto-complete="on" class="login-form"
ref="loginForm">
<el-form-item prop="mobile">
<el-input
placeholder="请输入手机号"
prefix-icon="el-icon-phone-outline"
type="text" maxlength="11"
v-model.number="loginForm.mobile">
</el-input>
</el-form-item>
<el-form-item prop="platformCaptcha">
<el-input @keyup.enter.native="doLogin" placeholder="请输入手机动态码" prefix-icon="el-icon-unlock" v-model="loginForm.platformCaptcha">
<el-button @click="sendCode()" type="primary" slot="append">{{ codeMsg }}</el-button>
</el-input>
</el-form-item>
<el-form-item>
<el-button :disabled="disabled"
:loading="loading"
@click.native.prevent="handleLogin"
class="login-button"
type="primary">
<span v-if="!loading">登 录</span>
<span v-else>登录中...</span>
</el-button>
</el-form-item>
</el-form>
</el-tab-pane>
</el-tabs>
</div>
</div>
<!--滑块验证-->
<el-dialog title="请拖动滑块完成拼图" width="360px" :visible.sync="isShowSliderVerify" :close-on-click-modal="false" @closed="refresh" append-to-body>
<slider-verify ref="sliderVerify" @success="onSuccess" @fail="onFail" @again="onAgain"></slider-verify>
</el-dialog>
<!--<div class="icp">
ICP证:<a href="https://beian.miit.gov.cn/" target="_blank">鄂ICP备16009506号-5</a>
</div>-->
</div>
</div>
</body>
<script src="${base!}/assets/platform/plugins/vue/vue.min.js"></script>
<script src="${base!}/assets/platform/plugins/element-ui/lib/index.js"></script>
<script src="${base!}/assets/platform/plugins/jquery/jquery-1.11.1.min.js"></script>
<script src="${base!}/assets/platform/plugins/jquery/jquery-3.5.1.min.js"></script>
<script src="${base!}/assets/platform/plugins/vue-loader/httpVueLoader.js"></script>
<script>
var vue = new Vue({
Vue.use(httpVueLoader)
</script>
<script>
const vue = new Vue({
el: '#app',
data() {
return {
// 是否禁用按钮
codeDisabled: false,
// 倒计时秒数
countdown: 60,
// 按钮上的文字
codeMsg: '获取动态码',
// 定时器
timer: null,
// 是否显示滑块验证
isShowSliderVerify: false,
loginForm: {
username: '',
password: '',
platformKey: '',
platformCaptcha: "",
platformCaptcha: '',
// 随机字符串
nonceStr: '',
// 验证值
value: '',
},
loginRules: {
username: [
@@ -241,46 +275,159 @@
password: [
{required: true, trigger: ['blur', 'change'], message: '密码不能为空'},
],
mobile: [
{ required: true, message: '手机号不能为空', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
],
platformCaptcha: [
{required: true, trigger: ['blur', 'change'], message: '验证码不能为空'},
{required: true, trigger: ['blur', 'change'], message: '动态码不能为空'},
],
},
loading: false,
disabled: false,
codeUrl: "${base!}/platform/login/captcha",
}
},
components: {
'slider-verify': httpVueLoader('/components/captcha/sliderVerify.vue'),
},
methods: {
async doLogin() {
try {
const valid = await this.$refs['loginForm'].validate()
if (valid) {
this.loading = true
const resp = await $.post("${base!}/platform/login/doLogin", this.loginForm)
this.loading = false
if (resp.code === 0) {
this.$message.success(resp.msg)
this.disabled = true
setTimeout(() => {
const redirect = this.getQueryString("redirect")
if (redirect) {
window.location.href = redirect
} else if (this.isMobile()) {
window.location.href = "${base!}/mobile/index"
} else {
window.location.href = "${base!}/platform/home"
}
}, 1000)
sendCode() {
if(this.codeDisabled) {
return
}
this.$refs.loginForm.validateField('mobile', async (valid) => {
if(!valid) {
const resp = await this.validMobile();
if (resp.code !== 0){
this.$message.warning(resp.msg)
return
}
/*发送验证码功能*/
//若发送验证码成功,则调用倒计时函数
const {code, data} = await $.post('/platform/login/mobileCaptcha', {mobile: this.loginForm.mobile})
if(code === 0) {
this.loginForm.platformKey = data.key
this.getCode();
} else {
this.$message.error(resp.msg)
this.getCode()
this.$message({showClose: true, type: 'warning', message: '动态码发送失败,请联系管理员'});
}
}
} catch (e) {
console.log(e)
})
},
// 获取验证码
getCode() {
// 验证码60秒倒计时
if (!this.timer) {
this.timer = setInterval(() => {
if (this.countdown > 0 && this.countdown <= 60) {
this.countdown--;
if (this.countdown !== 0) {
this.codeDisabled = true;
this.codeMsg = "重新发送(" + this.countdown + ")";
} else {
clearInterval(this.timer);
this.codeMsg = "获取动态码";
this.countdown = 60;
this.timer = null;
this.codeDisabled = false;
}
}
}, 1000)
}
},
//验证手机号是否存在
async validMobile() {
return await $.post('${base!}/platform/login/validMobile', {mobile: this.loginForm.mobile})
},
//验证图片滑动
async validVerify() {
return await $.post('${base!}/platform/login/validVerify', {
nonceStr: this.loginForm.nonceStr,
value: this.loginForm.value,
})
},
/* 滑动验证成功*/
async onSuccess(captcha) {
Object.assign(this.loginForm, captcha);
const resp = await this.validVerify()
if(resp.code === 0) {
await this.doLogin();
} else {
this.$refs.sliderVerify.verifyFailEvent(resp.msg);
}
},
/* 滑动验证失败*/
onFail(msg) {
this.message('error', msg || '验证失败,请控制拼图对齐缺口');
},
/* 滑动验证异常*/
onAgain() {
this.message('error', '滑动操作异常,请重试');
this.$refs.sliderVerify.refresh();
},
/* 刷新验证码*/
refresh() {
this.$refs.sliderVerify.refresh();
},
/* 提示弹框*/
message(type, message) {
this.$message({
showClose: true,
type: type,
message: message,
duration: 1500,
});
},
handleLogin() {
let self = this;
self.$refs.loginForm.validate((flag) => {
self.isShowSliderVerify = flag;
});
},
async doLogin() {
const valid = await this.$refs['loginForm'].validate()
if (valid) {
this.loginForm.loginType = 'SMS_CODE'
const resp = await $.post('${base!}/platform/login/doLogin', this.loginForm)
if (resp.code === 0) {
this.$message.success(resp.msg)
setTimeout(() => {
const redirect = this.getQueryString("redirect")
if (redirect) {
window.location.href = redirect
} else if (this.isMobile()) {
window.location.href = "${base!}/mobile/index"
} else {
window.location.href = "${base!}/platform/home"
}
}, 1000)
} else {
this.$message.error(resp.msg)
this.isShowSliderVerify = false;
}
}
/*$.post(url, self.loginForm, function (d) {
if (d.code == 0) {
self.$refs.sliderVerify.verifySuccessEvent();
self.$message({
showClose: true,
type: 'success',
message: '登录成功,正在跳转首页...',
duration: 1000
});
setTimeout(() => {
window.location.href = "${base!}/platform/home"
}, 500);
} else {
self.$message({
message: d.msg,
type: 'error'
})
self.isShowSliderVerify = false;
}
}, "json");*/
},
getQueryString(name) {
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
let r = window.location.search.substr(1).match(reg);
@@ -303,24 +450,16 @@
isMobile = true;
}
return isMobile;
},
async getCode() {
const {data} = await $.get('/platform/login/captcha')
this.codeUrl = data.codeUrl
this.loginForm.platformKey = data.key
}
},
created() {
this.year = new Date().getFullYear()
},
mounted() {
window.addEventListener('pageshow', (event) => {
console.log(event)
this.loading = false
this.disabled = false
})
},
created(){
this.getCode()
}
})
</script>