Files
dvcp_v2_wxcp_app/src/pages/login.vue

109 lines
2.6 KiB
Vue
Raw Normal View History

2021-11-15 10:29:05 +08:00
<template>
<section class="login">
2022-05-30 18:46:49 +08:00
<div v-if="appPath" class="gotoApp">
<b v-text="appPath"/>
<div>正在登录...</div>
</div>
2021-11-18 16:40:43 +08:00
<u-form :model="form" ref="loginForm" label-width="140" :rules="rules">
2021-11-15 15:53:44 +08:00
<u-form-item label="账号" prop="username">
2022-05-30 18:46:49 +08:00
<input v-model="form.username" placeholder="请输入手机号"/>
2021-11-15 10:29:05 +08:00
</u-form-item>
2021-11-15 15:53:44 +08:00
<u-form-item label="密码" prop="password">
2022-05-30 18:46:49 +08:00
<input type="password" v-model="form.password" placeholder="请输入密码" @confirm="handleLogin"/>
2021-11-15 10:29:05 +08:00
</u-form-item>
</u-form>
2022-05-30 18:46:49 +08:00
<div class="btn" @tap="handleLogin">登录</div>
2021-11-15 10:29:05 +08:00
</section>
</template>
<script>
2022-05-30 18:46:49 +08:00
import {mapActions, mapMutations, mapState} from "vuex";
2021-11-15 10:29:05 +08:00
export default {
name: "login",
computed: {
2022-05-30 18:46:49 +08:00
...mapState(['apps']),
2021-11-15 10:29:05 +08:00
rules() {
return {
2021-11-15 15:53:44 +08:00
username: [{required: true, message: "请输入 手机号"}],
password: [{required: true, message: "请输入 密码"}],
2021-11-15 10:29:05 +08:00
}
2022-05-30 18:46:49 +08:00
},
target() {
return decodeURIComponent(this.$route.query.back) || ""
},
2022-05-31 09:55:33 +08:00
currentApp() {
2022-06-09 10:23:58 +08:00
let path = this.target.replace(/(.+)[\\\/][^\\\/]+\??.*/, '$1')
2022-06-08 17:07:34 +08:00
return this.apps.find(e => e.libPath.indexOf(path) > -1) || {}
2022-05-31 09:55:33 +08:00
},
2022-05-30 18:46:49 +08:00
appPath() {
2022-05-31 09:55:33 +08:00
return this.currentApp?.label || ""
2021-11-15 10:29:05 +08:00
}
},
data() {
return {
2021-11-15 15:53:44 +08:00
form: {}
2021-11-15 10:29:05 +08:00
}
},
methods: {
2021-11-15 15:53:44 +08:00
...mapActions(['getToken']),
...mapMutations(['login']),
2021-11-15 10:29:05 +08:00
handleLogin() {
2021-11-25 16:02:53 +08:00
this.$refs.loginForm.validate(v => {
2021-11-15 10:29:05 +08:00
if (v) {
2022-06-08 17:07:34 +08:00
let {name: module, libPath} = this.currentApp,
corpId = 'ww596787bb70f08288'
if (/\/project\/police\//.test(libPath)) {
2022-06-06 10:15:45 +08:00
module = 'hnjc'
2022-06-08 17:07:34 +08:00
} else if (/\/project\/beta\//.test(libPath)) {
corpId = 'ww2a667717a70164f1'
module = 'wangge'
2022-06-06 10:15:45 +08:00
}
2022-06-08 17:07:34 +08:00
this.getToken({...this.form, module, corpId}).then(() => {
2022-05-30 18:46:49 +08:00
this.target ? uni.reLaunch({url: this.target}) : uni.navigateBack({})
2021-11-18 16:40:43 +08:00
}).catch(() => 0)
2021-11-15 10:29:05 +08:00
}
})
2021-11-25 16:02:53 +08:00
},
},
mounted() {
this.$refs.loginForm.setRules(this.rules)
2021-11-15 10:29:05 +08:00
}
}
</script>
<style lang="scss" scoped>
.login {
border-top: 1px solid #D4D4D4;
padding: 0 0 208px;
background: #F5F5F5;
box-sizing: border-box;
height: 100%;
2022-05-30 18:46:49 +08:00
.btn {
position: fixed;
left: 0;
bottom: 0;
width: 100vw;
background: $uni-color-primary;
color: #fff;
text-align: center;
line-height: 96px;
font-size: 32px;
2021-11-15 10:29:05 +08:00
}
2022-05-30 18:46:49 +08:00
.gotoApp {
background: #fff;
text-align: center;
padding: 32px;
b {
display: block;
font-size: 40px;
margin-bottom: 8px;
}
}
2021-11-15 10:29:05 +08:00
}
</style>