@moluoxixi/create-app 2.0.404 → 2.0.407

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.
Files changed (131) hide show
  1. package/README.md +41 -14
  2. package/dist/commands/create.js +9 -10
  3. package/dist/generators/react.js +0 -2
  4. package/dist/generators/vue.js +0 -2
  5. package/dist/test.js +8 -0
  6. package/dist/utils/deepMerge.js +1 -1
  7. package/dist/utils/featureMapping.d.ts +2 -2
  8. package/dist/utils/featureMapping.js +3 -5
  9. package/dist/utils/generateFrameworkProject.d.ts +0 -4
  10. package/dist/utils/generateFrameworkProject.js +1 -1
  11. package/dist/utils/install.d.ts +2 -1
  12. package/dist/utils/install.js +4 -3
  13. package/dist/utils/prompts.js +4 -30
  14. package/dist/utils/renderTemplate.js +9 -4
  15. package/package.json +2 -1
  16. package/templates/common/base/.gitmodules +4 -0
  17. package/templates/common/base/package.json +2 -0
  18. package/templates/common/base/vite.config.ts.ejs +13 -2
  19. package/templates/common/features/husky/package.json +2 -1
  20. package/templates/react/base/package.json +3 -1
  21. package/templates/react/{features/qiankun → base}/src/qiankun/index.ts +4 -0
  22. package/templates/react/base/src/stores/index.ts +5 -0
  23. package/templates/react/base/src/stores/user.ts +55 -0
  24. package/templates/react/{base/src/router/index.tsx.ejs → features/manualRoutes/src/router/index.tsx} +6 -5
  25. package/templates/react/features/pageRoutes/src/router/index.tsx +30 -0
  26. package/templates/vue/base/package.json +19 -15
  27. package/templates/vue/base/src/App.vue +1 -0
  28. package/templates/vue/base/src/assets/styles/base.scss +69 -0
  29. package/templates/vue/base/src/assets/styles/custom.scss +40 -0
  30. package/templates/vue/base/src/assets/styles/tailwind.scss +3 -0
  31. package/templates/vue/base/src/layouts/index.ts +22 -0
  32. package/templates/vue/base/src/main.ts.ejs +1 -0
  33. package/templates/vue/base/src/router/layout.vue +15 -0
  34. package/templates/vue/base/src/stores/index.ts +6 -0
  35. package/templates/vue/base/src/stores/modules/system.ts +51 -0
  36. package/templates/vue/base/src/stores/modules/user.ts +41 -0
  37. package/templates/vue/base/src/utils/index.ts +5 -0
  38. package/templates/vue/base/src/utils/modifyComponent.tsx +43 -0
  39. package/templates/vue/base/tsconfig.app.json +25 -16
  40. package/templates/vue/base/tsconfig.base.json +29 -22
  41. package/templates/vue/base/tsconfig.json +11 -11
  42. package/templates/vue/base/tsconfig.node.json +14 -14
  43. package/templates/vue/features/element-plus/src/assets/styles/element/fixQiankun.scss +10 -0
  44. package/templates/vue/features/element-plus/src/assets/styles/element/index.scss +3 -0
  45. package/templates/vue/features/element-plus/src/components/SubMenu/src/_types/index.ts +1 -5
  46. package/templates/vue/features/element-plus/src/components/SubMenu/src/_types/props.ts +16 -10
  47. package/templates/vue/features/element-plus/src/components/SubMenu/src/index.vue +60 -23
  48. package/templates/vue/features/element-plus/src/layouts/element.vue +106 -70
  49. package/templates/vue/features/manualRoutes/package.json +7 -0
  50. package/templates/vue/features/manualRoutes/src/router/index.ts +45 -0
  51. package/templates/vue/features/manualRoutes/src/router/layout.vue +11 -5
  52. package/templates/vue/features/manualRoutes/src/stores/index.ts +6 -0
  53. package/templates/vue/features/manualRoutes/src/stores/modules/system.ts +51 -0
  54. package/templates/vue/features/manualRoutes/src/stores/modules/user.ts +41 -0
  55. package/templates/vue/features/pageRoutes/package.json +4 -1
  56. package/templates/vue/features/pageRoutes/src/router/index.ts +46 -0
  57. package/templates/vue/features/pageRoutes/src/router/layout.vue +15 -0
  58. package/templates/vue/features/pageRoutes/src/stores/index.ts +6 -0
  59. package/templates/vue/features/pageRoutes/src/stores/modules/system.ts +51 -0
  60. package/templates/vue/features/pageRoutes/src/stores/modules/user.ts +41 -0
  61. package/templates/vue/features/sentry/package.json +3 -1
  62. package/templates/vue/features/sentry/src/stores/index.ts +13 -0
  63. package/templates/react/features/qiankun/package.json +0 -5
  64. package/templates/vue/base/src/router/index.ts.ejs +0 -36
  65. package/templates/vue/features/pinia/package.json +0 -7
  66. package/templates/vue/features/pinia/src/stores/index.ts +0 -15
  67. package/templates/vue/features/pinia/src/stores/system.ts +0 -59
  68. package/templates/vue/features/pinia/src/stores/user.ts +0 -56
  69. package/templates/vue/features/qiankun/node_modules/.bin/jiti +0 -17
  70. package/templates/vue/features/qiankun/node_modules/.bin/jiti.CMD +0 -12
  71. package/templates/vue/features/qiankun/node_modules/.bin/jiti.ps1 +0 -41
  72. package/templates/vue/features/qiankun/node_modules/.bin/sass +0 -17
  73. package/templates/vue/features/qiankun/node_modules/.bin/sass.CMD +0 -12
  74. package/templates/vue/features/qiankun/node_modules/.bin/sass.ps1 +0 -41
  75. package/templates/vue/features/qiankun/node_modules/.bin/terser +0 -17
  76. package/templates/vue/features/qiankun/node_modules/.bin/terser.CMD +0 -12
  77. package/templates/vue/features/qiankun/node_modules/.bin/terser.ps1 +0 -41
  78. package/templates/vue/features/qiankun/node_modules/.bin/tsc +0 -17
  79. package/templates/vue/features/qiankun/node_modules/.bin/tsc.CMD +0 -12
  80. package/templates/vue/features/qiankun/node_modules/.bin/tsc.ps1 +0 -41
  81. package/templates/vue/features/qiankun/node_modules/.bin/tsserver +0 -17
  82. package/templates/vue/features/qiankun/node_modules/.bin/tsserver.CMD +0 -12
  83. package/templates/vue/features/qiankun/node_modules/.bin/tsserver.ps1 +0 -41
  84. package/templates/vue/features/qiankun/node_modules/.bin/tsx +0 -17
  85. package/templates/vue/features/qiankun/node_modules/.bin/tsx.CMD +0 -12
  86. package/templates/vue/features/qiankun/node_modules/.bin/tsx.ps1 +0 -41
  87. package/templates/vue/features/qiankun/node_modules/.bin/vite +0 -17
  88. package/templates/vue/features/qiankun/node_modules/.bin/vite.CMD +0 -12
  89. package/templates/vue/features/qiankun/node_modules/.bin/vite.ps1 +0 -41
  90. package/templates/vue/features/qiankun/node_modules/.bin/yaml +0 -17
  91. package/templates/vue/features/qiankun/node_modules/.bin/yaml.CMD +0 -12
  92. package/templates/vue/features/qiankun/node_modules/.bin/yaml.ps1 +0 -41
  93. package/templates/vue/features/qiankun/package.json +0 -5
  94. package/templates/vue/features/qiankun/src/qiankun/index.ts +0 -74
  95. package/templates/vue/features/router/node_modules/.bin/tsc +0 -17
  96. package/templates/vue/features/router/node_modules/.bin/tsc.CMD +0 -12
  97. package/templates/vue/features/router/node_modules/.bin/tsc.ps1 +0 -41
  98. package/templates/vue/features/router/node_modules/.bin/tsserver +0 -17
  99. package/templates/vue/features/router/node_modules/.bin/tsserver.CMD +0 -12
  100. package/templates/vue/features/router/node_modules/.bin/tsserver.ps1 +0 -41
  101. package/templates/vue/features/router/package.json +0 -5
  102. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/jiti +0 -0
  103. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/jiti.CMD +0 -0
  104. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/jiti.ps1 +0 -0
  105. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/sass +0 -0
  106. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/sass.CMD +0 -0
  107. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/sass.ps1 +0 -0
  108. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/terser +0 -0
  109. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/terser.CMD +0 -0
  110. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/terser.ps1 +0 -0
  111. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsc +0 -0
  112. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsc.CMD +0 -0
  113. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsc.ps1 +0 -0
  114. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsserver +0 -0
  115. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsserver.CMD +0 -0
  116. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsserver.ps1 +0 -0
  117. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsx +0 -0
  118. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsx.CMD +0 -0
  119. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsx.ps1 +0 -0
  120. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/vite +0 -0
  121. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/vite.CMD +0 -0
  122. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/vite.ps1 +0 -0
  123. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/yaml +0 -0
  124. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/yaml.CMD +0 -0
  125. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/yaml.ps1 +0 -0
  126. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsc +0 -0
  127. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsc.CMD +0 -0
  128. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsc.ps1 +0 -0
  129. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsserver +0 -0
  130. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsserver.CMD +0 -0
  131. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsserver.ps1 +0 -0
