feat:增加获取用户信息以及token失效跳到登录页

This commit is contained in:
lixg
2022-11-25 15:13:20 +08:00
parent 1dd90d9b1e
commit 762dbf90a7
8 changed files with 81 additions and 13 deletions

View File

@@ -89,6 +89,7 @@ export default defineComponent({
});
};
orgTree();
return {
routes,
name: currentRouteName,

View File

@@ -2,11 +2,12 @@
* @Author: lixg lixg@dongwu-inc.com
* @Date: 2022-11-21 14:32:52
* @LastEditors: lixg lixg@dongwu-inc.com
* @LastEditTime: 2022-11-23 09:59:26
* @LastEditTime: 2022-11-25 15:05:34
* @FilePath: /fe-manage/src/api/config.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import axios from "axios";
// import { getCookie } from '../api/method'
// const Qs = require("qs");
// axios.defaults.headers.post["Content-Type"] =
@@ -24,8 +25,9 @@ const http = axios.create({
http.interceptors.request.use(
(config) => {
const token = localStorage.getItem("token");
// const token = getCookie('token')
// console.log('token', token)
if (token) {
// config.headers.token = token;
config.headers.token = token; //测试1111
} else {
console.log("当前请求页面无token,请执行操作!!!");
@@ -44,12 +46,15 @@ http.interceptors.request.use(
http.interceptors.response.use(
(response) => {
// console.log('response', response)
const {
data: { code, msg },
} = response;
// console.log('code', code)
if (code === 0 || code === 200) {
return response;
} else {
// window.open("https://u-pre.boe.com/web/", '_self');
console.log("api %o", msg);
}
return response;

View File

@@ -2,13 +2,13 @@
* @Author: lixg lixg@dongwu-inc.com
* @Date: 2022-11-04 22:45:31
* @LastEditors: lixg lixg@dongwu-inc.com
* @LastEditTime: 2022-11-24 15:11:25
* @LastEditTime: 2022-11-25 14:56:59
* @FilePath: /fe-manage/src/api/index1.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import http from "./config";
import qs from "qs";
// import { getCookie } from '../api/method'
/**
* 接口传参数方式get
* axios.get('/user', {
@@ -104,7 +104,8 @@ export const getMemberInfo = (obj) => http.post('/admin/orgStruct/getMemberInfo'
export const getAudienceInfo = (obj) => http.post('/admin/orgStruct/getAudienceInfo', obj)
//获取授权(修改版)
export const optionAuthPerm = (obj) => http.post('/admin/AuthPerm/optionAuthPerm', obj)
//获取用户登录
export const getUser = () => http.post('/admin/CheckUser/login')
// 获取组织结构树

View File

@@ -162,11 +162,47 @@ function autoComma(number) {
return 0;
}
}
//把token存到cookie
//name 字段名 value 字段值 perpetual 有效期
const setCookie = (name, value, perpetual) => {
console.log('存储token到cookie')
let exdate = new Date()
exdate.setDate(perpetual * 24 * 60 * 60 * 1000) //exdate.setDate(exdate.getDate() + 365)
document.cookie = name + '=' + value + ';expires=' + exdate.toGMTString()
//永久有效
//document.cookie = name + '=' + value + ';expires=' + 'Fri, 31 Dec 9999 23:59:59 GMT'
}
//获取cookie数据
//先写一个方法
function getCookie(name) {
//1.获取cookie字符串
var cookies = document.cookie;
//通过;来分割字符串
var cookie = cookies.split("; ");
// console.log('cookie', cookie)
//遍历,使键值对匹配上
for (var i = 0; i < cookie.length; i++) {
var arr = cookie[i].split("token=");
// console.log('arr', arr)
console.log('name', name)
// if (arr[0] == name) {
// console.log('arr[1]', arr[1])
// return arr[1];
// }
// console.log('arr[1]', arr[1])
return arr[1]
}
return "";
}
//最后通
//新建延迟
const commonData = {
timeout: 50
timeout: 50,
}
// const organizationalTree = [
// {
// title: "京东方",
@@ -376,6 +412,8 @@ export {
getWeek,
autoComma,
formatNumber,
setCookie,
getCookie,
commonData,
organizationalTree,
iframeUrl,

View File

@@ -31,7 +31,7 @@
"
src="../assets/images/img.jpg"
/>
<div>李玉冰</div>
<div>{{ username }}</div>
</div>
<div
class="signOutMain"
@@ -59,6 +59,7 @@
<script>
import { reactive, toRefs } from "vue";
import DownLoad from "../components/drawers/DownLoad";
import * as api from "../api/index1";
export default {
name: "NavTop",
components: {
@@ -67,6 +68,7 @@ export default {
setup() {
const state = reactive({
selectRole: "管理员",
username: "",
roleList: [
{
id: 1,
@@ -91,6 +93,21 @@ export default {
state.visible = true;
console.log("点击下载", state.visible);
};
const getUser = () => {
api
.getUser()
.then((res) => {
console.log("获取登录信息成功", res);
if (res.data.code === 200) {
state.username = res.data.data.realName;
}
})
.catch((err) => {
console.log("获取登录信息失败", err);
});
};
getUser();
return {
...toRefs(state),
changeRole,

View File

@@ -559,8 +559,6 @@ export default {
//获取选中部门的人员信息
const getPeoples = () => {
let obj = {
keyWord: "",
id: 0,
org: state.selectedKeys[0],
pageNo: state.currentPage,
pageSize: state.pageSize,
@@ -569,7 +567,7 @@ export default {
state.tableDataTotal = 0;
return;
}
// console.log("obj", obj);
console.log("obj", obj);
api
.getMemberInfo(obj)
.then((res) => {

View File

@@ -646,7 +646,11 @@ import QueryRight from "../../components/drawers/QueryRight";
import ManageRight from "../../components/drawers/ManageRight";
import * as api from "../../api/index1";
import { message } from "ant-design-vue";
import { toDate, commonData } from "../../api/method";
import {
toDate,
commonData,
// setCookie
} from "../../api/method";
import { storage } from "../../api/storage";
export default {
name: "learningPath",
@@ -1642,6 +1646,9 @@ export default {
onMounted(() => {
// console.log("执行");
getLearnPath();
// let cookie =
// "eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NjkzNTU0MjQsImV4cCI6MTY2OTM2MjYyNCwiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.a565952d942ac41a6258a187be48a9269a75d0bfc50c6f13eb42362fe2f3d76a";
// setCookie("token", cookie, 10);
});
return {

View File

@@ -195,7 +195,7 @@
tree-default-expand-all
:tree-data="classifyList2"
:fieldNames="{
children: 'children',
children: 'treeChildList',
label: 'name',
value: 'id',
}"
@@ -769,6 +769,7 @@ export default {
{ value: 2, label: "将小米" },
{ value: 3, label: "刘孟君" },
]);
//获取
//选择处理项目经理
let manager = "";