wangxx 4 miesięcy temu
rodzic
commit
497f372788
4 zmienionych plików z 229 dodań i 0 usunięć
  1. 15 0
      src/App.vue
  2. 88 0
      src/main.js
  3. 69 0
      src/permission.js
  4. 57 0
      src/settings.js

+ 15 - 0
src/App.vue

@@ -0,0 +1,15 @@
1
+<template>
2
+  <router-view />
3
+</template>
4
+
5
+<script setup>
6
+import useSettingsStore from '@/store/modules/settings'
7
+import { handleThemeStyle } from '@/utils/theme'
8
+
9
+onMounted(() => {
10
+  nextTick(() => {
11
+    // 初始化主题样式
12
+    handleThemeStyle(useSettingsStore().theme)
13
+  })
14
+})
15
+</script>

+ 88 - 0
src/main.js

@@ -0,0 +1,88 @@
1
+import { createApp } from 'vue'
2
+
3
+import Cookies from 'js-cookie'
4
+
5
+import ElementPlus from 'element-plus'
6
+import 'element-plus/dist/index.css'
7
+import 'element-plus/theme-chalk/dark/css-vars.css'
8
+import locale from 'element-plus/es/locale/lang/zh-cn'
9
+
10
+import '@/assets/styles/index.scss' // global css
11
+
12
+import App from './App'
13
+import store from './store'
14
+import router from './router'
15
+import directive from './directive' // directive
16
+
17
+// 注册指令
18
+import plugins from './plugins' // plugins
19
+import { download } from '@/utils/request'
20
+
21
+// svg图标
22
+import 'virtual:svg-icons-register'
23
+import SvgIcon from '@/components/SvgIcon'
24
+import elementIcons from '@/components/SvgIcon/svgicon'
25
+
26
+import './permission' // permission control
27
+
28
+import { useDict } from '@/utils/dict'
29
+import { getConfigKey } from "@/api/system/config"
30
+import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'
31
+
32
+// 分页组件
33
+import Pagination from '@/components/Pagination'
34
+// 自定义表格工具组件
35
+import RightToolbar from '@/components/RightToolbar'
36
+// 富文本组件
37
+import Editor from "@/components/Editor"
38
+// sql编辑器组件
39
+import SqlEdit from '@/components/sqlEdit';
40
+// 文件上传组件
41
+import FileUpload from "@/components/FileUpload"
42
+// 图片上传组件
43
+import ImageUpload from "@/components/ImageUpload"
44
+// 图片预览组件
45
+import ImagePreview from "@/components/ImagePreview"
46
+// 字典标签组件
47
+import DictTag from '@/components/DictTag'
48
+
49
+const app = createApp(App)
50
+
51
+// 全局方法挂载
52
+app.config.globalProperties.useDict = useDict
53
+app.config.globalProperties.download = download
54
+app.config.globalProperties.parseTime = parseTime
55
+app.config.globalProperties.resetForm = resetForm
56
+app.config.globalProperties.handleTree = handleTree
57
+app.config.globalProperties.addDateRange = addDateRange
58
+app.config.globalProperties.getConfigKey = getConfigKey
59
+app.config.globalProperties.selectDictLabel = selectDictLabel
60
+app.config.globalProperties.selectDictLabels = selectDictLabels
61
+
62
+// 全局组件挂载
63
+app.component('DictTag', DictTag)
64
+app.component('Pagination', Pagination)
65
+app.component('FileUpload', FileUpload)
66
+app.component('ImageUpload', ImageUpload)
67
+app.component('ImagePreview', ImagePreview)
68
+app.component('RightToolbar', RightToolbar)
69
+app.component('Editor', Editor)
70
+app.component('SqlEdit', SqlEdit);
71
+
72
+
73
+app.use(router)
74
+app.use(store)
75
+app.use(plugins)
76
+app.use(elementIcons)
77
+app.component('svg-icon', SvgIcon)
78
+
79
+directive(app)
80
+
81
+// 使用element-plus 并且设置全局的大小
82
+app.use(ElementPlus, {
83
+  locale: locale,
84
+  // 支持 large、default、small
85
+  size: Cookies.get('size') || 'default'
86
+})
87
+
88
+app.mount('#app')

