@charming_dans/elpis 0.0.0-stage → 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 (78) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc +55 -0
  3. package/README.md +294 -2
  4. package/app/controller/base.js +39 -0
  5. package/app/controller/project.js +77 -0
  6. package/app/controller/view.js +19 -0
  7. package/app/extend/database.js +5 -0
  8. package/app/extend/logger.js +38 -0
  9. package/app/middleware/api-params-verify.js +75 -0
  10. package/app/middleware/api-sign-verify.js +38 -0
  11. package/app/middleware/error-handler.js +34 -0
  12. package/app/middleware/project-handler.js +28 -0
  13. package/app/middleware.js +38 -0
  14. package/app/pages/asserts/custom.css +12 -0
  15. package/app/pages/boot.js +49 -0
  16. package/app/pages/common/curl.js +85 -0
  17. package/app/pages/common/utils.js +3 -0
  18. package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +20 -0
  19. package/app/pages/dashboard/complex-view/header-view/header-view.vue +118 -0
  20. package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +44 -0
  21. package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +39 -0
  22. package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +130 -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 +99 -0
  25. package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +113 -0
  26. package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +129 -0
  27. package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +128 -0
  28. package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +98 -0
  29. package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +25 -0
  30. package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +120 -0
  31. package/app/pages/dashboard/dashboard.vue +98 -0
  32. package/app/pages/dashboard/entry.dashboard.js +42 -0
  33. package/app/pages/store/index.js +3 -0
  34. package/app/pages/store/menu.js +61 -0
  35. package/app/pages/store/project.js +17 -0
  36. package/app/pages/widgets/header-container/asserts/logo.png +0 -0
  37. package/app/pages/widgets/header-container/header-container.vue +81 -0
  38. package/app/pages/widgets/schema-form/complex-view/input/input.vue +139 -0
  39. package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +138 -0
  40. package/app/pages/widgets/schema-form/complex-view/select/select.vue +116 -0
  41. package/app/pages/widgets/schema-form/form-item-config.js +23 -0
  42. package/app/pages/widgets/schema-form/schema-form.vue +131 -0
  43. package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +47 -0
  44. package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +63 -0
  45. package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +41 -0
  46. package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +48 -0
  47. package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +130 -0
  48. package/app/pages/widgets/schema-search-bar/search-item-config.js +27 -0
  49. package/app/pages/widgets/schema-table/schema-table.vue +237 -0
  50. package/app/pages/widgets/sider-container/sider-container.vue +30 -0
  51. package/app/public/static/logo.png +0 -0
  52. package/app/public/static/normalize.css +239 -0
  53. package/app/router/project.js +6 -0
  54. package/app/router/view.js +8 -0
  55. package/app/router-schema/project.js +30 -0
  56. package/app/service/base.js +12 -0
  57. package/app/service/project.js +47 -0
  58. package/app/view/entry.tpl +25 -0
  59. package/app/webpack/config/webpack.base.js +210 -0
  60. package/app/webpack/config/webpack.dev.js +58 -0
  61. package/app/webpack/config/webpack.prod.js +113 -0
  62. package/app/webpack/dev.js +56 -0
  63. package/app/webpack/libs/blank.js +1 -0
  64. package/app/webpack/prod.js +21 -0
  65. package/config/config.default.js +3 -0
  66. package/elpis-core/env.js +23 -0
  67. package/elpis-core/index.js +95 -0
  68. package/elpis-core/loader/config.js +50 -0
  69. package/elpis-core/loader/controller.js +66 -0
  70. package/elpis-core/loader/extend.js +56 -0
  71. package/elpis-core/loader/middleware.js +65 -0
  72. package/elpis-core/loader/router-schema.js +48 -0
  73. package/elpis-core/loader/router.js +41 -0
  74. package/elpis-core/loader/service.js +66 -0
  75. package/index.js +38 -0
  76. package/model/index.js +99 -0
  77. package/package.json +90 -4
  78. package/test/controller/project.test.js +205 -0
