@lixianwei/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.
- package/.eslintignore +2 -0
- package/.eslintrc +55 -0
- package/.idea/dictionaries/project.xml +8 -0
- package/.idea/elpis.iml +8 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +329 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +201 -0
- package/app/controller/base.js +77 -0
- package/app/controller/project.js +69 -0
- package/app/controller/view.js +20 -0
- package/app/extend/logger.js +35 -0
- package/app/middleware/api-params-verify.js +74 -0
- package/app/middleware/api-sign-verify.js +33 -0
- package/app/middleware/error-hander.js +32 -0
- package/app/middleware/project-handler.js +25 -0
- package/app/middleware.js +37 -0
- package/app/pages/asserts/custom.css +11 -0
- package/app/pages/boot.js +43 -0
- package/app/pages/common/curl.js +83 -0
- package/app/pages/common/index.js +2 -0
- package/app/pages/common/utils.js +0 -0
- package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +23 -0
- package/app/pages/dashboard/complex-view/header-view/header-view.vue +117 -0
- package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +40 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +45 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/tabel-panel/tabel-panel.vue +134 -0
- package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +20 -0
- package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +89 -0
- package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +101 -0
- package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +128 -0
- package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +119 -0
- package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +96 -0
- package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +21 -0
- package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +117 -0
- package/app/pages/dashboard/dashboard.vue +88 -0
- package/app/pages/dashboard/entry.dashboard.js +41 -0
- package/app/pages/router/index.js +11 -0
- package/app/pages/store/index.js +4 -0
- package/app/pages/store/menu.js +65 -0
- package/app/pages/store/project.js +16 -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 +103 -0
- package/app/pages/widgets/schema-form/complex-view/input/input.vue +142 -0
- package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +143 -0
- package/app/pages/widgets/schema-form/complex-view/select/select.vue +130 -0
- package/app/pages/widgets/schema-form/form-item-config.js +20 -0
- package/app/pages/widgets/schema-form/schema-form.vue +132 -0
- package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +48 -0
- package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +67 -0
- package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +40 -0
- package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +50 -0
- package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +142 -0
- package/app/pages/widgets/schema-search-bar/search-item-config.js +24 -0
- package/app/pages/widgets/schema-table/schema-table.vue +238 -0
- package/app/pages/widgets/sider-container/sider-container.vue +31 -0
- package/app/public/static/logo.png +0 -0
- package/app/public/static/normalize.css +239 -0
- package/app/router/project.js +9 -0
- package/app/router/view.js +7 -0
- package/app/router-schema/project.js +32 -0
- package/app/service/base.js +12 -0
- package/app/service/project.js +42 -0
- package/app/view/entry.tpl +26 -0
- package/app/webpack/config/webpack.base.js +219 -0
- package/app/webpack/config/webpack.dev.js +55 -0
- package/app/webpack/config/webpack.prod.js +118 -0
- package/app/webpack/dev.js +52 -0
- package/app/webpack/libs/blank.js +2 -0
- package/app/webpack/prod.js +18 -0
- package/config/config.default.js +3 -0
- package/elpis-core/env.js +20 -0
- package/elpis-core/index.js +92 -0
- package/elpis-core/loader/config.js +54 -0
- package/elpis-core/loader/controller.js +61 -0
- package/elpis-core/loader/extend.js +55 -0
- package/elpis-core/loader/middleware.js +61 -0
- package/elpis-core/loader/router-schema.js +39 -0
- package/elpis-core/loader/router.js +42 -0
- package/elpis-core/loader/service.js +64 -0
- package/index.js +41 -0
- package/model/index.js +105 -0
- package/package.json +94 -0
- package/test/controller/project.test.js +194 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {defineStore} from 'pinia'
|
|
2
|
+
import {ref} from 'vue'
|
|
3
|
+
export const userProjectStore = defineStore('project',()=>{
|
|
4
|
+
// 项目列表
|
|
5
|
+
const projectList =ref([])
|
|
6
|
+
|
|
7
|
+
// 设置项目列表
|
|
8
|
+
const setProjectList= function (list){
|
|
9
|
+
projectList.value = list
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
projectList,
|
|
14
|
+
setProjectList
|
|
15
|
+
}
|
|
16
|
+
})
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
<img src="./asserts/avatar.png" alt="" class="avatar">
|
|
17
|
+
<el-dropdown @command="handleUserCommand">
|
|
18
|
+
<span class="username">
|
|
19
|
+
{{userName}}
|
|
20
|
+
<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" />
|
|
32
|
+
</el-main>
|
|
33
|
+
</el-container>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup>
|
|
37
|
+
import {ref} from 'vue';
|
|
38
|
+
defineProps({
|
|
39
|
+
title: String,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const userName = ref('管理员')
|
|
43
|
+
|
|
44
|
+
const handleUserCommand =(e)=>{
|
|
45
|
+
console.log(e)
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<style scoped lang="less">
|
|
51
|
+
.header-container{
|
|
52
|
+
height: 100%;
|
|
53
|
+
min-width: 1000px;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
.header{
|
|
56
|
+
max-height: 120px;
|
|
57
|
+
border-bottom: 1px solid #e8e8e8;
|
|
58
|
+
.header-row{
|
|
59
|
+
height: 60px;
|
|
60
|
+
padding: 0 20px;
|
|
61
|
+
.title-panel{
|
|
62
|
+
width: 180px;
|
|
63
|
+
min-width: 180px;
|
|
64
|
+
.logo{
|
|
65
|
+
margin-right: 10px;
|
|
66
|
+
width: 25px;
|
|
67
|
+
height: 25px;
|
|
68
|
+
border-radius: 50%;
|
|
69
|
+
}
|
|
70
|
+
.text{
|
|
71
|
+
font-size: 15px;
|
|
72
|
+
font-weight: 500;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.setting-panel{
|
|
77
|
+
margin-left: auto;
|
|
78
|
+
min-width: 180px;
|
|
79
|
+
.avatar{
|
|
80
|
+
margin-right: 10px;
|
|
81
|
+
width: 30px;
|
|
82
|
+
height: 30px;
|
|
83
|
+
border-radius: 50%;
|
|
84
|
+
}
|
|
85
|
+
.username{
|
|
86
|
+
font-size: 16px;
|
|
87
|
+
font-weight: 500;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
height: 60px;
|
|
90
|
+
line-height: 60px;
|
|
91
|
+
outline: none;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
.main-container{}
|
|
98
|
+
}
|
|
99
|
+
:deep(.el-header){
|
|
100
|
+
padding: 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
|
|
2
|
+
<template>
|
|
3
|
+
<el-row
|
|
4
|
+
type="flex"
|
|
5
|
+
align="middle"
|
|
6
|
+
class="form-item"
|
|
7
|
+
>
|
|
8
|
+
<!-- label-->
|
|
9
|
+
<el-row
|
|
10
|
+
class="item-label"
|
|
11
|
+
justify="end"
|
|
12
|
+
>
|
|
13
|
+
<el-row
|
|
14
|
+
v-if="schema.option.required"
|
|
15
|
+
type="flex"
|
|
16
|
+
class="required"
|
|
17
|
+
>
|
|
18
|
+
*
|
|
19
|
+
</el-row>
|
|
20
|
+
{{ schema.label }}
|
|
21
|
+
</el-row>
|
|
22
|
+
<!-- value-->
|
|
23
|
+
<el-row class="item-value" >
|
|
24
|
+
<el-input
|
|
25
|
+
v-bind="schema.option"
|
|
26
|
+
class="component"
|
|
27
|
+
v-model="dtoValue"
|
|
28
|
+
:placeholder="placeholder"
|
|
29
|
+
:class="validTips?'valid-border':''"
|
|
30
|
+
@blur="onBlur"
|
|
31
|
+
@focus="onFocus"
|
|
32
|
+
></el-input>
|
|
33
|
+
</el-row>
|
|
34
|
+
<!-- 错误信息-->
|
|
35
|
+
<el-row v-if="validTips" class="valid-tips">
|
|
36
|
+
{{validTips}}
|
|
37
|
+
</el-row>
|
|
38
|
+
</el-row>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<script setup>
|
|
42
|
+
import {ref, watch, onMounted, toRefs, inject} from 'vue'
|
|
43
|
+
const ajv = inject('ajv')
|
|
44
|
+
|
|
45
|
+
const props = defineProps({
|
|
46
|
+
schema:Object,
|
|
47
|
+
schemaKey:String,
|
|
48
|
+
model:[String,Number],
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const { schema,schemaKey } = props;
|
|
52
|
+
const { model } = toRefs(props)
|
|
53
|
+
|
|
54
|
+
const name = ref('input')
|
|
55
|
+
const placeholder = ref('')
|
|
56
|
+
const dtoValue = ref(undefined)
|
|
57
|
+
const validTips = ref(null)
|
|
58
|
+
const initData = () => {
|
|
59
|
+
dtoValue.value = model.value ?? schema.option?.default;
|
|
60
|
+
validTips.value = null
|
|
61
|
+
|
|
62
|
+
const {minLength, maxLength,pattern} = schema;
|
|
63
|
+
const ruleList = [];
|
|
64
|
+
if(schema.options?.placeholder) {
|
|
65
|
+
ruleList.push(schema.options?.placeholder)
|
|
66
|
+
}
|
|
67
|
+
if(minLength) {
|
|
68
|
+
ruleList.push(`最小长度:${minLength}`)
|
|
69
|
+
}
|
|
70
|
+
if(maxLength) {
|
|
71
|
+
ruleList.push(`最大长度:${maxLength}`)
|
|
72
|
+
}
|
|
73
|
+
if(pattern) {
|
|
74
|
+
ruleList.push(`格式:${pattern}`)
|
|
75
|
+
}
|
|
76
|
+
placeholder.value = ruleList.join('|')
|
|
77
|
+
}
|
|
78
|
+
onMounted(()=>{
|
|
79
|
+
initData()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
watch([model,schema],()=>{
|
|
83
|
+
initData()
|
|
84
|
+
},{deep:true})
|
|
85
|
+
|
|
86
|
+
// 获取焦点时校验置空
|
|
87
|
+
const onFocus = ()=>{
|
|
88
|
+
validTips.value = null
|
|
89
|
+
}
|
|
90
|
+
// s失去焦点时校验
|
|
91
|
+
const onBlur = ()=>{
|
|
92
|
+
validate()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const validate = ()=>{
|
|
96
|
+
validTips.value = null
|
|
97
|
+
const {type} = schema;
|
|
98
|
+
// 校验是否必填
|
|
99
|
+
if(schema.option?.required && !dtoValue.value){
|
|
100
|
+
validTips.value = '不能为空'
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
// 校验schema
|
|
104
|
+
if(dtoValue.value){
|
|
105
|
+
const validate = ajv.compile(schema)
|
|
106
|
+
const valid = validate(dtoValue.value)
|
|
107
|
+
if(!valid&&validate.errors &&validate.errors[0]){
|
|
108
|
+
const {keyword,params} = validate.errors[0];
|
|
109
|
+
if(keyword === 'type'){
|
|
110
|
+
validTips.value = `类型必须为${type}`
|
|
111
|
+
}else if(keyword === 'maxLength'){
|
|
112
|
+
validTips.value = `最大长度应为${params.limit}`
|
|
113
|
+
}else if(keyword === 'minLength'){
|
|
114
|
+
validTips.value = `最小长度应为${params.limit}`
|
|
115
|
+
}else if(keyword === 'pattern'){
|
|
116
|
+
validTips.value = `格式不正确`
|
|
117
|
+
}else{
|
|
118
|
+
console.log(validate.errors[0])
|
|
119
|
+
validTips.value = `不符合要求`
|
|
120
|
+
}
|
|
121
|
+
return false
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return true
|
|
125
|
+
}
|
|
126
|
+
const getValue =()=>{
|
|
127
|
+
return dtoValue.value !==undefined ?{
|
|
128
|
+
[schemaKey]:dtoValue.value
|
|
129
|
+
}:{}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
defineExpose({
|
|
134
|
+
validate,
|
|
135
|
+
getValue,
|
|
136
|
+
name
|
|
137
|
+
})
|
|
138
|
+
</script>
|
|
139
|
+
|
|
140
|
+
<style scoped lang="less">
|
|
141
|
+
|
|
142
|
+
</style>
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
|
|
2
|
+
<template>
|
|
3
|
+
<el-row
|
|
4
|
+
type="flex"
|
|
5
|
+
align="middle"
|
|
6
|
+
class="form-item"
|
|
7
|
+
>
|
|
8
|
+
<!-- label-->
|
|
9
|
+
<el-row
|
|
10
|
+
class="item-label"
|
|
11
|
+
justify="end"
|
|
12
|
+
>
|
|
13
|
+
<el-row
|
|
14
|
+
v-if="schema.option.required"
|
|
15
|
+
type="flex"
|
|
16
|
+
class="required"
|
|
17
|
+
>
|
|
18
|
+
*
|
|
19
|
+
</el-row>
|
|
20
|
+
{{ schema.label }}
|
|
21
|
+
</el-row>
|
|
22
|
+
<!-- value-->
|
|
23
|
+
<el-row class="item-value">
|
|
24
|
+
<el-input-number
|
|
25
|
+
v-bind="schema.option"
|
|
26
|
+
v-model="dtoValue"
|
|
27
|
+
:controls="false"
|
|
28
|
+
class="component"
|
|
29
|
+
:placeholder="placeholder"
|
|
30
|
+
:class="validTips?'valid-border':''"
|
|
31
|
+
@blur="onBlur"
|
|
32
|
+
@focus="onFocus"
|
|
33
|
+
/>
|
|
34
|
+
</el-row>
|
|
35
|
+
<!-- 错误信息-->
|
|
36
|
+
<el-row
|
|
37
|
+
v-if="validTips"
|
|
38
|
+
class="valid-tips"
|
|
39
|
+
>
|
|
40
|
+
{{ validTips }}
|
|
41
|
+
</el-row>
|
|
42
|
+
</el-row>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup>
|
|
46
|
+
import {ref, watch, onMounted, toRefs, inject} from 'vue'
|
|
47
|
+
const ajv = inject('ajv')
|
|
48
|
+
|
|
49
|
+
const props = defineProps({
|
|
50
|
+
schema:Object,
|
|
51
|
+
schemaKey:String,
|
|
52
|
+
model:[String,Number],
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const { schema,schemaKey } = props;
|
|
56
|
+
const { model } = toRefs(props)
|
|
57
|
+
const name = ref('inputNumber')
|
|
58
|
+
const placeholder = ref('')
|
|
59
|
+
const dtoValue = ref(undefined)
|
|
60
|
+
const validTips = ref(null)
|
|
61
|
+
|
|
62
|
+
const initData = () => {
|
|
63
|
+
dtoValue.value = model.value ?? schema.option?.default;
|
|
64
|
+
validTips.value = null
|
|
65
|
+
|
|
66
|
+
const {minimum,maximum} = schema;
|
|
67
|
+
const ruleList = [];
|
|
68
|
+
if(schema.options?.placeholder) {
|
|
69
|
+
ruleList.push(schema.options?.placeholder)
|
|
70
|
+
}
|
|
71
|
+
if(minimum !== undefined ) {
|
|
72
|
+
ruleList.push(`最小值:${minimum}`)
|
|
73
|
+
}
|
|
74
|
+
if(maximum !== undefined) {
|
|
75
|
+
ruleList.push(`最大值:${maximum}`)
|
|
76
|
+
}
|
|
77
|
+
placeholder.value = ruleList.join('|')
|
|
78
|
+
}
|
|
79
|
+
onMounted(()=>{
|
|
80
|
+
initData()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
watch([model,schema],()=>{
|
|
84
|
+
initData()
|
|
85
|
+
},{deep:true})
|
|
86
|
+
|
|
87
|
+
// 获取焦点时校验置空
|
|
88
|
+
const onFocus = ()=>{
|
|
89
|
+
validTips.value = null
|
|
90
|
+
}
|
|
91
|
+
// s失去焦点时校验
|
|
92
|
+
const onBlur = ()=>{
|
|
93
|
+
validate()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const validate = ()=>{
|
|
97
|
+
validTips.value = null
|
|
98
|
+
const {type} = schema;
|
|
99
|
+
// 校验是否必填
|
|
100
|
+
if(schema.option?.required && !dtoValue.value){
|
|
101
|
+
validTips.value = '不能为空'
|
|
102
|
+
return false
|
|
103
|
+
}
|
|
104
|
+
// 校验schema
|
|
105
|
+
if(dtoValue.value){
|
|
106
|
+
const validate = ajv.compile(schema)
|
|
107
|
+
const valid = validate(dtoValue.value)
|
|
108
|
+
if(!valid&&validate.errors &&validate.errors[0]){
|
|
109
|
+
const {keyword,params} = validate.errors[0];
|
|
110
|
+
if(keyword === 'type'){
|
|
111
|
+
validTips.value = `类型必须为${type}`
|
|
112
|
+
}else if(keyword === 'minimum'){
|
|
113
|
+
validTips.value = `最大值应为${params.limit}`
|
|
114
|
+
}else if(keyword === 'maximum'){
|
|
115
|
+
validTips.value = `最小值应为${params.limit}`
|
|
116
|
+
}else{
|
|
117
|
+
console.log(validate.errors[0])
|
|
118
|
+
validTips.value = `不符合要求`
|
|
119
|
+
}
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return true
|
|
124
|
+
}
|
|
125
|
+
const getValue =()=>{
|
|
126
|
+
return dtoValue.value !==undefined ?{
|
|
127
|
+
[schemaKey]:dtoValue.value
|
|
128
|
+
}:{}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
defineExpose({
|
|
133
|
+
validate,
|
|
134
|
+
getValue,
|
|
135
|
+
name
|
|
136
|
+
})
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<style scoped lang="less">
|
|
140
|
+
:deep(.el-input-number .el-input__inner){
|
|
141
|
+
text-align: left;
|
|
142
|
+
}
|
|
143
|
+
</style>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
|
|
2
|
+
<template>
|
|
3
|
+
<el-row
|
|
4
|
+
type="flex"
|
|
5
|
+
align="middle"
|
|
6
|
+
class="form-item"
|
|
7
|
+
>
|
|
8
|
+
<!-- label-->
|
|
9
|
+
<el-row
|
|
10
|
+
class="item-label"
|
|
11
|
+
justify="end"
|
|
12
|
+
>
|
|
13
|
+
<el-row
|
|
14
|
+
v-if="schema.option.required"
|
|
15
|
+
type="flex"
|
|
16
|
+
class="required"
|
|
17
|
+
>
|
|
18
|
+
*
|
|
19
|
+
</el-row>
|
|
20
|
+
{{ schema.label }}
|
|
21
|
+
</el-row>
|
|
22
|
+
<!-- value-->
|
|
23
|
+
<el-row class="item-value" >
|
|
24
|
+
<el-select
|
|
25
|
+
v-model="dtoValue"
|
|
26
|
+
v-bind="schema.option"
|
|
27
|
+
class="component"
|
|
28
|
+
:class="validTips?'valid-border':''"
|
|
29
|
+
@change="onChange"
|
|
30
|
+
>
|
|
31
|
+
<el-option
|
|
32
|
+
v-for="item in schema.option?.enumList"
|
|
33
|
+
:key="item.value"
|
|
34
|
+
:label="item.label"
|
|
35
|
+
:value="item.value">
|
|
36
|
+
</el-option>
|
|
37
|
+
</el-select>
|
|
38
|
+
</el-row>
|
|
39
|
+
<!-- 错误信息-->
|
|
40
|
+
<el-row v-if="validTips" class="valid-tips">
|
|
41
|
+
{{validTips}}
|
|
42
|
+
</el-row>
|
|
43
|
+
</el-row>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script setup>
|
|
47
|
+
import {ref, watch, onMounted, toRefs, inject} from 'vue'
|
|
48
|
+
const ajv = inject('ajv')
|
|
49
|
+
|
|
50
|
+
const props = defineProps({
|
|
51
|
+
schema:Object,
|
|
52
|
+
schemaKey:String,
|
|
53
|
+
model:[String,Number],
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const { schema,schemaKey } = props;
|
|
57
|
+
const { model } = toRefs(props)
|
|
58
|
+
const name = ref('select')
|
|
59
|
+
const dtoValue = ref(undefined)
|
|
60
|
+
const validTips = ref(null)
|
|
61
|
+
const initData = () => {
|
|
62
|
+
dtoValue.value = model.value ?? schema.option?.default;
|
|
63
|
+
validTips.value = null
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
onMounted(()=>{
|
|
67
|
+
initData()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
watch([model,schema],()=>{
|
|
71
|
+
initData()
|
|
72
|
+
},{deep:true})
|
|
73
|
+
|
|
74
|
+
const onChange =()=>{
|
|
75
|
+
validate()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const validate = ()=>{
|
|
80
|
+
validTips.value = null
|
|
81
|
+
// const {type} = schema;
|
|
82
|
+
// 校验是否必填
|
|
83
|
+
if(schema.option?.required && !dtoValue.value){
|
|
84
|
+
validTips.value = '不能为空'
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
// 校验schema
|
|
88
|
+
if(dtoValue.value){
|
|
89
|
+
console.log('处理')
|
|
90
|
+
|
|
91
|
+
let dtoEnum =[];
|
|
92
|
+
if(schema.option?.enumList){
|
|
93
|
+
dtoEnum = schema.option?.enumList.map(item=>item.value)
|
|
94
|
+
}
|
|
95
|
+
const validate = ajv.compile({
|
|
96
|
+
schema,
|
|
97
|
+
...{enum: dtoEnum}
|
|
98
|
+
});
|
|
99
|
+
const valid = validate(dtoValue.value)
|
|
100
|
+
if(!valid && validate.errors &&validate.errors[0]){
|
|
101
|
+
if(validate.errors[0].keyword === 'enum'){
|
|
102
|
+
validTips.value = '取值超出枚举范围'
|
|
103
|
+
}else{
|
|
104
|
+
console.log(validate.errors[0])
|
|
105
|
+
validTips.value = '不符合要求'
|
|
106
|
+
}
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return true
|
|
111
|
+
}
|
|
112
|
+
const getValue =()=>{
|
|
113
|
+
return dtoValue.value !==undefined ?{
|
|
114
|
+
[schemaKey]:dtoValue.value
|
|
115
|
+
}:{}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
defineExpose({
|
|
120
|
+
validate,
|
|
121
|
+
getValue,
|
|
122
|
+
name
|
|
123
|
+
})
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<style scoped lang="less">
|
|
127
|
+
:deep(.el-input-number .el-input__inner){
|
|
128
|
+
text-align: left;
|
|
129
|
+
}
|
|
130
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
// 业务扩展 form-item配置
|
|
5
|
+
import BusinessFormItemConfig from '$businessFormItemConfig'
|
|
6
|
+
const FormItemConfig = {
|
|
7
|
+
input:{
|
|
8
|
+
component:input
|
|
9
|
+
},
|
|
10
|
+
inputNumber:{
|
|
11
|
+
component:inputNumber
|
|
12
|
+
},
|
|
13
|
+
select:{
|
|
14
|
+
component:select
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default {
|
|
18
|
+
...FormItemConfig,
|
|
19
|
+
...BusinessFormItemConfig
|
|
20
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
|
|
2
|
+
<template>
|
|
3
|
+
<el-row v-if="schema&&schema.properties" class="schema-form">
|
|
4
|
+
<template v-for="(itemSchema,key) in schema.properties">
|
|
5
|
+
<component
|
|
6
|
+
v-show="itemSchema.option.visible !==false"
|
|
7
|
+
ref="formComlist"
|
|
8
|
+
:is="FormItemConfig[itemSchema.option?.comType]?.component"
|
|
9
|
+
:schemaKey="key"
|
|
10
|
+
:schema="itemSchema"
|
|
11
|
+
:model="model ? model[key] : undefined"
|
|
12
|
+
></component>
|
|
13
|
+
</template>
|
|
14
|
+
</el-row>
|
|
15
|
+
</template>
|
|
16
|
+
<script setup>
|
|
17
|
+
import{ref,toRefs,provide,onMounted} from "vue"
|
|
18
|
+
import FormItemConfig from "./form-item-config";
|
|
19
|
+
|
|
20
|
+
const Ajv = require('ajv')
|
|
21
|
+
const ajv = new Ajv()
|
|
22
|
+
provide('ajv',ajv)
|
|
23
|
+
|
|
24
|
+
const props = defineProps({
|
|
25
|
+
/*
|
|
26
|
+
* {
|
|
27
|
+
* type:'object',
|
|
28
|
+
properties: {
|
|
29
|
+
key:{
|
|
30
|
+
...schema,//标准schema 配置
|
|
31
|
+
type:'',//字段类型
|
|
32
|
+
label:'',//字段的中文名
|
|
33
|
+
// 字段在search-bar 中的相关配置
|
|
34
|
+
option:{
|
|
35
|
+
...eleComponentConfig,//标准 el-component 配置
|
|
36
|
+
comType:'',//控件类型 input/select/input-number
|
|
37
|
+
required:false,//表单是否必填
|
|
38
|
+
visible:true,//是否展示 (true/false)默认为true
|
|
39
|
+
disabled:false,//是否禁用 (true/false)默认false default:'',//默认值
|
|
40
|
+
// comType === select
|
|
41
|
+
enumList:[]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
* }
|
|
46
|
+
* */
|
|
47
|
+
schema:Object,
|
|
48
|
+
/*
|
|
49
|
+
* 表单数据
|
|
50
|
+
* */
|
|
51
|
+
model:Object
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const {schema,model} = toRefs(props)
|
|
57
|
+
|
|
58
|
+
onMounted(()=>{
|
|
59
|
+
console.log(schema.value)
|
|
60
|
+
console.log('1111',model.value)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const formComlist =ref([])
|
|
65
|
+
// 表单校验
|
|
66
|
+
const validate =()=>{
|
|
67
|
+
return formComlist.value.every(component => component.validate())
|
|
68
|
+
}
|
|
69
|
+
// 获取表单值
|
|
70
|
+
const getValue =()=>{
|
|
71
|
+
return formComlist.value.reduce((dtoObj,component)=>{
|
|
72
|
+
return {
|
|
73
|
+
...dtoObj,
|
|
74
|
+
...component.getValue()
|
|
75
|
+
}
|
|
76
|
+
},{})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
defineExpose({
|
|
80
|
+
validate,
|
|
81
|
+
getValue
|
|
82
|
+
})
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<style lang="less">
|
|
88
|
+
.schema-form{
|
|
89
|
+
.form-item{
|
|
90
|
+
margin-bottom:20px;
|
|
91
|
+
min-width: 500px;
|
|
92
|
+
.item-label{
|
|
93
|
+
margin-right: 15px;
|
|
94
|
+
min-width: 70px;
|
|
95
|
+
text-align: right;
|
|
96
|
+
font-size: 14px;
|
|
97
|
+
color: #fff;
|
|
98
|
+
word-break: break-all;
|
|
99
|
+
.required{
|
|
100
|
+
top: 2px;
|
|
101
|
+
padding-left: 4px;
|
|
102
|
+
color: #f56c6c;
|
|
103
|
+
font-size: 20px;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
.item-value{
|
|
107
|
+
.component{
|
|
108
|
+
width: 320px;
|
|
109
|
+
}
|
|
110
|
+
.valid-border{
|
|
111
|
+
.el-input__wrapper{
|
|
112
|
+
border: 1px dashed #f93f3f;
|
|
113
|
+
box-shadow: 0 0 0 0 ;
|
|
114
|
+
}
|
|
115
|
+
.el-select__wrapper{
|
|
116
|
+
border: 1px dashed #f93f3f;
|
|
117
|
+
box-shadow: 0 0 0 0 ;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
.valid-tips{
|
|
122
|
+
margin-left: 10px;
|
|
123
|
+
height: 36px;
|
|
124
|
+
line-height: 36px;
|
|
125
|
+
overflow: hidden;
|
|
126
|
+
font-size: 12px;
|
|
127
|
+
color: #f93f3f;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
</style>
|