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