登录调整

master
yujialong 4 months ago
parent 5c6c5e8ea4
commit 7d741c9436
  1. 2
      src/api/index.js
  2. 4
      src/layouts/header/index.vue
  3. 588
      src/pages/account/login/index.vue
  4. 32
      src/pages/account/redirect/index.vue
  5. 243
      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 => { })
}, },

@ -1,64 +1,56 @@
<template> <template>
<div class="wrap"> <div class="wrap">
<div class="main"> <div class="main">
<div class="box"> <div class="box">
<el-tabs v-model="activeName" @tab-click="handleClick"> <el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="账号登录" name="1"></el-tab-pane> <el-tab-pane label="账号登录" name="1"></el-tab-pane>
<el-tab-pane label="手机号/邮箱登录" name="2"></el-tab-pane> <el-tab-pane label="手机号/邮箱登录" name="2"></el-tab-pane>
<el-form :model="loginForm" :rules="loginRules" ref="loginForm" style="margin-top: 20px"> <el-form :model="loginForm" :rules="loginRules" ref="loginForm" style="margin-top: 20px">
<el-form-item v-if="activeName === '1'" prop="account"> <el-form-item v-if="activeName === '1'" prop="account">
<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 v-if="activeName === '2'" prop="account"> <el-form-item v-if="activeName === '2'" prop="account">
<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" </el-input>
placeholder="请输入密码" </el-form-item>
v-model.trim="loginForm.password" <el-form-item prop="code">
> <el-input placeholder="请输入验证码" v-model.trim="loginForm.code" @keyup.enter.native="submitFormLogin">
</el-input> </el-input>
</el-form-item> <img @click="getVerImg" :src="verificationIMG" class="verification" alt="">
<el-form-item prop="code"> </el-form-item>
<el-input <el-button class="submit" type="primary" @click="submitFormLogin">马上登录</el-button>
placeholder="请输入验证码" </el-form>
v-model.trim="loginForm.code" </el-tabs>
@keyup.enter.native="submitFormLogin" </div>
>
</el-input>
<img @click="getVerImg" :src="verificationIMG" class="verification" alt="">
</el-form-item>
<el-button class="submit" type="primary" @click="submitFormLogin">马上登录</el-button>
</el-form>
</el-tabs>
</div>
</div>
<el-dialog title="绑定手机号" :visible.sync="phoneVisible" :close-on-click-modal="false" width="30%">
<div style='padding: 0 13px 20px 13px;'>
依据国家政策法规需绑定手机号进行网络实名才可登录使用本平台
</div>
<el-form ref="form" label-width="60px">
<el-form-item label="手机号">
<el-input style="width: 100%;" placeholder="请输入手机号" v-model="phone" maxlength="11"></el-input>
</el-form-item>
<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>
</div>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="phoneVisible = false"> </el-button>
<el-button type="primary" @click="phoneSubmit"> </el-button>
</span>
</el-dialog>
<v-footer class="footer"></v-footer>
</div> </div>
<el-dialog title="绑定手机号" :visible.sync="phoneVisible" :close-on-click-modal="false" width="30%">
<div style='padding: 0 13px 20px 13px;'>
依据国家政策法规需绑定手机号进行网络实名才可登录使用本平台
</div>
<el-form ref="form" label-width="60px">
<el-form-item label="手机号">
<el-input style="width: 100%;" placeholder="请输入手机号" v-model="phone" maxlength="11"></el-input>
</el-form-item>
<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>
</div>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="phoneVisible = false"> </el-button>
<el-button type="primary" @click="phoneSubmit"> </el-button>
</span>
</el-dialog>
<v-footer class="footer"></v-footer>
</div>
</template> </template>
<script> <script>
@ -68,276 +60,272 @@ 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: {
account: "", account: "",
password: "", password: "",
code: "", // code: "", //
random: "", // random: "", //
distinguish: 1, // ,1,2 distinguish: 1, // ,1,2
type: 0, // 0-> 1-> 2-> type: 0, // 0-> 1-> 2->
platform: Setting.platformId platform: Setting.platformId
}, },
loginRules: { loginRules: {
account: [{ required: true, message: "请输入账号", trigger: "blur" }], account: [{ required: true, message: "请输入账号", trigger: "blur" }],
password: [{ required: true, message: "请输入密码", trigger: "blur" }], password: [{ required: true, message: "请输入密码", trigger: "blur" }],
code: [{ required: true, message: "请输入验证码", trigger: "blur" }] code: [{ required: true, message: "请输入验证码", trigger: "blur" }]
}, },
verificationIMG: "", verificationIMG: "",
phoneVisible: false, // phoneVisible: false, //
phone: "", phone: "",
phoneCode: "", phoneCode: "",
phoneDisabled: false, phoneDisabled: false,
phoneTimer: null, phoneTimer: null,
phoneBtnText: "发送验证码" phoneBtnText: "发送验证码"
}; };
},
components: {
vFooter
},
created () {
this.getVerImg();
},
mounted () {
//
this.$once("hook:beforeDestroy", function () {
clearInterval(this.phoneTimer);
this.phoneTimer = null;
});
},
methods: {
...mapMutations("user", [
"SET_ROLENAME", 'SET_FROM'
]),
...mapActions("user", [
"setCustomerName"
]),
getVerImg () { //
this.loginForm.random = Math.floor(Math.random() * 999999999);
this.verificationIMG = this.api.verification + "?random=" + `${this.loginForm.random}`;
},
handleClick (tab, event) { //
this.loginForm.account = "";
this.$refs.loginForm.clearValidate();
this.loginRules.account[0].message = tab.index === "1" ? "请输入账号" : "请输入手机号/邮箱";
}, },
components: { submitFormLogin () { //
vFooter this.$refs.loginForm.validate(valid => {
if (valid) {
this.loginForm.distinguish = Number(this.activeName);
this.$post(this.api.logins, this.loginForm).then(res => {
if (res && res.status == 30001) {
this.phoneVisible = true;
}
this.getVerImg()
this.loginForm.code = ''
util.local.set(Setting.tokenKey, res.data.token, Setting.tokenExpires);
this.SET_FROM(false)
this.getRole()
this.queryCustomer()
}).catch(res => {
this.getVerImg()
this.loginForm.code = ''
})
} else {
return util.errorMsg("请检查表单数据");
}
});
}, },
created() { //
this.getVerImg(); getRole () {
this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`).then(res => {
this.SET_ROLENAME(res)
}).catch(err => { })
}, },
mounted() { queryCustomer () { //
// const path = '/product/list' //
this.$once("hook:beforeDestroy", function() { 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 => { })
},
phoneCountdown () {
let count = 60;
if (!this.phoneTimer) {
this.phoneDisabled = true;
this.phoneTimer = setInterval(() => {
console.log("倒计时中");
if (count > 0) {
count--;
this.phoneBtnText = `${count}秒后重试`;
} else {
this.phoneDisabled = false;
clearInterval(this.phoneTimer); clearInterval(this.phoneTimer);
this.phoneTimer = null; this.phoneTimer = null;
}); this.phoneBtnText = `发送验证码`;
}
}, 1000);
}
}, },
methods: { sendPhoneCode () {
...mapMutations("user", [ if (!this.phone) return util.warningMsg("请输入手机号");
"SET_ROLENAME", 'SET_FROM' if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号");
]), let data = {
...mapActions("user", [ platform: Setting.platformId,
"setCustomer", "setCustomerName" phone: this.phone,
]), types: 2
getVerImg() { // };
this.loginForm.random = Math.floor(Math.random() * 999999999); this.$post(this.api.sendPhoneOrEmailCode, data).then(res => {
this.verificationIMG = this.api.verification + "?random=" + `${this.loginForm.random}`; if (res.message.opener) {
}, this.phoneCountdown();
handleClick(tab, event) { // this.phoneOpener = res.message.opener;
this.loginForm.account = ""; } else {
this.$refs.loginForm.clearValidate(); util.errorMsg(res.message);
this.loginRules.account[0].message = tab.index === "1" ? "请输入账号" : "请输入手机号/邮箱";
},
submitFormLogin() { //
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loginForm.distinguish = Number(this.activeName);
this.$post(this.api.logins, this.loginForm).then(res => {
if (res && res.status == 30001) {
this.phoneVisible = true;
}
this.getVerImg()
this.loginForm.code = ''
util.local.set(Setting.tokenKey, res.data.token, Setting.tokenExpires);
this.SET_FROM(false)
this.getRole()
this.queryCustomer()
}).catch(res => {
this.getVerImg()
this.loginForm.code = ''
})
} else {
return util.errorMsg("请检查表单数据");
}
});
},
//
getRole() {
this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`).then(res => {
this.SET_ROLENAME(res)
}).catch(err => {})
},
queryCustomer() { //
this.$get(this.api.isClient).then(res => {
util.successMsg("登录成功");
this.setCustomer(res.customer);
res.customerName && this.setCustomerName(res.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 => {});
},
phoneCountdown() {
let count = 60;
if (!this.phoneTimer) {
this.phoneDisabled = true;
this.phoneTimer = setInterval(() => {
console.log("倒计时中");
if (count > 0) {
count--;
this.phoneBtnText = `${count}秒后重试`;
} else {
this.phoneDisabled = false;
clearInterval(this.phoneTimer);
this.phoneTimer = null;
this.phoneBtnText = `发送验证码`;
}
}, 1000);
}
},
sendPhoneCode() {
if (!this.phone) return util.warningMsg("请输入手机号");
if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号");
let data = {
platform: Setting.platformId,
phone: this.phone,
types: 2
};
this.$post(this.api.sendPhoneOrEmailCode, data).then(res => {
if (res.message.opener) {
this.phoneCountdown();
this.phoneOpener = res.message.opener;
} else {
util.errorMsg(res.message);
}
}).catch(res => {});
},
phoneSubmit() {
if (!this.phone) return util.warningMsg("请输入手机号");
if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号");
if (!this.phoneCode) return util.warningMsg("请输入验证码");
let data = {
phone: this.phone,
types: 2,
code: this.phoneCode,
opener: this.phoneOpener,
platform: Setting.platformId,
account: this.loginForm.account
};
this.$post(this.api.bindPhoneOrEmail, data).then(res => {
util.successMsg("绑定成功");
this.loginForm.phone = this.phone;
this.phoneVisible = false;
util.local.set(Setting.tokenKey, res.token, Setting.tokenExpires);
let redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : "/index";
this.$router.replace(redirect);
util.successMsg("登录成功");
this.queryCustomer();
}).catch(res => {
});
} }
}).catch(res => { });
},
phoneSubmit () {
if (!this.phone) return util.warningMsg("请输入手机号");
if (!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg("请输入正确的手机号");
if (!this.phoneCode) return util.warningMsg("请输入验证码");
let data = {
phone: this.phone,
types: 2,
code: this.phoneCode,
opener: this.phoneOpener,
platform: Setting.platformId,
account: this.loginForm.account
};
this.$post(this.api.bindPhoneOrEmail, data).then(res => {
util.successMsg("绑定成功");
this.loginForm.phone = this.phone;
this.phoneVisible = false;
util.local.set(Setting.tokenKey, res.token, Setting.tokenExpires);
let redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : "/index";
this.$router.replace(redirect);
util.successMsg("登录成功");
this.queryCustomer();
}).catch(res => {
});
} }
}
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.wrap { .wrap {
position: relative; position: relative;
width: 100%;
height: 100%;
background-image: url(../../../assets/img/login-bg.png);
background-size: 100%;
.header {
width: 100%; width: 100%;
height: 100%; height: 60px;
background-image: url(../../../assets/img/login-bg.png); position: absolute;
background-size: 100%; top: 0;
.header { left: 0;
width: 100%; background-color: #fff;
height: 60px; display: flex;
position: absolute; justify-content: space-between;
top: 0; align-items: center;
left: 0; font-size: 18px;
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 18px;
.logo { .logo {
width: 150px; width: 150px;
margin-left: 20px; margin-left: 20px;
&.hh { &.hh {
width: 220px; width: 220px;
} }
}
} }
/deep/ .main { }
position: absolute;
left: 50%;
top: 42px;
transform: translate(-50%, 0);
width: 1200px;
height: 82%;
margin-top: 60px;
background-image: url(../../../assets/img/login-input.png);
box-shadow: 0px 0px 79px 0px rgba(11, 15, 65, 0.36);
overflow: hidden;
.box {
width: 548px;
position: absolute;
left: 50%;
top: 50px;
transform: translate(-50%, 0);
.el-tabs__nav-scroll {
display: flex;
justify-content: center;
}
.el-tabs__nav-wrap::after { /deep/ .main {
background-color: #fff; position: absolute;
opacity: 0; left: 50%;
top: 42px;
transform: translate(-50%, 0);
width: 1200px;
height: 82%;
margin-top: 60px;
background-image: url(../../../assets/img/login-input.png);
box-shadow: 0px 0px 79px 0px rgba(11, 15, 65, 0.36);
overflow: hidden;
.el-tabs__active-bar { .box {
background-color: #000; width: 548px;
border-radius: 2px; position: absolute;
} left: 50%;
top: 50px;
transform: translate(-50%, 0);
.el-tabs__item { .el-tabs__nav-scroll {
padding: 0 90px; display: flex;
color: #999; justify-content: center;
}
&:hover { .el-tabs__nav-wrap::after {
color: #000; background-color: #fff;
} opacity: 0;
&.is-active { .el-tabs__active-bar {
color: #333; background-color: #000;
font-weight: bold; border-radius: 2px;
} }
}
}
.el-input__inner { .el-tabs__item {
height: 80px; padding: 0 90px;
line-height: 80px; color: #999;
border: 1px solid rgba(220, 220, 220, 1);
border-radius: 2px;
}
.verification { &:hover {
position: absolute; color: #000;
top: 1px; }
right: 1px;
width: 160px;
height: 78px;
cursor: pointer;
}
.submit { &.is-active {
width: 100%; color: #333;
height: 88px; font-weight: bold;
margin-bottom: 50px; }
font-weight: bold;
background: linear-gradient(90deg, rgba(94, 206, 253, 1), rgba(91, 67, 231, 1));
box-shadow: 0px 7px 27px 0px rgba(50, 129, 255, 0.51);
border-radius: 10px;
}
} }
} }
.footer { .el-input__inner {
height: 80px;
line-height: 80px;
border: 1px solid rgba(220, 220, 220, 1);
border-radius: 2px;
}
.verification {
position: absolute; position: absolute;
bottom: 0; top: 1px;
left: 0; right: 1px;
width: 160px;
height: 78px;
cursor: pointer;
}
.submit {
width: 100%; width: 100%;
height: 88px;
margin-bottom: 50px;
font-weight: bold;
background: linear-gradient(90deg, rgba(94, 206, 253, 1), rgba(91, 67, 231, 1));
box-shadow: 0px 7px 27px 0px rgba(50, 129, 255, 0.51);
border-radius: 10px;
}
} }
}
.footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
} }
</style> </style>

