登录调整

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 {
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 => { })
},

@ -1,64 +1,56 @@
<template>
<div class="wrap">
<div class="main">
<div class="box">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="账号登录" name="1"></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-item v-if="activeName === '1'" prop="account">
<el-input v-model.trim="loginForm.account" placeholder="请输入账号"></el-input>
</el-form-item>
<el-form-item v-if="activeName === '2'" prop="account">
<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>
</el-form-item>
<el-form-item prop="code">
<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>
<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 class="wrap">
<div class="main">
<div class="box">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="账号登录" name="1"></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-item v-if="activeName === '1'" prop="account">
<el-input v-model.trim="loginForm.account" placeholder="请输入账号"></el-input>
</el-form-item>
<el-form-item v-if="activeName === '2'" prop="account">
<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>
</el-form-item>
<el-form-item prop="code">
<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>
<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>
</template>
<script>
@ -68,276 +60,272 @@ import util from "@/libs/util";
import Setting from "@/setting";
export default {
data: function() {
return {
activeName: "1",
loginForm: {
account: "",
password: "",
code: "", //
random: "", //
distinguish: 1, // ,1,2
type: 0, // 0-> 1-> 2->
platform: Setting.platformId
},
loginRules: {
account: [{ required: true, message: "请输入账号", trigger: "blur" }],
password: [{ required: true, message: "请输入密码", trigger: "blur" }],
code: [{ required: true, message: "请输入验证码", trigger: "blur" }]
},
verificationIMG: "",
phoneVisible: false, //
phone: "",
phoneCode: "",
phoneDisabled: false,
phoneTimer: null,
phoneBtnText: "发送验证码"
};
data: function () {
return {
activeName: "1",
loginForm: {
account: "",
password: "",
code: "", //
random: "", //
distinguish: 1, // ,1,2
type: 0, // 0-> 1-> 2->
platform: Setting.platformId
},
loginRules: {
account: [{ required: true, message: "请输入账号", trigger: "blur" }],
password: [{ required: true, message: "请输入密码", trigger: "blur" }],
code: [{ required: true, message: "请输入验证码", trigger: "blur" }]
},
verificationIMG: "",
phoneVisible: false, //
phone: "",
phoneCode: "",
phoneDisabled: false,
phoneTimer: null,
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: {
vFooter
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("请检查表单数据");
}
});
},
created() {
this.getVerImg();
//
getRole () {
this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`).then(res => {
this.SET_ROLENAME(res)
}).catch(err => { })
},
mounted() {
//
this.$once("hook:beforeDestroy", function() {
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 => { })
},
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);
}
},
methods: {
...mapMutations("user", [
"SET_ROLENAME", 'SET_FROM'
]),
...mapActions("user", [
"setCustomer", "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" ? "请输入账号" : "请输入手机号/邮箱";
},
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 => {
});
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 => {
});
}
}
};
</script>
<style lang="scss" scoped>
.wrap {
position: relative;
position: relative;
width: 100%;
height: 100%;
background-image: url(../../../assets/img/login-bg.png);
background-size: 100%;
.header {
width: 100%;
height: 100%;
background-image: url(../../../assets/img/login-bg.png);
background-size: 100%;
.header {
width: 100%;
height: 60px;
position: absolute;
top: 0;
left: 0;
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 18px;
height: 60px;
position: absolute;
top: 0;
left: 0;
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 18px;
.logo {
width: 150px;
margin-left: 20px;
.logo {
width: 150px;
margin-left: 20px;
&.hh {
width: 220px;
}
}
&.hh {
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);
/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;
.el-tabs__nav-scroll {
display: flex;
justify-content: center;
}
.box {
width: 548px;
position: absolute;
left: 50%;
top: 50px;
transform: translate(-50%, 0);
.el-tabs__nav-wrap::after {
background-color: #fff;
opacity: 0;
.el-tabs__active-bar {
background-color: #000;
border-radius: 2px;
}
.el-tabs__nav-scroll {
display: flex;
justify-content: center;
}
.el-tabs__item {
padding: 0 90px;
color: #999;
.el-tabs__nav-wrap::after {
background-color: #fff;
opacity: 0;
&:hover {
color: #000;
}
.el-tabs__active-bar {
background-color: #000;
border-radius: 2px;
}
&.is-active {
color: #333;
font-weight: bold;
}
}
}
.el-tabs__item {
padding: 0 90px;
color: #999;
.el-input__inner {
height: 80px;
line-height: 80px;
border: 1px solid rgba(220, 220, 220, 1);
border-radius: 2px;
}
&:hover {
color: #000;
}
.verification {
position: absolute;
top: 1px;
right: 1px;
width: 160px;
height: 78px;
cursor: pointer;
}
.submit {
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;
}
&.is-active {
color: #333;
font-weight: bold;
}
}
}
}
.footer {
.el-input__inner {
height: 80px;
line-height: 80px;
border: 1px solid rgba(220, 220, 220, 1);
border-radius: 2px;
}
.verification {
position: absolute;
bottom: 0;
left: 0;
top: 1px;
right: 1px;
width: 160px;
height: 78px;
cursor: pointer;
}
.submit {
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>

@ -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 => {
this.SET_ROLENAME(res)
}).catch(err => { })
async getRole () {
const res = await this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`)
this.SET_ROLENAME(res)
},
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 => { })
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 => { })
}
}
};

