|
@@ -0,0 +1,189 @@
|
|
|
+<template>
|
|
|
+ <div class="login-box">
|
|
|
+ <div class="login-title">
|
|
|
+ <div class="login-title-value">登录红链</div>
|
|
|
+ <div class="login-title-line"></div>
|
|
|
+ </div>
|
|
|
+ <div class="login-form">
|
|
|
+ <el-form :model="loginForm" :rules="loginRules" status-icon ref="loginForm" label-position="left">
|
|
|
+ <el-form-item prop="phone">
|
|
|
+ <el-input type="text" prefix-icon="iconfont huifont-shoujihao" v-model="loginForm.phone"
|
|
|
+ placeholder="手机号" maxlength="11">
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="password">
|
|
|
+ <el-input type="password" prefix-icon="iconfont huifont-mima" v-model="loginForm.password"
|
|
|
+ :show-password="true" placeholder="请输入密码">
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <el-button type="primary" @click="loginSubmit" :loading="loginLoading">登录</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="register">
|
|
|
+ <span @click="$router.push('/loginRegister/register')">手机验证码登录</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import {
|
|
|
+ login,
|
|
|
+ getImgCode,
|
|
|
+ sendPhoneCode,
|
|
|
+ getUserInfo,
|
|
|
+ selectOrangaized
|
|
|
+ } from '@/httpApi/loginRegister';
|
|
|
+ import {
|
|
|
+ getProjectListByIdentity
|
|
|
+ } from '@/httpApi/space'
|
|
|
+ import {
|
|
|
+ getIdentityResource
|
|
|
+ } from '@/httpApi/system'
|
|
|
+ import {
|
|
|
+ setToken,
|
|
|
+ setComment
|
|
|
+ } from '@/uitls/auth';
|
|
|
+ export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ loginForm: {
|
|
|
+ phone: '',
|
|
|
+ password: ''
|
|
|
+ },
|
|
|
+ loginLoading: false,
|
|
|
+ loginRules: {
|
|
|
+ phone: [{
|
|
|
+ required: true,
|
|
|
+ message: '请输入手机号',
|
|
|
+ trigger: 'blur'
|
|
|
+ }, {
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ if (!/^1[123456789]\d{9}$/.test(value)) {
|
|
|
+ callback(new Error("请输入正确的手机号"));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ password: [{
|
|
|
+ required: true,
|
|
|
+ message: '请输入密码',
|
|
|
+ trigger: 'blur'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ localStorage.removeItem('chatToken');
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ loginSubmit() {
|
|
|
+ if (this.loginLoading) return;
|
|
|
+ this.loginLoading = true;
|
|
|
+ this.$refs['loginForm'].validate(valid => {
|
|
|
+ if (!valid) return this.loginLoading = false;
|
|
|
+ this.loginFunc();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ loginFunc() {
|
|
|
+ let postData = {
|
|
|
+ phone: this.loginForm.phone,
|
|
|
+ password: this.loginForm.password
|
|
|
+ }
|
|
|
+ login(postData).then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ setToken(res.data.token);
|
|
|
+ getUserInfo().then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ let user = res.data;
|
|
|
+ if (user.projectId === -1) {
|
|
|
+ let organziation = user.organizationList.find(node => node
|
|
|
+ .contactTel == user.phone);
|
|
|
+ selectOrangaized(organziation)
|
|
|
+ this.$store.dispatch('app/changeOrganization', organziation);
|
|
|
+ this.$store.dispatch('app/changeUser', user);
|
|
|
+ this.$store.dispatch('projectBase/changeProject', {});
|
|
|
+ this.$store.dispatch('app/changeIdentity', {
|
|
|
+ id: 6,
|
|
|
+ name: '所有者',
|
|
|
+ remark: '所有者'
|
|
|
+ });
|
|
|
+ localStorage.setItem('projectId', 0);
|
|
|
+ return this.successLogin('/work/space/project');
|
|
|
+ } else {
|
|
|
+ this.$store.dispatch('app/changeOrganization', user.organization);
|
|
|
+ this.$store.dispatch('app/changeUser', user);
|
|
|
+ this.$store.dispatch('app/changeMenuData', user.resource ? JSON.parse(
|
|
|
+ user.resource) : []);
|
|
|
+ setComment(user.menu ? user.menu : JSON.stringify([]));
|
|
|
+ this.initProjectData(user.projectId, user.identityId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.loginLoading = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.loginLoading = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ initProjectData(projectId, identityId) {
|
|
|
+ getProjectListByIdentity().then(res => {
|
|
|
+ if (res.state) {
|
|
|
+ if (res.data.length === 0) {
|
|
|
+ this.$store.dispatch('projectBase/changeProject', {});
|
|
|
+ this.$store.dispatch('app/changeIdentity', {
|
|
|
+ id: 6,
|
|
|
+ name: '所有者',
|
|
|
+ remark: '所有者'
|
|
|
+ });
|
|
|
+ localStorage.setItem('projectId', 0);
|
|
|
+ return this.successLogin('/work/space/project');
|
|
|
+ }
|
|
|
+ let project = projectId === -1 ? res.data[0] : res.data.find(node => node.id ===
|
|
|
+ projectId);
|
|
|
+ this.$store.dispatch('projectBase/changeProject', project);
|
|
|
+ let identity = identityId === -1 ? project.projectListIdentity[0] : project
|
|
|
+ .projectListIdentity.find(node => node.id === identityId);
|
|
|
+ this.$store.dispatch('app/changeIdentity', identity);
|
|
|
+ localStorage.setItem('projectId', projectId);
|
|
|
+ this.successLogin('/');
|
|
|
+ } else {
|
|
|
+ this.loginLoading = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ successLogin(url) {
|
|
|
+ let item = this.$store.getters.identity;
|
|
|
+ if (item.id === 3 || this.$store.getters.user.userId === 1) {
|
|
|
+ this.loginLoading = false;
|
|
|
+ this.$router.push(url);
|
|
|
+ this.$message.success('登录成功');
|
|
|
+ } else {
|
|
|
+ getIdentityResource({
|
|
|
+ identityId: item.id,
|
|
|
+ type: this.$store.getters.project.type || 1
|
|
|
+ }).then(node => {
|
|
|
+ if (node.state) {
|
|
|
+ let role = node.data[0] || {};
|
|
|
+ this.$store.dispatch('app/changeMenuData', role
|
|
|
+ .resource ? JSON.parse(role.resource) : []);
|
|
|
+ setComment(role.menus ? role.menus : JSON.stringify(
|
|
|
+ []));
|
|
|
+ this.loginLoading = false;
|
|
|
+ this.$router.push(url);
|
|
|
+ this.$message.success('登录成功');
|
|
|
+ } else {
|
|
|
+ this.loginLoading = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+
|
|
|
+</style>
|