@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.
- package/.eslintignore +3 -0
- package/.eslintrc +55 -0
- package/README.md +294 -2
- package/app/controller/base.js +39 -0
- package/app/controller/project.js +77 -0
- package/app/controller/view.js +19 -0
- package/app/extend/database.js +5 -0
- package/app/extend/logger.js +38 -0
- package/app/middleware/api-params-verify.js +75 -0
- package/app/middleware/api-sign-verify.js +38 -0
- package/app/middleware/error-handler.js +34 -0
- package/app/middleware/project-handler.js +28 -0
- package/app/middleware.js +38 -0
- package/app/pages/asserts/custom.css +12 -0
- package/app/pages/boot.js +49 -0
- package/app/pages/common/curl.js +85 -0
- package/app/pages/common/utils.js +3 -0
- package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +20 -0
- package/app/pages/dashboard/complex-view/header-view/header-view.vue +118 -0
- package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +44 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +39 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +130 -0
- package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +23 -0
- package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +99 -0
- package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +113 -0
- package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +129 -0
- package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +128 -0
- package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +98 -0
- package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +25 -0
- package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +120 -0
- package/app/pages/dashboard/dashboard.vue +98 -0
- package/app/pages/dashboard/entry.dashboard.js +42 -0
- package/app/pages/store/index.js +3 -0
- package/app/pages/store/menu.js +61 -0
- package/app/pages/store/project.js +17 -0
- package/app/pages/widgets/header-container/asserts/logo.png +0 -0
- package/app/pages/widgets/header-container/header-container.vue +81 -0
- package/app/pages/widgets/schema-form/complex-view/input/input.vue +139 -0
- package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +138 -0
- package/app/pages/widgets/schema-form/complex-view/select/select.vue +116 -0
- package/app/pages/widgets/schema-form/form-item-config.js +23 -0
- package/app/pages/widgets/schema-form/schema-form.vue +131 -0
- package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +47 -0
- package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +63 -0
- package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +41 -0
- package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +48 -0
- package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +130 -0
- package/app/pages/widgets/schema-search-bar/search-item-config.js +27 -0
- package/app/pages/widgets/schema-table/schema-table.vue +237 -0
- package/app/pages/widgets/sider-container/sider-container.vue +30 -0
- package/app/public/static/logo.png +0 -0
- package/app/public/static/normalize.css +239 -0
- package/app/router/project.js +6 -0
- package/app/router/view.js +8 -0
- package/app/router-schema/project.js +30 -0
- package/app/service/base.js +12 -0
- package/app/service/project.js +47 -0
- package/app/view/entry.tpl +25 -0
- package/app/webpack/config/webpack.base.js +210 -0
- package/app/webpack/config/webpack.dev.js +58 -0
- package/app/webpack/config/webpack.prod.js +113 -0
- package/app/webpack/dev.js +56 -0
- package/app/webpack/libs/blank.js +1 -0
- package/app/webpack/prod.js +21 -0
- package/config/config.default.js +3 -0
- package/elpis-core/env.js +23 -0
- package/elpis-core/index.js +95 -0
- package/elpis-core/loader/config.js +50 -0
- package/elpis-core/loader/controller.js +66 -0
- package/elpis-core/loader/extend.js +56 -0
- package/elpis-core/loader/middleware.js +65 -0
- package/elpis-core/loader/router-schema.js +48 -0
- package/elpis-core/loader/router.js +41 -0
- package/elpis-core/loader/service.js +66 -0
- package/index.js +38 -0
- package/model/index.js +99 -0
- package/package.json +90 -4
- package/test/controller/project.test.js +205 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import boot from '$elpisPages/boot.js';
|
|
2
|
+
import dashboard from './dashboard.vue';
|
|
3
|
+
import businessDashboardRouterConfig from '$businessDashboardRouterConfig';
|
|
4
|
+
|
|
5
|
+
const routes = [];
|
|
6
|
+
|
|
7
|
+
// 头部菜单路由
|
|
8
|
+
routes.push({
|
|
9
|
+
path: '/view/dashboard/iframe',
|
|
10
|
+
component: () => import('./complex-view/iframe-view/iframe-view.vue')
|
|
11
|
+
});
|
|
12
|
+
routes.push({
|
|
13
|
+
path: '/view/dashboard/schema',
|
|
14
|
+
component: () => import('./complex-view/schema-view/schema-view.vue')
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const siderRoutes = [{
|
|
18
|
+
path: 'iframe',
|
|
19
|
+
component: () => import('./complex-view/iframe-view/iframe-view.vue')
|
|
20
|
+
}, {
|
|
21
|
+
path: 'schema',
|
|
22
|
+
component: () => import('./complex-view/schema-view/schema-view.vue')
|
|
23
|
+
}]
|
|
24
|
+
// 侧边栏菜单路由
|
|
25
|
+
routes.push({
|
|
26
|
+
path: '/view/dashboard/sider',
|
|
27
|
+
component: () => import('./complex-view/sider-view/sider-view.vue'),
|
|
28
|
+
children: siderRoutes
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 业务拓展路由
|
|
32
|
+
if (typeof businessDashboardRouterConfig === 'function') {
|
|
33
|
+
businessDashboardRouterConfig({ routes, siderRoutes });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 侧边栏兜底策略
|
|
37
|
+
routes.push({
|
|
38
|
+
path: '/view/dashboard/sider/:chapters+',
|
|
39
|
+
component: () => import('./complex-view/sider-view/sider-view.vue')
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
boot(dashboard, { routes });
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
export const useMenuStore = defineStore('menu', () => {
|
|
5
|
+
// 菜单列表
|
|
6
|
+
const menuList = ref([]);
|
|
7
|
+
|
|
8
|
+
// 设置菜单列表
|
|
9
|
+
const setMenuList = function(list) {
|
|
10
|
+
menuList.value = list;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 找出菜单目录
|
|
15
|
+
* @param key 搜索字段
|
|
16
|
+
* @param value 搜索值
|
|
17
|
+
* @param mList 要搜索的菜单列表
|
|
18
|
+
*/
|
|
19
|
+
const findMenuItem = function({ key, value }, mList = menuList.value) {
|
|
20
|
+
for (let i = 0; i < mList.length; ++i) {
|
|
21
|
+
const menuItem = mList[i];
|
|
22
|
+
if (!menuItem) { continue; }
|
|
23
|
+
|
|
24
|
+
const { menuType, moduleType } = menuItem;
|
|
25
|
+
|
|
26
|
+
if (menuItem[key] === value) {
|
|
27
|
+
return menuItem;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (menuType === 'group' && menuItem.subMenu) {
|
|
31
|
+
const mItem = findMenuItem({ key, value }, menuItem.subMenu);
|
|
32
|
+
if (mItem) { return mItem; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (moduleType === 'sider' && menuItem.siderConfig && menuItem.siderConfig.menu) {
|
|
36
|
+
const mItem = findMenuItem({ key, value }, menuItem.siderConfig.menu);
|
|
37
|
+
if (mItem) { return mItem; }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 找出第一个菜单目录
|
|
44
|
+
* @param mList 菜单列表
|
|
45
|
+
*/
|
|
46
|
+
const findFirstMenuItem = function(mList = menuList.value) {
|
|
47
|
+
if (!mList || !mList[0]) { return; }
|
|
48
|
+
let firstMenuItem = mList[0];
|
|
49
|
+
if (firstMenuItem.subMenu) {
|
|
50
|
+
firstMenuItem = findMenuItem(firstMenuItem.subMenu);
|
|
51
|
+
}
|
|
52
|
+
return firstMenuItem;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
menuList,
|
|
57
|
+
setMenuList,
|
|
58
|
+
findMenuItem,
|
|
59
|
+
findFirstMenuItem
|
|
60
|
+
}
|
|
61
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
export const useProjectStore = defineStore('project', () => {
|
|
5
|
+
// 项目列表
|
|
6
|
+
const projectList = ref([]);
|
|
7
|
+
|
|
8
|
+
// 设置项目列表
|
|
9
|
+
const setProjectList = function(list) {
|
|
10
|
+
projectList.value = list;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
projectList,
|
|
15
|
+
setProjectList
|
|
16
|
+
}
|
|
17
|
+
});
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-container class="header-container">
|
|
3
|
+
<el-header class="header">
|
|
4
|
+
<el-row type="flex" align="middle" class="header-row">
|
|
5
|
+
<!-- 左上方 title -->
|
|
6
|
+
<el-row type="flex" align="middle" class="title-panel">
|
|
7
|
+
<img src="./asserts/logo.png" class="logo"/>
|
|
8
|
+
<el-row class="text">{{title}}</el-row>
|
|
9
|
+
</el-row>
|
|
10
|
+
<!-- 插槽:菜单区域 -->
|
|
11
|
+
<slot name="menu-content"></slot>
|
|
12
|
+
<!-- 右上方区域 -->
|
|
13
|
+
<el-row type="flex" align="middle" justify="end" class="setting-panel">
|
|
14
|
+
<!-- 插槽:设置区域 -->
|
|
15
|
+
<slot name="setting-content"></slot>
|
|
16
|
+
<component
|
|
17
|
+
v-if="BusinessHeaderConfig?.userPanel"
|
|
18
|
+
:is="BusinessHeaderConfig?.userPanel.component"
|
|
19
|
+
></component>
|
|
20
|
+
</el-row>
|
|
21
|
+
</el-row>
|
|
22
|
+
</el-header>
|
|
23
|
+
<el-main class="main-container">
|
|
24
|
+
<!-- 插槽:核心内容填充区域 -->
|
|
25
|
+
<slot name="main-content"></slot>
|
|
26
|
+
</el-main>
|
|
27
|
+
</el-container>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script setup>
|
|
31
|
+
import BusinessHeaderConfig from '$bussinessHeaderConfig';
|
|
32
|
+
defineProps({
|
|
33
|
+
title: String
|
|
34
|
+
});
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<style lang="less" scoped>
|
|
38
|
+
.header-container {
|
|
39
|
+
height: 100%;
|
|
40
|
+
min-width: 1000px;
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
|
|
43
|
+
.header {
|
|
44
|
+
max-height: 120px;
|
|
45
|
+
border-bottom: 1px solid #E8E8E8;
|
|
46
|
+
|
|
47
|
+
.header-row {
|
|
48
|
+
height: 60px;
|
|
49
|
+
padding: 0 20px;
|
|
50
|
+
|
|
51
|
+
.title-panel {
|
|
52
|
+
width: 180px;
|
|
53
|
+
min-width: 180px;
|
|
54
|
+
|
|
55
|
+
.logo {
|
|
56
|
+
margin-right: 10px;
|
|
57
|
+
width: 25px;
|
|
58
|
+
height: 25px;
|
|
59
|
+
border-radius: 50%;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.text {
|
|
63
|
+
font-size: 15px;
|
|
64
|
+
font-weight: 500;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.setting-panel {
|
|
69
|
+
margin-left: auto;
|
|
70
|
+
min-width: 180px;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.main-container {}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:deep(.el-header) {
|
|
79
|
+
padding: 0;
|
|
80
|
+
}
|
|
81
|
+
</style>
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-row type="flex" align="middle" class="form-item">
|
|
3
|
+
<!-- label -->
|
|
4
|
+
<el-row class="item-label" justify="end">
|
|
5
|
+
<el-row
|
|
6
|
+
v-if="schema.option?.required"
|
|
7
|
+
type="flex"
|
|
8
|
+
class="required"
|
|
9
|
+
>*</el-row>
|
|
10
|
+
{{schema.label}}
|
|
11
|
+
</el-row>
|
|
12
|
+
<!-- value -->
|
|
13
|
+
<el-row class="item-value">
|
|
14
|
+
<el-input
|
|
15
|
+
v-model="dtoValue"
|
|
16
|
+
v-bind="schema.option"
|
|
17
|
+
:placeholder="placeholder"
|
|
18
|
+
class="component"
|
|
19
|
+
:class="validTips ? 'valid-border' : ''"
|
|
20
|
+
@focus="onFocus"
|
|
21
|
+
@blur="onBlur"
|
|
22
|
+
></el-input>
|
|
23
|
+
</el-row>
|
|
24
|
+
<!-- 错误信息 -->
|
|
25
|
+
<el-row v-if="validTips" class="valid-tips">
|
|
26
|
+
{{ validTips }}
|
|
27
|
+
</el-row>
|
|
28
|
+
</el-row>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script setup>
|
|
32
|
+
import { ref, toRefs, watch, inject, onMounted } from 'vue';
|
|
33
|
+
const ajv = inject('ajv');
|
|
34
|
+
|
|
35
|
+
const props = defineProps({
|
|
36
|
+
schemaKey: String,
|
|
37
|
+
schema: Object,
|
|
38
|
+
model: String
|
|
39
|
+
});
|
|
40
|
+
const { schemaKey, schema } = props;
|
|
41
|
+
const { model } = toRefs(props);
|
|
42
|
+
|
|
43
|
+
const name = ref('input');
|
|
44
|
+
const dtoValue = ref();
|
|
45
|
+
const placeholder = ref('');
|
|
46
|
+
const validTips = ref(null);
|
|
47
|
+
|
|
48
|
+
const initData = () => {
|
|
49
|
+
dtoValue.value = model.value ?? schema.option?.default;
|
|
50
|
+
validTips.value = null;
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
minLength,
|
|
54
|
+
maxLength,
|
|
55
|
+
pattern
|
|
56
|
+
} = schema;
|
|
57
|
+
|
|
58
|
+
const ruleList = [];
|
|
59
|
+
if (schema.option?.placeholder) {
|
|
60
|
+
ruleList.push(schema.option.placeholder);
|
|
61
|
+
}
|
|
62
|
+
if (minLength) {
|
|
63
|
+
ruleList.push(`最小长度: ${minLength}`);
|
|
64
|
+
}
|
|
65
|
+
if (maxLength) {
|
|
66
|
+
ruleList.push(`最大长度: ${maxLength}`);
|
|
67
|
+
}
|
|
68
|
+
if (pattern) {
|
|
69
|
+
ruleList.push(`格式: ${pattern}`);
|
|
70
|
+
}
|
|
71
|
+
placeholder.value = ruleList.join('|');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onMounted(() => {
|
|
75
|
+
initData();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
watch([ model, schema ], () => {
|
|
79
|
+
initData();
|
|
80
|
+
}, { deep: true });
|
|
81
|
+
|
|
82
|
+
const validate = () => {
|
|
83
|
+
validTips.value = null;
|
|
84
|
+
|
|
85
|
+
const { type } = schema;
|
|
86
|
+
|
|
87
|
+
// 校验是否必填
|
|
88
|
+
if (schema.option?.required && !dtoValue.value) {
|
|
89
|
+
validTips.value = '不能为空';
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ajv 校验 schema
|
|
94
|
+
if (dtoValue.value) {
|
|
95
|
+
const validate = ajv.compile(schema);
|
|
96
|
+
const valid = validate(dtoValue.value);
|
|
97
|
+
if (!valid && validate.errors && validate.errors[0]) {
|
|
98
|
+
const { keyword, params } = validate.errors[0];
|
|
99
|
+
if (keyword === 'type') {
|
|
100
|
+
validTips.value = `类型必须为 ${type}`;
|
|
101
|
+
} else if (keyword === 'maxLength') {
|
|
102
|
+
validTips.value = `最大长度应为 ${params.limit}`;
|
|
103
|
+
} else if (keyword === 'minLength') {
|
|
104
|
+
validTips.value = `最小长度应为 ${params.limit}`;
|
|
105
|
+
} else if (keyword === 'pattern') {
|
|
106
|
+
validTips.value = '格式不正确';
|
|
107
|
+
} else {
|
|
108
|
+
console.log(validate.errors[0]);
|
|
109
|
+
validTips.value = '不符合要求';
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const getValue = () => {
|
|
119
|
+
return dtoValue.value !== undefined ? {
|
|
120
|
+
[schemaKey]: dtoValue.value
|
|
121
|
+
} : {}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const onFocus = () => {
|
|
125
|
+
validTips.value = null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const onBlur = () => {
|
|
129
|
+
validate();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
defineExpose({
|
|
133
|
+
name,
|
|
134
|
+
validate,
|
|
135
|
+
getValue
|
|
136
|
+
});
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<style lang="less" scoped></style>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-row type="flex" align="middle" class="form-item">
|
|
3
|
+
<!-- label -->
|
|
4
|
+
<el-row class="item-label" justify="end">
|
|
5
|
+
<el-row
|
|
6
|
+
v-if="schema.option?.required"
|
|
7
|
+
type="flex"
|
|
8
|
+
class="required"
|
|
9
|
+
>*</el-row>
|
|
10
|
+
{{schema.label}}
|
|
11
|
+
</el-row>
|
|
12
|
+
<!-- value -->
|
|
13
|
+
<el-row class="item-value">
|
|
14
|
+
<el-input-number
|
|
15
|
+
v-model="dtoValue"
|
|
16
|
+
v-bind="schema.option"
|
|
17
|
+
:controls="false"
|
|
18
|
+
:placeholder="placeholder"
|
|
19
|
+
class="component"
|
|
20
|
+
:class="validTips ? 'valid-border' : ''"
|
|
21
|
+
@focus="onFocus"
|
|
22
|
+
@blur="onBlur"
|
|
23
|
+
></el-input-number>
|
|
24
|
+
</el-row>
|
|
25
|
+
<!-- 错误信息 -->
|
|
26
|
+
<el-row v-if="validTips" class="valid-tips">
|
|
27
|
+
{{ validTips }}
|
|
28
|
+
</el-row>
|
|
29
|
+
</el-row>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script setup>
|
|
33
|
+
import { ref, toRefs, watch, inject, onMounted } from 'vue';
|
|
34
|
+
const ajv = inject('ajv');
|
|
35
|
+
|
|
36
|
+
const props = defineProps({
|
|
37
|
+
schemaKey: String,
|
|
38
|
+
schema: Object,
|
|
39
|
+
model: Number
|
|
40
|
+
});
|
|
41
|
+
const { schemaKey, schema } = props;
|
|
42
|
+
const { model } = toRefs(props);
|
|
43
|
+
|
|
44
|
+
const name = ref('inputNumber');
|
|
45
|
+
const dtoValue = ref();
|
|
46
|
+
const placeholder = ref('');
|
|
47
|
+
const validTips = ref(null);
|
|
48
|
+
|
|
49
|
+
const initData = () => {
|
|
50
|
+
dtoValue.value = model.value ?? schema.option?.default;
|
|
51
|
+
validTips.value = null;
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
minimum,
|
|
55
|
+
maximum
|
|
56
|
+
} = schema;
|
|
57
|
+
|
|
58
|
+
const ruleList = [];
|
|
59
|
+
if (schema.option?.placeholder) {
|
|
60
|
+
ruleList.push(schema.option.placeholder);
|
|
61
|
+
}
|
|
62
|
+
if (minimum !== undefined) {
|
|
63
|
+
ruleList.push(`最小值: ${minimum}`);
|
|
64
|
+
}
|
|
65
|
+
if (maximum !== undefined) {
|
|
66
|
+
ruleList.push(`最大值: ${maximum}`);
|
|
67
|
+
}
|
|
68
|
+
placeholder.value = ruleList.join('|');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onMounted(() => {
|
|
72
|
+
initData();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
watch([ model, schema ], () => {
|
|
76
|
+
initData();
|
|
77
|
+
}, { deep: true });
|
|
78
|
+
|
|
79
|
+
const validate = () => {
|
|
80
|
+
validTips.value = null;
|
|
81
|
+
|
|
82
|
+
const { type } = schema;
|
|
83
|
+
|
|
84
|
+
// 校验是否必填
|
|
85
|
+
if (schema.option?.required && !dtoValue.value) {
|
|
86
|
+
validTips.value = '不能为空';
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ajv 校验 schema
|
|
91
|
+
if (dtoValue.value) {
|
|
92
|
+
const validate = ajv.compile(schema);
|
|
93
|
+
const valid = validate(dtoValue.value);
|
|
94
|
+
if (!valid && validate.errors && validate.errors[0]) {
|
|
95
|
+
const { keyword, params } = validate.errors[0];
|
|
96
|
+
if (keyword === 'type') {
|
|
97
|
+
validTips.value = `类型必须为 ${type}`;
|
|
98
|
+
} else if (keyword === 'minimum') {
|
|
99
|
+
validTips.value = `最小值应为 ${params.limit}`;
|
|
100
|
+
} else if (keyword === 'maximum') {
|
|
101
|
+
validTips.value = `最大值应为 ${params.limit}`;
|
|
102
|
+
} else {
|
|
103
|
+
console.log(validate.errors[0]);
|
|
104
|
+
validTips.value = '不符合要求';
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const getValue = () => {
|
|
114
|
+
return dtoValue.value !== undefined ? {
|
|
115
|
+
[schemaKey]: dtoValue.value
|
|
116
|
+
} : {}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const onFocus = () => {
|
|
120
|
+
validTips.value = null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const onBlur = () => {
|
|
124
|
+
validate();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
defineExpose({
|
|
128
|
+
name,
|
|
129
|
+
validate,
|
|
130
|
+
getValue
|
|
131
|
+
});
|
|
132
|
+
</script>
|
|
133
|
+
|
|
134
|
+
<style lang="less" scoped>
|
|
135
|
+
:deep(.el-input-number .el-input__inner) {
|
|
136
|
+
text-align: left;
|
|
137
|
+
}
|
|
138
|
+
</style>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-row type="flex" align="middle" class="form-item">
|
|
3
|
+
<!-- label -->
|
|
4
|
+
<el-row class="item-label" justify="end">
|
|
5
|
+
<el-row
|
|
6
|
+
v-if="schema.option?.required"
|
|
7
|
+
type="flex"
|
|
8
|
+
class="required"
|
|
9
|
+
>*</el-row>
|
|
10
|
+
{{schema.label}}
|
|
11
|
+
</el-row>
|
|
12
|
+
<!-- value -->
|
|
13
|
+
<el-row class="item-value">
|
|
14
|
+
<el-select
|
|
15
|
+
v-model="dtoValue"
|
|
16
|
+
v-bind="schema.option"
|
|
17
|
+
class="component"
|
|
18
|
+
:class="validTips ? 'valid-border' : ''"
|
|
19
|
+
@change="onChange"
|
|
20
|
+
>
|
|
21
|
+
<el-option
|
|
22
|
+
v-for="item in schema.option?.enumList"
|
|
23
|
+
:key="item.value"
|
|
24
|
+
:label="item.label"
|
|
25
|
+
:value="item.value"
|
|
26
|
+
></el-option>
|
|
27
|
+
</el-select>
|
|
28
|
+
</el-row>
|
|
29
|
+
<!-- 错误信息 -->
|
|
30
|
+
<el-row v-if="validTips" class="valid-tips">
|
|
31
|
+
{{ validTips }}
|
|
32
|
+
</el-row>
|
|
33
|
+
</el-row>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup>
|
|
37
|
+
import { ref, toRefs, watch, inject, onMounted } from 'vue';
|
|
38
|
+
const ajv = inject('ajv');
|
|
39
|
+
|
|
40
|
+
const props = defineProps({
|
|
41
|
+
schemaKey: String,
|
|
42
|
+
schema: Object,
|
|
43
|
+
model: null
|
|
44
|
+
});
|
|
45
|
+
const { schemaKey, schema } = props;
|
|
46
|
+
const { model } = toRefs(props);
|
|
47
|
+
|
|
48
|
+
const name = ref('select');
|
|
49
|
+
const dtoValue = ref();
|
|
50
|
+
const validTips = ref(null);
|
|
51
|
+
|
|
52
|
+
const initData = () => {
|
|
53
|
+
dtoValue.value = model.value ?? schema.option?.default;
|
|
54
|
+
validTips.value = null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
initData();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
watch([ model, schema ], () => {
|
|
62
|
+
initData();
|
|
63
|
+
}, { deep: true });
|
|
64
|
+
|
|
65
|
+
const validate = () => {
|
|
66
|
+
validTips.value = null;
|
|
67
|
+
|
|
68
|
+
// 校验是否必填
|
|
69
|
+
if (schema.option?.required && !dtoValue.value) {
|
|
70
|
+
validTips.value = '不能为空';
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ajv 校验 schema
|
|
75
|
+
if (dtoValue.value) {
|
|
76
|
+
let dtoEnum = [];
|
|
77
|
+
if (schema.option?.enumList) {
|
|
78
|
+
dtoEnum = schema.option?.enumList.map(item => item.value);
|
|
79
|
+
}
|
|
80
|
+
const validate = ajv.compile({
|
|
81
|
+
schema,
|
|
82
|
+
... { enum: dtoEnum }
|
|
83
|
+
});
|
|
84
|
+
const valid = validate(dtoValue.value);
|
|
85
|
+
if (!valid && validate.errors && validate.errors[0]) {
|
|
86
|
+
if (validate.errors[0].keyword === 'enum') {
|
|
87
|
+
validTips.value = '取值超出枚举范围';
|
|
88
|
+
} else {
|
|
89
|
+
console.log(validate.errors[0]);
|
|
90
|
+
validTips.value = '不符合要求';
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const getValue = () => {
|
|
100
|
+
return dtoValue.value !== undefined ? {
|
|
101
|
+
[schemaKey]: dtoValue.value
|
|
102
|
+
} : {}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const onChange = () => {
|
|
106
|
+
validate();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
defineExpose({
|
|
110
|
+
name,
|
|
111
|
+
validate,
|
|
112
|
+
getValue
|
|
113
|
+
});
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<style lang="less" scoped></style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import input from './complex-view/input/input.vue';
|
|
2
|
+
import inputNumber from './complex-view/input-number/input-number.vue';
|
|
3
|
+
import select from './complex-view/select/select.vue';
|
|
4
|
+
|
|
5
|
+
// 业务扩展 form-item 配置
|
|
6
|
+
import BusinessFormItemConfig from '$businessFormItemConfig';
|
|
7
|
+
|
|
8
|
+
const FormItemConfig = {
|
|
9
|
+
input: {
|
|
10
|
+
component: input
|
|
11
|
+
},
|
|
12
|
+
inputNumber: {
|
|
13
|
+
component: inputNumber
|
|
14
|
+
},
|
|
15
|
+
select: {
|
|
16
|
+
component: select
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
...FormItemConfig,
|
|
22
|
+
...BusinessFormItemConfig
|
|
23
|
+
}
|