@@ -1,84 +1,120 @@
1
1
  <template>
2
- <el-container class="layout-container">
3
- <el-aside :width="sidebarCollapsed ? '64px' : '200px'" class="layout-aside">
4
- <div class="logo">
5
- <span v-if="!sidebarCollapsed">Logo</span>
6
- </div>
7
- <el-menu
8
- :collapse="sidebarCollapsed"
9
- default-active="1"
10
- class="layout-menu"
11
- >
12
- <el-menu-item index="1">
13
- <template #title>
14
- 首页
15
- </template>
16
- </el-menu-item>
17
- <el-menu-item index="2">
18
- <template #title>
19
- 关于
20
- </template>
21
- </el-menu-item>
22
- </el-menu>
23
- </el-aside>
24
- <el-container>
25
- <el-header class="layout-header">
26
- <el-button @click="toggleSidebar">
27
- {{ sidebarCollapsed ? '展开' : '折叠' }}
28
- </el-button>
29
- </el-header>
30
- <el-main class="layout-main">
31
- <slot />
32
- </el-main>
33
- </el-container>
34
- </el-container>
2
+ <ElConfigProvider :namespace="systemCode" :empty-values="[undefined]">
3
+ <div
4
+ class="h-full"
5
+ :class="{ 'h-screen!': !qiankunWindow.__POWERED_BY_QIANKUN__ }"
6
+ :style="`--el-color-primary: ${themeColor || '#3A77FF'};`"
7
+ >
8
+ <ElContainer class="w-full h-full">
9
+ <ElHeader
10
+ v-if="!qiankunWindow.__POWERED_BY_QIANKUN__"
11
+ class="headerbox"
12
+ style="padding: 0"
13
+ height="60"
14
+ >
15
+ <div class="w-full h-full bg-primary flex justify-center">
16
+ <ElMenu :default-active="defaultTab" :ellipsis="false" mode="horizontal" router>
17
+ <SubMenu menu-height="60" :routes="routes" />
18
+ </ElMenu>
19
+ </div>
20
+ </ElHeader>
21
+ <ElMain>
22
+ <ElContainer class="h-full w-full">
23
+ <ElMain style="background-color: #fff">
24
+ <transition name="fade">
25
+ <RouterView v-slot="{ Component, route }">
26
+ <keep-alive>
27
+ <component :is="Component" v-if="route.meta.keep" :key="route.path" />
28
+ </keep-alive>
29
+ <component :is="Component" v-if="!route.meta.keep" :key="route.path" />
30
+ </RouterView>
31
+ </transition>
32
+ </ElMain>
33
+ </ElContainer>
34
+ </ElMain>
35
+ </ElContainer>
36
+ </div>
37
+ </ElConfigProvider>
35
38
  </template>
