登录调整

master
yujialong 4 months ago
parent 5c6c5e8ea4
commit 7d741c9436
  1. 2
      src/api/index.js
  2. 4
      src/layouts/header/index.vue
  3. 56
      src/pages/account/login/index.vue
  4. 20
      src/pages/account/redirect/index.vue
  5. 45
      src/store/modules/user.js

@ -6,7 +6,6 @@ const host2 = 'http://121.37.12.51/'
export default {
logins: `users/users/user/login`, //登录
verification: `${host}users/users/user/captcha`,// 验证码图片
isClient: `users/users/user/isClient`,// 是否为客户
getUserAllRoleByToken: `users/users/role/getUserAllRoleByToken`,
getSchoolIdByToken: `users/users/data/user/getSchoolIdByToken`,
deleteProfile: `users/users/userInfo/deleteProfile`,
@ -14,6 +13,7 @@ export default {
getCurrentTime: `competition/competition/management/getCurrentTime`,
heartbeatDetection: `nakadai/message/heartbeatDetection`,
encrypt: `nakadai/data/encrypt`,
logout: `users/users/user/logout`,
getPlayAuth: `nakadai/nakadai/oss/getPlayAuth`, // 获取播放凭证

@ -170,10 +170,6 @@ export default {
this.setUserId(userId)
userAvatars && this.setAvatar(userAvatars)
this.setUserName(userName)
} else {
this.$get(this.api.isClient).then(res => {
res.customerName && this.setUserName(res.customerName)
}).catch(res => { })
}
}).catch(res => { })
},