@ -1,137 +1,128 @@
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";
/**
* 用户信息
* */
export default {
namespaced: true,
state: {
customer: false, // true:为客户,没有个人中心
customerName: "", // 客户名称
title: "",
logoUrl: "",
avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
userId: '',
userName: "",
roleId: "",
dataTime: "",
roleName: '',
schoolId: '',
fromClient: false, // 是否从学生端登录
logView: false // 是否查询过日志状态,如果有,则不再调接口
},
mutations: {
SET_INFO: (state, info) => {
if (info.avatar) state.avatar = info.userAvatars;
state.userId = info.userId;
state.userName = info.userName;
state.roleId = info.roleId;
state.dataTime = info.dataTime;
},
SET_CUSTOMER: (state, customer) => {
state.customer = customer;
},
SET_CUSTOMER_NAME: (state, customerName) => {
state.customerName = customerName;
},
SET_TITLE: (state, title) => {
state.title = title;
},
SET_LOGO_URL: (state, logoUrl) => {
state.logoUrl = logoUrl;
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar;
},
SET_USERNAME: (state, userName) => {
state.userName = userName;
},
SET_ROLENAME: (state, roleName) => {
state.roleName = roleName
},
SET_FROM: (state, fromClient) => {
state.fromClient = fromClient
},
SET_SCHOOLID: (state, schoolId) => {
state.schoolId = schoolId
},
SET_LOG: (state) => {
state.logView = true
},
setUserId: (state, userId) => {
state.userId = userId
},
},
actions: {
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重做权限,因权限系统封装
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);
namespaced: true,
state: {
customerName: "", // 客户名称
title: "",
logoUrl: "",
avatar: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
userId: '',
userName: "",
roleId: "",
dataTime: "",
roleName: '',
schoolId: '',
fromClient: false, // 是否从学生端登录
logView: false // 是否查询过日志状态,如果有,则不再调接口
},
mutations: {
SET_INFO: (state, info) => {
if (info.avatar) state.avatar = info.userAvatars;
state.userId = info.userId;
state.userName = info.userName;
state.roleId = info.roleId;
state.dataTime = info.dataTime;
},
SET_CUSTOMER_NAME: (state, customerName) => {
state.customerName = customerName;
},
SET_TITLE: (state, title) => {
state.title = title;
},
SET_LOGO_URL: (state, logoUrl) => {
state.logoUrl = logoUrl;
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar;
},
SET_USERNAME: (state, userName) => {
state.userName = userName;
},
SET_ROLENAME: (state, roleName) => {
state.roleName = roleName
},
SET_FROM: (state, fromClient) => {
state.fromClient = fromClient
},
SET_SCHOOLID: (state, schoolId) => {
state.schoolId = schoolId
},
SET_LOG: (state) => {
state.logView = true
},
setUserId: (state, userId) => {
state.userId = userId
},
},
actions: {
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
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);
}
}).catch(error => {
reject(error);
});
});
},
logout({ commit, state, dispatch }) {
return new Promise((resolve, reject) => {
util.local.remove(Setting.storeKey);
util.local.remove(Setting.tokenKey);
if (state.fromClient) {
util.cookies.remove('serverLogin')
location.href = Setting.isDev
? `http://${location.hostname}:8082/#/`
: Setting.isTest
? `${location.origin}/student/#/login`
: `${location.origin}/#/login`
} else {
location.reload()
}
resolve();
});
},
setInfo({ state, commit }, info) {
commit("SET_INFO", info);
},
setTitle({ state, commit }, title) {
commit("SET_TITLE", title);
},
setLogoUrl({ state, commit }, logoUrl) {
commit("SET_LOGO_URL", logoUrl);
},
setCustomer({ state, commit }, customer) {
commit("SET_CUSTOMER", customer);
},
setCustomerName({ state, commit }, customerName) {
commit("SET_CUSTOMER_NAME", customerName);
},
setAvatar({ state, commit }, avatar) {
commit("SET_AVATAR", avatar);
},
setUserName({ state, commit }, userName) {
commit("SET_USERNAME", userName);
}
reject(res);
}
}).catch(error => {
reject(error);
});
});
},
logout ({ commit, state, dispatch }) {
return new Promise((resolve, reject) => {
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
? `http://${location.hostname}:8082/#/`
: Setting.isTest
? `${location.origin}/student/#/login`
: `${location.origin}/#/login`
} else {
location.reload()
}
resolve()
}).catch(error => {
reject(error)
})
})
},
setInfo ({ state, commit }, info) {
commit("SET_INFO", info);
},
setTitle ({ state, commit }, title) {
commit("SET_TITLE", title);
},
setLogoUrl ({ state, commit }, logoUrl) {
commit("SET_LOGO_URL", logoUrl);
},
setCustomerName ({ state, commit }, customerName) {
commit("SET_CUSTOMER_NAME", customerName);
},
setAvatar ({ state, commit }, avatar) {
commit("SET_AVATAR", avatar);
},
setUserName ({ state, commit }, userName) {
commit("SET_USERNAME", userName);
}
}
};
Loading…
Cancel
Save