module-menu-vue 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/components/User/UserInfo.vue +27 -3
- package/src/components/User/service.js +23 -0
- package/src/components/Util/axios.js +25 -64
- package/src/components/Util/userInfo.js +1 -2
- package/src/main.js +8 -0
- package/src/components/Util/config.js +0 -10
- package/src/components/Util/permessionUtils.js +0 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "module-menu-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "城市大数据平台菜单--Vue版",
|
|
5
5
|
"main": "/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"axios": "^1.4.0",
|
|
13
13
|
"core-js": "^3.8.3",
|
|
14
14
|
"element-ui": "^2.15.13",
|
|
15
|
-
"vue": "^2.6.14"
|
|
15
|
+
"vue": "^2.6.14",
|
|
16
|
+
"vue-axios": "^3.5.2"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@babel/core": "^7.12.16",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
</template>
|
|
31
31
|
|
|
32
32
|
<script >
|
|
33
|
-
// import
|
|
34
|
-
import {logout} from '../Util/permessionUtils'
|
|
33
|
+
// import {logout} from './service.js'
|
|
35
34
|
import {userMenuIcon} from './constant.js'
|
|
35
|
+
import { getStore } from '../Util/userInfo.js';
|
|
36
36
|
export default {
|
|
37
37
|
name: 'UserInfo',
|
|
38
38
|
data () {
|
|
@@ -60,10 +60,34 @@ export default {
|
|
|
60
60
|
} else if (flag === 'systerm') {
|
|
61
61
|
url = '/#/admin/user/index'
|
|
62
62
|
} else if (flag === 'logout') {
|
|
63
|
-
|
|
63
|
+
this.logoutFunc()
|
|
64
64
|
}
|
|
65
65
|
window.location.href = url;
|
|
66
66
|
},
|
|
67
|
+
logoutFunc () {
|
|
68
|
+
const config = {
|
|
69
|
+
headers: {}
|
|
70
|
+
}
|
|
71
|
+
const TENANT_ID = getStore({ name: "tenantId" }) || '1';
|
|
72
|
+
const isToken = (config.headers || {}).isToken === false;
|
|
73
|
+
const token = getStore({ name: 'access_token' });
|
|
74
|
+
if (token && !isToken) {
|
|
75
|
+
config.headers["Authorization"] = `Bearer ${token}`; // token
|
|
76
|
+
}
|
|
77
|
+
if (TENANT_ID) {
|
|
78
|
+
config.headers["TENANT-ID"] = TENANT_ID; // 租户ID
|
|
79
|
+
}
|
|
80
|
+
this.axios({
|
|
81
|
+
method: 'delete',
|
|
82
|
+
url: '/auth/token/logout',
|
|
83
|
+
...config
|
|
84
|
+
}).then(res => {
|
|
85
|
+
console.log('res', res)
|
|
86
|
+
location.href = '/#/login'
|
|
87
|
+
}).catch((err) => {
|
|
88
|
+
console.error(err)
|
|
89
|
+
})
|
|
90
|
+
},
|
|
67
91
|
getUserName () {
|
|
68
92
|
const userInfo = JSON.parse(sessionStorage.getItem('bigdata-userInfo')||"{}");
|
|
69
93
|
if (userInfo && userInfo.content && Object.keys(userInfo.content).length > 0 && userInfo.content.username) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import request from 'axios'
|
|
2
|
+
import { Message } from 'element-ui';
|
|
3
|
+
const DEFAULT_LOGOUT_URL = '/#/login'
|
|
4
|
+
export const logout = () => {
|
|
5
|
+
return request({
|
|
6
|
+
url: '/auth/token/logout',
|
|
7
|
+
method: 'delete'
|
|
8
|
+
})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 校验token是否失效
|
|
12
|
+
export const checkToken = (token) => {
|
|
13
|
+
return request({
|
|
14
|
+
url: `/auth/oauth/check_token?token=${token}`,
|
|
15
|
+
method: 'get'
|
|
16
|
+
}).then().catch(() => {
|
|
17
|
+
Message.error({content:'用户凭证已过期,请重新登录', onClose: ()=>{
|
|
18
|
+
localStorage.clear();
|
|
19
|
+
sessionStorage.clear();
|
|
20
|
+
window.location.href = DEFAULT_LOGOUT_URL;
|
|
21
|
+
}});
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
// import axios from 'axios';
|
|
2
|
+
import { getStore } from './userInfo.js';
|
|
3
|
+
import { checkToken} from '../User/service.js';
|
|
4
|
+
// import qs from "qs";
|
|
5
5
|
|
|
6
|
-
let tokenValue='
|
|
6
|
+
let tokenValue='200ad182-7aec-4473-98a4-08d3d8bccf73';
|
|
7
7
|
|
|
8
|
-
axios.interceptors.response.use(
|
|
8
|
+
this.axios.interceptors.response.use(
|
|
9
9
|
(response) => {
|
|
10
10
|
if (response.status === 200) {
|
|
11
11
|
return response;
|
|
@@ -33,68 +33,29 @@ axios.interceptors.response.use(
|
|
|
33
33
|
// 其他错误处理
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return Promise.reject(error.response
|
|
36
|
+
return Promise.reject(error.response?.data);
|
|
37
37
|
},
|
|
38
38
|
);
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return params;
|
|
51
|
-
}
|
|
52
|
-
params.headers.common['Authorization'] = `Bearer ${token}`;
|
|
53
|
-
params.headers.common['TENANT-ID'] = TENANT_ID;
|
|
54
|
-
return params;
|
|
40
|
+
this.axios.interceptors.request.use(config => {
|
|
41
|
+
console.log('-----', token, isToken, TENANT_ID)
|
|
42
|
+
const TENANT_ID = getStore({ name: "tenantId" }) || '1';
|
|
43
|
+
const isToken = (config.headers || {}).isToken === false;
|
|
44
|
+
const token = getStore({ name: 'access_token' });
|
|
45
|
+
if (token && !isToken) {
|
|
46
|
+
config.headers["Authorization"] = `Bearer ${token}`; // token
|
|
47
|
+
}
|
|
48
|
+
if (TENANT_ID) {
|
|
49
|
+
config.headers["TENANT-ID"] = TENANT_ID; // 租户ID
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
// config.headers["Authorization"] = "Bearer " + '9e3f86b0-41e2-436a-9f0d-aeace114cc66'; // token
|
|
52
|
+
// config.headers["TENANT-ID"] = 1; // 租户ID
|
|
53
|
+
// config.paramsSerializer = function (params) {
|
|
54
|
+
// return qs.stringify(params, { arrayFormat: "repeat" });
|
|
55
|
+
// };
|
|
56
|
+
return config;
|
|
59
57
|
},
|
|
60
|
-
|
|
61
|
-
// 对请求错误做些什么
|
|
58
|
+
error => {
|
|
62
59
|
return Promise.reject(error);
|
|
63
|
-
},
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
function Axios(method, api, params, map) {
|
|
67
|
-
// 几个外部特殊接口
|
|
68
|
-
// 退出登录
|
|
69
|
-
let httpDefult = {
|
|
70
|
-
method: method,
|
|
71
|
-
params: params,
|
|
72
|
-
...map,
|
|
73
60
|
}
|
|
74
|
-
|
|
75
|
-
httpDefult.url = `${baseCof.baseSever}${api}`;
|
|
76
|
-
} else if (api === '/admin/social/logoutUri') {
|
|
77
|
-
httpDefult.url = api
|
|
78
|
-
} else if(api.search("check_token") !== -1){
|
|
79
|
-
httpDefult.url = `${baseCof.baseSever}${api}`
|
|
80
|
-
} else if (method === 'get') {
|
|
81
|
-
httpDefult.url = `${baseCof.baseSever}${baseCof.basePath}${api}`
|
|
82
|
-
} else if (method === 'post') {
|
|
83
|
-
httpDefult.url = `${baseCof.baseSever}${baseCof.basePath}${api}`
|
|
84
|
-
} else {
|
|
85
|
-
httpDefult.url = `${baseCof.baseSever}${baseCof.basePath}${api}`
|
|
86
|
-
}
|
|
87
|
-
console.log('httpDefult', httpDefult)
|
|
88
|
-
|
|
89
|
-
return new Promise((resolve, reject) => {
|
|
90
|
-
axios(httpDefult)
|
|
91
|
-
.then((res) => {
|
|
92
|
-
resolve(res);
|
|
93
|
-
})
|
|
94
|
-
.catch((err) => {
|
|
95
|
-
reject(err);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default Axios;
|
|
61
|
+
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 获取认证相关的localStorage/SessionStorage
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
export const getStore = (params) => {
|
|
5
5
|
let { name } = params;
|
|
6
6
|
const { debug } = params;
|
|
7
7
|
const keyName = 'bigdata-';
|
|
@@ -31,7 +31,6 @@ function getStore(params) {
|
|
|
31
31
|
}
|
|
32
32
|
return content;
|
|
33
33
|
}
|
|
34
|
-
export default getStore;
|
|
35
34
|
|
|
36
35
|
export const getUserName = () => {
|
|
37
36
|
const userInfo = getStore({ name: 'userInfo' });
|
package/src/main.js
CHANGED
|
@@ -2,8 +2,16 @@ import Vue from 'vue'
|
|
|
2
2
|
import App from './App.vue'
|
|
3
3
|
import ElementUI from 'element-ui';
|
|
4
4
|
import 'element-ui/lib/theme-chalk/index.css';
|
|
5
|
+
import axios from 'axios'
|
|
6
|
+
import VueAxios from 'vue-axios'
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
Vue.config.productionTip = false
|
|
6
10
|
Vue.use(ElementUI);
|
|
11
|
+
window.axios = axios
|
|
12
|
+
Vue.use(VueAxios, axios)
|
|
13
|
+
|
|
14
|
+
|
|
7
15
|
new Vue({
|
|
8
16
|
render: h => h(App),
|
|
9
17
|
}).$mount('#app')
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const address = window.location.hostname
|
|
2
|
-
const port = window.location.port
|
|
3
|
-
const baseCof = process.env.NODE_ENV === 'production' ?{
|
|
4
|
-
baseSever: `https://${address}:${port}`,
|
|
5
|
-
basePath: `/app/cmcc/data`,
|
|
6
|
-
}:{
|
|
7
|
-
baseSever: 'http://localhost:8000',
|
|
8
|
-
basePath: '/cmcc/data',
|
|
9
|
-
};
|
|
10
|
-
export default baseCof;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Axios from './axios.js';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_LOGOUT_URL = '/#/login'
|
|
4
|
-
// 退出登录
|
|
5
|
-
export const logout = () => {
|
|
6
|
-
Axios('delete','/auth/token/logout', '', {} )
|
|
7
|
-
.then(() => {
|
|
8
|
-
localStorage.clear();
|
|
9
|
-
sessionStorage.clear();
|
|
10
|
-
window.location.href = DEFAULT_LOGOUT_URL;
|
|
11
|
-
})
|
|
12
|
-
.catch((error) => {
|
|
13
|
-
console.error('Error while logging out, error:', error);
|
|
14
|
-
this.$message.error('服务器错误,请稍后重试');
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
// 校验token是否失效
|
|
18
|
-
export const checkToken = (token) => {
|
|
19
|
-
Axios('get',`/auth/oauth/check_token?token=${token}`, '', {} ).then(
|
|
20
|
-
).catch(() => {
|
|
21
|
-
this.$message.error({content:'用户凭证已过期,请重新登录', onClose: ()=>{
|
|
22
|
-
localStorage.clear();
|
|
23
|
-
sessionStorage.clear();
|
|
24
|
-
window.location.href = DEFAULT_LOGOUT_URL;
|
|
25
|
-
}});
|
|
26
|
-
})
|
|
27
|
-
}
|