@ -13,19 +13,11 @@
<el-input v-model.trim="loginForm.account" placeholder="请输入手机号/邮箱"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
type="password"
placeholder="请输入密码"
v-model.trim="loginForm.password"
>
<el-input type="password" placeholder="请输入密码" v-model.trim="loginForm.password">
</el-input>
</el-form-item>
<el-form-item prop="code">
<el-input
placeholder="请输入验证码"
v-model.trim="loginForm.code"
@keyup.enter.native="submitFormLogin"
>
<el-input placeholder="请输入验证码" v-model.trim="loginForm.code" @keyup.enter.native="submitFormLogin">
</el-input>
<img @click="getVerImg" :src="verificationIMG" class="verification" alt="">
</el-form-item>
@ -46,8 +38,8 @@
<el-form-item label="验证码">
<div style="display: flex;">
<el-input v-model="phoneCode" placeholder="请输入验证码" maxlength="6"></el-input>
<el-button style="margin-left: 10px" type="text" @click="sendPhoneCode"
:disabled="phoneDisabled">{{ phoneBtnText }}
<el-button style="margin-left: 10px" type="text" @click="sendPhoneCode" :disabled="phoneDisabled">{{
phoneBtnText }}
</el-button>
</div>
</el-form-item>
@ -68,7 +60,7 @@ import util from "@/libs/util";
import Setting from "@/setting";
export default {
data: function() {
data: function () {
return {
activeName: "1",
loginForm: {
@ -97,12 +89,12 @@ export default {
components: {
vFooter
},
created() {
created () {
this.getVerImg();
},
mounted() {
mounted () {
//
this.$once("hook:beforeDestroy", function() {
this.$once("hook:beforeDestroy", function () {
clearInterval(this.phoneTimer);
this.phoneTimer = null;
});
@ -112,18 +104,18 @@ export default {
"SET_ROLENAME", 'SET_FROM'
]),
...mapActions("user", [
"setCustomer", "setCustomerName"
"setCustomerName"
]),
getVerImg() { //
getVerImg () { //
this.loginForm.random = Math.floor(Math.random() * 999999999);
this.verificationIMG = this.api.verification + "?random=" + `${this.loginForm.random}`;
},
handleClick(tab, event) { //
handleClick (tab, event) { //
this.loginForm.account = "";
this.$refs.loginForm.clearValidate();
this.loginRules.account[0].message = tab.index === "1" ? "请输入账号" : "请输入手机号/邮箱";
},
submitFormLogin() { //
submitFormLogin () { //
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loginForm.distinguish = Number(this.activeName);
@ -147,25 +139,19 @@ export default {
});
},
//
getRole() {
getRole () {
this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`).then(res => {
this.SET_ROLENAME(res)
}).catch(err => {})
}).catch(err => { })
},
queryCustomer() { //
this.$get(this.api.isClient).then(res => {
util.successMsg("登录成功");
this.setCustomer(res.customer);
res.customerName && this.setCustomerName(res.customerName);
queryCustomer () { //
const path = '/product/list' //
this.$get(`${this.api.getUserRolesPermissionMenu}?platformId=${Setting.platformId}`).then(res => {
const list = res.permissionMenu[0].children
this.$router.push(list.find(e => e.path === path) ? path : list[0].path)
}).catch(err => {})
}).catch(res => {});
}).catch(err => { })
},
phoneCountdown() {
phoneCountdown () {
let count = 60;
if (!this.phoneTimer) {
this.phoneDisabled = true;
@ -183,7 +169,7 @@ export default {
}, 1000);
}
},
sendPhoneCode() {
sendPhoneCode () {
if (!this.phone) return util.warningMsg("请输入手机号");
if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号");
let data = {
@ -198,9 +184,9 @@ export default {
} else {
util.errorMsg(res.message);
}
}).catch(res => {});
}).catch(res => { });
},
phoneSubmit() {
phoneSubmit () {
if (!this.phone) return util.warningMsg("请输入手机号");
if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号");
if (!this.phoneCode) return util.warningMsg("请输入验证码");
@ -236,6 +222,7 @@ export default {
height: 100%;
background-image: url(../../../assets/img/login-bg.png);
background-size: 100%;
.header {
width: 100%;
height: 60px;
@ -257,6 +244,7 @@ export default {
}
}
}
/deep/ .main {
position: absolute;
left: 50%;

@ -2,7 +2,7 @@
<script>
import { mapActions, mapMutations } from "vuex";
import util from "@/libs/util";
import Util from '@/libs/util'
import Setting from "@/setting";
export default {
data: function () {
@ -19,32 +19,28 @@ export default {
"SET_ROLENAME", 'SET_FROM'
]),
...mapActions("user", [
"setCustomer", "setCustomerName"
"setCustomerName"
]),
setLogin () {
this.SET_FROM(true)
util.local.set(Setting.tokenKey, window.atob(decodeURI(this.token)), Setting.tokenExpires);
Util.local.set(Setting.tokenKey, window.atob(decodeURI(this.token)), Setting.tokenExpires);
this.getRole()
this.queryCustomer()
},
//
getRole () {
this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`).then(res => {
async getRole () {
const res = await this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`)
this.SET_ROLENAME(res)
}).catch(err => { })
},
queryCustomer () { //
this.$get(this.api.isClient).then(res => {
util.successMsg('登录成功')
this.setCustomer(res.customer)
this.setCustomerName(res.customerName)
async queryCustomer () { //
Util.successMsg('登录成功')
this.setCustomerName(Util.cookies.get('customerName'))
const path = '/product/list' //
this.$get(`${this.api.getUserRolesPermissionMenu}?platformId=${Setting.platformId}`).then(res => {
const list = res.permissionMenu[0].children
this.$router.push(list.find(e => e.path === path) ? path : list[0].path)
}).catch(err => { })
}).catch(res => { })
}
}
};

@ -1,8 +1,7 @@
import Setting from "@/setting";
import util from "@/libs/util";
import { post, get, del, put } from "@/plugins/requests/index.js";
import { post } from "@/plugins/requests/index.js";
import api from "@/api";
import addRoutes from "@/libs/route/addRoutes";
/**
* 用户信息
@ -10,7 +9,6 @@ import addRoutes from "@/libs/route/addRoutes";
export default {
namespaced: true,
state: {
customer: false, // true:为客户,没有个人中心
customerName: "", // 客户名称
title: "",
logoUrl: "",
@ -32,9 +30,6 @@ export default {
state.roleId = info.roleId;
state.dataTime = info.dataTime;
},
SET_CUSTOMER: (state, customer) => {
state.customer = customer;
},
SET_CUSTOMER_NAME: (state, customerName) => {
state.customerName = customerName;
},
@ -67,17 +62,12 @@ export default {
},
},
actions: {
login({ state, commit }, userInfo) {
login ({ state, commit }, userInfo) {
return new Promise((resolve, reject) => {
post(api.logins, userInfo).then(res => {
// console.log(JSON.stringify(res));
if (res.status == 200) {
let { data } = res;
// 生成路由权限
// 每个系统都是用这套角色权限代码的,后端也是基本一样,除了个别字段可能会不一样
// 总体来说就两个步骤: 1是生成能够访问的路由的数组集合,2是生成能看到的按钮的数组集合
// res.message.listValue && Setting.dynamicRoute && addRoutes(res.message.listValue)
// 2021-10-13重做权限,因权限系统封装
let { data } = res
util.local.set(Setting.tokenKey, data.token, Setting.tokenExpires);
commit("SET_CUSTOMER", data.customer);
commit("SET_CUSTOMER_NAME", data.customerName);
@ -95,10 +85,11 @@ export default {
});
});
},
logout({ commit, state, dispatch }) {
logout ({ commit, state, dispatch }) {
return new Promise((resolve, reject) => {
util.local.remove(Setting.storeKey);
util.local.remove(Setting.tokenKey);
post(api.logout).then(() => {
util.local.remove(Setting.storeKey)
util.local.remove(Setting.tokenKey)
if (state.fromClient) {
util.cookies.remove('serverLogin')
location.href = Setting.isDev
@ -109,28 +100,28 @@ export default {
} else {
location.reload()
}
resolve();
});
resolve()
}).catch(error => {
reject(error)
})
})
},
setInfo({ state, commit }, info) {
setInfo ({ state, commit }, info) {
commit("SET_INFO", info);
},
setTitle({ state, commit }, title) {
setTitle ({ state, commit }, title) {
commit("SET_TITLE", title);
},
setLogoUrl({ state, commit }, logoUrl) {
setLogoUrl ({ state, commit }, logoUrl) {
commit("SET_LOGO_URL", logoUrl);
},
setCustomer({ state, commit }, customer) {
commit("SET_CUSTOMER", customer);
},
setCustomerName({ state, commit }, customerName) {
setCustomerName ({ state, commit }, customerName) {
commit("SET_CUSTOMER_NAME", customerName);
},
setAvatar({ state, commit }, avatar) {
setAvatar ({ state, commit }, avatar) {
commit("SET_AVATAR", avatar);
},
setUserName({ state, commit }, userName) {
setUserName ({ state, commit }, userName) {
commit("SET_USERNAME", userName);
}
}

Loading…
Cancel
Save