@@ -0,0 +1,113 @@
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
+
28
+ <script setup>
29
+ import { ref, inject } from 'vue';
30
+ import $curl from '$elpisCommon/curl.js';
31
+
32
+ const {
33
+ api,
34
+ components
35
+ } = inject('schemaViewData');
36
+
37
+ const name = ref('detailPanel');
38
+
39
+ const isShow = ref(false);
40
+ const loading = ref(false);
41
+ const title = ref('');
42
+ const mainKey = ref('');
43
+ const mainValue = ref();
44
+ const dtoModel = ref({});
45
+
46
+ const show = (rowData) => {
47
+ const { config } = components.value[name.value];
48
+
49
+ title.value = config.title;
50
+ mainKey.value = config.mainKey; // 表单主键
51
+ mainValue.value = rowData[config.mainKey]; // 表单主键值
52
+ dtoModel.value = {};
53
+
54
+ isShow.value = true;
55
+
56
+ fetchFormData();
57
+ }
58
+
59
+ const fetchFormData = async () => {
60
+ if (loading.value) { return; }
61
+
62
+ loading.value = true;
63
+ const res = await $curl({
64
+ method: 'get',
65
+ url: api.value,
66
+ query: {
67
+ [mainKey.value]: mainValue.value
68
+ }
69
+ });
70
+ loading.value = false;
71
+
72
+ if (!res || !res.success || !res.data) {
73
+ return;
74
+ }
75
+
76
+ dtoModel.value = res.data;
77
+ }
78
+
79
+ defineExpose({
80
+ name,
81
+ show
82
+ })
83
+ </script>
84
+
85
+ <style lang="less" scoped>
86
+ .detail-panel {
87
+ border: 1px solid #a6a6a6;
88
+ padding: 30px;
89
+
90
+ .row-item {
91
+ height: 40px;
92
+ line-height: 40px;
93
+ font-size: 20px;
94
+
95
+ .item-label {
96
+ margin-right: 20px;
97
+ width: 120px;
98
+ color: #ffffff;
99
+ }
100
+
101
+ .item-value {
102
+ color: #d2dae4;
103
+ display: block;
104
+ width: 250px;
105
+ overflow: hidden;
106
+ text-overflow: ellipsis;
107
+ white-space: nowrap;
108
+ word-break: break-all;
109
+ overflow-wrap: break-word;
110
+ }
111
+ }
112
+ }
113
+ </style>
@@ -0,0 +1,129 @@
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
+ <schema-form
13
+ ref="schemaFormRef"
14
+ v-loading="loading"
15
+ :schema="components[name]?.schema"
16
+ :model="dtoModel"
17
+ ></schema-form>
18
+ </template>
19
+ <template #footer>
20
+ <el-button
21
+ type="primary"
22
+ @click="save"
23
+ >{{saveBtnText}}</el-button>
24
+ </template>
25
+ </el-drawer>
26
+ </template>
27
+
28
+ <script setup>
29
+ import { ref, inject } from 'vue';
30
+ import { ElNotification } from 'element-plus';
31
+ import $curl from '$elpisCommon/curl';
32
+ import SchemaForm from '$elpisWidgets/schema-form/schema-form';
33
+
34
+ const {
35
+ api,
36
+ components
37
+ } = inject('schemaViewData');
38
+
39
+ const emit = defineEmits([ 'command' ]);
40
+
41
+ const name = ref('editForm');
42
+
43
+ const schemaFormRef = ref(null);
44
+ const isShow = ref(false);
45
+ const loading = ref(false);
46
+ const title = ref('');
47
+ const saveBtnText = ref('');
48
+ const mainKey = ref('');
49
+ const mainValue = ref();
50
+ const dtoModel = ref({});
51
+
52
+ const show = (rowData) => {
53
+ const { config } = components.value[name.value];
54
+
55
+ title.value = config.title;
56
+ saveBtnText.value = config.saveBtnText;
57
+ mainKey.value = config.mainKey; // 表单主键
58
+ mainValue.value = rowData[config.mainKey]; // 表单主键值
59
+ dtoModel.value = {};
60
+
61
+ isShow.value = true;
62
+
63
+ fetchFormData();
64
+ }
65
+
66
+ const close = () => {
67
+ isShow.value = false;
68
+ }
69
+
70
+ const fetchFormData = async () => {
71
+ if (loading.value) { return; }
72
+
73
+ loading.value = true;
74
+ const res = await $curl({
75
+ method: 'get',
76
+ url: api.value,
77
+ query: {
78
+ [mainKey.value]: mainValue.value
79
+ }
80
+ });
81
+ loading.value = false;
82
+
83
+ if (!res || !res.success || !res.data) {
84
+ return;
85
+ }
86
+
87
+ dtoModel.value = res.data;
88
+ }
89
+
90
+ const save = async () => {
91
+ if (loading.value) { return; }
92
+
93
+ if (!schemaFormRef.value.validate()) { return; }
94
+
95
+ loading.value = true;
96
+ const res = await $curl({
97
+ method: 'put',
98
+ url: api.value,
99
+ data: {
100
+ [mainKey.value]: mainValue.value,
101
+ ...schemaFormRef.value.getValue()
102
+ }
103
+ })
104
+ loading.value = false;
105
+
106
+ if (!res || !res.success) {
107
+ return;
108
+ }
109
+
110
+ ElNotification({
111
+ title: '修改成功',
112
+ message: '修改成功',
113
+ type: 'success'
114
+ });
115
+
116
+ close();
117
+
118
+ emit('command', {
119
+ event: 'loadTableData'
120
+ });
121
+ }
122
+
123
+ defineExpose({
124
+ name,
125
+ show
126
+ });
127
+ </script>
128
+
129
+ <style lang="less" scoped></style>
@@ -0,0 +1,128 @@
1
+ import { ref, watch, onMounted, nextTick } from 'vue';
2
+ import { useRoute } from 'vue-router';
3
+ import { useMenuStore } from '$elpisStore/menu.js';
4
+
5
+ export const useSchema = function() {
6
+ const route = useRoute();
7
+ const menuStore = useMenuStore();
8
+
9
+ const api = ref('');
10
+ const tableSchema = ref({});
11
+ const tableConfig = ref();
12
+ const searchSchema = ref({});
13
+ const searchConfig = ref();
14
+ const components = ref({});
15
+
16
+ // 构造 schemaConfig 相关配置,输送给 schemaView 解释。
17
+ const buildData = function() {
18
+ const { key, sider_key: siderKey } = route.query;
19
+
20
+ const mItem = menuStore.findMenuItem({
21
+ key: 'key',
22
+ value: siderKey ?? key
23
+ });
24
+
25
+ if (mItem && mItem.schemaConfig) {
26
+ const { schemaConfig: sConfig } = mItem;
27
+
28
+ const configSchema = JSON.parse(JSON.stringify(sConfig.schema));
29
+
30
+ api.value = sConfig.api ?? '';
31
+
32
+ tableSchema.value = {};
33
+ tableConfig.value = undefined;
34
+ searchSchema.value = {};
35
+ searchConfig.value = undefined;
36
+ components.value = {};
37
+ nextTick(() => {
38
+ // 构造 tableSchema 和 tableConfig
39
+ tableSchema.value = buildDtoSchema(configSchema, 'table');
40
+ tableConfig.value = sConfig.tableConfig;
41
+
42
+ // 构造 searchSchema 和 searchConfig
43
+ const dtoSearchSchema = buildDtoSchema(configSchema, 'search');
44
+ for (const key in dtoSearchSchema.properties) {
45
+ if (route.query[key] !== undefined) {
46
+ dtoSearchSchema.properties[key].option.default = route.query[key];
47
+ }
48
+ }
49
+ searchSchema.value = dtoSearchSchema;
50
+ searchConfig.value = sConfig.searchConfig;
51
+
52
+ // 构造 components = { comKey: { schema: {}, config: {} } }
53
+ const { componentConfig } = sConfig;
54
+ if (componentConfig && Object.keys(componentConfig).length > 0) {
55
+ const dtoComponents = {};
56
+ for (const comName in componentConfig) {
57
+ dtoComponents[comName] = {
58
+ schema: buildDtoSchema(configSchema, comName),
59
+ config: componentConfig[comName]
60
+ }
61
+ }
62
+ components.value = dtoComponents;
63
+ }
64
+ });
65
+ }
66
+ }
67
+
68
+ // 通用构建 schema 方法(清除噪音)
69
+ const buildDtoSchema = (_schema, comName) => {
70
+ if (!_schema?.properties) { return {}; }
71
+
72
+ const dtoSchema = {
73
+ type: 'object',
74
+ properties: {}
75
+ }
76
+
77
+ // 提取有效 schema 字段信息
78
+ for (const key in _schema.properties) {
79
+ const props = _schema.properties[key];
80
+ if (props[`${comName}Option`]) {
81
+ let dtoProps = {};
82
+
83
+ // 提取 props 中非 option 的部分,存放到 dtoProps 中
84
+ for (const pKey in props) {
85
+ if (pKey.indexOf('Option') < 0) {
86
+ dtoProps[pKey] = props[pKey];
87
+ }
88
+ }
89
+
90
+ // 处理 comName Option
91
+ dtoProps = Object.assign({}, dtoProps, { option: props[`${comName}Option`] });
92
+
93
+ // 处理 required 字段
94
+ const { required } = _schema;
95
+ if (required && required.find(pk => pk === key)) {
96
+ dtoProps.option.required = true;
97
+ }
98
+
99
+ dtoSchema.properties[key] = dtoProps;
100
+ }
101
+ }
102
+
103
+ return dtoSchema;
104
+ }
105
+
106
+ watch([
107
+ () => route.query.key,
108
+ () => route.query.sider_key,
109
+ () => menuStore.menuList
110
+ ], () => {
111
+ buildData();
112
+ }, {
113
+ deep: true
114
+ });
115
+
116
+ onMounted(() => {
117
+ buildData();
118
+ });
119
+
120
+ return {
121
+ api,
122
+ tableSchema,
123
+ tableConfig,
124
+ searchSchema,
125
+ searchConfig,
126
+ components
127
+ }
128
+ }
@@ -0,0 +1,98 @@
1
+ <template>
2
+ <el-row class="schema-view">
3
+ <search-panel
4
+ v-if="searchSchema?.properties && Object.keys(searchSchema.properties).length > 0"
5
+ @search="onSearch"
6
+ ></search-panel>
7
+ <table-panel
8
+ ref="tablePanelRef"
9
+ @operate="onTableOperate"
10
+ ></table-panel>
11
+ <component
12
+ v-for="(item, key) in components"
13
+ :key="key"
14
+ :is="ComponentConfig[key]?.component"
15
+ ref="comListRef"
16
+ @command="onComponentCommand"
17
+ ></component>
18
+ </el-row>
19
+ </template>
20
+
21
+ <script setup>
22
+ import { ref, provide } from 'vue';
23
+ import SearchPanel from './complex-view/search-panel/search-panel.vue';
24
+ import TablePanel from './complex-view/table-panel/table-panel.vue';
25
+ import ComponentConfig from './components/component-config.js';
26
+ import { useSchema } from './hook/schema.js';
27
+
28
+ const {
29
+ api,
30
+ tableSchema,
31
+ tableConfig,
32
+ searchSchema,
33
+ searchConfig,
34
+ components
35
+ } = useSchema();
36
+
37
+ const apiParmas = ref({});
38
+ provide('schemaViewData', {
39
+ api,
40
+ apiParmas,
41
+ tableSchema,
42
+ tableConfig,
43
+ searchSchema,
44
+ searchConfig,
45
+ components
46
+ });
47
+
48
+ const tablePanelRef = ref(null);
49
+ const comListRef = ref([]);
50
+
51
+ const onSearch = (searchValObj) => {
52
+ apiParmas.value = searchValObj;
53
+ }
54
+
55
+ // table 事件映射
56
+ const EventHandlerMap = {
57
+ showComponent: showComponent
58
+ }
59
+ const onTableOperate = ({ btnConfig, rowData }) => {
60
+ const { eventKey } = btnConfig;
61
+ if (EventHandlerMap[eventKey]) {
62
+ EventHandlerMap[eventKey]({ btnConfig, rowData })
63
+ }
64
+ }
65
+ // showComponent 展示动态组件
66
+ function showComponent({ btnConfig, rowData }) {
67
+ const { comName } = btnConfig.eventOption;
68
+ if (!comName) {
69
+ console.error('没配置组件名');
70
+ return;
71
+ }
72
+
73
+ const comRef = comListRef.value.find(item => item.name === comName);
74
+ if (!comRef || typeof comRef.show !== 'function') {
75
+ console.error(`找不到组件:${comName}`);
76
+ return;
77
+ }
78
+
79
+ comRef.show(rowData);
80
+ }
81
+
82
+ // 响应组件事件
83
+ const onComponentCommand = (data) => {
84
+ const { event } = data;
85
+ if (event === 'loadTableData') {
86
+ tablePanelRef.value.loadTableData();
87
+ }
88
+ }
89
+ </script>
90
+
91
+ <style lang="less" scoped>
92
+ .schema-view {
93
+ display: flex;
94
+ flex-direction: column;
95
+ height: 100%;
96
+ width: 100%;
97
+ }
98
+ </style>
@@ -0,0 +1,25 @@
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
+ <sub-menu
8
+ v-if="item.subMenu && item.subMenu.length > 0"
9
+ :menu-item="item"
10
+ ></sub-menu>
11
+ <el-menu-item
12
+ v-else
13
+ :index="item.key"
14
+ >
15
+ {{ item.name }}
16
+ </el-menu-item>
17
+ </div>
18
+ </el-sub-menu>
19
+ </template>
20
+
21
+ <script setup>
22
+ const { menuItem } = defineProps([ 'menuItem' ]);
23
+ </script>
24
+
25
+ <style lang="less" scoped></style>
@@ -0,0 +1,120 @@
1
+ <template>
2
+ <sider-container>
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
+ <sub-menu
11
+ v-if="item.subMenu && item.subMenu.length > 0"
12
+ :menu-item="item"
13
+ ></sub-menu>
14
+ <el-menu-item
15
+ v-else
16
+ :index="item.key"
17
+ >
18
+ {{ item.name }}
19
+ </el-menu-item>
20
+ </template>
21
+ </el-menu>
22
+ </template>
23
+ <template #main-content>
24
+ <router-view></router-view>
25
+ </template>
26
+ </sider-container>
27
+ </template>
28
+
29
+ <script setup>
30
+ import { ref, watch, onMounted } from 'vue';
31
+ import { useRouter, useRoute } from 'vue-router';
32
+ import { useMenuStore } from '$elpisStore/menu.js';
33
+ import SiderContainer from '$elpisWidgets/sider-container/sider-container';
34
+ import SubMenu from './complex-view/sub-menu/sub-menu.vue';
35
+
36
+ const router = useRouter();
37
+ const route = useRoute();
38
+ const menuStore = useMenuStore();
39
+
40
+ const menuList = ref([]);
41
+ const setMenuList = function() {
42
+ const menuItem = menuStore.findMenuItem({
43
+ key: 'key',
44
+ value: route.query.key
45
+ });
46
+ if (menuItem && menuItem.siderConfig && menuItem.siderConfig.menu) {
47
+ menuList.value = menuItem.siderConfig.menu;
48
+ }
49
+ }
50
+
51
+ const activeKey = ref('');
52
+ const setActiveKey = function() {
53
+ let siderMenuItem = menuStore.findMenuItem({
54
+ key: 'key',
55
+ value: route.query.sider_key
56
+ });
57
+
58
+ // 如果首次加载 sider-view,用户未选中左侧菜单,需要默认选中第一个
59
+ if (!siderMenuItem) {
60
+ const hMenuItem = menuStore.findMenuItem({
61
+ key: 'key',
62
+ value: route.query.key
63
+ });
64
+ if (hMenuItem && hMenuItem.siderConfig && hMenuItem.siderConfig.menu) {
65
+ const siderMenuList = hMenuItem.siderConfig.menu;
66
+ siderMenuItem = menuStore.findFirstMenuItem(siderMenuList); // 找出左侧菜单中的第一项
67
+ if (siderMenuItem) {
68
+ handleMenuSelect(siderMenuItem.key);
69
+ }
70
+ }
71
+ }
72
+
73
+ activeKey.value = siderMenuItem?.key;
74
+ }
75
+
76
+ watch(() => route.query.key, () => {
77
+ setMenuList();
78
+ setActiveKey();
79
+ });
80
+ watch(() => menuStore.menuList, () => {
81
+ setMenuList();
82
+ setActiveKey();
83
+ }, { deep: true });
84
+ onMounted(() => {
85
+ setMenuList();
86
+ setActiveKey();
87
+ });
88
+
89
+ const onMenuSelect = function (menuKey) {
90
+ handleMenuSelect(menuKey);
91
+ }
92
+
93
+ const handleMenuSelect = function(menuKey) {
94
+ const menuItem = menuStore.findMenuItem({
95
+ key: 'key',
96
+ value: menuKey
97
+ });
98
+
99
+ const { moduleType, key, customConfig } = menuItem;
100
+
101
+ // 如果是当前页面,不处理
102
+ if (key === route.query.sider_key) { return; }
103
+
104
+ const pathMap = {
105
+ iframe: '/iframe',
106
+ schema: '/schema',
107
+ custom: customConfig?.path
108
+ }
109
+ router.push({
110
+ path: `/view/dashboard/sider${pathMap[moduleType]}`,
111
+ query: {
112
+ key: route.query.key,
113
+ sider_key: key,
114
+ proj_key: route.query.proj_key
115
+ }
116
+ })
117
+ }
118
+ </script>
119
+
120
+ <style lang="less" scoped></style>
@@ -0,0 +1,98 @@
1
+ <template>
2
+ <el-config-provider :locale="zhCn">
3
+ <header-view :proj-name="projName" @menu-select="onMenuSelect">
4
+ <template #main-content>
5
+ <router-view></router-view>
6
+ </template>
7
+ </header-view>
8
+ </el-config-provider>
9
+ </template>
10
+
11
+ <script setup>
12
+ import { ref, onMounted } from 'vue';
13
+ import { useRouter, useRoute } from 'vue-router';
14
+ import zhCn from 'element-plus/es/locale/lang/zh-cn';
15
+ import HeaderView from './complex-view/header-view/header-view.vue';
16
+ import $curl from '$elpisCommon/curl.js';
17
+ import { useMenuStore } from '$elpisStore/menu.js';
18
+ import { useProjectStore } from '$elpisStore/project.js';
19
+
20
+ const router = useRouter();
21
+ const route = useRoute();
22
+ const menuStore = useMenuStore();
23
+ const projectStore = useProjectStore();
24
+
25
+ onMounted(() => {
26
+ getProjectList();
27
+ getProjectConfig();
28
+ });
29
+
30
+ const projName = ref('');
31
+
32
+ // 请求 /api/project/list 接口,并缓存到 project-store 中
33
+ async function getProjectList() {
34
+ const res = await $curl({
35
+ method: 'get',
36
+ url: '/api/project/list',
37
+ query: {
38
+ proj_key: route.query.proj_key,
39
+ }
40
+ });
41
+
42
+ if (!res || !res.success || !res.data) {
43
+ return;
44
+ }
45
+
46
+ projectStore.setProjectList(res.data);
47
+ }
48
+
49
+ // 请求 /api/project 接口,并缓存到 menu-store 中
50
+ async function getProjectConfig() {
51
+ const res = await $curl({
52
+ method: 'get',
53
+ url: '/api/project',
54
+ query: {
55
+ proj_key: route.query.proj_key,
56
+ }
57
+ });
58
+
59
+ if (!res || !res.success || !res.data) {
60
+ return;
61
+ }
62
+
63
+ const { name, menu } = res.data;
64
+
65
+ projName.value = name;
66
+
67
+ menuStore.setMenuList(menu);
68
+ }
69
+
70
+ // 点击菜单回调方法
71
+ const onMenuSelect = function(menuItem) {
72
+ const { moduleType, key, customConfig } = menuItem;
73
+
74
+ // 如果是当前页面,不处理
75
+ if (key === route.query.key) { return; }
76
+
77
+ const pathMap = {
78
+ sider: '/sider',
79
+ iframe: '/iframe',
80
+ schema: '/schema',
81
+ custom: customConfig?.path
82
+ }
83
+
84
+ router.push({
85
+ path: `/view/dashboard${pathMap[moduleType]}`,
86
+ query: {
87
+ key,
88
+ proj_key: route.query.proj_key
89
+ }
90
+ })
91
+ }
92
+ </script>
93
+
94
+ <style lang="less" scoped>
95
+ :deep(.el-main) {
96
+ padding: 0;
97
+ }
98
+ </style>