36
39
 
37
- <script setup lang="ts">
38
- /**
39
- * Element Plus 布局组件
40
- */
41
- import { ref } from 'vue'
40
+ <script lang="ts" setup>
41
+ import { ElConfigProvider, ElContainer, ElHeader, ElMain, ElMenu } from 'element-plus'
42
+ import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
43
+ import { computed, reactive } from 'vue'
44
+ import { RouterView, useRouter } from 'vue-router'
45
+ import SubMenu from '@/components/SubMenu'
46
+ import { useSystemStore } from '@/stores/modules/system'
42
47
 
43
- const sidebarCollapsed = ref(false)
44
-
45
- function toggleSidebar(): void {
46
- sidebarCollapsed.value = !sidebarCollapsed.value
47
- }
48
+ const router = useRouter()
49
+ const routes = reactive(router.options.routes[0].children!)
50
+ const systemStore = useSystemStore()
51
+ const themeColor = computed(() => systemStore.themeColor)
52
+ const systemCode = computed(() => {
53
+ return systemStore.systemCode
54
+ })
55
+ const defaultTab = computed(() => router.currentRoute.value.path)
48
56
  </script>
49
57
 
50
- <style scoped lang="scss">
51
- .layout-container {
52
- height: 100vh;
58
+ <style lang="scss" scoped>
59
+ :deep(.el-main) {
60
+ --el-main-padding: 12px !important;
53
61
  }
54
-
55
- .layout-aside {
56
- background-color: #304156;
57
- transition: width 0.3s;
62
+ .bg-primary {
63
+ background-color: var(--el-color-primary);
58
64
  }
65
+ .headerbox {
66
+ :deep(.el-menu) {
67
+ background-color: var(--el-color-primary);
59
68
 
60
- .logo {
61
- height: 60px;
62
- display: flex;
63
- align-items: center;
64
- justify-content: center;
65
- color: #fff;
66
- font-size: 20px;
67
- font-weight: bold;
68
- }
69
+ .el-menu-item,
70
+ .el-sub-menu {
71
+ background-color: var(--el-color-primary);
72
+ color: #fff !important;
69
73
 
70
- .layout-menu {
71
- border-right: none;
72
- }
74
+ .el-sub-menu__title {
75
+ background-color: var(--el-color-primary);
76
+ color: #fff !important;
77
+ }
73
78
 
74
- .layout-header {
75
- background-color: #fff;
76
- box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
77
- display: flex;
78
- align-items: center;
79
- }
79
+ &.is-active,
80
+ &:hover {
81
+ background-color: #fff;
82
+ color: var(--el-color-primary) !important;
83
+
84
+ .el-sub-menu__title,
85
+ .el-sub-menu__title:hover {
86
+ background-color: #fff;
87
+ color: var(--el-color-primary) !important;
88
+ }
89
+ }
90
+ }
91
+
92
+ &.el-menu--popup {
93
+ background-color: #fff;
94
+
95
+ .el-sub-menu,
96
+ .el-menu-item {
97
+ background-color: #fff !important;
98
+ color: var(--el-color-primary) !important;
99
+
100
+ .el-sub-menu__title {
101
+ background-color: #fff;
102
+ color: var(--el-color-primary) !important;
103
+ }
104
+
105
+ &.is-active,
106
+ &:hover {
107
+ background-color: var(--el-color-primary) !important;
108
+ color: #fff !important;
80
109
 
81
- .layout-main {
82
- background-color: #f0f2f5;
110
+ .el-sub-menu__title,
111
+ .el-sub-menu__title:hover {
112
+ background-color: var(--el-color-primary) !important;
113
+ color: #fff !important;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
83
119
  }
84
120
  </style>
@@ -0,0 +1,7 @@
1
+ {
2
+ "dependencies": {
3
+ "vite-plugin-qiankun": "^1.0.15",
4
+ "radash": "^12.1.0",
5
+ "vue-router": "^4.4.5"
6
+ }
7
+ }
@@ -0,0 +1,45 @@
1
+ import { cloneDeep } from 'lodash-es'
2
+ import { assign, isEmpty } from 'radash'
3
+ import { routes } from './routes'
4
+ import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
5
+ import { createRouter, createWebHistory } from 'vue-router'
6
+
7
+ // 手动配置的路由
8
+ const Routes = [
9
+ {
10
+ path: '/',
11
+ name: 'layout',
12
+ component: () => import('@/router/layout.vue' as string),
13
+ redirect: routes[0]?.path,
14
+ children: routes,
15
+ },
16
+ {
17
+ path: '/:pathMatch(.*)*',
18
+ redirect: '/',
19
+ },
20
+ ]
21
+
22
+ function getRouter(props: any) {
23
+ let base: string
24
+ const routes = cloneDeep(Routes)
25
+ if (qiankunWindow.__POWERED_BY_QIANKUN__) {
26
+ const { activeRule } = props.data
27
+ base = activeRule
28
+ }
29
+ else {
30
+ base = import.meta.env.VITE_APP_CODE
31
+ }
32
+ const router = createRouter({
33
+ history: createWebHistory(base),
34
+ routes,
35
+ })
36
+ router.beforeEach((_, from, next) => {
37
+ if (isEmpty(history.state.current)) {
38
+ assign(history.state, { current: from.fullPath })
39
+ }
40
+ next()
41
+ })
42
+ return router
43
+ }
44
+
45
+ export default getRouter
@@ -1,9 +1,15 @@
1
1
  <template>
2
- <RouterView />
2
+ <component :is="layout" />
3
3
  </template>
4
4
 
5
- <script setup lang="ts">
6
- /**
7
- * 路由布局组件
8
- */
5
+ <script lang="ts" setup>
6
+ import { computed } from 'vue'
7
+ import layouts from '@/layouts'
8
+ import { useSystemStore } from '@/stores/modules/system'
9
+
10
+ const systemInfo = useSystemStore()
11
+ const layoutType = computed(() => systemInfo.layout)
12
+ const layout = computed(() => layouts[layoutType.value])
9
13
  </script>
14
+
15
+ <style lang="scss" scoped></style>
@@ -0,0 +1,6 @@
1
+ import { createPinia } from 'pinia'
2
+ import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
3
+
4
+ const store = createPinia()
5
+ store.use(piniaPluginPersistedstate)
6
+ export { store }
@@ -0,0 +1,51 @@
1
+ import { defineStore } from 'pinia'
2
+ import { store } from '../index.ts'
3
+
4
+ /**
5
+ * 系统对象
6
+ * @returns {object} 系统存储对象
7
+ */
8
+ const systemStore = defineStore('system', {
9
+ state: () => ({
10
+ /**
11
+ * 主题颜色
12
+ * @type {string}
13
+ */
14
+ themeColor: '#3a77ff',
15
+ /**
16
+ * 布局
17
+ * @type {string}
18
+ */
19
+ layout: 'element',
20
+ /**
21
+ * 系统编码
22
+ * @type {string}
23
+ */
24
+ systemCode: import.meta.env.VITE_APP_CODE || '',
25
+ }),
26
+ actions: {
27
+ setSystemCode(systemCode: string) {
28
+ // 将当前的主题颜色设置为传入的颜色
29
+ this.systemCode = systemCode
30
+ },
31
+ /**
32
+ * 设置布局
33
+ * @param {string} layout - 新的布局
34
+ */
35
+ setLayout(layout: string) {
36
+ this.layout = layout
37
+ },
38
+ /**
39
+ * 设置主题颜色
40
+ * @param {string} color - 新的主题颜色
41
+ */
42
+ setTheme(color: string) {
43
+ // 将当前的主题颜色设置为传入的颜色
44
+ this.themeColor = color
45
+ },
46
+ },
47
+ })
48
+
49
+ export function useSystemStore() {
50
+ return systemStore(store)
51
+ }
@@ -0,0 +1,41 @@
1
+ import { defineStore } from 'pinia'
2
+ import { ref } from 'vue'
3
+ import { store } from '@/stores'
4
+
5
+ export const userStore = defineStore(
6
+ 'user',
7
+ () => {
8
+ // 定义token
9
+ const token = ref('')
10
+
11
+ /**
12
+ * 用户登录
13
+ * @param userInfo 用户信息(可选,qiankun 环境下可能从主应用传递)
14
+ */
15
+ const userLogin = async (userInfo?: any) => {
16
+ // 如果传递了用户信息,可以在这里处理登录逻辑
17
+ // 例如:设置 token、保存用户信息等
18
+ if (userInfo) {
19
+ // 可以根据实际需求处理用户信息
20
+ console.log('User login with info:', userInfo)
21
+ }
22
+ }
23
+
24
+ /**
25
+ * 获取 token
26
+ * @returns token 值
27
+ */
28
+ const getToken = () => {
29
+ return token.value
30
+ }
31
+
32
+ return { getToken, userLogin, token }
33
+ },
34
+ {
35
+ persist: true,
36
+ },
37
+ )
38
+
39
+ export function useUserStore() {
40
+ return userStore(store)
41
+ }
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "dependencies": {
3
- "vite-plugin-pages": "^0.32.5"
3
+ "vite-plugin-pages": "^0.32.5",
4
+ "vite-plugin-qiankun": "^1.0.15",
5
+ "radash": "^12.1.0",
6
+ "vue-router": "^4.4.5"
4
7
  }
5
8
  }
@@ -0,0 +1,46 @@
1
+ import { cloneDeep } from 'lodash-es'
2
+ import { assign, isEmpty } from 'radash'
3
+ import routes from '~pages'
4
+ import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
5
+ import { createRouter, createWebHistory } from 'vue-router'
6
+
7
+ // 自动生成的路由
8
+ const routesChildrens = routes
9
+ const Routes = [
10
+ {
11
+ path: '/',
12
+ name: 'layout',
13
+ component: () => import('@/router/layout.vue' as string),
14
+ redirect: routes[0]?.path,
15
+ children: routesChildrens,
16
+ },
17
+ {
18
+ path: '/:pathMatch(.*)*',
19
+ redirect: '/',
20
+ },
21
+ ]
22
+
23
+ function getRouter(props: any) {
24
+ let base: string
25
+ const routes = cloneDeep(Routes)
26
+ if (qiankunWindow.__POWERED_BY_QIANKUN__) {
27
+ const { activeRule } = props.data
28
+ base = activeRule
29
+ }
30
+ else {
31
+ base = import.meta.env.VITE_APP_CODE
32
+ }
33
+ const router = createRouter({
34
+ history: createWebHistory(base),
35
+ routes,
36
+ })
37
+ router.beforeEach((_, from, next) => {
38
+ if (isEmpty(history.state.current)) {
39
+ assign(history.state, { current: from.fullPath })
40
+ }
41
+ next()
42
+ })
43
+ return router
44
+ }
45
+
46
+ export default getRouter
@@ -0,0 +1,15 @@
1
+ <template>
2
+ <component :is="layout" />
3
+ </template>
4
+
5
+ <script lang="ts" setup>
6
+ import { computed } from 'vue'
7
+ import layouts from '@/layouts'
8
+ import { useSystemStore } from '@/stores/modules/system'
9
+
10
+ const systemInfo = useSystemStore()
11
+ const layoutType = computed(() => systemInfo.layout)
12
+ const layout = computed(() => layouts[layoutType.value])
13
+ </script>
14
+
15
+ <style lang="scss" scoped></style>
@@ -0,0 +1,6 @@
1
+ import { createPinia } from 'pinia'
2
+ import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
3
+
4
+ const store = createPinia()
5
+ store.use(piniaPluginPersistedstate)
6
+ export { store }
@@ -0,0 +1,51 @@
1
+ import { defineStore } from 'pinia'
2
+ import { store } from '../index.ts'
3
+
4
+ /**
5
+ * 系统对象
6
+ * @returns {object} 系统存储对象
7
+ */
8
+ const systemStore = defineStore('system', {
9
+ state: () => ({
10
+ /**
11
+ * 主题颜色
12
+ * @type {string}
13
+ */
14
+ themeColor: '#3a77ff',
15
+ /**
16
+ * 布局
17
+ * @type {string}
18
+ */
19
+ layout: 'element',
20
+ /**
21
+ * 系统编码
22
+ * @type {string}
23
+ */
24
+ systemCode: import.meta.env.VITE_APP_CODE || '',
25
+ }),
26
+ actions: {
27
+ setSystemCode(systemCode: string) {
28
+ // 将当前的主题颜色设置为传入的颜色
29
+ this.systemCode = systemCode
30
+ },
31
+ /**
32
+ * 设置布局
33
+ * @param {string} layout - 新的布局
34
+ */
35
+ setLayout(layout: string) {
36
+ this.layout = layout
37
+ },
38
+ /**
39
+ * 设置主题颜色
40
+ * @param {string} color - 新的主题颜色
41
+ */
42
+ setTheme(color: string) {
43
+ // 将当前的主题颜色设置为传入的颜色
44
+ this.themeColor = color
45
+ },
46
+ },
47
+ })
48
+
49
+ export function useSystemStore() {
50
+ return systemStore(store)
51
+ }
@@ -0,0 +1,41 @@
1
+ import { defineStore } from 'pinia'
2
+ import { ref } from 'vue'
3
+ import { store } from '@/stores'
4
+
5
+ export const userStore = defineStore(
6
+ 'user',
7
+ () => {
8
+ // 定义token
9
+ const token = ref('')
10
+
11
+ /**
12
+ * 用户登录
13
+ * @param userInfo 用户信息(可选,qiankun 环境下可能从主应用传递)
14
+ */
15
+ const userLogin = async (userInfo?: any) => {
16
+ // 如果传递了用户信息,可以在这里处理登录逻辑
17
+ // 例如:设置 token、保存用户信息等
18
+ if (userInfo) {
19
+ // 可以根据实际需求处理用户信息
20
+ console.log('User login with info:', userInfo)
21
+ }
22
+ }
23
+
24
+ /**
25
+ * 获取 token
26
+ * @returns token 值
27
+ */
28
+ const getToken = () => {
29
+ return token.value
30
+ }
31
+
32
+ return { getToken, userLogin, token }
33
+ },
34
+ {
35
+ persist: true,
36
+ },
37
+ )
38
+
39
+ export function useUserStore() {
40
+ return userStore(store)
41
+ }
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "dependencies": {
3
3
  "@sentry/vue": "^9.27.0",
4
- "@sentry/vite-plugin": "^3.5.0"
4
+ "@sentry/vite-plugin": "^3.5.0",
5
+ "pinia": "^2.2.7",
6
+ "pinia-plugin-persistedstate": "^3.2.1"
5
7
  }
6
8
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Pinia Store 配置
3
+ * 配置 Pinia 状态管理,集成持久化插件和 Sentry 监控插件
4
+ */
5
+
6
+ import { createSentryPiniaPlugin } from '@sentry/vue'
7
+ import { createPinia } from 'pinia'
8
+ import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
9
+
10
+ const store = createPinia()
11
+ store.use(piniaPluginPersistedstate)
12
+ store.use(createSentryPiniaPlugin())
13
+ export { store }
@@ -1,5 +0,0 @@
1
- {
2
- "dependencies": {
3
- "vite-plugin-qiankun": "^1.0.15"
4
- }
5
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * 路由配置
3
- */
4
-
5
- <% if (qiankun) { -%>
6
- import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
7
- <% } -%>
8
- import { createRouter, createWebHistory } from 'vue-router'
9
- <% if (routeMode === 'file-system') { -%>
10
- import routes from '~pages'
11
- <% } else { -%>
12
- import { routes } from './routes'
13
- <% } -%>
14
-
15
- /**
16
- * 获取路由实例
17
- * @param props 路由属性
18
- * @returns 路由实例
19
- */
20
- export default function getRouter(props: Record<string, unknown> = {}) {
21
- const router = createRouter({
22
- history: createWebHistory(
23
- <% if (qiankun) { -%>
24
- qiankunWindow.__POWERED_BY_QIANKUN__
25
- ? '/sub-app/'
26
- : import.meta.env.BASE_URL,
27
- <% } else { -%>
28
- import.meta.env.BASE_URL,
29
- <% } -%>
30
- ),
31
- routes,
32
- })
33
-
34
- return router
35
- }
36
-
@@ -1,7 +0,0 @@
1
- {
2
- "dependencies": {
3
- "pinia": "^2.3.0",
4
- "pinia-plugin-persistedstate": "^3.2.1",
5
- "vue": "latest"
6
- }
7
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Pinia 状态管理配置
3
- */
4
-
5
- import { createPinia } from 'pinia'
6
- import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
7
-
8
- export const store = createPinia()
9
-
10
- // 使用持久化插件
11
- store.use(piniaPluginPersistedstate)
12
-
13
- export * from './system'
14
- // 导出 store 模块
15
- export * from './user'