@ -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,137 +1,128 @@
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";
/** /**
* 用户信息 * 用户信息
* */ * */
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
customer: false, // true:为客户,没有个人中心 customerName: "", // 客户名称
customerName: "", // 客户名称 title: "",
title: "", logoUrl: "",
logoUrl: "", avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png", userId: '',
userId: '', userName: "",
userName: "", roleId: "",
roleId: "", dataTime: "",
dataTime: "", roleName: '',
roleName: '', schoolId: '',
schoolId: '', fromClient: false, // 是否从学生端登录
fromClient: false, // 是否从学生端登录 logView: false // 是否查询过日志状态,如果有,则不再调接口
logView: false // 是否查询过日志状态,如果有,则不再调接口 },
}, mutations: {
mutations: { SET_INFO: (state, info) => {
SET_INFO: (state, info) => { if (info.avatar) state.avatar = info.userAvatars;
if (info.avatar) state.avatar = info.userAvatars; state.userId = info.userId;
state.userId = info.userId; state.userName = info.userName;
state.userName = info.userName; state.roleId = info.roleId;
state.roleId = info.roleId; state.dataTime = info.dataTime;
state.dataTime = info.dataTime; },
}, SET_CUSTOMER_NAME: (state, customerName) => {
SET_CUSTOMER: (state, customer) => { state.customerName = customerName;
state.customer = customer; },
}, SET_TITLE: (state, title) => {
SET_CUSTOMER_NAME: (state, customerName) => { state.title = title;
state.customerName = customerName; },
}, SET_LOGO_URL: (state, logoUrl) => {
SET_TITLE: (state, title) => { state.logoUrl = logoUrl;
state.title = title; },
}, SET_AVATAR: (state, avatar) => {
SET_LOGO_URL: (state, logoUrl) => { state.avatar = avatar;
state.logoUrl = logoUrl; },
}, SET_USERNAME: (state, userName) => {
SET_AVATAR: (state, avatar) => { state.userName = userName;
state.avatar = avatar; },
}, SET_ROLENAME: (state, roleName) => {
SET_USERNAME: (state, userName) => { state.roleName = roleName
state.userName = userName; },
}, SET_FROM: (state, fromClient) => {
SET_ROLENAME: (state, roleName) => { state.fromClient = fromClient
state.roleName = roleName },
}, SET_SCHOOLID: (state, schoolId) => {
SET_FROM: (state, fromClient) => { state.schoolId = schoolId
state.fromClient = fromClient },
}, SET_LOG: (state) => {
SET_SCHOOLID: (state, schoolId) => { state.logView = true
state.schoolId = schoolId },
}, setUserId: (state, userId) => {
SET_LOG: (state) => { state.userId = userId
state.logView = true },
}, },
setUserId: (state, userId) => { actions: {
state.userId = userId login ({ state, commit }, userInfo) {
}, return new Promise((resolve, reject) => {
}, post(api.logins, userInfo).then(res => {
actions: { // console.log(JSON.stringify(res));
login({ state, commit }, userInfo) { if (res.status == 200) {
return new Promise((resolve, reject) => { let { data } = res
post(api.logins, userInfo).then(res => { util.local.set(Setting.tokenKey, data.token, Setting.tokenExpires);
// console.log(JSON.stringify(res)); commit("SET_CUSTOMER", data.customer);
if (res.status == 200) { commit("SET_CUSTOMER_NAME", data.customerName);
let { data } = res; util.successMsg("登录成功");
// 生成路由权限 commit("SET_INFO", data);
// 每个系统都是用这套角色权限代码的,后端也是基本一样,除了个别字段可能会不一样 resolve();
// 总体来说就两个步骤: 1是生成能够访问的路由的数组集合,2是生成能看到的按钮的数组集合 } else {
// res.message.listValue && Setting.dynamicRoute && addRoutes(res.message.listValue) console.log(res.message)
// 2021-10-13重做权限,因权限系统封装 util.errorMsg(res.message);
util.local.set(Setting.tokenKey, data.token, Setting.tokenExpires);
commit("SET_CUSTOMER", data.customer);
commit("SET_CUSTOMER_NAME", data.customerName);
util.successMsg("登录成功");
commit("SET_INFO", data);
resolve();
} else {
console.log(res.message)
util.errorMsg(res.message);
reject(res); reject(res);
} }
}).catch(error => { }).catch(error => {
reject(error); reject(error);
}); });
}); });
}, },
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)
if (state.fromClient) { util.local.remove(Setting.tokenKey)
util.cookies.remove('serverLogin') if (state.fromClient) {
location.href = Setting.isDev util.cookies.remove('serverLogin')
? `http://${location.hostname}:8082/#/` location.href = Setting.isDev
: Setting.isTest ? `http://${location.hostname}:8082/#/`
? `${location.origin}/student/#/login` : Setting.isTest
: `${location.origin}/#/login` ? `${location.origin}/student/#/login`
} else { : `${location.origin}/#/login`
location.reload() } else {
} location.reload()
resolve(); }
}); resolve()
}, }).catch(error => {
setInfo({ state, commit }, info) { reject(error)
commit("SET_INFO", info); })
}, })
setTitle({ state, commit }, title) { },
commit("SET_TITLE", title); setInfo ({ state, commit }, info) {
}, commit("SET_INFO", info);
setLogoUrl({ state, commit }, logoUrl) { },
commit("SET_LOGO_URL", logoUrl); setTitle ({ state, commit }, title) {
}, commit("SET_TITLE", title);
setCustomer({ state, commit }, customer) { },
commit("SET_CUSTOMER", customer); setLogoUrl ({ state, commit }, logoUrl) {
}, commit("SET_LOGO_URL", logoUrl);
setCustomerName({ state, commit }, customerName) { },
commit("SET_CUSTOMER_NAME", customerName); setCustomerName ({ state, commit }, customerName) {
}, commit("SET_CUSTOMER_NAME", customerName);
setAvatar({ state, commit }, avatar) { },
commit("SET_AVATAR", avatar); setAvatar ({ state, commit }, avatar) {
}, commit("SET_AVATAR", avatar);
setUserName({ state, commit }, userName) { },
commit("SET_USERNAME", userName); setUserName ({ state, commit }, userName) {
} commit("SET_USERNAME", userName);
} }
}
}; };
Loading…
Cancel
Save