登录调整

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

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

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

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

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

Loading…
Cancel
Save