xto-fronted 0.1.7 → 0.1.9
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/README.md +4 -0
- package/dist/components/Login/index.vue.d.ts +15 -0
- package/dist/config/index.d.ts +25 -5
- package/dist/index.d.ts +17 -4
- package/dist/index.es.js +1272 -55
- package/dist/index.umd.js +1 -1
- package/dist/router/dynamicRoutes.d.ts +19 -25
- package/dist/router/index.d.ts +24 -4
- package/dist/router/staticRoutes.d.ts +15 -2
- package/dist/stores/menu.d.ts +14 -8
- package/dist/style.css +1 -1
- package/dist/utils/request.d.ts +8 -0
- package/package.json +2 -10
- package/.env.development +0 -3
- package/.env.production +0 -3
- package/dist/403-DM5wfQkM.js +0 -31
- package/dist/404-BurAu5LC.js +0 -31
- package/dist/index-BNiEld34.js +0 -15
- package/dist/index-Be9RiEfo.js +0 -98
- package/dist/index-BqRv1bdN.js +0 -1185
- package/dist/index-CQLVXvNJ.js +0 -15
- package/dist/index-CyiE8n2V.js +0 -15
- package/dist/index-xauR1bOL.js +0 -15
- package/dist/views/dashboard/index.vue.d.ts +0 -2
- package/dist/views/login/index.vue.d.ts +0 -4
- package/dist/views/system/menu/index.vue.d.ts +0 -2
- package/dist/views/system/role/index.vue.d.ts +0 -2
- package/dist/views/system/user/index.vue.d.ts +0 -2
- package/index.html +0 -13
- package/public/vite.svg +0 -10
- package/src/App.vue +0 -20
- package/src/api/auth.ts +0 -35
- package/src/api/menu.ts +0 -13
- package/src/api/system.ts +0 -65
- package/src/api/user.ts +0 -12
- package/src/assets/styles/_dark.scss +0 -407
- package/src/assets/styles/_reset.scss +0 -126
- package/src/assets/styles/_root.scss +0 -140
- package/src/assets/styles/_transition.scss +0 -119
- package/src/assets/styles/_variables.scss +0 -45
- package/src/assets/styles/index.scss +0 -187
- package/src/components/Layout/Footer.vue +0 -17
- package/src/components/Layout/Header.vue +0 -335
- package/src/components/Layout/Sidebar.vue +0 -213
- package/src/components/Layout/Tabs.vue +0 -20
- package/src/components/Layout/index.vue +0 -62
- package/src/composables/index.ts +0 -9
- package/src/composables/useApp.ts +0 -170
- package/src/composables/useAuth.ts +0 -70
- package/src/composables/useForm.ts +0 -79
- package/src/composables/useMenu.ts +0 -141
- package/src/composables/useTable.ts +0 -97
- package/src/config/index.ts +0 -19
- package/src/directives/permission.ts +0 -41
- package/src/enums/index.ts +0 -63
- package/src/env.d.ts +0 -17
- package/src/index.ts +0 -44
- package/src/main.ts +0 -29
- package/src/router/dynamicRoutes.ts +0 -163
- package/src/router/index.ts +0 -71
- package/src/router/staticRoutes.ts +0 -43
- package/src/stores/app.ts +0 -145
- package/src/stores/auth.ts +0 -45
- package/src/stores/index.ts +0 -15
- package/src/stores/menu.ts +0 -158
- package/src/stores/user.ts +0 -41
- package/src/types/api.d.ts +0 -103
- package/src/types/global.d.ts +0 -45
- package/src/types/router.d.ts +0 -48
- package/src/types/xto.d.ts +0 -149
- package/src/utils/auth.ts +0 -86
- package/src/utils/permission.ts +0 -30
- package/src/utils/request.ts +0 -126
- package/src/utils/storage.ts +0 -72
- package/src/views/dashboard/index.vue +0 -32
- package/src/views/error/403.vue +0 -57
- package/src/views/error/404.vue +0 -57
- package/src/views/login/index.vue +0 -141
- package/src/views/system/menu/index.vue +0 -32
- package/src/views/system/role/index.vue +0 -32
- package/src/views/system/user/index.vue +0 -32
- package/tsconfig.json +0 -26
- package/tsconfig.node.json +0 -11
- package/vite.config.ts +0 -139
- /package/dist/{views/error → components/Error}/403.vue.d.ts +0 -0
- /package/dist/{views/error → components/Error}/404.vue.d.ts +0 -0
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 应用核心 Hook
|
|
3
|
-
* 封装登录、退出、初始化等核心逻辑
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { computed, ref } from 'vue'
|
|
7
|
-
import { useRouter, useRoute } from 'vue-router'
|
|
8
|
-
import { Message } from '@xto/feedback'
|
|
9
|
-
import { useAuthStore } from '@/stores/auth'
|
|
10
|
-
import { useUserStore } from '@/stores/user'
|
|
11
|
-
import { useMenuStore } from '@/stores/menu'
|
|
12
|
-
import { login as loginApi, logout as logoutApi } from '@/api/auth'
|
|
13
|
-
import { getCurrentUser } from '@/api/user'
|
|
14
|
-
import { getUserMenu } from '@/api/menu'
|
|
15
|
-
import type { UserInfo, RemoteMenuItem, LoginResult } from '@/types/api'
|
|
16
|
-
|
|
17
|
-
export function useApp() {
|
|
18
|
-
const router = useRouter()
|
|
19
|
-
const route = useRoute()
|
|
20
|
-
const authStore = useAuthStore()
|
|
21
|
-
const userStore = useUserStore()
|
|
22
|
-
const menuStore = useMenuStore()
|
|
23
|
-
|
|
24
|
-
const loading = ref(false)
|
|
25
|
-
|
|
26
|
-
// ========== 计算属性 ==========
|
|
27
|
-
|
|
28
|
-
// 是否已登录
|
|
29
|
-
const isLoggedIn = computed(() => authStore.isLoggedIn)
|
|
30
|
-
|
|
31
|
-
// 用户信息
|
|
32
|
-
const userInfo = computed(() => userStore.userInfo)
|
|
33
|
-
|
|
34
|
-
// 用户名
|
|
35
|
-
const userName = computed(() => userStore.userName || '')
|
|
36
|
-
|
|
37
|
-
// 菜单列表
|
|
38
|
-
const menuList = computed(() => menuStore.menuList)
|
|
39
|
-
|
|
40
|
-
// 首页路径
|
|
41
|
-
const indexPath = computed(() => menuStore.index)
|
|
42
|
-
|
|
43
|
-
// ========== 登录 ==========
|
|
44
|
-
|
|
45
|
-
const login = async (uid: string, password: string) => {
|
|
46
|
-
loading.value = true
|
|
47
|
-
try {
|
|
48
|
-
// 1. 清除旧状态
|
|
49
|
-
clearAllState()
|
|
50
|
-
|
|
51
|
-
// 2. 调用登录接口
|
|
52
|
-
const res = await loginApi({ uid, password })
|
|
53
|
-
const loginData = res.data as LoginResult
|
|
54
|
-
|
|
55
|
-
// 3. 保存登录信息
|
|
56
|
-
authStore.login(loginData as unknown as Record<string, unknown>)
|
|
57
|
-
|
|
58
|
-
// 4. 加载用户信息
|
|
59
|
-
await loadUserInfo()
|
|
60
|
-
|
|
61
|
-
// 5. 加载菜单
|
|
62
|
-
await loadMenu()
|
|
63
|
-
|
|
64
|
-
// 6. 处理跳转
|
|
65
|
-
const redirectUrl = route.query['redirectUrl'] as string
|
|
66
|
-
if (redirectUrl) {
|
|
67
|
-
const url = decodeURIComponent(redirectUrl)
|
|
68
|
-
if (url.startsWith('http')) {
|
|
69
|
-
// 外网地址,带上 code 跳转
|
|
70
|
-
const code = loginData.code
|
|
71
|
-
location.href = url.includes('?') ? `${url}&code=${code}` : `${url}?code=${code}`
|
|
72
|
-
} else {
|
|
73
|
-
await router.replace(url)
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
await router.replace(indexPath.value || '/')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
Message.success('登录成功')
|
|
80
|
-
return { success: true, data: loginData }
|
|
81
|
-
} catch (error: any) {
|
|
82
|
-
Message.error(error?.message || '登录失败')
|
|
83
|
-
return { success: false, error }
|
|
84
|
-
} finally {
|
|
85
|
-
loading.value = false
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ========== 退出登录 ==========
|
|
90
|
-
|
|
91
|
-
const logout = async (showMessage = true) => {
|
|
92
|
-
try {
|
|
93
|
-
await logoutApi()
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.error('退出登录接口失败', error)
|
|
96
|
-
} finally {
|
|
97
|
-
clearAllState()
|
|
98
|
-
router.push('/login')
|
|
99
|
-
if (showMessage) {
|
|
100
|
-
Message.success('退出登录成功')
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ========== 加载用户信息 ==========
|
|
106
|
-
|
|
107
|
-
const loadUserInfo = async () => {
|
|
108
|
-
const res = await getCurrentUser()
|
|
109
|
-
userStore.setUserInfo(res.data as UserInfo)
|
|
110
|
-
return res.data
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// ========== 加载菜单 ==========
|
|
114
|
-
|
|
115
|
-
const loadMenu = async () => {
|
|
116
|
-
const res = await getUserMenu()
|
|
117
|
-
menuStore.setMenuFromRemote(res.data as RemoteMenuItem[])
|
|
118
|
-
return menuStore.menuList
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ========== 初始化应用(路由守卫中使用) ==========
|
|
122
|
-
|
|
123
|
-
const initApp = async () => {
|
|
124
|
-
if (!authStore.isLoggedIn) {
|
|
125
|
-
return false
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
// 如果有 token 但没有用户信息,则加载
|
|
130
|
-
if (!userStore.userInfo) {
|
|
131
|
-
await loadUserInfo()
|
|
132
|
-
}
|
|
133
|
-
// 如果没有菜单,则加载
|
|
134
|
-
if (!menuStore.hasMenu) {
|
|
135
|
-
await loadMenu()
|
|
136
|
-
}
|
|
137
|
-
return true
|
|
138
|
-
} catch (error) {
|
|
139
|
-
console.error('初始化应用失败', error)
|
|
140
|
-
clearAllState()
|
|
141
|
-
return false
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ========== 清除所有状态 ==========
|
|
146
|
-
|
|
147
|
-
const clearAllState = () => {
|
|
148
|
-
authStore.logout()
|
|
149
|
-
userStore.clearUserInfo()
|
|
150
|
-
menuStore.clearMenu()
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
// 状态
|
|
155
|
-
loading,
|
|
156
|
-
isLoggedIn,
|
|
157
|
-
userInfo,
|
|
158
|
-
userName,
|
|
159
|
-
menuList,
|
|
160
|
-
indexPath,
|
|
161
|
-
|
|
162
|
-
// 方法
|
|
163
|
-
login,
|
|
164
|
-
logout,
|
|
165
|
-
loadUserInfo,
|
|
166
|
-
loadMenu,
|
|
167
|
-
initApp,
|
|
168
|
-
clearAllState
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 权限 Hook
|
|
3
|
-
* 封装权限检查、按钮权限等逻辑
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { computed } from 'vue'
|
|
7
|
-
import { useMenuStore } from '@/stores/menu'
|
|
8
|
-
import { useAuthStore } from '@/stores/auth'
|
|
9
|
-
import { useUserStore } from '@/stores/user'
|
|
10
|
-
|
|
11
|
-
export function useAuth() {
|
|
12
|
-
const menuStore = useMenuStore()
|
|
13
|
-
const authStore = useAuthStore()
|
|
14
|
-
const userStore = useUserStore()
|
|
15
|
-
|
|
16
|
-
// 是否已登录
|
|
17
|
-
const isLoggedIn = computed(() => authStore.isLoggedIn)
|
|
18
|
-
|
|
19
|
-
// 用户名
|
|
20
|
-
const userName = computed(() => userStore.userName)
|
|
21
|
-
|
|
22
|
-
// 用户信息
|
|
23
|
-
const userInfo = computed(() => userStore.userInfo)
|
|
24
|
-
|
|
25
|
-
// ========== 检查按钮权限 ==========
|
|
26
|
-
|
|
27
|
-
const hasPermission = (permission: string | string[]): boolean => {
|
|
28
|
-
const currentPath = window.location.pathname
|
|
29
|
-
const btnList = menuStore.menuBtnListMap[currentPath] || []
|
|
30
|
-
const btnCodes = btnList.map(item => item.code)
|
|
31
|
-
|
|
32
|
-
if (Array.isArray(permission)) {
|
|
33
|
-
return permission.some(p => btnCodes.includes(p))
|
|
34
|
-
}
|
|
35
|
-
return btnCodes.includes(permission)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ========== 检查是否有任一权限 ==========
|
|
39
|
-
|
|
40
|
-
const hasAnyPermission = (permissions: string[]): boolean => {
|
|
41
|
-
return permissions.some(p => hasPermission(p))
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ========== 检查是否有全部权限 ==========
|
|
45
|
-
|
|
46
|
-
const hasAllPermissions = (permissions: string[]): boolean => {
|
|
47
|
-
return permissions.every(p => hasPermission(p))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ========== 获取当前页面按钮权限列表 ==========
|
|
51
|
-
|
|
52
|
-
const getCurrentPagePermissions = (): string[] => {
|
|
53
|
-
const currentPath = window.location.pathname
|
|
54
|
-
const btnList = menuStore.menuBtnListMap[currentPath] || []
|
|
55
|
-
return btnList.map(item => item.code)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
// 状态
|
|
60
|
-
isLoggedIn,
|
|
61
|
-
userName,
|
|
62
|
-
userInfo,
|
|
63
|
-
|
|
64
|
-
// 方法
|
|
65
|
-
hasPermission,
|
|
66
|
-
hasAnyPermission,
|
|
67
|
-
hasAllPermissions,
|
|
68
|
-
getCurrentPagePermissions
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 表单组合函数
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { ref, reactive } from 'vue'
|
|
6
|
-
|
|
7
|
-
export interface FormOptions<T = any> {
|
|
8
|
-
rules?: Record<string, any[]>
|
|
9
|
-
onSubmit?: (data: T) => Promise<void> | void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function useForm<T extends Record<string, any> = Record<string, any>>(
|
|
13
|
-
initialValues: T,
|
|
14
|
-
options: FormOptions<T> = {}
|
|
15
|
-
) {
|
|
16
|
-
const { rules, onSubmit } = options
|
|
17
|
-
|
|
18
|
-
const formRef = ref()
|
|
19
|
-
const formData = reactive<T>({ ...initialValues } as T)
|
|
20
|
-
const loading = ref(false)
|
|
21
|
-
const visible = ref(false)
|
|
22
|
-
const isEdit = ref(false)
|
|
23
|
-
|
|
24
|
-
// 打开新增
|
|
25
|
-
const openAdd = () => {
|
|
26
|
-
resetForm()
|
|
27
|
-
isEdit.value = false
|
|
28
|
-
visible.value = true
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 打开编辑
|
|
32
|
-
const openEdit = (data: Partial<T>) => {
|
|
33
|
-
Object.assign(formData, data)
|
|
34
|
-
isEdit.value = true
|
|
35
|
-
visible.value = true
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 关闭
|
|
39
|
-
const close = () => {
|
|
40
|
-
visible.value = false
|
|
41
|
-
resetForm()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 重置表单
|
|
45
|
-
const resetForm = () => {
|
|
46
|
-
Object.keys(initialValues).forEach(key => {
|
|
47
|
-
(formData as any)[key] = initialValues[key]
|
|
48
|
-
})
|
|
49
|
-
formRef.value?.resetFields()
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 提交
|
|
53
|
-
const handleSubmit = async () => {
|
|
54
|
-
try {
|
|
55
|
-
await formRef.value?.validate()
|
|
56
|
-
loading.value = true
|
|
57
|
-
await onSubmit?.(formData as T)
|
|
58
|
-
close()
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error(error)
|
|
61
|
-
} finally {
|
|
62
|
-
loading.value = false
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
formRef,
|
|
68
|
-
formData,
|
|
69
|
-
rules,
|
|
70
|
-
loading,
|
|
71
|
-
visible,
|
|
72
|
-
isEdit,
|
|
73
|
-
openAdd,
|
|
74
|
-
openEdit,
|
|
75
|
-
close,
|
|
76
|
-
resetForm,
|
|
77
|
-
handleSubmit
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 菜单 Hook
|
|
3
|
-
* 封装菜单渲染、搜索、图标映射等逻辑
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ref, computed } from 'vue'
|
|
7
|
-
import { useRoute, useRouter } from 'vue-router'
|
|
8
|
-
import { useMenuStore } from '@/stores/menu'
|
|
9
|
-
import { useAppStore } from '@/stores/app'
|
|
10
|
-
import type { MenuItem } from '@/types/api'
|
|
11
|
-
|
|
12
|
-
// 默认图标映射
|
|
13
|
-
const defaultIconMap: Record<string, string> = {
|
|
14
|
-
home: '🏠',
|
|
15
|
-
dashboard: '📊',
|
|
16
|
-
system: '⚙️',
|
|
17
|
-
user: '👤',
|
|
18
|
-
role: '👥',
|
|
19
|
-
menu: '📋',
|
|
20
|
-
setting: '🔧'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useMenu(iconMap?: Record<string, string>) {
|
|
24
|
-
const route = useRoute()
|
|
25
|
-
const router = useRouter()
|
|
26
|
-
const menuStore = useMenuStore()
|
|
27
|
-
const appStore = useAppStore()
|
|
28
|
-
|
|
29
|
-
// 合并图标映射
|
|
30
|
-
const mergedIconMap = { ...defaultIconMap, ...iconMap }
|
|
31
|
-
|
|
32
|
-
// 搜索关键词
|
|
33
|
-
const searchKeyword = ref('')
|
|
34
|
-
|
|
35
|
-
// 当前激活菜单
|
|
36
|
-
const activeMenu = computed(() => route.path)
|
|
37
|
-
|
|
38
|
-
// 侧边栏是否折叠
|
|
39
|
-
const isCollapsed = computed(() => appStore.isCollapsed)
|
|
40
|
-
|
|
41
|
-
// 菜单列表
|
|
42
|
-
const menuList = computed(() => menuStore.menuList)
|
|
43
|
-
|
|
44
|
-
// 是否有菜单
|
|
45
|
-
const hasMenu = computed(() => menuStore.hasMenu)
|
|
46
|
-
|
|
47
|
-
// ========== 扁平化菜单(用于搜索) ==========
|
|
48
|
-
|
|
49
|
-
const flattenMenus = (
|
|
50
|
-
menus: MenuItem[],
|
|
51
|
-
parentTitle = ''
|
|
52
|
-
): (MenuItem & { parentTitle: string })[] => {
|
|
53
|
-
const result: (MenuItem & { parentTitle: string })[] = []
|
|
54
|
-
menus.forEach(menu => {
|
|
55
|
-
if (menu.children && menu.children.length > 0) {
|
|
56
|
-
result.push(...flattenMenus(menu.children, menu.title))
|
|
57
|
-
} else {
|
|
58
|
-
result.push({ ...menu, parentTitle })
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
return result
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ========== 搜索结果 ==========
|
|
65
|
-
|
|
66
|
-
const searchResults = computed(() => {
|
|
67
|
-
if (!searchKeyword.value.trim()) return []
|
|
68
|
-
const flatMenus = flattenMenus(menuList.value)
|
|
69
|
-
return flatMenus.filter(menu =>
|
|
70
|
-
menu.title.toLowerCase().includes(searchKeyword.value.toLowerCase())
|
|
71
|
-
)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
// ========== 过滤后的菜单列表 ==========
|
|
75
|
-
|
|
76
|
-
const filteredMenuList = computed(() => {
|
|
77
|
-
if (!searchKeyword.value.trim()) return menuList.value
|
|
78
|
-
|
|
79
|
-
return menuList.value.map(menu => {
|
|
80
|
-
if (menu.children && menu.children.length > 0) {
|
|
81
|
-
const filteredChildren = menu.children.filter(child =>
|
|
82
|
-
child.title.toLowerCase().includes(searchKeyword.value.toLowerCase())
|
|
83
|
-
)
|
|
84
|
-
if (filteredChildren.length > 0) {
|
|
85
|
-
return { ...menu, children: filteredChildren }
|
|
86
|
-
}
|
|
87
|
-
return null
|
|
88
|
-
}
|
|
89
|
-
if (menu.title.toLowerCase().includes(searchKeyword.value.toLowerCase())) {
|
|
90
|
-
return menu
|
|
91
|
-
}
|
|
92
|
-
return null
|
|
93
|
-
}).filter(Boolean) as MenuItem[]
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
// ========== 获取菜单图标 ==========
|
|
97
|
-
|
|
98
|
-
const getMenuIcon = (icon?: string): string => {
|
|
99
|
-
return mergedIconMap[icon || ''] || '📄'
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// ========== 菜单选择 ==========
|
|
103
|
-
|
|
104
|
-
const handleMenuSelect = (index: string) => {
|
|
105
|
-
if (index && index !== route.path) {
|
|
106
|
-
router.push(index)
|
|
107
|
-
searchKeyword.value = ''
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ========== 搜索结果点击 ==========
|
|
112
|
-
|
|
113
|
-
const handleSearchItemClick = (path: string) => {
|
|
114
|
-
router.push(path)
|
|
115
|
-
searchKeyword.value = ''
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// ========== 清除搜索 ==========
|
|
119
|
-
|
|
120
|
-
const clearSearch = () => {
|
|
121
|
-
searchKeyword.value = ''
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
// 状态
|
|
126
|
-
searchKeyword,
|
|
127
|
-
activeMenu,
|
|
128
|
-
isCollapsed,
|
|
129
|
-
menuList,
|
|
130
|
-
hasMenu,
|
|
131
|
-
searchResults,
|
|
132
|
-
filteredMenuList,
|
|
133
|
-
|
|
134
|
-
// 方法
|
|
135
|
-
flattenMenus,
|
|
136
|
-
getMenuIcon,
|
|
137
|
-
handleMenuSelect,
|
|
138
|
-
handleSearchItemClick,
|
|
139
|
-
clearSearch
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 表格组合函数
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { ref, reactive, computed } from 'vue'
|
|
6
|
-
|
|
7
|
-
export interface TableOptions<T = any> {
|
|
8
|
-
fetchData: (params: any) => Promise<{ list: T[]; total: number }>
|
|
9
|
-
defaultPageSize?: number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function useTable<T = any>(options: TableOptions<T>) {
|
|
13
|
-
const { fetchData, defaultPageSize = 10 } = options
|
|
14
|
-
|
|
15
|
-
const loading = ref(false)
|
|
16
|
-
const data = ref<T[]>([]) as any
|
|
17
|
-
const total = ref(0)
|
|
18
|
-
const currentPage = ref(1)
|
|
19
|
-
const pageSize = ref(defaultPageSize)
|
|
20
|
-
|
|
21
|
-
const searchParams = reactive<Record<string, any>>({})
|
|
22
|
-
|
|
23
|
-
// 获取数据
|
|
24
|
-
const getData = async () => {
|
|
25
|
-
loading.value = true
|
|
26
|
-
try {
|
|
27
|
-
const params = {
|
|
28
|
-
...searchParams,
|
|
29
|
-
page: currentPage.value,
|
|
30
|
-
pageSize: pageSize.value
|
|
31
|
-
}
|
|
32
|
-
const result = await fetchData(params)
|
|
33
|
-
data.value = result.list
|
|
34
|
-
total.value = result.total
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error(error)
|
|
37
|
-
} finally {
|
|
38
|
-
loading.value = false
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 搜索
|
|
43
|
-
const handleSearch = () => {
|
|
44
|
-
currentPage.value = 1
|
|
45
|
-
getData()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 重置
|
|
49
|
-
const handleReset = () => {
|
|
50
|
-
Object.keys(searchParams).forEach(key => {
|
|
51
|
-
searchParams[key] = undefined
|
|
52
|
-
})
|
|
53
|
-
currentPage.value = 1
|
|
54
|
-
getData()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 分页改变
|
|
58
|
-
const handlePageChange = (page: number) => {
|
|
59
|
-
currentPage.value = page
|
|
60
|
-
getData()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 每页条数改变
|
|
64
|
-
const handleSizeChange = (size: number) => {
|
|
65
|
-
pageSize.value = size
|
|
66
|
-
currentPage.value = 1
|
|
67
|
-
getData()
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 刷新
|
|
71
|
-
const refresh = () => {
|
|
72
|
-
getData()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 分页配置
|
|
76
|
-
const pagination = computed(() => ({
|
|
77
|
-
current: currentPage.value,
|
|
78
|
-
pageSize: pageSize.value,
|
|
79
|
-
total: total.value
|
|
80
|
-
}))
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
loading,
|
|
84
|
-
data,
|
|
85
|
-
total,
|
|
86
|
-
currentPage,
|
|
87
|
-
pageSize,
|
|
88
|
-
searchParams,
|
|
89
|
-
pagination,
|
|
90
|
-
getData,
|
|
91
|
-
handleSearch,
|
|
92
|
-
handleReset,
|
|
93
|
-
handlePageChange,
|
|
94
|
-
handleSizeChange,
|
|
95
|
-
refresh
|
|
96
|
-
}
|
|
97
|
-
}
|
package/src/config/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 应用配置
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface AppConfig {
|
|
6
|
-
webTitle: string
|
|
7
|
-
baseUrl: string
|
|
8
|
-
appId: string
|
|
9
|
-
clientId: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const config: AppConfig = {
|
|
13
|
-
webTitle: import.meta.env.VITE_APP_NAME || 'analysis-web',
|
|
14
|
-
baseUrl: 'https://cloud-api-test.tineco.com',
|
|
15
|
-
appId: import.meta.env.VITE_APP_ID || 'DBU-CONTENT-ANALYSIS',
|
|
16
|
-
clientId: import.meta.env.VITE_APP_CLIENT_ID || 'Tineco'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default config
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 权限指令
|
|
3
|
-
* v-permission="['user:edit']" 或 v-permission="'user:edit'"
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Directive, DirectiveBinding } from 'vue'
|
|
7
|
-
import { useMenuStore } from '@/stores/menu'
|
|
8
|
-
|
|
9
|
-
const permission: Directive = {
|
|
10
|
-
mounted(el: HTMLElement, binding: DirectiveBinding<string | string[]>) {
|
|
11
|
-
const menuStore = useMenuStore()
|
|
12
|
-
const { value } = binding
|
|
13
|
-
|
|
14
|
-
if (!value) return
|
|
15
|
-
|
|
16
|
-
// 获取当前页面的按钮权限
|
|
17
|
-
const currentPath = window.location.pathname
|
|
18
|
-
const btnList = menuStore.menuBtnListMap[currentPath] || []
|
|
19
|
-
const btnCodes = btnList.map(item => item.code)
|
|
20
|
-
|
|
21
|
-
// 判断是否有权限
|
|
22
|
-
let hasPermission = false
|
|
23
|
-
if (Array.isArray(value)) {
|
|
24
|
-
hasPermission = value.some(p => btnCodes.includes(p))
|
|
25
|
-
} else {
|
|
26
|
-
hasPermission = btnCodes.includes(value)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 没有权限则移除元素
|
|
30
|
-
if (!hasPermission) {
|
|
31
|
-
el.parentNode?.removeChild(el)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default permission
|
|
37
|
-
|
|
38
|
-
// 注册指令
|
|
39
|
-
export function setupPermissionDirective(app: any) {
|
|
40
|
-
app.directive('permission', permission)
|
|
41
|
-
}
|
package/src/enums/index.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 枚举常量
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// 状态
|
|
6
|
-
export enum Status {
|
|
7
|
-
ENABLED = 1,
|
|
8
|
-
DISABLED = 0
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// 性别
|
|
12
|
-
export enum Gender {
|
|
13
|
-
UNKNOWN = 0,
|
|
14
|
-
MALE = 1,
|
|
15
|
-
FEMALE = 2
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 菜单类型
|
|
19
|
-
export enum MenuType {
|
|
20
|
-
DIRECTORY = 0,
|
|
21
|
-
MENU = 1,
|
|
22
|
-
BUTTON = 2
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 状态文本映射
|
|
26
|
-
export const StatusText: Record<Status, string> = {
|
|
27
|
-
[Status.ENABLED]: '启用',
|
|
28
|
-
[Status.DISABLED]: '禁用'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 性别文本映射
|
|
32
|
-
export const GenderText: Record<Gender, string> = {
|
|
33
|
-
[Gender.UNKNOWN]: '未知',
|
|
34
|
-
[Gender.MALE]: '男',
|
|
35
|
-
[Gender.FEMALE]: '女'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 菜单类型文本映射
|
|
39
|
-
export const MenuTypeText: Record<MenuType, string> = {
|
|
40
|
-
[MenuType.DIRECTORY]: '目录',
|
|
41
|
-
[MenuType.MENU]: '菜单',
|
|
42
|
-
[MenuType.BUTTON]: '按钮'
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 状态选项
|
|
46
|
-
export const StatusOptions = [
|
|
47
|
-
{ label: '启用', value: Status.ENABLED },
|
|
48
|
-
{ label: '禁用', value: Status.DISABLED }
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
// 性别选项
|
|
52
|
-
export const GenderOptions = [
|
|
53
|
-
{ label: '未知', value: Gender.UNKNOWN },
|
|
54
|
-
{ label: '男', value: Gender.MALE },
|
|
55
|
-
{ label: '女', value: Gender.FEMALE }
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
// 菜单类型选项
|
|
59
|
-
export const MenuTypeOptions = [
|
|
60
|
-
{ label: '目录', value: MenuType.DIRECTORY },
|
|
61
|
-
{ label: '菜单', value: MenuType.MENU },
|
|
62
|
-
{ label: '按钮', value: MenuType.BUTTON }
|
|
63
|
-
]
|
package/src/env.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
2
|
-
|
|
3
|
-
declare module '*.vue' {
|
|
4
|
-
import type { DefineComponent } from 'vue'
|
|
5
|
-
const component: DefineComponent<{}, {}, any>
|
|
6
|
-
export default component
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface ImportMetaEnv {
|
|
10
|
-
readonly VITE_APP_TITLE: string
|
|
11
|
-
readonly VITE_API_BASE_URL: string
|
|
12
|
-
readonly VITE_USE_MOCK: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface ImportMeta {
|
|
16
|
-
readonly env: ImportMetaEnv
|
|
17
|
-
}
|