+ 69 - 0
src/permission.js

@@ -0,0 +1,69 @@
1
+import router from './router'
2
+import { ElMessage } from 'element-plus'
3
+import NProgress from 'nprogress'
4
+import 'nprogress/nprogress.css'
5
+import { getToken } from '@/utils/auth'
6
+import { isHttp, isPathMatch } from '@/utils/validate'
7
+import { isRelogin } from '@/utils/request'
8
+import useUserStore from '@/store/modules/user'
9
+import useSettingsStore from '@/store/modules/settings'
10
+import usePermissionStore from '@/store/modules/permission'
11
+
12
+NProgress.configure({ showSpinner: false })
13
+
14
+const whiteList = ['/login', '/register']
15
+
16
+const isWhiteList = (path) => {
17
+  return whiteList.some(pattern => isPathMatch(pattern, path))
18
+}
19
+
20
+router.beforeEach((to, from, next) => {
21
+  NProgress.start()
22
+  if (getToken()) {
23
+    to.meta.title && useSettingsStore().setTitle(to.meta.title)
24
+    /* has token*/
25
+    if (to.path === '/login') {
26
+      next({ path: '/' })
27
+      NProgress.done()
28
+    } else if (isWhiteList(to.path)) {
29
+      next()
30
+    } else {
31
+      if (useUserStore().roles.length === 0) {
32
+        isRelogin.show = true
33
+        // 判断当前用户是否已拉取完user_info信息
34
+        useUserStore().getInfo().then(() => {
35
+          isRelogin.show = false
36
+          usePermissionStore().generateRoutes().then(accessRoutes => {
37
+            // 根据roles权限生成可访问的路由表
38
+            accessRoutes.forEach(route => {
39
+              if (!isHttp(route.path)) {
40
+                router.addRoute(route) // 动态添加可访问路由表
41
+              }
42
+            })
43
+            next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
44
+          })
45
+        }).catch(err => {
46
+          useUserStore().logOut().then(() => {
47
+            ElMessage.error(err)
48
+            next({ path: '/' })
49
+          })
50
+        })
51
+      } else {
52
+        next()
53
+      }
54
+    }
55
+  } else {
56
+    // 没有token
57
+    if (isWhiteList(to.path)) {
58
+      // 在免登录白名单,直接进入
59
+      next()
60
+    } else {
61
+      next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
62
+      NProgress.done()
63
+    }
64
+  }
65
+})
66
+
67
+router.afterEach(() => {
68
+  NProgress.done()
69
+})

+ 57 - 0
src/settings.js

@@ -0,0 +1,57 @@
1
+export default {
2
+  /**
3
+   * 网页标题
4
+   */
5
+  title: import.meta.env.VITE_APP_TITLE,
6
+
7
+  /**
8
+   * 侧边栏主题 深色主题theme-dark,浅色主题theme-light
9
+   */
10
+  sideTheme: 'theme-dark',
11
+
12
+  /**
13
+   * 是否系统布局配置
14
+   */
15
+  showSettings: true,
16
+
17
+  /**
18
+   * 是否显示顶部导航
19
+   */
20
+  topNav: false,
21
+
22
+  /**
23
+   * 是否显示 tagsView
24
+   */
25
+  tagsView: true,
26
+  
27
+  /**
28
+   * 显示页签图标
29
+   */
30
+  tagsIcon: false,
31
+
32
+  /**
33
+   * 是否固定头部
34
+   */
35
+  fixedHeader: false,
36
+
37
+  /**
38
+   * 是否显示logo
39
+   */
40
+  sidebarLogo: true,
41
+
42
+  /**
43
+   * 是否显示动态标题
44
+   */
45
+  dynamicTitle: false,
46
+
47
+  /**
48
+   * 是否显示底部版权
49
+   */
50
+  footerVisible: false,
51
+
52
+  /**
53
+   * 底部版权文本内容
54
+   */
55
+  footerContent: 'Copyright © 2018-2025 RuoYi. All Rights Reserved.'
56
+}
57
+