module-menu-vue 0.0.14 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "module-menu-vue",
3
- "version": "0.0.14",
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 Axios from '../Util/axios.js';
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
- logout()
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 baseCof from './config';
3
- import getStore from './userInfo';
4
- import { checkToken} from './permessionUtils';
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='6c34dfbb-030f-4de1-ac4c-0e215f1fb098';
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,69 +33,29 @@ axios.interceptors.response.use(
33
33
  // 其他错误处理
34
34
  }
35
35
  }
36
- return Promise.reject(error.response.data);
36
+ return Promise.reject(error.response?.data);
37
37
  },
38
38
  );
39
39
 
40
- /** 全局请求拦截器 */
41
- axios.interceptors.request.use(
42
- async (params) => {
43
- console.log('process.env', process.env)
44
- // 生产环境,对接门户时,需要在请求头中设置token等信息
45
- // if (process.env.NODE_ENV === 'production') {
46
- const TENANT_ID = getStore({ name: 'tenantId' }) || '1';
47
- const isToken = (params.headers || {}).isToken === false;
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;
48
44
  const token = getStore({ name: 'access_token' });
49
- if (!(token && !isToken) || !TENANT_ID) {
50
- // 如果是调用退出登录接口,则不再执行退出登录逻辑,防止出现重复调用退出登录的循环
51
- return params;
45
+ if (token && !isToken) {
46
+ config.headers["Authorization"] = `Bearer ${token}`; // token
52
47
  }
53
- params.headers.common['Authorization'] = `Bearer ${token}`;
54
- params.headers.common['TENANT-ID'] = TENANT_ID;
55
- return params;
56
- // }
57
- // params.headers.common['Authorization'] = `Bearer ${tokenValue}`;
58
- // params.headers.common['TENANT-ID'] = '1';
59
- // return params;
48
+ if (TENANT_ID) {
49
+ config.headers["TENANT-ID"] = TENANT_ID; // 租户ID
50
+ }
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;
60
57
  },
61
- function (error) {
62
- // 对请求错误做些什么
58
+ error => {
63
59
  return Promise.reject(error);
64
- },
65
- );
66
-
67
- function Axios(method, api, params, map) {
68
- // 几个外部特殊接口
69
- // 退出登录
70
- let httpDefult = {
71
- method: method,
72
- params: params,
73
- ...map,
74
60
  }
75
- if(api === '/auth/token/logout'){
76
- httpDefult.url = `${baseCof.baseSever}${api}`;
77
- } else if (api === '/admin/social/logoutUri') {
78
- httpDefult.url = api
79
- } else if(api.search("check_token") !== -1){
80
- httpDefult.url = `${baseCof.baseSever}${api}`
81
- } else if (method === 'get') {
82
- httpDefult.url = `${baseCof.baseSever}${baseCof.basePath}${api}`
83
- } else if (method === 'post') {
84
- httpDefult.url = `${baseCof.baseSever}${baseCof.basePath}${api}`
85
- } else {
86
- httpDefult.url = `${baseCof.baseSever}${baseCof.basePath}${api}`
87
- }
88
- console.log('httpDefult', httpDefult)
89
-
90
- return new Promise((resolve, reject) => {
91
- axios(httpDefult)
92
- .then((res) => {
93
- resolve(res);
94
- })
95
- .catch((err) => {
96
- reject(err);
97
- });
98
- });
99
- }
100
-
101
- export default Axios;
61
+ );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 获取认证相关的localStorage/SessionStorage
3
3
  */
4
- function getStore(params) {
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,26 +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().catch(() => {
20
- this.$message.error({content:'用户凭证已过期,请重新登录', onClose: ()=>{
21
- localStorage.clear();
22
- sessionStorage.clear();
23
- window.location.href = DEFAULT_LOGOUT_URL;
24
- }});
25
- })
26
- }