Files
dvcp_v2_wxcp_app/src/pages/login.vue

143 lines
3.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: {
...mapActions(['getToken', 'getAccount', 'getCode']),
2022-06-14 09:44:09 +08:00
...mapMutations(['login', 'logout', 'setModule']),
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-07-25 14:26:26 +08:00
this.getSystem().then(({module, corpId}) => this.handleSignIn({...this.form, module, corpId}))
2021-11-15 10:29:05 +08:00
}
})
2021-11-25 16:02:53 +08:00
},
2022-06-10 16:24:29 +08:00
handleLogout() {
2022-06-10 16:46:03 +08:00
this.$http.delete("/auth/token/logout").finally(() => this.logout())
2022-07-25 14:21:30 +08:00
},
handleSignIn(params) {
2022-07-25 14:26:26 +08:00
return this.getToken(params).then(() => {
2022-07-25 14:21:30 +08:00
if (module != 'AppCountryAlbum') {
this.getAccount({module})
}
this.target ? uni.reLaunch({url: this.target}) : uni.navigateBack({})
2022-07-25 14:26:26 +08:00
}).catch(() => 0)
2022-07-25 14:21:30 +08:00
},
getSystem() {
let {name: module, libPath} = this.currentApp,
corpId = 'ww596787bb70f08288'
if (/\/project\/police\//.test(libPath)) {
module = 'hnjc'
} else if (/\/project\/saas\//.test(libPath)) {
module = 'online'
} else if (/\/project\/xincheng\//.test(libPath)) {
module = 'xaxc'
2022-12-30 16:26:52 +08:00
} else if (/\/project\/qianxinan\//.test(libPath)) {
module = 'qxn'
2022-07-25 14:21:30 +08:00
} else if (/\/project\/beta\//.test(libPath)) {
corpId = 'ww2a667717a70164f1'
module = 'wangge'
}
this.setModule(module)
2022-07-25 14:26:26 +08:00
return Promise.resolve({corpId, module})
2022-06-10 16:24:29 +08:00
}
},
onShow() {
if (/wxwork/.test(navigator.userAgent)) {
//在企微端
if (this.$route.query.code) {
2022-07-25 14:21:30 +08:00
const {code} = this.$route.query
this.handleSignIn({code})
} else {
2022-07-25 14:22:01 +08:00
this.getSystem().then(() => this.getCode().catch(err => {
this.err = err
2022-07-25 14:22:01 +08:00
}))
}
} else {
this.handleLogout()
}
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>