@codertqy/elpis 1.0.0

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 (83) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +55 -0
  3. package/README.md +218 -0
  4. package/app/controller/base.js +40 -0
  5. package/app/controller/project.js +81 -0
  6. package/app/controller/view.js +22 -0
  7. package/app/extend/logger.js +43 -0
  8. package/app/middleware/api-params-verify.js +73 -0
  9. package/app/middleware/api-sign-verify.js +49 -0
  10. package/app/middleware/error-handler.js +31 -0
  11. package/app/middleware/project-handler.js +26 -0
  12. package/app/middleware.js +44 -0
  13. package/app/pages/assets/custom.css +14 -0
  14. package/app/pages/boot.js +56 -0
  15. package/app/pages/common/curl.js +84 -0
  16. package/app/pages/common/index.css +3 -0
  17. package/app/pages/common/utils.js +1 -0
  18. package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +19 -0
  19. package/app/pages/dashboard/complex-view/header-view/header-view.vue +126 -0
  20. package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +45 -0
  21. package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +35 -0
  22. package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +120 -0
  23. package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +23 -0
  24. package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +87 -0
  25. package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +100 -0
  26. package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +122 -0
  27. package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +161 -0
  28. package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +95 -0
  29. package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +19 -0
  30. package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +135 -0
  31. package/app/pages/dashboard/dashboard.vue +86 -0
  32. package/app/pages/dashboard/entry.dashboard.js +48 -0
  33. package/app/pages/store/index.js +3 -0
  34. package/app/pages/store/menu.js +68 -0
  35. package/app/pages/store/project.js +12 -0
  36. package/app/pages/widgets/header-container/asserts/avatar.png +0 -0
  37. package/app/pages/widgets/header-container/asserts/logo.png +0 -0
  38. package/app/pages/widgets/header-container/header-container.vue +107 -0
  39. package/app/pages/widgets/schema-form/complex-view/input/input.vue +138 -0
  40. package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +140 -0
  41. package/app/pages/widgets/schema-form/complex-view/select/select.vue +122 -0
  42. package/app/pages/widgets/schema-form/form-item-config.js +20 -0
  43. package/app/pages/widgets/schema-form/schema-form.vue +135 -0
  44. package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +51 -0
  45. package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +63 -0
  46. package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +41 -0
  47. package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +49 -0
  48. package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +126 -0
  49. package/app/pages/widgets/schema-search-bar/search-item-config.js +22 -0
  50. package/app/pages/widgets/schema-table/schema-table.vue +259 -0
  51. package/app/pages/widgets/sider-container/sider-container.vue +27 -0
  52. package/app/public/output/entry.page1.tpl +40 -0
  53. package/app/public/output/entry.page2.tpl +11 -0
  54. package/app/public/static/logo.png +0 -0
  55. package/app/public/static/normalize.css +239 -0
  56. package/app/router/project.js +22 -0
  57. package/app/router/view.js +17 -0
  58. package/app/router-schema/project.js +34 -0
  59. package/app/service/base.js +15 -0
  60. package/app/service/project.js +59 -0
  61. package/app/view/entry.tpl +25 -0
  62. package/app/webpack/config/webpack.base.js +280 -0
  63. package/app/webpack/config/webpack.dev.js +57 -0
  64. package/app/webpack/config/webpack.prod.js +127 -0
  65. package/app/webpack/dev.js +63 -0
  66. package/app/webpack/libs/blank.js +1 -0
  67. package/app/webpack/prod.js +22 -0
  68. package/config/config.beta.js +1 -0
  69. package/config/config.default.js +3 -0
  70. package/config/config.prod.js +1 -0
  71. package/elpis-core/env.js +27 -0
  72. package/elpis-core/index.js +98 -0
  73. package/elpis-core/loader/config.js +58 -0
  74. package/elpis-core/loader/controller.js +93 -0
  75. package/elpis-core/loader/extend.js +63 -0
  76. package/elpis-core/loader/middleware.js +84 -0
  77. package/elpis-core/loader/router-schema.js +56 -0
  78. package/elpis-core/loader/router.js +50 -0
  79. package/elpis-core/loader/service.js +85 -0
  80. package/index.js +38 -0
  81. package/model/index.js +129 -0
  82. package/package.json +92 -0
  83. package/test/controller/project.test.js +214 -0
