af-mobile-client-vue3 1.3.98 → 1.4.1

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.
@@ -980,7 +980,7 @@ async function handleLazySearch(searchText: string) {
980
980
  }
981
981
 
982
982
  lastFetchId.value++
983
- const fetchId = this.lastFetchId
983
+ const fetchId = lastFetchId.value
984
984
  // 根据搜索关键词过滤结果
985
985
  const results = await runLogic(logicName, value, serviceName) as any
986
986
  if (fetchId !== lastFetchId.value) {
@@ -1,131 +1,131 @@
1
- import type { RouteLocationNormalized } from 'vue-router'
2
- import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
3
- import { UserType } from '@af-mobile-client-vue3/types/auth'
4
- import { hasAuthority } from '@af-mobile-client-vue3/utils/authority-utils'
5
- import { isExternalUser } from '@af-mobile-client-vue3/utils/platform-auth'
6
- import { showToast } from 'vant'
7
-
8
- // 不需要登录拦截的路由配置
9
- const loginIgnore = {
10
- names: ['404', '403', 'user-appointment', 'appointment-form', 'appointment-history', 'AuthLoading'], // 根据路由名称匹配
11
- paths: ['/login', '/XReportFormIframeView', '/invoiceShow', '/register', '/loading'], // 根据路由fullPath匹配
12
- /**
13
- * 判断路由是否包含在该配置中
14
- * @param route vue-router 的 route 对象
15
- */
16
- includes(route) {
17
- return this.names.includes(route.name) || this.paths.includes(route.path)
18
- },
19
- }
20
-
21
- /**
22
- * 登录守卫 - 支持外部用户微信授权
23
- * @param to 目标路由
24
- * @param from 来源路由
25
- * @param next 导航函数
26
- */
27
- function loginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
28
- const userStore = useUserStore()
29
- const token = userStore.getToken()
30
-
31
- // 跳过不需要登录验证的路由
32
- if (loginIgnore.includes(to)) {
33
- next()
34
- return
35
- }
36
-
37
- // 已登录用户的处理
38
- if (token) {
39
- // 如果已登录且访问登录页,重定向到首页
40
- if (to.path === '/login') {
41
- const defaultRoute = userStore.getDefaultRoute()
42
- next({ path: defaultRoute })
43
- return
44
- }
45
- next()
46
- return
47
- }
48
-
49
- // 未登录用户的处理
50
- if (!token) {
51
- // 使用统一的检测函数判断用户类型
52
- const externalResult = isExternalUser(to)
53
-
54
- if (externalResult.isExternal) {
55
- // 外部用户统一跳转到 loading 页面
56
- const query: any = {
57
- redirect: to.path,
58
- }
59
-
60
- // 直接将认证参数传递到路由查询参数中
61
- if (externalResult.authParams) {
62
- Object.assign(query, externalResult.authParams)
63
- }
64
-
65
- next({
66
- path: '/loading',
67
- query,
68
- })
69
- return
70
- }
71
-
72
- // 内部用户跳转到登录页
73
- showToast({
74
- message: '登录状态已失效,请重新登录!',
75
- position: 'bottom',
76
- })
77
- next({ path: '/login' })
78
- }
79
- }
80
-
81
- /**
82
- * 权限守卫 - 支持外部用户权限检查
83
- * @param to 目标路由
84
- * @param from 来源路由
85
- * @param next 导航函数
86
- */
87
- function authorityGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
88
- const userStore = useUserStore()
89
- const userType = userStore.getUserType()
90
- const permissions = userStore.getPermissions()
91
- const roles = userStore.getRoles()
92
-
93
- // 跳过不需要权限验证的路由
94
- if (loginIgnore.includes(to)) {
95
- next()
96
- return
97
- }
98
-
99
- const meta = to.meta
100
-
101
- // 如果路由不需要认证,直接通过
102
- if (meta.requiresAuth === false) {
103
- next()
104
- return
105
- }
106
-
107
- // 检查用户类型权限
108
- const isExternalUser = userType === UserType.EXTERNAL
109
- const allowExternalUser = meta.allowExternalUser ?? false
110
-
111
- if (isExternalUser && !allowExternalUser) {
112
- // 外部用户访问不被允许的页面,重定向到403页面
113
- next({ path: '/403' })
114
- return
115
- }
116
-
117
- // 传统权限检查
118
- if (!hasAuthority(to, permissions, roles)) {
119
- // 没有权限,重定向到403页面
120
- next({ path: '/403' })
121
- return
122
- }
123
-
124
- // 权限检查通过
125
- next()
126
- }
127
-
128
- export default {
129
- beforeEach: [loginGuard, authorityGuard],
130
- afterEach: [],
131
- }
1
+ import type { RouteLocationNormalized } from 'vue-router'
2
+ import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
3
+ import { UserType } from '@af-mobile-client-vue3/types/auth'
4
+ import { hasAuthority } from '@af-mobile-client-vue3/utils/authority-utils'
5
+ import { isExternalUser } from '@af-mobile-client-vue3/utils/platform-auth'
6
+ import { showToast } from 'vant'
7
+
8
+ // 不需要登录拦截的路由配置
9
+ const loginIgnore = {
10
+ names: ['404', '403', 'user-appointment', 'appointment-form', 'appointment-history', 'AuthLoading'], // 根据路由名称匹配
11
+ paths: ['/login', '/XReportFormIframeView', '/invoiceShow', '/register', '/loading'], // 根据路由fullPath匹配
12
+ /**
13
+ * 判断路由是否包含在该配置中
14
+ * @param route vue-router 的 route 对象
15
+ */
16
+ includes(route) {
17
+ return this.names.includes(route.name) || this.paths.includes(route.path)
18
+ },
19
+ }
20
+
21
+ /**
22
+ * 登录守卫 - 支持外部用户微信授权
23
+ * @param to 目标路由
24
+ * @param from 来源路由
25
+ * @param next 导航函数
26
+ */
27
+ function loginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
28
+ const userStore = useUserStore()
29
+ const token = userStore.getToken()
30
+
31
+ // 跳过不需要登录验证的路由
32
+ if (loginIgnore.includes(to)) {
33
+ next()
34
+ return
35
+ }
36
+
37
+ // 已登录用户的处理
38
+ if (token) {
39
+ // 如果已登录且访问登录页,重定向到首页
40
+ if (to.path === '/login') {
41
+ const defaultRoute = userStore.getDefaultRoute()
42
+ next({ path: defaultRoute })
43
+ return
44
+ }
45
+ next()
46
+ return
47
+ }
48
+
49
+ // 未登录用户的处理
50
+ if (!token) {
51
+ // 使用统一的检测函数判断用户类型
52
+ const externalResult = isExternalUser(to)
53
+
54
+ if (externalResult.isExternal) {
55
+ // 外部用户统一跳转到 loading 页面
56
+ const query: any = {
57
+ redirect: to.path,
58
+ }
59
+ Object.assign(query, to.query)
60
+ // 直接将认证参数传递到路由查询参数中
61
+ if (externalResult.authParams) {
62
+ Object.assign(query, externalResult.authParams)
63
+ }
64
+
65
+ next({
66
+ path: '/loading',
67
+ query,
68
+ })
69
+ return
70
+ }
71
+
72
+ // 内部用户跳转到登录页
73
+ showToast({
74
+ message: '登录状态已失效,请重新登录!',
75
+ position: 'bottom',
76
+ })
77
+ next({ path: '/login' })
78
+ }
79
+ }
80
+
81
+ /**
82
+ * 权限守卫 - 支持外部用户权限检查
83
+ * @param to 目标路由
84
+ * @param from 来源路由
85
+ * @param next 导航函数
86
+ */
87
+ function authorityGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
88
+ const userStore = useUserStore()
89
+ const userType = userStore.getUserType()
90
+ const permissions = userStore.getPermissions()
91
+ const roles = userStore.getRoles()
92
+
93
+ // 跳过不需要权限验证的路由
94
+ if (loginIgnore.includes(to)) {
95
+ next()
96
+ return
97
+ }
98
+
99
+ const meta = to.meta
100
+
101
+ // 如果路由不需要认证,直接通过
102
+ if (meta.requiresAuth === false) {
103
+ next()
104
+ return
105
+ }
106
+
107
+ // 检查用户类型权限
108
+ const isExternalUser = userType === UserType.EXTERNAL
109
+ const allowExternalUser = meta.allowExternalUser ?? false
110
+
111
+ if (isExternalUser && !allowExternalUser) {
112
+ // 外部用户访问不被允许的页面,重定向到403页面
113
+ next({ path: '/403' })
114
+ return
115
+ }
116
+
117
+ // 传统权限检查
118
+ if (!hasAuthority(to, permissions, roles)) {
119
+ // 没有权限,重定向到403页面
120
+ next({ path: '/403' })
121
+ return
122
+ }
123
+
124
+ // 权限检查通过
125
+ next()
126
+ }
127
+
128
+ export default {
129
+ beforeEach: [loginGuard, authorityGuard],
130
+ afterEach: [],
131
+ }