yuang-framework-ui-common 1.0.29 → 1.0.31

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.
@@ -1,4 +1,5 @@
1
1
  import axios from "axios"
2
+ import type { AxiosResponse } from 'axios';
2
3
 
3
4
  import { showErrorMessage } from '../utils/messageUtils';
4
5
  import { alertMessageBox } from '../utils/messageBoxUtils';
@@ -14,8 +15,10 @@ const messageMap = {
14
15
  responseSturctError: '响应结构错误',
15
16
  }
16
17
 
18
+ const apiBaseUrl = '/gateway-server';
19
+
17
20
  const http = axios.create({
18
- baseURL: '/gateway-server',
21
+ baseURL: apiBaseUrl,
19
22
  timeout: 10000,
20
23
  headers: {}
21
24
  })
@@ -36,7 +39,7 @@ http.interceptors.request.use(async config => {
36
39
 
37
40
 
38
41
  /* 响应拦截器 */
39
- http.interceptors.response.use((res) => {
42
+ http.interceptors.response.use(async (res: any) => {
40
43
  if (!res?.data?.statusCode) {
41
44
  showErrorMessage(messageMap.responseSturctError);
42
45
  return Promise.reject(new Error(messageMap.responseSturctError));
@@ -66,11 +69,9 @@ http.interceptors.response.use((res) => {
66
69
  window.location.href = getSsoLoginUrl() || '';
67
70
  return Promise.reject(new Error(res?.data?.message));
68
71
  } else if (res?.data?.statusCode === 815002) {
69
- axios.get('/sso-api/client/auth/getSsoRefreshToken').then(res => {
70
- setSsoAccessToken(res.data.data);
71
- // 重发请求
72
- return axios.request(res.config);
73
- })
72
+ await refreshSsoAccessToken(res);
73
+ // 重发请求
74
+ return axios.request(res.config);
74
75
  } else if (res?.data?.statusCode === 815003) {
75
76
  showErrorMessage(res?.data?.message || messageMap.requestError);
76
77
  return Promise.reject(new Error(res?.data?.message));
@@ -123,4 +124,24 @@ const beforeRequestConfig = (config: any) => {
123
124
  }
124
125
 
125
126
 
127
+ /**
128
+ * 刷新ssoAccessToken
129
+ * @param res
130
+ */
131
+ const refreshSsoAccessToken = (res: any) => {
132
+ return new Promise((resolve, reject) => {
133
+ const config = res.config
134
+ config.params = {
135
+ ssoRefreshToken: encodeURIComponent(getLocalStorageItem("ssoRefreshToken") ?? ''),
136
+ }
137
+ axios.get(`/sso-api/client/auth/getSsoRefreshToken`, config).then(res => {
138
+ if (res?.data?.statusCode !== 200) {
139
+ return reject();
140
+ }
141
+ setSsoAccessToken(res.data.data);
142
+ return resolve(void 0);
143
+ });
144
+ });
145
+ }
146
+
126
147
  export { http }
@@ -7,8 +7,7 @@ import {getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem} from '
7
7
  const getSsoLoginUrl = (redirectUrl = '') => {
8
8
  let apiFullBaseUrl = (window as any).$config?.apiFullBaseUrl;
9
9
  if(!apiFullBaseUrl) {
10
- console.error('参数[apiFullBaseUrl]为空');
11
- return;
10
+ throw new Error('参数[apiFullBaseUrl]为空');
12
11
  }
13
12
  let ssoLoginUrl = `${apiFullBaseUrl}/sso-api/server/sso/login`;
14
13
  if (!redirectUrl) {
@@ -22,8 +21,7 @@ const getSsoLoginUrl = (redirectUrl = '') => {
22
21
  const getSsoLogoutUrl = (redirectUrl = '') => {
23
22
  let apiFullBaseUrl = (window as any).$config?.apiFullBaseUrl;
24
23
  if(!apiFullBaseUrl) {
25
- console.error('参数[apiFullBaseUrl]为空');
26
- return;
24
+ throw new Error('参数[apiFullBaseUrl]为空');
27
25
  }
28
26
  let ssoLogoutUrl = `${apiFullBaseUrl}/sso-api/server/sso/logout`;
29
27
  if (!redirectUrl) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "vite",
7
+ "dev": "vite --mode dev",
8
8
  "build": "vite build",
9
9
  "preview": "vite preview",
10
10
  "test:unit": "vitest",
@@ -29,7 +29,7 @@
29
29
  "@wangeditor/editor-for-vue": "^5.1.12",
30
30
  "axios": "^1.7.3",
31
31
  "crypto-js": "^4.2.0",
32
- "element-plus": "^2.7.8",
32
+ "element-plus": "^2.8.4",
33
33
  "js-cookie": "^3.0.5",
34
34
  "jsencrypt": "^3.3.2",
35
35
  "lodash": "^4.17.21",
package/src/main.ts CHANGED
@@ -11,8 +11,11 @@ const app = createApp(App)
11
11
  app.use(createPinia())
12
12
  app.use(router)
13
13
 
14
-
15
- initConfig(app);
14
+ const config = {
15
+ apiBaseUrl: import.meta.env.VITE_API_BASE_URL,
16
+ apiFullBaseUrl: import.meta.env.VITE_API_FULL_BASE_URL
17
+ };
18
+ initConfig(app, config);
16
19
 
17
20
  app.mount('#app')
18
21
 
@@ -1,9 +1,20 @@
1
1
  import {createRouter, createWebHistory} from 'vue-router'
2
2
  import {getExceptionRoutes} from '../../lib/utils/vueRouterUtils'
3
3
 
4
+ import { getSsoAccessToken, getSsoLoginRoutePath } from '../../lib/utils/ssoUtils';
5
+
6
+
4
7
  const router = createRouter({
5
8
  history: createWebHistory(import.meta.env.BASE_URL),
6
9
  routes: [
10
+ {
11
+ path: '/sso/login/index',
12
+ component: () => import('@/views/sso/login/index.vue'),
13
+ meta: {
14
+ title: '登录',
15
+ isAnonymous: true
16
+ }
17
+ },
7
18
  {
8
19
  path: '/config/gateway-config',
9
20
  component: () => import('@/views/config/gateway-config.vue')
@@ -26,14 +37,27 @@ const router = createRouter({
26
37
  component: () => import('@/views/utils/message-utils.vue')
27
38
  },
28
39
 
40
+
41
+
42
+ {
43
+ path: '/example/table/index',
44
+ component: () => import('@/views/example/table/index.vue')
45
+ },
46
+
29
47
  ...getExceptionRoutes()
30
48
  ]
31
49
  })
32
50
 
33
51
 
34
52
  /* 路由守卫 */
35
- router.beforeEach(async (to, from, next) => {
36
- next();
53
+ router.beforeEach(async (to) => {
54
+ if (!getSsoAccessToken()) {
55
+ if (!to.meta?.isAnonymous) {
56
+ return getSsoLoginRoutePath(to.fullPath);
57
+ }
58
+ return;
59
+ }
60
+ return;
37
61
  });
38
62
 
39
63
 
@@ -0,0 +1,150 @@
1
+ <template>
2
+ <div>
3
+
4
+ <el-button @click="test">测试</el-button>
5
+ <el-button @click="test2">测试2</el-button>
6
+ <el-button @click="test3">测试3</el-button>
7
+
8
+ <el-table
9
+ :data="tableData1"
10
+ style="width: 100%"
11
+ row-key="id"
12
+ border ref="tableRef2"
13
+ lazy
14
+ :load="load"
15
+ :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
16
+ >
17
+ <el-table-column prop="date" label="Date"/>
18
+ <el-table-column prop="name" label="Name"/>
19
+ <el-table-column prop="address" label="Address"/>
20
+ </el-table>
21
+ </div>
22
+ </template>
23
+ <script lang="ts" setup>
24
+ import { onMounted, ref } from 'vue'
25
+
26
+ const tableRef2 = ref(null);
27
+
28
+
29
+ interface User {
30
+ id: number
31
+ date: string
32
+ name: string
33
+ address: string
34
+ hasChildren?: boolean
35
+ children?: User[]
36
+ }
37
+
38
+ const load = (
39
+ row: User,
40
+ treeNode: unknown,
41
+ resolve: (data: User[]) => void
42
+ ) => {
43
+ setTimeout(() => {
44
+ resolve([
45
+ {
46
+ id: 31,
47
+ date: '2016-05-01',
48
+ name: 'wangxiaohu',
49
+ address: 'No. 189, Grove St, Los Angeles',
50
+ },
51
+ {
52
+ id: 32,
53
+ date: '2016-05-01',
54
+ name: 'wangxiaohu',
55
+ address: 'No. 189, Grove St, Los Angeles',
56
+ },
57
+ ])
58
+ // resolve([]);
59
+ }, 1000)
60
+ }
61
+
62
+
63
+ const tableData1: User[] = [
64
+ {
65
+ id: 1,
66
+ date: '2016-05-02',
67
+ name: 'wangxiaohu',
68
+ address: 'No. 189, Grove St, Los Angeles',
69
+ hasChildren: true
70
+ },
71
+ {
72
+ id: 2,
73
+ date: '2016-05-04',
74
+ name: 'wangxiaohu',
75
+ address: 'No. 189, Grove St, Los Angeles',
76
+ },
77
+ {
78
+ id: 3,
79
+ date: '2016-05-01',
80
+ name: 'wangxiaohu',
81
+ hasChildren: true,
82
+ address: 'No. 189, Grove St, Los Angeles',
83
+ },
84
+ {
85
+ id: 4,
86
+ date: '2016-05-03',
87
+ name: 'wangxiaohu',
88
+ address: 'No. 189, Grove St, Los Angeles',
89
+ },
90
+ ]
91
+
92
+ onMounted(() => {
93
+ setTimeout(() => {
94
+ const elements = document.getElementsByClassName('el-table__expand-icon') as any;
95
+ if (!elements[0].classList.contains('el-table__expand-icon--expanded')) {
96
+ elements[0] && elements[0].click();
97
+ }
98
+ }, 500);
99
+ })
100
+
101
+ const test = () => {
102
+ tableRef2.value.updateKeyChildren(1, [
103
+ {
104
+ id: 11,
105
+ date: '2016-05-03',
106
+ name: '测试123123312',
107
+ address: 'No. 189, Grove St, Los Angeles',
108
+ }, {
109
+ id: 22,
110
+ date: '2016-05-03',
111
+ name: 'updateKeyChildren',
112
+ address: 'No. 189, Grove St, Los Angeles',
113
+ },
114
+ ])
115
+
116
+ }
117
+
118
+ const test2 = () => {
119
+ tableRef2.value.updateKeyChildren(1, [ ])
120
+
121
+ }
122
+
123
+ const test3 = () => {
124
+ tableRef2.value.updateKeyChildren(1, [
125
+ {
126
+ id: 11,
127
+ date: '2016-05-03',
128
+ name: '测试123123312',
129
+ address: 'No. 189, Grove St, Los Angeles',
130
+ }, {
131
+ id: 22,
132
+ date: '2016-05-03',
133
+ name: 'updateKeyChildren',
134
+ address: 'No. 189, Grove St, Los Angeles',
135
+ },{
136
+ id: 33,
137
+ date: '2016-05-03',
138
+ name: 'updateKeyChildren',
139
+ address: 'No. 189, Grove St, Los Angeles',
140
+ },{
141
+ id: 44,
142
+ date: '2016-05-03',
143
+ name: 'updateKeyChildren',
144
+ address: 'No. 189, Grove St, Los Angeles',
145
+ },
146
+ ])
147
+
148
+ }
149
+
150
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <!-- <div>登录中...</div>-->
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { getCurrentInstance, onMounted } from 'vue';
7
+ import { useRouter } from 'vue-router';
8
+
9
+ import { getSsoLoginUrl, setSsoAccessToken } from '../../../../lib/utils/ssoUtils';
10
+
11
+ const router = useRouter();
12
+
13
+ const { proxy } = getCurrentInstance() as any;
14
+
15
+ onMounted(() => {
16
+ const code = router.currentRoute.value.query.code;
17
+ if (!code) {
18
+ window.location.href = getSsoLoginUrl(window.location.href) || '';
19
+ // 这里一定要return,不return还是会继续执行下面的代码
20
+ return;
21
+ }
22
+
23
+ proxy.$http.get('/sso-api/client/auth/getSsoAccessToken', { params: { code: code } }).then((res: any) => {
24
+ setSsoAccessToken(res.data.data);
25
+ let redirectRoutePath = router.currentRoute.value.query.redirectRoutePath ?? ('/sso/login/login-success' as any);
26
+ redirectRoutePath = removeParameter(redirectRoutePath, 'code');
27
+
28
+ router.push(redirectRoutePath);
29
+ });
30
+ });
31
+
32
+ const removeParameter = (url: string, parameter: string) => {
33
+ // 使用正则表达式匹配参数
34
+ const regex = new RegExp('[?&]' + parameter + '=[^&]*&?');
35
+ const newUrl = url.replace(regex, (match, offset, string) => {
36
+ offset;
37
+ string;
38
+ return match.includes('&') ? '&' : '';
39
+ });
40
+ return newUrl;
41
+ }
42
+ </script>
43
+
44
+ <style scoped></style>
@@ -3,9 +3,11 @@
3
3
  </template>
4
4
 
5
5
  <script setup lang="ts">
6
- import {onMounted, ref} from 'vue';
6
+ import {onMounted, ref, getCurrentInstance} from 'vue';
7
7
  import {getSsoEncrypt} from '../../../lib/utils/ssoUtils';
8
8
 
9
+ const {proxy} = getCurrentInstance() as any;
10
+
9
11
  let ssoEncrypt = ref('');
10
12
 
11
13
  onMounted(async () => {