@@ -0,0 +1,100 @@
1
+ <template>
2
+ <el-drawer
3
+ v-model="isShow"
4
+ direction="rtl"
5
+ :destroy-on-close="true"
6
+ :size="550"
7
+ >
8
+ <template #header>
9
+ <h3>{{ title }}</h3>
10
+ </template>
11
+ <template #default>
12
+ <el-card v-loading="loading" shadow="always" class="detail-panel">
13
+ <el-row
14
+ v-for="(item, key) in components[name]?.schema?.properties"
15
+ :key="key"
16
+ type="flex"
17
+ align="middle"
18
+ class="row-item"
19
+ >
20
+ <el-row class="item-label">{{ item.label }}:</el-row>
21
+ <el-row class="item-value">{{ dtoModel[key] }}</el-row>
22
+ </el-row>
23
+ </el-card>
24
+ </template>
25
+ </el-drawer>
26
+ </template>
27
+ <script setup>
28
+ import { ref, inject } from "vue";
29
+ import $curl from "$elpisCommon/curl.js";
30
+
31
+ const { api, components } = inject("schemaViewData");
32
+ const name = ref("detailPanel");
33
+ const isShow = ref(false);
34
+ const loading = ref(false);
35
+
36
+ const title = ref("");
37
+ const mainKey = ref("");
38
+ const mainValue = ref("");
39
+ const dtoModel = ref({});
40
+ const show = (rowData) => {
41
+ const { config } = components.value[name.value];
42
+
43
+ title.value = config.title;
44
+ mainKey.value = config.mainKey; // 表单组件
45
+ mainValue.value = rowData[config.mainKey]; //表单主键值
46
+ dtoModel.value = {};
47
+
48
+ isShow.value = true;
49
+
50
+ fetchFormData();
51
+ };
52
+
53
+ const fetchFormData = async () => {
54
+ if (loading.value) {
55
+ return;
56
+ }
57
+ loading.value = true;
58
+
59
+ const res = await $curl({
60
+ method: "get",
61
+ url: api.value,
62
+ query: {
63
+ [mainKey.value]: mainValue.value,
64
+ },
65
+ });
66
+
67
+ loading.value = false;
68
+
69
+ if (!res || !res.success || !res.data) {
70
+ return;
71
+ }
72
+ dtoModel.value = res.data;
73
+ console.log(res.data);
74
+ };
75
+
76
+ defineExpose({
77
+ name,
78
+ show,
79
+ });
80
+ </script>
81
+
82
+ <style scoped lang="less">
83
+ .detail-panel {
84
+ border: 1px solid #a6a6a6;
85
+ padding: 30px;
86
+ .row-item {
87
+ height: 40px;
88
+ line-height: 40px;
89
+ font-size: 20px;
90
+ .item-label {
91
+ margin-right: 20px;
92
+ width: 120px;
93
+ color: #ffffff;
94
+ }
95
+ .item-value {
96
+ color: #d2dae4;
97
+ }
98
+ }
99
+ }
100
+ </style>
@@ -0,0 +1,122 @@
1
+ <template>
2
+ <el-drawer
3
+ v-model="isShow"
4
+ direction="rtl"
5
+ :destroy-on-close="true"
6
+ :size="550"
7
+ >
8
+ <template #header>
9
+ <h3>{{ title }}</h3>
10
+ </template>
11
+ <template #default>
12
+ <SchemaForm
13
+ ref="schemaFormRef"
14
+ v-loading="loading"
15
+ :schema="components[name]?.schema"
16
+ :model="dtoModel"
17
+ ></SchemaForm>
18
+ </template>
19
+ <template #footer>
20
+ <el-button type="primary" @click="save">{{ saveBtnText }}</el-button>
21
+ </template>
22
+ </el-drawer>
23
+ </template>
24
+ <script setup>
25
+ import { ElNotification } from "element-plus";
26
+ import { ref, inject } from "vue";
27
+ import $curl from "$elpisCommon/curl";
28
+ import SchemaForm from "$elpisWidgets/schema-form/schema-form";
29
+
30
+ const { api, components } = inject("schemaViewData");
31
+ const emit = defineEmits(["command"]);
32
+
33
+ const schemaFormRef = ref();
34
+ const name = ref("editForm");
35
+
36
+ const loading = ref(false);
37
+ const isShow = ref(false);
38
+ const title = ref("");
39
+ const saveBtnText = ref("");
40
+ const mainKey = ref("");
41
+ const mainValue = ref();
42
+ const dtoModel = ref({});
43
+ const show = (rowData) => {
44
+ const { config } = components.value[name.value];
45
+
46
+ title.value = config.title;
47
+ saveBtnText.value = config.saveBtnText;
48
+ mainKey.value = config.mainKey; // 表单主键
49
+ mainValue.value = rowData[config.mainKey]; //表单组件值
50
+ dtoModel.value = {};
51
+
52
+ isShow.value = true;
53
+
54
+ fetchFormData();
55
+ };
56
+ const close = () => {
57
+ isShow.value = false;
58
+ };
59
+ const fetchFormData = async () => {
60
+ if (loading.value) {
61
+ return;
62
+ }
63
+ loading.value = true;
64
+
65
+ const res = await $curl({
66
+ method: "get",
67
+ url: api.value,
68
+ query: {
69
+ [mainKey.value]: mainValue.value,
70
+ },
71
+ });
72
+
73
+ loading.value = false;
74
+
75
+ if (!res || !res.success || !res.data) {
76
+ return;
77
+ }
78
+
79
+ dtoModel.value = res.data;
80
+ };
81
+
82
+ const save = async () => {
83
+ if (loading.value) {
84
+ return;
85
+ }
86
+ if (!schemaFormRef.value.validate()) {
87
+ return;
88
+ }
89
+ loading.value = true;
90
+
91
+ const res = await $curl({
92
+ method: "put",
93
+ url: api.value,
94
+ data: {
95
+ [mainKey.value]: mainValue.value,
96
+ ...schemaFormRef.value.getValue(),
97
+ },
98
+ });
99
+ loading.value = false;
100
+
101
+ if (!res || !res.success) {
102
+ return;
103
+ }
104
+ ElNotification({
105
+ title: "修改成功",
106
+ message: "修改成功",
107
+ type: "success",
108
+ });
109
+
110
+ close();
111
+ emit("command", {
112
+ event: "loadTableData",
113
+ });
114
+ };
115
+
116
+ defineExpose({
117
+ name,
118
+ show,
119
+ });
120
+ </script>
121
+
122
+ <style scoped lang="less"></style>
@@ -0,0 +1,161 @@
1
+ /**
2
+ * 数据驱动文件
3
+ */
4
+ import { onMounted, ref, watch, nextTick } from "vue";
5
+ import { useRoute } from "vue-router";
6
+ import { useMenuStore } from "$elpisStore/menu.js";
7
+
8
+ export const useSchema = () => {
9
+ const route = useRoute();
10
+ const menuStore = useMenuStore();
11
+
12
+ const api = ref("");
13
+ const tableSchema = ref({});
14
+ const tableConfig = ref();
15
+
16
+ const searchSchema = ref({});
17
+ const searchConfig = ref();
18
+
19
+ // 动态组件
20
+ const components = ref({});
21
+ // 构造 schemaConfig 相关配置、输送给 schemaView 解析
22
+ const buildData = () => {
23
+ const { key, sider_key: siderKey } = route.query;
24
+ const mItem = menuStore.findMenuItem({
25
+ key: "key",
26
+ value: siderKey ?? key,
27
+ });
28
+
29
+ if (mItem && mItem.schemaConfig) {
30
+ const { schemaConfig: sConfig } = mItem;
31
+ const configSchema = JSON.parse(JSON.stringify(sConfig.schema));
32
+ api.value = sConfig.api ?? "";
33
+
34
+ tableSchema.value = {};
35
+ tableConfig.value = undefined;
36
+
37
+ searchSchema.value = {};
38
+ searchConfig.value = undefined;
39
+
40
+ components.value = {};
41
+
42
+ nextTick(() => {
43
+ // 构造 tableSchema 和 tableConfig
44
+ tableSchema.value = buildDtoSchema(configSchema, "table");
45
+ tableConfig.value = sConfig.tableConfig;
46
+
47
+ // 构造 searchSchema 和 searchConfig
48
+ const dtoSearchSchema = buildDtoSchema(configSchema, "search");
49
+ // 判断当前是否是携带参数跳转过来的搜索框
50
+ for (const key in dtoSearchSchema.properties) {
51
+ if (route.query[key] !== undefined) {
52
+ dtoSearchSchema.properties[key].option.default = route.query[key];
53
+ }
54
+ }
55
+ searchSchema.value = dtoSearchSchema;
56
+ searchConfig.value = sConfig.searchConfig;
57
+
58
+ // 构造 components = { key: { schema, config } }
59
+ const { componentConfig } = sConfig;
60
+ if (componentConfig && Object.keys(componentConfig).length > 0) {
61
+ const dtoComponents = {};
62
+
63
+ // comName就是key标识
64
+ for (const comName in componentConfig) {
65
+ dtoComponents[comName] = {
66
+ schema: buildDtoSchema(configSchema, comName),
67
+ config: componentConfig[comName],
68
+ };
69
+ }
70
+ /**
71
+ * 此时拿到的数据结构为
72
+ * dtoComponents = {
73
+ * createForm:{
74
+ * schema:{
75
+ * product_name:"",
76
+ * },
77
+ * config:{
78
+ * title:"",// 表单标题
79
+ * saveBtnText:'',//保存按钮文案
80
+ * }
81
+ * }
82
+ * }
83
+ */
84
+ components.value = dtoComponents;
85
+ }
86
+ });
87
+ }
88
+ };
89
+
90
+ /**
91
+ * 构建对应的 schema 方法(清除噪音)(比如searchSchema/tableSchema)
92
+ * 将schema字段中带有option结尾的属性换为 option
93
+ * @param {*} 配置名:schema/custom/iframe等
94
+ * @param {*} 所属组件:table/search
95
+ * @returns
96
+ */
97
+ const buildDtoSchema = (_schema, comName) => {
98
+ if (!_schema?.properties) {
99
+ return {};
100
+ }
101
+ const dtoSchema = {
102
+ type: "object",
103
+ properties: {},
104
+ };
105
+
106
+ // 提取有效 schema 字段信息
107
+ for (const key in _schema.properties) {
108
+ const props = _schema.properties[key];
109
+ // 如果有对应的Option, 提取该 Option 里面的内容
110
+ if (props[`${comName}Option`]) {
111
+ let dtoProps = {};
112
+
113
+ // 提取 props 中非 Option 的部分,存放到 dtoProps 中
114
+ for (const pKey in props) {
115
+ if (pKey.indexOf("Option") < 0) {
116
+ dtoProps[pKey] = props[pKey];
117
+ }
118
+ }
119
+
120
+ // 将 comNameOption 字段名修改为 option 然后结合在 dtoProps 中
121
+ dtoProps = Object.assign({}, dtoProps, {
122
+ option: props[`${comName}Option`],
123
+ });
124
+
125
+ // 处理 required 字段
126
+ const { required } = _schema;
127
+ if (required && required.find((pk) => pk === key)) {
128
+ dtoProps.option.required = true;
129
+ }
130
+
131
+ dtoSchema.properties[key] = dtoProps;
132
+ }
133
+ }
134
+ return dtoSchema;
135
+ };
136
+
137
+ // 监听路由与数据的变化,重新构建
138
+ watch(
139
+ [
140
+ () => route.query.key,
141
+ () => route.query.sider_key,
142
+ () => menuStore.menuList,
143
+ ],
144
+ () => {
145
+ buildData();
146
+ },
147
+ { deep: true },
148
+ );
149
+
150
+ onMounted(() => {
151
+ buildData();
152
+ });
153
+ return {
154
+ api,
155
+ tableSchema,
156
+ tableConfig,
157
+ searchSchema,
158
+ searchConfig,
159
+ components,
160
+ };
161
+ };
@@ -0,0 +1,95 @@
1
+ <template>
2
+ <el-row class="schema-view">
3
+ <SearchPanel
4
+ v-if="
5
+ searchSchema?.properties &&
6
+ Object.keys(searchSchema.properties).length > 0
7
+ "
8
+ @search="onSearch"
9
+ ></SearchPanel>
10
+ <TableBanel ref="tablePanelRef" @operate="onTableOperate"></TableBanel>
11
+ <!-- 弹窗等组件 -->
12
+ <component
13
+ v-for="(item, key) in components"
14
+ :key="key"
15
+ :is="ComponentConfig[key]?.component"
16
+ ref="comListRef"
17
+ @command="onComponentCommand"
18
+ ></component>
19
+ </el-row>
20
+ </template>
21
+ <script setup>
22
+ import { provide, ref } from "vue";
23
+ import SearchPanel from "./complex-view/search-panel/search-panel.vue";
24
+ import TableBanel from "./complex-view/table-panel/table-panel.vue";
25
+ import { useSchema } from "./hook/schema";
26
+ import ComponentConfig from "./components/component-config";
27
+ const {
28
+ api,
29
+ tableSchema,
30
+ tableConfig,
31
+ searchSchema,
32
+ searchConfig,
33
+ components,
34
+ } = useSchema();
35
+
36
+ const apiParams = ref({});
37
+ provide("schemaViewData", {
38
+ api,
39
+ apiParams,
40
+ tableSchema,
41
+ tableConfig,
42
+ searchSchema,
43
+ searchConfig,
44
+ components,
45
+ });
46
+
47
+ const tablePanelRef = ref(null);
48
+ const comListRef = ref([]);
49
+
50
+ const onSearch = (searchValObj) => {
51
+ apiParams.value = searchValObj;
52
+ };
53
+ // showComponent 展示动态组件 找到对应的组件调用展示方法
54
+ const showComponent = ({ btnConfig, rowData }) => {
55
+ const { comName } = btnConfig?.eventOption;
56
+ if (!comName) {
57
+ console.error("comName is not found");
58
+ return;
59
+ }
60
+ const comRef = comListRef.value.find((item) => item.name === comName);
61
+ if (!comRef || typeof comRef.show !== "function") {
62
+ return;
63
+ }
64
+ comRef.show(rowData);
65
+ };
66
+
67
+ // table 事件映射
68
+ const EVentHandleMap = {
69
+ showComponent: showComponent,
70
+ };
71
+
72
+ const onTableOperate = ({ btnConfig, rowData }) => {
73
+ const { eventKey } = btnConfig;
74
+ if (EVentHandleMap[eventKey]) {
75
+ EVentHandleMap[eventKey]({ btnConfig, rowData });
76
+ }
77
+ };
78
+
79
+ // 根据子组件抛出的事件名称来执行相应的方法
80
+ const onComponentCommand = (data) => {
81
+ const { event } = data;
82
+ if (event === "loadTableData") {
83
+ tablePanelRef.value.loadTableData();
84
+ }
85
+ };
86
+ </script>
87
+
88
+ <style scoped lang="less">
89
+ .schema-view {
90
+ display: flex;
91
+ flex-direction: column;
92
+ height: 100%;
93
+ width: 100%;
94
+ }
95
+ </style>
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <el-sub-menu :index="menuItem.key">
3
+ <template #title>
4
+ {{ menuItem.name }}
5
+ </template>
6
+ <div :key="item.key" v-for="item in menuItem.subMenu">
7
+ <SubMenu
8
+ v-if="item.subMenu && item.subMenu.length > 0"
9
+ :menuItem="item"
10
+ ></SubMenu>
11
+ <el-menu-item v-else :index="item.key">{{ item.name }}</el-menu-item>
12
+ </div>
13
+ </el-sub-menu>
14
+ </template>
15
+ <script setup>
16
+ const { menuItem } = defineProps(["menuItem"]);
17
+ </script>
18
+
19
+ <style scoped lang="less"></style>
@@ -0,0 +1,135 @@
1
+ <template>
2
+ <SiderContainer>
3
+ <template #menu-content>
4
+ <el-menu
5
+ :default-active="activeKey"
6
+ :ellipsis="false"
7
+ @select="onMenuSelect"
8
+ >
9
+ <template v-for="item in menuList">
10
+ <!-- group -->
11
+ <SubMenu
12
+ v-if="item.subMenu && item.subMenu.length > 0"
13
+ :menuItem="item"
14
+ ></SubMenu>
15
+ <!-- module -->
16
+ <el-menu-item v-else :index="item.key">{{ item.name }}</el-menu-item>
17
+ </template>
18
+ </el-menu>
19
+ </template>
20
+ <template #main-content>
21
+ <router-view></router-view>
22
+ </template>
23
+ </SiderContainer>
24
+ </template>
25
+ <script setup>
26
+ import { onMounted, ref, watch } from "vue";
27
+ import { useRoute, useRouter } from "vue-router";
28
+ import { useMenuStore } from "$elpisStore/menu";
29
+ import SiderContainer from "$elpisWidgets/sider-container/sider-container.vue";
30
+ import SubMenu from "./complex-view/sub-menu/sub-menu.vue";
31
+
32
+ const route = useRoute();
33
+ const router = useRouter();
34
+ const menuStore = useMenuStore();
35
+
36
+ const menuList = ref([]);
37
+ const activeKey = ref("");
38
+ // 监听变化
39
+ watch(
40
+ () => route.query.key,
41
+ () => {
42
+ setMenuList();
43
+ setActiveKey();
44
+ },
45
+ );
46
+ // 数据获取到之后
47
+ watch(
48
+ () => menuStore.menuList,
49
+ () => {
50
+ setMenuList();
51
+ setActiveKey();
52
+ },
53
+ { deep: true },
54
+ );
55
+
56
+ onMounted(() => {
57
+ setMenuList();
58
+ setActiveKey();
59
+ });
60
+
61
+ // 获取侧边栏数据
62
+ const setMenuList = () => {
63
+ const menuItem = menuStore.findMenuItem({
64
+ key: "key",
65
+ value: route.query.key,
66
+ });
67
+ if (menuItem && menuItem.siderConfig && menuItem.siderConfig.menu) {
68
+ menuList.value = menuItem.siderConfig.menu;
69
+ }
70
+ };
71
+
72
+ /**
73
+ * 高亮选中
74
+ */
75
+ const setActiveKey = () => {
76
+ let siderMenuItem = menuStore.findMenuItem({
77
+ key: "key",
78
+ value: route.query.sider_key,
79
+ });
80
+ // 没有siderMenuItem
81
+ // 也就是当用户点击某个头部路由时,展示出侧边栏,默认的加载第一次是没有sider_key的
82
+ // 这样会导致侧边栏没有选中以及右侧没数据,需要用户手动点击一次,这样是不适合的
83
+ if (!siderMenuItem) {
84
+ // 重新找一遍,而不是使用menuList,不影响性能的其实
85
+ const hMenyItem = menuStore.findMenuItem({
86
+ key: "key",
87
+ value: route.query.key,
88
+ });
89
+ if (hMenyItem && hMenyItem.siderConfig && hMenyItem.siderConfig.menu) {
90
+ const siderMenuList = hMenyItem.siderConfig.menu;
91
+ siderMenuItem = menuStore.findFirstMenuItem(siderMenuList); //找出左侧菜单中的第一个
92
+ if (siderMenuItem) {
93
+ // TODO:处理侧边栏选中菜单逻辑
94
+ handleMenuSelect(siderMenuItem.key);
95
+ }
96
+ }
97
+ }
98
+ // 因为只是赋值,可以使用?,和下面的保持数组结构不一样
99
+ activeKey.value = siderMenuItem?.key;
100
+ };
101
+
102
+ const onMenuSelect = (menuKey) => {
103
+ // 比如,用户点击和默认选中是抽离出来的
104
+ handleMenuSelect(menuKey);
105
+ };
106
+
107
+ // 抽离出来公共方法
108
+ const handleMenuSelect = (menuKey) => {
109
+ const menuItem = menuStore.findMenuItem({
110
+ key: "key",
111
+ value: menuKey,
112
+ });
113
+ const { moduleType, key, customConfig } = menuItem;
114
+ // 如果是当前页面不处理
115
+ if (key === route.query.sider_key) {
116
+ return;
117
+ }
118
+ const pathMap = {
119
+ iframe: "/iframe",
120
+ schema: "/schema",
121
+ custom: customConfig?.path,
122
+ };
123
+ router.push({
124
+ path: `/view/dashboard/sider${pathMap[moduleType]}`,
125
+ query: {
126
+ key: route.query.key,
127
+ // 使用找出来的key
128
+ sider_key: key,
129
+ proj_key: route.query.proj_key,
130
+ },
131
+ });
132
+ };
133
+ </script>
134
+
135
+ <style scoped lang="less"></style>