@zhangnpm302/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 +67 -0
- package/.gitattributes +1 -0
- package/README.md +2 -3
- package/app/controller/base.js +39 -0
- package/app/controller/project.js +100 -0
- package/app/controller/view.js +21 -0
- package/app/extend/logger.js +36 -0
- package/app/middleware/api-params-verify.js +85 -0
- package/app/middleware/api-sign-verify.js +32 -0
- package/app/middleware/error-handler.js +35 -0
- package/app/middleware/project-handler.js +31 -0
- package/app/middleware.js +40 -0
- package/app/pages/assets/custom.css +11 -0
- package/app/pages/boot.js +50 -0
- package/app/pages/common/curl.js +88 -0
- package/app/pages/common/utils.js +5 -0
- package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +28 -0
- package/app/pages/dashboard/complex-view/header-view/header-view.vue +125 -0
- package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +48 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +42 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +157 -0
- package/app/pages/dashboard/complex-view/schema-view/components/component.config.js +24 -0
- package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +122 -0
- package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +118 -0
- package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +150 -0
- package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +184 -0
- package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +120 -0
- package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +30 -0
- package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +132 -0
- package/app/pages/dashboard/dashboard.vue +100 -0
- package/app/pages/dashboard/entry.dashboard.js +52 -0
- package/app/pages/dashboard/readme.md +4 -0
- package/app/pages/store/index.js +5 -0
- package/app/pages/store/menu.js +61 -0
- package/app/pages/store/project.js +18 -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 +105 -0
- package/app/pages/widgets/schema-form/complex-view/input/input.vue +143 -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 +133 -0
- package/app/pages/widgets/schema-form/form-item-config.js +25 -0
- package/app/pages/widgets/schema-form/schema-form.vue +152 -0
- package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +63 -0
- package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +85 -0
- package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +59 -0
- package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +66 -0
- package/app/pages/widgets/schema-search-bar/schema-config.js +30 -0
- package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +145 -0
- package/app/pages/widgets/schema-table/schema-table.vue +275 -0
- package/app/pages/widgets/sider-container/sider-container.vue +29 -0
- package/app/router/project.js +11 -0
- package/app/router/view.js +9 -0
- package/app/router-schema/project.js +55 -0
- package/app/service/base.js +12 -0
- package/app/service/project.js +78 -0
- package/app/view/entry.tpl +29 -0
- package/app/webpack/config/webpack.base.js +223 -0
- package/app/webpack/config/webpack.dev.js +59 -0
- package/app/webpack/config/webpack.prod.js +128 -0
- package/app/webpack/dev.js +60 -0
- package/app/webpack/libs/blank.js +1 -0
- package/app/webpack/prod.js +22 -0
- package/config/config.default.js +4 -0
- package/docs/dashboard-model.js +193 -0
- package/elpis-core/env.js +24 -0
- package/elpis-core/index.js +95 -0
- package/elpis-core/loader/config.js +66 -0
- package/elpis-core/loader/controller.js +74 -0
- package/elpis-core/loader/extend.js +62 -0
- package/elpis-core/loader/middleware.js +74 -0
- package/elpis-core/loader/router-schema.js +50 -0
- package/elpis-core/loader/router.js +50 -0
- package/elpis-core/loader/service.js +69 -0
- package/index.js +48 -0
- package/model/business/model.js +210 -0
- package/model/business/project/jd.js +62 -0
- package/model/business/project/pdd.js +86 -0
- package/model/business/project/taobao.js +45 -0
- package/model/course/model.js +21 -0
- package/model/course/project/bilibili.js +49 -0
- package/model/course/project/douyin.js +29 -0
- package/model/demo.json +246 -0
- package/model/index.js +153 -0
- package/package.json +103 -4
- package/test/controller/project.test.js +220 -0
- package/testmain/project.test.js +228 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-config-provider :locale="zhCn">
|
|
3
|
+
<header-view :projName="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
|
+
<script setup>
|
|
11
|
+
// 中文化
|
|
12
|
+
import { ref, onMounted } from 'vue'
|
|
13
|
+
import { useRouter, useRoute } from 'vue-router'
|
|
14
|
+
// 中文化
|
|
15
|
+
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
|
16
|
+
import HeaderView from './complex-view/header-view/header-view.vue'
|
|
17
|
+
import $curl from '$elpisCommon/curl'
|
|
18
|
+
import { useMenuStore } from '$elpisStore/menu.js'
|
|
19
|
+
import { useProjectStore } from '$elpisStore/project.js'
|
|
20
|
+
|
|
21
|
+
const router = useRouter()
|
|
22
|
+
const route = useRoute()
|
|
23
|
+
const menuStore = useMenuStore()
|
|
24
|
+
const projectStore = useProjectStore()
|
|
25
|
+
|
|
26
|
+
onMounted(() => {
|
|
27
|
+
getProjectList()
|
|
28
|
+
getProjectConfig()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const projName = ref('')
|
|
32
|
+
|
|
33
|
+
// 请求/api/project/list接口 ,并缓存到project-store
|
|
34
|
+
async function getProjectList() {
|
|
35
|
+
const res = await $curl({
|
|
36
|
+
method: 'get',
|
|
37
|
+
url: '/api/project/list',
|
|
38
|
+
query: {
|
|
39
|
+
// 测试TODO:动态获取当前项目key
|
|
40
|
+
proj_key: route.query.proj_key
|
|
41
|
+
// proj_key: 'douyin'
|
|
42
|
+
// proj_key: 'taobao'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
})
|
|
46
|
+
if (!res || !res.success || !res.data) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
projectStore.setProjectList(res.data)
|
|
50
|
+
}
|
|
51
|
+
// 请求/api/project接口,并缓存到menu-store
|
|
52
|
+
async function getProjectConfig() {
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const res = await $curl({
|
|
56
|
+
method: 'get',
|
|
57
|
+
url: '/api/project',
|
|
58
|
+
query: {
|
|
59
|
+
// 测试TODO:动态获取当前项目key
|
|
60
|
+
proj_key: route.query.proj_key
|
|
61
|
+
// proj_key: 'douyin'
|
|
62
|
+
// proj_key: 'taobao'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
})
|
|
66
|
+
if (!res || !res.success || !res.data) {
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { name, menu } = res.data
|
|
71
|
+
projName.value = name
|
|
72
|
+
menuStore.setMenuList(menu)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 点击菜单回调
|
|
76
|
+
const onMenuSelect = function(menuItem) {
|
|
77
|
+
const { moduleType, key, customConfig } = menuItem
|
|
78
|
+
// 如果是当前页面 不处理
|
|
79
|
+
if (key === route.query.key) return
|
|
80
|
+
|
|
81
|
+
const pathMap = {
|
|
82
|
+
sider: '/sider',
|
|
83
|
+
iframe: '/iframe',
|
|
84
|
+
schema: '/schema',
|
|
85
|
+
custom: customConfig?.path
|
|
86
|
+
}
|
|
87
|
+
router.push({
|
|
88
|
+
path: `/view/dashboard${pathMap[moduleType]}`,
|
|
89
|
+
query: {
|
|
90
|
+
key,
|
|
91
|
+
proj_key: route.query.proj_key
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
</script>
|
|
96
|
+
<style lang="less" scoped>
|
|
97
|
+
:deep(.el-main) {
|
|
98
|
+
padding: 0;
|
|
99
|
+
}
|
|
100
|
+
</style>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import boot from '$elpisPages/boot.js'
|
|
2
|
+
import dashboard from './dashboard.vue'
|
|
3
|
+
import businessDashboardRouterConfig from '$businessDashboardRouterConfig'
|
|
4
|
+
|
|
5
|
+
// let businessDashboardRouterConfig
|
|
6
|
+
// try {
|
|
7
|
+
// if ()
|
|
8
|
+
// businessDashboardRouterConfig = require('$businessDashboardRouterConfig')
|
|
9
|
+
// } catch (e) {}
|
|
10
|
+
const routes = []
|
|
11
|
+
|
|
12
|
+
// 头部菜单路由
|
|
13
|
+
routes.push({
|
|
14
|
+
path: '/view/dashboard/iframe',
|
|
15
|
+
component: () => import('./complex-view/iframe-view/iframe-view.vue')
|
|
16
|
+
})
|
|
17
|
+
routes.push({
|
|
18
|
+
path: '/view/dashboard/schema',
|
|
19
|
+
component: () => import('./complex-view/schema-view/schema-view.vue')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const siderRoutes = [
|
|
23
|
+
{
|
|
24
|
+
path: 'iframe',
|
|
25
|
+
component: () => import('./complex-view/iframe-view/iframe-view.vue')
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
path: 'schema',
|
|
29
|
+
component: () => import('./complex-view/schema-view/schema-view.vue')
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
// 侧边栏菜单路由
|
|
34
|
+
// sider
|
|
35
|
+
routes.push({
|
|
36
|
+
path: '/view/dashboard/sider',
|
|
37
|
+
component: () => import('./complex-view/sider-view/sider-view.vue'),
|
|
38
|
+
children: siderRoutes
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// 业务拓展路由
|
|
42
|
+
if (typeof businessDashboardRouterConfig === 'function') {
|
|
43
|
+
businessDashboardRouterConfig({ routes, siderRoutes })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 侧边栏兜底策略
|
|
47
|
+
routes.push({
|
|
48
|
+
path: '/view/dashboard/sider/:chapters+',
|
|
49
|
+
component: () => import('./complex-view/sider-view/sider-view.vue'),
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
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
|
+
* @params key 搜索字段
|
|
16
|
+
* @param value 搜索值
|
|
17
|
+
* @mList 要搜索的菜单列表
|
|
18
|
+
*/
|
|
19
|
+
console.log(menuList, 'mlist')
|
|
20
|
+
const findMenuItem = function({ key, value }, mList = menuList.value) {
|
|
21
|
+
for (let i = 0; i < mList.length; ++i) {
|
|
22
|
+
const menuItem = mList[i]
|
|
23
|
+
|
|
24
|
+
if (!menuItem) continue
|
|
25
|
+
|
|
26
|
+
const { menuType, moduleType } = menuItem
|
|
27
|
+
// menuType: 'module' moduleType: 'schema'
|
|
28
|
+
// key: 'client', value: 'client'
|
|
29
|
+
if (menuItem[key] === value) return menuItem
|
|
30
|
+
if (menuType === 'group' && menuItem.subMenu) {
|
|
31
|
+
const mItem = findMenuItem({ key, value }, menuItem.subMenu)
|
|
32
|
+
if (mItem) return mItem
|
|
33
|
+
}
|
|
34
|
+
if (moduleType === 'sider' && menuItem.siderConfig && menuItem.siderConfig.menu) {
|
|
35
|
+
const mItem = findMenuItem({ key, value }, menuItem.siderConfig.menu)
|
|
36
|
+
if (mItem) return mItem
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 找出次第一个菜单目录,无论他是不是sider菜单
|
|
43
|
+
* @param {*} mList 菜单列表
|
|
44
|
+
*/
|
|
45
|
+
const findFirstMenuItem = function(mList = menuList.value) {
|
|
46
|
+
if (!mList || !mList[0]) return
|
|
47
|
+
let firstMenuItem = mList[0]
|
|
48
|
+
// 他是group
|
|
49
|
+
if (firstMenuItem.subMenu) {
|
|
50
|
+
firstMenuItem = findMenuItem(firstMenuItem.subMenu)
|
|
51
|
+
}
|
|
52
|
+
return firstMenuItem
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
menuList,
|
|
56
|
+
setMenuList,
|
|
57
|
+
findMenuItem,
|
|
58
|
+
findFirstMenuItem
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
18
|
+
})
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,105 @@
|
|
|
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 class="logo" src="./asserts/logo.png" alt="" />
|
|
8
|
+
<el-row class="text">
|
|
9
|
+
{{ title }}
|
|
10
|
+
</el-row>
|
|
11
|
+
</el-row>
|
|
12
|
+
<!-- 插槽,菜单区域 -->
|
|
13
|
+
<slot name="menu-content"></slot>
|
|
14
|
+
<!-- 右上方区域 -->
|
|
15
|
+
<el-row type="flex" align="middle" justify="end" class="setting-panel">
|
|
16
|
+
<!-- 设置区域 -->
|
|
17
|
+
<slot name="setting-content"></slot>
|
|
18
|
+
<img src="./asserts/avatar.png" alt="" class="avatar" />
|
|
19
|
+
<el-dropdown @command="handleUserCommand">
|
|
20
|
+
<span class="username">
|
|
21
|
+
{{ userName }}
|
|
22
|
+
<i class="el-icon-arrow-down el-icon--right"></i>
|
|
23
|
+
</span>
|
|
24
|
+
<template #dropdown>
|
|
25
|
+
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
|
|
26
|
+
</template>
|
|
27
|
+
</el-dropdown>
|
|
28
|
+
</el-row>
|
|
29
|
+
</el-row>
|
|
30
|
+
</el-header>
|
|
31
|
+
<el-main class="main-container">
|
|
32
|
+
<!-- 外部拓展填充区域 -->
|
|
33
|
+
<slot name="main-content"></slot>
|
|
34
|
+
</el-main>
|
|
35
|
+
</el-container>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script setup>
|
|
39
|
+
import { ref } from 'vue'
|
|
40
|
+
|
|
41
|
+
defineProps({
|
|
42
|
+
title: String
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const userName = ref('哲玄')
|
|
47
|
+
const handleUserCommand = function(event) {
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<style lang="less" scoped>
|
|
54
|
+
.header-container {
|
|
55
|
+
height: 100%;
|
|
56
|
+
min-width: 1000px;
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
.header {
|
|
59
|
+
max-height: 120px;
|
|
60
|
+
border-bottom: 1px solid #e8e8e8;
|
|
61
|
+
.header-row {
|
|
62
|
+
height: 60px;
|
|
63
|
+
padding: 0 20px;
|
|
64
|
+
.title-panel {
|
|
65
|
+
width: 180px;
|
|
66
|
+
min-width: 180px;
|
|
67
|
+
.logo {
|
|
68
|
+
margin-right: 10px;
|
|
69
|
+
width: 25px;
|
|
70
|
+
height: 25px;
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
}
|
|
73
|
+
.text {
|
|
74
|
+
font-size: 15px;
|
|
75
|
+
font-weight: 500;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
.setting-panel {
|
|
79
|
+
margin-left: auto;
|
|
80
|
+
min-width: 180px;
|
|
81
|
+
.avatar {
|
|
82
|
+
margin-right: 12px;
|
|
83
|
+
width: 30px;
|
|
84
|
+
height: 30px;
|
|
85
|
+
border-radius: 50%;
|
|
86
|
+
}
|
|
87
|
+
.username {
|
|
88
|
+
font-size: 16px;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
height: 60px;
|
|
92
|
+
line-height: 60px;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
.main-container {
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
:deep(.el-header) {
|
|
103
|
+
padding: 0%;
|
|
104
|
+
}
|
|
105
|
+
</style>
|
|
@@ -0,0 +1,143 @@
|
|
|
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-bind="schema.option"
|
|
16
|
+
v-model="dtoValue"
|
|
17
|
+
:placeholder="placeholder"
|
|
18
|
+
class="component"
|
|
19
|
+
:class="validTips ? 'valid-border' : ''"
|
|
20
|
+
@focus="onFocus"
|
|
21
|
+
@blur="onBlur"
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
</el-input>
|
|
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, onMounted, inject } from 'vue'
|
|
35
|
+
const ajv = inject('ajv')
|
|
36
|
+
const props = defineProps({
|
|
37
|
+
schemaKey: String,
|
|
38
|
+
schema: Object,
|
|
39
|
+
model: String
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const { schemaKey, schema } = props
|
|
43
|
+
const { model } = toRefs(props)
|
|
44
|
+
|
|
45
|
+
const name = ref('input')
|
|
46
|
+
|
|
47
|
+
// dtoValue最好改成undefined
|
|
48
|
+
const dtoValue = ref()
|
|
49
|
+
const validTips = ref(null)
|
|
50
|
+
const placeholder = ref('')
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const initData = () => {
|
|
54
|
+
dtoValue.value = model.value ?? schema.option?.default
|
|
55
|
+
validTips.value = null
|
|
56
|
+
const {
|
|
57
|
+
minLength,
|
|
58
|
+
maxLength,
|
|
59
|
+
pattern
|
|
60
|
+
} = schema
|
|
61
|
+
|
|
62
|
+
const ruleList = []
|
|
63
|
+
if (schema.option?.placeholder) {
|
|
64
|
+
ruleList.push(schema.option?.placeholder)
|
|
65
|
+
}
|
|
66
|
+
if (minLength) {
|
|
67
|
+
ruleList.push(`最小长度:${minLength}`)
|
|
68
|
+
}
|
|
69
|
+
if (maxLength) {
|
|
70
|
+
ruleList.push(`最小长度:${maxLength}`)
|
|
71
|
+
}
|
|
72
|
+
if (pattern) {
|
|
73
|
+
ruleList.push(`格式:${pattern}`)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
placeholder.value = ruleList.join('|')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onMounted(() => {
|
|
80
|
+
initData()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
watch([model, schema], () => {
|
|
84
|
+
initData()
|
|
85
|
+
}, { deep: true })
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// 便于父组件 遍历 validate 方法
|
|
90
|
+
const validate = () => {
|
|
91
|
+
validTips.value = null
|
|
92
|
+
const { type } = schema
|
|
93
|
+
// 校验是否必填
|
|
94
|
+
if (schema.option?.required && !dtoValue.value) {
|
|
95
|
+
validTips.value = '不能为空'
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
// ajv 校验 schema
|
|
99
|
+
if (dtoValue.value) {
|
|
100
|
+
const validate = ajv.compile(schema)
|
|
101
|
+
const valid = validate(dtoValue.value)
|
|
102
|
+
if (!valid && validate.errors && validate.errors[0]) {
|
|
103
|
+
const { keyword, params } = validate.errors[0]
|
|
104
|
+
if (keyword === 'type') {
|
|
105
|
+
validTips.value = `类型必须为 ${type}`
|
|
106
|
+
} else if (keyword === 'maxLength') {
|
|
107
|
+
validTips.value = `最大长度为 ${params.limit}`
|
|
108
|
+
} else if (keyword === 'minLength') {
|
|
109
|
+
validTips.value = `最小长度为 ${params.limit}`
|
|
110
|
+
} else if (keyword === 'pattern') {
|
|
111
|
+
validTips.value = '格式不正确'
|
|
112
|
+
} else {
|
|
113
|
+
console.log(validate.errors[0])
|
|
114
|
+
validTips.value = '不符合要求'
|
|
115
|
+
}
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const getValue = () => {
|
|
123
|
+
return dtoValue.value !== undefined ? {
|
|
124
|
+
[schemaKey]: dtoValue.value
|
|
125
|
+
} : {}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const onFocus = () => {
|
|
129
|
+
validTips.value = null
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const onBlur = () => {
|
|
133
|
+
validate()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
defineExpose({
|
|
137
|
+
name,
|
|
138
|
+
validate,
|
|
139
|
+
getValue
|
|
140
|
+
})
|
|
141
|
+
</script>
|
|
142
|
+
|
|
143
|
+
<style lang="less" scoped></style>
|
|
@@ -0,0 +1,143 @@
|
|
|
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-bind="schema.option"
|
|
16
|
+
v-model="dtoValue"
|
|
17
|
+
:placeholder="placeholder"
|
|
18
|
+
class="component"
|
|
19
|
+
:class="validTips ? 'valid-border' : ''"
|
|
20
|
+
@focus="onFocus"
|
|
21
|
+
@blur="onBlur"
|
|
22
|
+
>
|
|
23
|
+
|
|
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, onMounted, inject } from 'vue'
|
|
35
|
+
const ajv = inject('ajv')
|
|
36
|
+
const props = defineProps({
|
|
37
|
+
schemaKey: String,
|
|
38
|
+
schema: Object,
|
|
39
|
+
model: Number
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const { schemaKey, schema } = props
|
|
43
|
+
const { model } = toRefs(props)
|
|
44
|
+
|
|
45
|
+
const name = ref('inputNumber')
|
|
46
|
+
// dtoValue最好改成undefined
|
|
47
|
+
const dtoValue = ref()
|
|
48
|
+
const validTips = ref(null)
|
|
49
|
+
const placeholder = ref('')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const initData = () => {
|
|
53
|
+
dtoValue.value = model.value ?? schema.option?.default
|
|
54
|
+
validTips.value = null
|
|
55
|
+
const {
|
|
56
|
+
// minLength,
|
|
57
|
+
// maxLength,
|
|
58
|
+
// pattern
|
|
59
|
+
minimum,
|
|
60
|
+
maximum,
|
|
61
|
+
} = schema
|
|
62
|
+
|
|
63
|
+
const ruleList = []
|
|
64
|
+
if (schema.option?.placeholder) {
|
|
65
|
+
ruleList.push(schema.option?.placeholder)
|
|
66
|
+
}
|
|
67
|
+
if (minimum !== undefined) {
|
|
68
|
+
ruleList.push(`最小值:${minimum}`)
|
|
69
|
+
}
|
|
70
|
+
if (maximum !== undefined) {
|
|
71
|
+
ruleList.push(`最大值:${maximum}`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
placeholder.value = ruleList.join('|')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onMounted(() => {
|
|
78
|
+
initData()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
watch([model, schema], () => {
|
|
82
|
+
initData()
|
|
83
|
+
}, { deep: true })
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// 便于父组件 遍历 validate 方法
|
|
88
|
+
const validate = () => {
|
|
89
|
+
validTips.value = null
|
|
90
|
+
const { type } = schema
|
|
91
|
+
// 校验是否必填
|
|
92
|
+
if (schema.option?.required && !dtoValue.value) {
|
|
93
|
+
validTips.value = '不能为空'
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
// ajv 校验 schema
|
|
97
|
+
if (dtoValue.value) {
|
|
98
|
+
const validate = ajv.compile(schema)
|
|
99
|
+
const valid = validate(dtoValue.value)
|
|
100
|
+
if (!valid && validate.errors && validate.errors[0]) {
|
|
101
|
+
const { keyword, params } = validate.errors[0]
|
|
102
|
+
if (keyword === 'type') {
|
|
103
|
+
validTips.value = `类型必须为 ${type}`
|
|
104
|
+
} else if (keyword === 'minimum') {
|
|
105
|
+
validTips.value = `最小值应为 ${params.limit}`
|
|
106
|
+
} else if (keyword === 'maximum') {
|
|
107
|
+
validTips.value = `最大值应为 ${params.limit}`
|
|
108
|
+
} else {
|
|
109
|
+
console.log(validate.errors[0])
|
|
110
|
+
validTips.value = '不符合要求'
|
|
111
|
+
}
|
|
112
|
+
return false
|
|
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>
|
|
140
|
+
:deep(.el-input-number .el-input__inner ) {
|
|
141
|
+
text-align: left;
|
|
142
|
+
}
|
|
143
|
+
</style>
|