Commit 0adf3cc1 authored by 周远喜's avatar 周远喜

登陆切换

parent 0c231368
...@@ -2,7 +2,7 @@ import request from '@/plugins/request'; ...@@ -2,7 +2,7 @@ import request from '@/plugins/request';
export function AccountLogin (data) { export function AccountLogin (data) {
return request({ return request({
url: '/api/login', url: `${authUrl}/api/services/app/auth/login`,
method: 'post', method: 'post',
data data
}); });
......
...@@ -33,7 +33,6 @@ export default { ...@@ -33,7 +33,6 @@ export default {
}, },
mounted() { mounted() {
this.getMenu(); this.getMenu();
this.initUserInfo();
}, },
watch: { watch: {
// 监听路由 控制侧边栏显示 标记当前顶栏菜单(如需要) // 监听路由 控制侧边栏显示 标记当前顶栏菜单(如需要)
...@@ -66,29 +65,7 @@ export default { ...@@ -66,29 +65,7 @@ export default {
} }
}, },
methods: { methods: {
//获取用户基本信息
initUserInfo() {
let userInfo = this.$store.state.admin.user.info;
let parma = {
Id: userInfo.userId
};
this.$http.sysUser.getuserinfo(parma).then(res => {
if (res.result) {
if (
res.result.avatarUrl &&
res.result.avatarUrl != "" &&
res.result.avatarUrl != null
) {
res.result.avatarUrl = fileUrlDown + res.result.avatarUrl;
}
this.$store.commit("admin/user/setUserAvatar", res.result);
} else {
this.$Message.error("用户信息查询失败!");
}
});
},
//用户中心结束
//menu
getMenu() { getMenu() {
this.$http.sysUser.getusermenu().then(res => { this.$http.sysUser.getusermenu().then(res => {
if (res.result) { if (res.result) {
......
<template> <template>
<div class="account"> <div class="account">
<Carousel v-model="value1" autoplay autoplay-speed="5000" loop class="zmd"> <Carousel v-model="value1" autoplay :autoplay-speed="5000" loop class="zmd">
<CarouselItem> <CarouselItem>
<div class="bg bg0">1</div> <div class="bg bg0">1</div>
</CarouselItem> </CarouselItem>
...@@ -29,17 +29,16 @@ ...@@ -29,17 +29,16 @@
<!-- <div class="page-account-top-desc tc">SaaS MES 制造执行系统</div> --> <!-- <div class="page-account-top-desc tc">SaaS MES 制造执行系统</div> -->
</div> </div>
<h3 class="mb20">用户登陆</h3> <h3 class="mb20">用户登陆</h3>
<Login @on-submit="oidc"> <Login @on-submit="handleSubmit">
<UserName name="username" value="admin" /> <UserName name="username" value="13211111111" />
<Password name="password" value="admin" enter-to-submit /> <Password name="password" value="1" enter-to-submit />
<div class="page-account-auto-login mb20"> <div class="page-account-auto-login mb20">
<Checkbox v-model="autoLogin" >{{ $t('page.login.remember') }}</Checkbox> <Checkbox v-model="autoLogin">{{ $t('page.login.remember') }}</Checkbox>
<a href>{{ $t('page.login.forgot') }}</a> <a href>{{ $t('page.login.forgot') }}</a>
</div> </div>
<div class="mt20"> <div class="mt20">
<Submit class="shadown">{{ $t('page.login.submit') }}</Submit> <Submit class="shadown">{{ $t('page.login.submit') }}</Submit>
</div> </div>
</Login> </Login>
</div> </div>
</div> </div>
...@@ -58,6 +57,7 @@ export default { ...@@ -58,6 +57,7 @@ export default {
components: { iCopyright }, components: { iCopyright },
data() { data() {
return { return {
value1: 0,
autoLogin: true autoLogin: true
}; };
}, },
...@@ -66,34 +66,6 @@ export default { ...@@ -66,34 +66,6 @@ export default {
}, },
methods: { methods: {
...mapActions("admin/account", ["login"]), ...mapActions("admin/account", ["login"]),
oidc() {
let that = this;
mgr.getUser().then(function(user) {
if (user) {
console.info("user",user)
that.msg = "该用户已经登录";
const userInfos = {
token: user.access_token,
login_id: user.profile.name,
userId:
user.profile[
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
],
accountId: user.profile.sub,
tanantCode: user.profile.TanantCode,
name: "Aresn",
avatar:
"https://dev-file.iviewui.com/userinfoPDvn9gKWYihR24SpgC319vXY8qniCqj4/avatar",
access: ["admin"]
};
// that.$store.commit('setUserInfo',userInfos);
that.oidcLogin(userInfos);
window.location = "/";
} else {
mgr.signinRedirect();
}
});
},
/** /**
* @description 登录 * @description 登录
* 表单校验已有 iView Pro 自动完成,如有需要修改,请阅读 iView Pro 文档 * 表单校验已有 iView Pro 自动完成,如有需要修改,请阅读 iView Pro 文档
...@@ -104,26 +76,50 @@ export default { ...@@ -104,26 +76,50 @@ export default {
this.login({ this.login({
username, username,
password password
}).then(() => { }).then(r => {
// 重定向对象不存在则返回顶层路径 if (r > 0) {
this.$router.replace(this.$route.query.redirect || "/"); this.$Message.success("登陆成功!");
this.initUserInfo(r);
} else {
this.$Message.error("登陆失败!");
}
}); });
} }
}, },
oidcLogin(user) { initUserInfo(id) {
util.cookies.set("uuid", user.userId); let parma = {
util.cookies.set("token", user.token); Id: id
// 设置 vuex 用户信息 };
this.$store.dispatch("admin/user/set", user, { root: true }); this.$http.sysUser.getuserinfo(parma).then(res => {
// 用户登录后从持久化数据加载一系列的设置 if (res.result) {
this.$store.dispatch("load"); if (
this.$store.commit("setUserInfo", user); res.result.avatarUrl &&
res.result.avatarUrl != "" &&
res.result.avatarUrl != null
) {
res.result.avatarUrl = fileUrlDown + res.result.avatarUrl;
}
let info = res.result;
info.auth = ["admin"];
info.avatar = info.avatarUrl;
info.userId=info.id;
info.name=info.userName;
this.$store.dispatch("admin/user/set", info, {
root: true
});
// setUserInfo
this.$store.commit("setUserInfo",info)
this.$router.replace(this.$route.query.redirect || "/");
} else {
this.$Message.error("用户信息22查询失败!");
}
});
} }
} }
}; };
</script> </script>
<style lang="less"> <style lang="less">
@jianju:40px; @jianju: 40px;
.account { .account {
position: fixed; position: fixed;
width: 100%; width: 100%;
...@@ -160,12 +156,14 @@ export default { ...@@ -160,12 +156,14 @@ export default {
left: @jianju; left: @jianju;
right: @jianju; right: @jianju;
bottom: @jianju; bottom: @jianju;
background: rgba(38,128,235, 0.3); background: rgba(38, 128, 235, 0.3);
display: flex; display: flex;
.ad{ .ad {
flex: 1; flex: 1;
text-align: center; text-align: center;
img{margin-top: 400px;} img {
margin-top: 400px;
}
} }
.login { .login {
background-color: white; background-color: white;
...@@ -176,14 +174,13 @@ export default { ...@@ -176,14 +174,13 @@ export default {
// background-position-y: 525px; // background-position-y: 525px;
.ivu-input-wrapper { .ivu-input-wrapper {
margin-bottom: 5px; margin-bottom: 5px;
} }
.mt20{ .mt20 {
margin-top: 50px; margin-top: 50px;
.shadown{ .shadown {
box-shadow: 1px 5px 15px #2680EB; box-shadow: 1px 5px 15px #2680eb;
} }
.ivu-btn-large{ .ivu-btn-large {
height: 50px !important; height: 50px !important;
} }
} }
......
...@@ -94,7 +94,7 @@ Vue.component("DTSpan", DTSpan) ...@@ -94,7 +94,7 @@ Vue.component("DTSpan", DTSpan)
Vue.component("DTSearch", DTSearch) Vue.component("DTSearch", DTSearch)
//注入mock //注入mock
require("../mock") // require("../mock")
Vue.prototype.$api=request; Vue.prototype.$api=request;
Vue.prototype.$http=Api; Vue.prototype.$http=Api;
Vue.prototype.$u = Henq; Vue.prototype.$u = Henq;
......
...@@ -13,6 +13,14 @@ function errorCreate (msg) { ...@@ -13,6 +13,14 @@ function errorCreate (msg) {
// 记录和显示错误 // 记录和显示错误
function errorLog (err) { function errorLog (err) {
if(err&&err.response&&err.response.status==500){
console.log(err.response)
Message.error({
content: err.response.data.error.message,
duration: 5
})
return;
}
// 添加到日志 // 添加到日志
$nuxt.$store.dispatch('admin/log/push', { $nuxt.$store.dispatch('admin/log/push', {
message: '数据请求异常', message: '数据请求异常',
...@@ -28,18 +36,18 @@ function errorLog (err) { ...@@ -28,18 +36,18 @@ function errorLog (err) {
console.log(err); console.log(err);
} }
// 显示提示,可配置使用 iView 的 $Message 还是 $Notice 组件来显示 // 显示提示,可配置使用 iView 的 $Message 还是 $Notice 组件来显示
if (Setting.errorModalType === 'Message') { // if (Setting.errorModalType === 'Message') {
Message.error({ // Message.error({
content: err.message, // content: err.message,
duration: Setting.modalDuration // duration: Setting.modalDuration
}); // });
} else if (Setting.errorModalType === 'Notice') { // } else if (Setting.errorModalType === 'Notice') {
Notice.error({ // Notice.error({
title: '提示', // title: '提示',
desc: err.message, // desc: err.message,
duration: Setting.modalDuration // duration: Setting.modalDuration
}); // });
} // }
} }
// 创建一个 axios 实例 // 创建一个 axios 实例
...@@ -83,7 +91,7 @@ service.interceptors.request.use( ...@@ -83,7 +91,7 @@ service.interceptors.request.use(
}, },
error => { error => {
// 发送失败 // 发送失败
console.log(error); // console.log(error);
Promise.reject(error); Promise.reject(error);
} }
); );
......
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
* */ * */
import util from '@/libs/util'; import util from '@/libs/util';
// import router from '@/router'; // import router from '@/router';
import { AccountLogin, AccountRegister } from '@/api/account'; import {
import Oidc from 'oidc-client' AccountLogin,
import { Modal } from 'view-design'; AccountRegister
export const actions={ } from '@/api/account';
import {
Modal
} from 'view-design';
export const actions = {
/** /**
* @description 登录 * @description 登录
* @param {Object} param context * @param {Object} param context
...@@ -14,7 +18,9 @@ export const actions={ ...@@ -14,7 +18,9 @@ export const actions={
* @param {Object} param password {String} 密码 * @param {Object} param password {String} 密码
* @param {Object} param route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式 * @param {Object} param route {Object} 登录成功后定向的路由对象 任何 vue-router 支持的格式
*/ */
login ({ dispatch }, { login({
dispatch
}, {
username = '', username = '',
password = '' password = ''
} = {}) { } = {}) {
...@@ -32,14 +38,24 @@ export const actions={ ...@@ -32,14 +38,24 @@ export const actions={
// 如有必要 token 需要定时更新,默认保存一天,可在 setting.js 中修改 // 如有必要 token 需要定时更新,默认保存一天,可在 setting.js 中修改
// 如果你的 token 不是通过 cookie 携带,而是普通字段,也可视情况存储在 localStorage // 如果你的 token 不是通过 cookie 携带,而是普通字段,也可视情况存储在 localStorage
console.warn(res); console.warn(res);
util.cookies.set('uuid', res.uuid); if (res.result) {
util.cookies.set('token', res.token);
// 设置 vuex 用户信息 util.cookies.set('uuid', res.result.userId);
await dispatch('admin/user/set', res.info, { root: true }); util.cookies.set('tanantCode', res.result.tanantCode);
// 用户登录后从持久化数据加载一系列的设置 util.cookies.set('token', res.result.accessToken);
await dispatch('load'); sessionStorage.setItem('token', res.result.accessToken)
// // 设置 vuex 用户信息
// await dispatch('admin/user/set', res.info, {
// root: true
// });
// // 用户登录后从持久化数据加载一系列的设置
// await dispatch('load');
// 结束 // 结束
resolve(res.result.userId);
} else {
resolve(); resolve();
}
}) })
.catch(err => { .catch(err => {
// console.log('err: ', err); // console.log('err: ', err);
...@@ -50,23 +66,23 @@ export const actions={ ...@@ -50,23 +66,23 @@ export const actions={
/** /**
* @description 退出登录 * @description 退出登录
* */ * */
logout ({ commit, dispatch }, { confirm = false, vm } = {}) { logout({
var mgr = new Oidc.UserManager(window.authConfig) commit,
async function logout () { dispatch
}, {
confirm = false,
vm
} = {}) {
async function logout() {
// 删除cookie // 删除cookie
util.cookies.remove('token'); util.cookies.remove('token');
util.cookies.remove('uuid'); util.cookies.remove('uuid');
// 清空 vuex 用户信息 // 清空 vuex 用户信息
await dispatch('admin/user/set', {}, { root: true }); await dispatch('admin/user/set', {}, {
// 跳转路由 root: true
// alert(123) });
sessionStorage.clear();
window.frames[0].sessionStorage.clear() localStorage.clear();
sessionStorage.clear()
mgr.events.addUserSignedOut(function() {
log('User signed out of OP')
mgr.removeUser()
})
$nuxt.$router.push("/account/login"); $nuxt.$router.push("/account/login");
} }
...@@ -74,7 +90,7 @@ export const actions={ ...@@ -74,7 +90,7 @@ export const actions={
Modal.confirm({ Modal.confirm({
title: vm.$t('basicLayout.logout.confirmTitle'), title: vm.$t('basicLayout.logout.confirmTitle'),
content: vm.$t('basicLayout.logout.confirmContent'), content: vm.$t('basicLayout.logout.confirmContent'),
onOk () { onOk() {
logout(); logout();
} }
}); });
...@@ -90,7 +106,9 @@ export const actions={ ...@@ -90,7 +106,9 @@ export const actions={
* @param {Object} param mobile {String} 手机号码 * @param {Object} param mobile {String} 手机号码
* @param {Object} param captcha {String} 验证码 * @param {Object} param captcha {String} 验证码
*/ */
register ({ dispatch }, { register({
dispatch
}, {
mail = '', mail = '',
password = '', password = '',
mobile = '', mobile = '',
...@@ -110,7 +128,9 @@ export const actions={ ...@@ -110,7 +128,9 @@ export const actions={
util.cookies.set('uuid', res.uuid); util.cookies.set('uuid', res.uuid);
util.cookies.set('token', res.token); util.cookies.set('token', res.token);
// 设置 vuex 用户信息 // 设置 vuex 用户信息
await dispatch('admin/user/set', res.info, { root: true }); await dispatch('admin/user/set', res.info, {
root: true
});
// 用户登录后从持久化数据加载一系列的设置 // 用户登录后从持久化数据加载一系列的设置
await dispatch('load'); await dispatch('load');
// 结束 // 结束
...@@ -127,12 +147,19 @@ export const actions={ ...@@ -127,12 +147,19 @@ export const actions={
* @param {Object} state vuex state * @param {Object} state vuex state
* @param {Object} dispatch vuex dispatch * @param {Object} dispatch vuex dispatch
*/ */
load ({ state, dispatch }) { load({
state,
dispatch
}) {
return new Promise(async resolve => { return new Promise(async resolve => {
// 加载用户登录信息 // 加载用户登录信息
await dispatch('admin/user/load', null, { root: true }); await dispatch('admin/user/load', null, {
root: true
});
// 持久化数据加载上次退出时的多页列表 // 持久化数据加载上次退出时的多页列表
await dispatch('admin/page/openedLoad', null, { root: true }); await dispatch('admin/page/openedLoad', null, {
root: true
});
// end // end
resolve(); resolve();
}) })
......
...@@ -41,8 +41,8 @@ export const mutations={ ...@@ -41,8 +41,8 @@ export const mutations={
}, },
setUserInfo(state, userInfo) { setUserInfo(state, userInfo) {
state.userInfo = userInfo; state.userInfo = userInfo;
sessionStorage.setItem("userInfo", JSON.stringify(userInfo)); // sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
sessionStorage.setItem("token", userInfo.token); // sessionStorage.setItem("token", userInfo.token);
}, },
addUser(state,user){ addUser(state,user){
state.userMap.push(user); state.userMap.push(user);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment