@moluoxixi/create-app 2.0.404 → 2.0.406

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 (129) hide show
  1. package/dist/commands/create.js +0 -1
  2. package/dist/generators/react.js +0 -2
  3. package/dist/generators/vue.js +0 -2
  4. package/dist/test.js +8 -0
  5. package/dist/utils/deepMerge.js +1 -1
  6. package/dist/utils/featureMapping.d.ts +2 -2
  7. package/dist/utils/featureMapping.js +3 -5
  8. package/dist/utils/generateFrameworkProject.d.ts +0 -4
  9. package/dist/utils/generateFrameworkProject.js +1 -1
  10. package/dist/utils/install.js +1 -1
  11. package/dist/utils/prompts.js +4 -30
  12. package/dist/utils/renderTemplate.js +9 -4
  13. package/package.json +2 -1
  14. package/templates/common/base/.gitmodules +4 -0
  15. package/templates/common/base/package.json +2 -0
  16. package/templates/common/base/vite.config.ts.ejs +13 -2
  17. package/templates/common/features/husky/package.json +2 -1
  18. package/templates/react/base/package.json +3 -1
  19. package/templates/react/{features/qiankun → base}/src/qiankun/index.ts +4 -0
  20. package/templates/react/base/src/stores/index.ts +5 -0
  21. package/templates/react/base/src/stores/user.ts +55 -0
  22. package/templates/react/{base/src/router/index.tsx.ejs → features/manualRoutes/src/router/index.tsx} +6 -5
  23. package/templates/react/features/pageRoutes/src/router/index.tsx +30 -0
  24. package/templates/vue/base/package.json +5 -1
  25. package/templates/vue/base/src/App.vue +1 -0
  26. package/templates/vue/base/src/assets/styles/base.scss +69 -0
  27. package/templates/vue/base/src/assets/styles/custom.scss +40 -0
  28. package/templates/vue/base/src/assets/styles/tailwind.scss +3 -0
  29. package/templates/vue/base/src/layouts/index.ts +22 -0
  30. package/templates/vue/base/src/main.ts.ejs +1 -0
  31. package/templates/vue/base/src/router/layout.vue +15 -0
  32. package/templates/vue/base/src/stores/index.ts +6 -0
  33. package/templates/vue/base/src/stores/modules/system.ts +51 -0
  34. package/templates/vue/base/src/stores/modules/user.ts +41 -0
  35. package/templates/vue/base/src/utils/index.ts +5 -0
  36. package/templates/vue/base/src/utils/modifyComponent.tsx +43 -0
  37. package/templates/vue/base/tsconfig.app.json +25 -16
  38. package/templates/vue/base/tsconfig.base.json +29 -22
  39. package/templates/vue/base/tsconfig.json +11 -11
  40. package/templates/vue/base/tsconfig.node.json +14 -14
  41. package/templates/vue/features/element-plus/src/assets/styles/element/fixQiankun.scss +10 -0
  42. package/templates/vue/features/element-plus/src/assets/styles/element/index.scss +3 -0
  43. package/templates/vue/features/element-plus/src/components/SubMenu/src/_types/index.ts +1 -5
  44. package/templates/vue/features/element-plus/src/components/SubMenu/src/_types/props.ts +16 -10
  45. package/templates/vue/features/element-plus/src/components/SubMenu/src/index.vue +60 -23
  46. package/templates/vue/features/element-plus/src/layouts/element.vue +106 -70
  47. package/templates/vue/features/manualRoutes/package.json +7 -0
  48. package/templates/vue/features/manualRoutes/src/router/index.ts +45 -0
  49. package/templates/vue/features/manualRoutes/src/router/layout.vue +11 -5
  50. package/templates/vue/features/manualRoutes/src/stores/index.ts +6 -0
  51. package/templates/vue/features/manualRoutes/src/stores/modules/system.ts +51 -0
  52. package/templates/vue/features/manualRoutes/src/stores/modules/user.ts +41 -0
  53. package/templates/vue/features/pageRoutes/package.json +4 -1
  54. package/templates/vue/features/pageRoutes/src/router/index.ts +46 -0
  55. package/templates/vue/features/pageRoutes/src/router/layout.vue +15 -0
  56. package/templates/vue/features/pageRoutes/src/stores/index.ts +6 -0
  57. package/templates/vue/features/pageRoutes/src/stores/modules/system.ts +51 -0
  58. package/templates/vue/features/pageRoutes/src/stores/modules/user.ts +41 -0
  59. package/templates/vue/features/sentry/package.json +3 -1
  60. package/templates/vue/features/sentry/src/stores/index.ts +13 -0
  61. package/templates/react/features/qiankun/package.json +0 -5
  62. package/templates/vue/base/src/router/index.ts.ejs +0 -36
  63. package/templates/vue/features/pinia/package.json +0 -7
  64. package/templates/vue/features/pinia/src/stores/index.ts +0 -15
  65. package/templates/vue/features/pinia/src/stores/system.ts +0 -59
  66. package/templates/vue/features/pinia/src/stores/user.ts +0 -56
  67. package/templates/vue/features/qiankun/node_modules/.bin/jiti +0 -17
  68. package/templates/vue/features/qiankun/node_modules/.bin/jiti.CMD +0 -12
  69. package/templates/vue/features/qiankun/node_modules/.bin/jiti.ps1 +0 -41
  70. package/templates/vue/features/qiankun/node_modules/.bin/sass +0 -17
  71. package/templates/vue/features/qiankun/node_modules/.bin/sass.CMD +0 -12
  72. package/templates/vue/features/qiankun/node_modules/.bin/sass.ps1 +0 -41
  73. package/templates/vue/features/qiankun/node_modules/.bin/terser +0 -17
  74. package/templates/vue/features/qiankun/node_modules/.bin/terser.CMD +0 -12
  75. package/templates/vue/features/qiankun/node_modules/.bin/terser.ps1 +0 -41
  76. package/templates/vue/features/qiankun/node_modules/.bin/tsc +0 -17
  77. package/templates/vue/features/qiankun/node_modules/.bin/tsc.CMD +0 -12
  78. package/templates/vue/features/qiankun/node_modules/.bin/tsc.ps1 +0 -41
  79. package/templates/vue/features/qiankun/node_modules/.bin/tsserver +0 -17
  80. package/templates/vue/features/qiankun/node_modules/.bin/tsserver.CMD +0 -12
  81. package/templates/vue/features/qiankun/node_modules/.bin/tsserver.ps1 +0 -41
  82. package/templates/vue/features/qiankun/node_modules/.bin/tsx +0 -17
  83. package/templates/vue/features/qiankun/node_modules/.bin/tsx.CMD +0 -12
  84. package/templates/vue/features/qiankun/node_modules/.bin/tsx.ps1 +0 -41
  85. package/templates/vue/features/qiankun/node_modules/.bin/vite +0 -17
  86. package/templates/vue/features/qiankun/node_modules/.bin/vite.CMD +0 -12
  87. package/templates/vue/features/qiankun/node_modules/.bin/vite.ps1 +0 -41
  88. package/templates/vue/features/qiankun/node_modules/.bin/yaml +0 -17
  89. package/templates/vue/features/qiankun/node_modules/.bin/yaml.CMD +0 -12
  90. package/templates/vue/features/qiankun/node_modules/.bin/yaml.ps1 +0 -41
  91. package/templates/vue/features/qiankun/package.json +0 -5
  92. package/templates/vue/features/qiankun/src/qiankun/index.ts +0 -74
  93. package/templates/vue/features/router/node_modules/.bin/tsc +0 -17
  94. package/templates/vue/features/router/node_modules/.bin/tsc.CMD +0 -12
  95. package/templates/vue/features/router/node_modules/.bin/tsc.ps1 +0 -41
  96. package/templates/vue/features/router/node_modules/.bin/tsserver +0 -17
  97. package/templates/vue/features/router/node_modules/.bin/tsserver.CMD +0 -12
  98. package/templates/vue/features/router/node_modules/.bin/tsserver.ps1 +0 -41
  99. package/templates/vue/features/router/package.json +0 -5
  100. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/jiti +0 -0
  101. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/jiti.CMD +0 -0
  102. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/jiti.ps1 +0 -0
  103. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/sass +0 -0
  104. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/sass.CMD +0 -0
  105. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/sass.ps1 +0 -0
  106. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/terser +0 -0
  107. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/terser.CMD +0 -0
  108. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/terser.ps1 +0 -0
  109. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsc +0 -0
  110. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsc.CMD +0 -0
  111. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsc.ps1 +0 -0
  112. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsserver +0 -0
  113. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsserver.CMD +0 -0
  114. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsserver.ps1 +0 -0
  115. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsx +0 -0
  116. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsx.CMD +0 -0
  117. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/tsx.ps1 +0 -0
  118. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/vite +0 -0
  119. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/vite.CMD +0 -0
  120. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/vite.ps1 +0 -0
  121. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/yaml +0 -0
  122. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/yaml.CMD +0 -0
  123. /package/templates/{react/features/qiankun → vue/features/manualRoutes}/node_modules/.bin/yaml.ps1 +0 -0
  124. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsc +0 -0
  125. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsc.CMD +0 -0
  126. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsc.ps1 +0 -0
  127. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsserver +0 -0
  128. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsserver.CMD +0 -0
  129. /package/templates/vue/features/{pinia → pageRoutes}/node_modules/.bin/tsserver.ps1 +0 -0
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 工具函数导出
3
+ */
4
+
5
+ export * from './modifyComponent'
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 组件修改工具
3
+ * 用于修改组件的行为,特别是 Element Plus 组件在 qiankun 环境下的行为
4
+ */
5
+
6
+ import type { ComponentInstance } from 'vue'
7
+ import { computed, defineComponent } from 'vue'
8
+
9
+ /**
10
+ * 使用修改后的 props 包装组件
11
+ * @param OriginalComponent 原始组件
12
+ * @param modifier 属性修改函数
13
+ * @returns 包装后的组件
14
+ */
15
+ function withModifiedProps(
16
+ OriginalComponent: ComponentInstance<any>,
17
+ modifier = (v: any) => v,
18
+ ) {
19
+ return defineComponent({
20
+ name: OriginalComponent.name,
21
+ setup(_: any, { attrs, slots }) {
22
+ const modifiedProps = computed(() => modifier(attrs))
23
+ return () => <OriginalComponent {...modifiedProps.value} v-slots={slots} />
24
+ },
25
+ })
26
+ }
27
+
28
+ /**
29
+ * 修改组件的行为
30
+ * @param app Vue 应用实例
31
+ * @param components 需要修改的组件数组
32
+ * @param modifier 属性修改函数
33
+ */
34
+ export function modifyComponents(
35
+ app: any,
36
+ components: ComponentInstance<any>[],
37
+ modifier = (v: any) => v,
38
+ ) {
39
+ components.forEach((component) => {
40
+ const newComponent = withModifiedProps(component, modifier)
41
+ app.component(newComponent.name, newComponent)
42
+ })
43
+ }
@@ -1,16 +1,25 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
6
- "baseUrl": ".",
7
- "paths": {
8
- "@/*": ["./src/*"]
9
- }
10
- },
11
- "include": [
12
- "env.d.ts",
13
- "src/**/*",
14
- "src/**/*.vue"
15
- ]
16
- }
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "types": [
7
+ "vite/client"
8
+ ],
9
+ "composite": true
10
+ },
11
+ "vueCompilerOptions": {
12
+ "plugins": [
13
+ "@vue-macros/volar/define-models",
14
+ "@vue-macros/volar/define-slots",
15
+ "@vue-macros/volar/define-props",
16
+ "@vue-macros/volar/define-emits"
17
+ ]
18
+ },
19
+ "exclude": [
20
+ "dist",
21
+ "node_modules",
22
+ "cypress",
23
+ "vite.config.ts"
24
+ ]
25
+ }
@@ -1,22 +1,29 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
- "moduleResolution": "bundler",
9
- "allowImportingTsExtensions": true,
10
- "isolatedModules": true,
11
- "moduleDetection": "force",
12
- "noEmit": true,
13
- "jsx": "preserve",
14
- "strict": true,
15
- "noUnusedLocals": true,
16
- "noUnusedParameters": true,
17
- "noFallthroughCasesInSwitch": true,
18
- "noUncheckedSideEffectImports": true,
19
- "resolveJsonModule": true,
20
- "esModuleInterop": true
21
- }
22
- }
1
+ {
2
+ "lib": [
3
+ "DOM",
4
+ "ESNext"
5
+ ],
6
+ "compilerOptions": {
7
+ "target": "ESNext",
8
+ "jsx": "preserve",
9
+ "baseUrl": ".",
10
+ "paths": {
11
+ "@/*": [
12
+ "src/*"
13
+ ]
14
+ },
15
+ "resolveJsonModule": true,
16
+ "allowJs": true,
17
+ "strict": true,
18
+ "strictNullChecks": true,
19
+ "noUnusedLocals": true,
20
+ "noEmit": false,
21
+ "esModuleInterop": true,
22
+ "forceConsistentCasingInFileNames": true,
23
+ "isolatedModules": true,
24
+ "skipLibCheck": true,
25
+ "allowImportingTsExtensions": false,
26
+ "composite": true,
27
+ "declaration": true
28
+ }
29
+ }
@@ -1,11 +1,11 @@
1
- {
2
- "files": [],
3
- "references": [
4
- {
5
- "path": "./tsconfig.app.json"
6
- },
7
- {
8
- "path": "./tsconfig.node.json"
9
- }
10
- ]
11
- }
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.app.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.node.json"
9
+ }
10
+ ]
11
+ }
@@ -1,14 +1,14 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
6
- "types": ["node"]
7
- },
8
- "include": [
9
- "vite.config.*",
10
- "eslint.config.*",
11
- "commitlint.config.*",
12
- "scripts/**/*"
13
- ]
14
- }
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "NodeNext",
5
+ "moduleResolution": "nodenext",
6
+ "noEmit": false,
7
+ "allowImportingTsExtensions": true,
8
+ "rewriteRelativeImportExtensions": true,
9
+ "composite": true
10
+ },
11
+ "include": [
12
+ "vite.config.ts"
13
+ ]
14
+ }
@@ -0,0 +1,10 @@
1
+ .el-button {
2
+ border: 1px solid var(--border-color-1);
3
+ &--text {
4
+ border-color: transparent;
5
+ }
6
+ }
7
+
8
+ .el-radio-button__inner {
9
+ border: 1px solid var(--border-color-1);
10
+ }
@@ -2,6 +2,9 @@
2
2
  * Element Plus 样式定制
3
3
  * 自定义 Element Plus 主题
4
4
  */
5
+ @forward 'element-plus/theme-chalk/src/mixins/config.scss' with (
6
+ $namespace: $namespace
7
+ );
5
8
 
6
9
  @forward 'element-plus/theme-chalk/src/common/var.scss' with (
7
10
  $colors: (
@@ -1,5 +1 @@
1
- /**
2
- * SubMenu 类型导出
3
- */
4
-
5
- export * from './props'
1
+ export * from './props'
@@ -1,10 +1,16 @@
1
- /**
2
- * SubMenu Props 类型定义
3
- */
4
-
5
- import type { RouteRecordRaw } from 'vue-router'
6
-
7
- export interface SubMenuProps {
8
- /** 菜单列表 */
9
- menuList: RouteRecordRaw[]
10
- }
1
+ export interface subMenuRouteMetaType {
2
+ title?: string
3
+ [key: string]: unknown
4
+ }
5
+
6
+ export interface subMenuRouteType {
7
+ path?: string
8
+ name?: string
9
+ meta?: subMenuRouteMetaType
10
+ children?: subMenuRouteType[]
11
+ }
12
+
13
+ export interface propsType {
14
+ routes: subMenuRouteType[]
15
+ menuHeight?: number
16
+ }
@@ -1,23 +1,60 @@
1
- <template>
2
- <template v-for="item in menuList" :key="item.path">
3
- <el-sub-menu v-if="item.children?.length" :index="item.path">
4
- <template #title>
5
- <span>{{ item.meta?.title }}</span>
6
- </template>
7
- <SubMenu :menu-list="item.children" />
8
- </el-sub-menu>
9
- <el-menu-item v-else :index="item.path">
10
- <span>{{ item.meta?.title }}</span>
11
- </el-menu-item>
12
- </template>
13
- </template>
14
-
15
- <script setup lang="ts">
16
- /**
17
- * SubMenu 子菜单组件
18
- * 递归渲染菜单
19
- */
20
- import type { SubMenuProps } from './_types'
21
-
22
- defineProps<SubMenuProps>()
23
- </script>
1
+ <template>
2
+ <template
3
+ v-for="(route, index) in props.routes"
4
+ :key="getRouteKey(route, index)"
5
+ >
6
+ <ElSubMenu
7
+ v-if="hasChildren(route)"
8
+ :teleported="false"
9
+ :index="getRouteIndex(route, index)"
10
+ >
11
+ <template #title>
12
+ {{ getRouteTitle(route) }}
13
+ </template>
14
+ <div :style="`max-height: calc(100vh - ${props.menuHeight || 0}px - 30px);overflow: auto`">
15
+ <SubMenu :routes="route.children ?? []" />
16
+ </div>
17
+ </ElSubMenu>
18
+
19
+ <ElMenuItem
20
+ v-else
21
+ :index="getRouteIndex(route, index)"
22
+ >
23
+ {{ getRouteTitle(route) }}
24
+ </ElMenuItem>
25
+ </template>
26
+ </template>
27
+
28
+ <script setup lang="ts">
29
+ import type { propsType, subMenuRouteType } from './_types'
30
+
31
+ import { ElMenuItem, ElSubMenu } from 'element-plus'
32
+
33
+ defineOptions({
34
+ name: 'SubMenu',
35
+ inheritAttrs: false,
36
+ })
37
+
38
+ const props = withDefaults(defineProps<propsType>(), {
39
+ routes: () => [],
40
+ menuHeight: 60,
41
+ })
42
+
43
+ function getRouteKey(route: subMenuRouteType, index: number): string {
44
+ return route.path ?? `${index}`
45
+ }
46
+
47
+ function getRouteTitle(route: subMenuRouteType): string {
48
+ const fallback = route.name ?? ''
49
+ const metaTitle = route.meta?.title ?? ''
50
+ return metaTitle || fallback
51
+ }
52
+
53
+ function getRouteIndex(route: subMenuRouteType, index: number): string {
54
+ return route.path ?? `${index}`
55
+ }
56
+
57
+ function hasChildren(route: subMenuRouteType): boolean {
58
+ return Array.isArray(route.children) && route.children.length > 0
59
+ }
60
+ </script>
@@ -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
+ }