@elementplus-kit/uikit 1.6.0 → 1.7.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/build.log +0 -0
- package/components/button/index.ts +4 -0
- package/components/button/src/constants.ts +50 -0
- package/components/button/src/index.ts +264 -0
- package/components/button/style/index.scss +3 -0
- package/components/config.ts +4 -0
- package/components/dialog/index.ts +6 -0
- package/components/dialog/src/constants.ts +3 -0
- package/components/dialog/src/index.ts +54 -0
- package/components/dialog/style/index.scss +18 -0
- package/components/dictLabel/index.ts +4 -0
- package/components/dictLabel/src/index.vue +21 -0
- package/components/drawer/index.ts +4 -0
- package/components/drawer/src/constants.ts +3 -0
- package/components/drawer/src/index.ts +53 -0
- package/components/drawer/style/index.scss +18 -0
- package/components/form/index.ts +4 -0
- package/components/form/src/FormItem.ts +398 -0
- package/components/form/src/constants.ts +161 -0
- package/components/form/src/index.ts +198 -0
- package/components/form/src/types.ts +39 -0
- package/components/form/src/utils.ts +4 -0
- package/components/form/style/index.scss +5 -0
- package/components/pagination/index.ts +4 -0
- package/components/pagination/src/constants.ts +5 -0
- package/components/pagination/src/index.ts +50 -0
- package/components/search/index.ts +4 -0
- package/components/search/src/index.tsx +294 -0
- package/components/search/style/index.scss +104 -0
- package/components/table/index.ts +4 -0
- package/components/table/src/TableColumn.ts +116 -0
- package/components/table/src/constants.ts +42 -0
- package/components/table/src/index.ts +250 -0
- package/components/table/src/index2.ts +219 -0
- package/components/table/src/index3.ts +233 -0
- package/components/table/src/tableDictLabel.vue +21 -0
- package/components/table/src/tableaa.ts +71 -0
- package/components/table/src/type.ts +0 -0
- package/components/table/type/index.scss +0 -0
- package/components/table2/index.ts +4 -0
- package/components/table2/src/config.ts +5 -0
- package/components/table2/src/index.ts +12 -0
- package/components/table2/src/render.ts +136 -0
- package/components/table2/src/types.ts +39 -0
- package/components/table2/style/index.scss +0 -0
- package/components//346/250/241/346/235/277/index.tsx +57 -0
- package/components//346/250/241/346/235/277/ttt.ts +66 -0
- package/components//346/250/241/346/235/277/ttt.vue +18 -0
- package/index.ts +2 -0
- package/package.json +1 -4
- package/vite.config.ts +30 -0
- package//345/205/266/344/273/226/core/dialog/elementPlus/dialogWarp.vue +151 -0
- package//345/205/266/344/273/226/core/dialog/index.ts +10 -0
- package//345/205/266/344/273/226/core/form/elementPlus/elementWarp.ts +15 -0
- package//345/205/266/344/273/226/core/form/elementPlus/elementWarp.vue +16 -0
- package//345/205/266/344/273/226/core/form/elementPlus/formRender.ts +55 -0
- package//345/205/266/344/273/226/core/form/index.ts +10 -0
- package//345/205/266/344/273/226/core/table/config.ts +5 -0
- package//345/205/266/344/273/226/core/table/render.ts +91 -0
- package//345/205/266/344/273/226/core/table/warp.ts +11 -0
- package//345/205/266/344/273/226/core/utils/fetch.ts +58 -0
- package//345/205/266/344/273/226/useMessage.ts +95 -0
- package/dist/index.css +0 -1
- package/dist/index.mjs +0 -1079
- package/dist/index.umd.js +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface FormItemListItem {
|
|
2
|
+
type: string
|
|
3
|
+
label?: string
|
|
4
|
+
prop: string
|
|
5
|
+
required?: Boolean
|
|
6
|
+
vIf?: boolean | ((item: FormItemListItem) => boolean)
|
|
7
|
+
dictType?: string
|
|
8
|
+
options?: Array<Object>
|
|
9
|
+
col?: Number
|
|
10
|
+
formItem?: Object
|
|
11
|
+
attrs?: Object
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FormItemList {
|
|
15
|
+
module: Object
|
|
16
|
+
formOpsions: FormItemListItem[]
|
|
17
|
+
readonly: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type formType =
|
|
21
|
+
| 'input'
|
|
22
|
+
| 'textarea'
|
|
23
|
+
| 'input-number'
|
|
24
|
+
| 'select'
|
|
25
|
+
| 'select-v2'
|
|
26
|
+
| 'cascader'
|
|
27
|
+
| 'tree-select'
|
|
28
|
+
| 'radio'
|
|
29
|
+
| 'checkbox'
|
|
30
|
+
| 'time-select'
|
|
31
|
+
| 'date-picker'
|
|
32
|
+
| 'time-picker'
|
|
33
|
+
| 'rate'
|
|
34
|
+
| 'color-picker'
|
|
35
|
+
| 'slider'
|
|
36
|
+
| 'switch'
|
|
37
|
+
| 'text'
|
|
38
|
+
| 'html'
|
|
39
|
+
| 'slot'
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
} from "vue";
|
|
6
|
+
|
|
7
|
+
// import { CForm, CDrawer } from "@elementplus-kit/uikit";
|
|
8
|
+
// import '../style/index.scss';
|
|
9
|
+
|
|
10
|
+
export default defineComponent({
|
|
11
|
+
props: {
|
|
12
|
+
// modelValue: {
|
|
13
|
+
// type: Object,
|
|
14
|
+
// default: {}
|
|
15
|
+
// },
|
|
16
|
+
// formOptions: {
|
|
17
|
+
// type: Array,
|
|
18
|
+
// default: () => []
|
|
19
|
+
// },
|
|
20
|
+
// isDrawer: {
|
|
21
|
+
// type: Boolean,
|
|
22
|
+
// default: false
|
|
23
|
+
// },
|
|
24
|
+
},
|
|
25
|
+
// emits: ['update:modelValue', 'search', 'reset', 'close'],
|
|
26
|
+
|
|
27
|
+
setup(props, { emit, slots, attrs, expose }) {
|
|
28
|
+
// 自己的 slot
|
|
29
|
+
// const slotsList = ["active", "btn-left", "btn-right"];
|
|
30
|
+
// console.log('slots', slots);
|
|
31
|
+
// console.log('attrs', attrs);
|
|
32
|
+
// 解析 attrs 中的事件
|
|
33
|
+
// const getEvent = () => {
|
|
34
|
+
// let formObj: any = {};
|
|
35
|
+
// Object.keys(attrs)?.forEach((name) => {
|
|
36
|
+
// if (name.indexOf("on") === 0) {
|
|
37
|
+
// formObj[name] = attrs[name];
|
|
38
|
+
// }
|
|
39
|
+
// })
|
|
40
|
+
// return formObj
|
|
41
|
+
// };
|
|
42
|
+
|
|
43
|
+
// 解析插槽
|
|
44
|
+
// const getSlot = () => {
|
|
45
|
+
// let formObj = {};
|
|
46
|
+
// Object.keys(slots).forEach((key) => {
|
|
47
|
+
// if (!slotsList.includes(key)) {
|
|
48
|
+
// formObj[key] = slots[key];
|
|
49
|
+
// }
|
|
50
|
+
// });
|
|
51
|
+
// return formObj
|
|
52
|
+
// };
|
|
53
|
+
return () => (
|
|
54
|
+
<div className="xxxxxxx">xxxxxxx</div>
|
|
55
|
+
)
|
|
56
|
+
},
|
|
57
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
h,
|
|
4
|
+
computed,
|
|
5
|
+
toRefs,
|
|
6
|
+
getCurrentInstance,
|
|
7
|
+
provide,
|
|
8
|
+
defineComponent,
|
|
9
|
+
type ExtractPropTypes,
|
|
10
|
+
type PropType,
|
|
11
|
+
} from 'vue'
|
|
12
|
+
import { ElConfigProvider, ElForm, ElRow, ElCol } from 'element-plus'
|
|
13
|
+
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
|
14
|
+
import { get, has, isArray, isBoolean, isFunction, isNumber } from 'lodash-es'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const propsAttrs = {
|
|
18
|
+
// 表单数据
|
|
19
|
+
model: { type: Object, default: () => ({}) },
|
|
20
|
+
// 表单项
|
|
21
|
+
formOptions: { type: Array, default: () => [] },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type PropsAttrs = ExtractPropTypes<typeof propsAttrs>
|
|
25
|
+
|
|
26
|
+
export default defineComponent({
|
|
27
|
+
props: propsAttrs,
|
|
28
|
+
emits: [...getEmits()],
|
|
29
|
+
setup(props: PropsAttrs, { attrs: $attrs, emit, slots, expose }) {
|
|
30
|
+
|
|
31
|
+
// 暴露方法
|
|
32
|
+
expose({
|
|
33
|
+
optionsRef,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// 解构props
|
|
37
|
+
const { model, formOptions, readonly, gutter, col } = toRefs(props)
|
|
38
|
+
|
|
39
|
+
// 渲染表单
|
|
40
|
+
const renderForm = () => {
|
|
41
|
+
return h(
|
|
42
|
+
ElConfigProvider,
|
|
43
|
+
{
|
|
44
|
+
locale: zhCn,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
default: () =>
|
|
48
|
+
h(
|
|
49
|
+
ElForm,
|
|
50
|
+
{
|
|
51
|
+
ref: cFormFnRef,
|
|
52
|
+
...$attrs,
|
|
53
|
+
class: allReadonly.value ? 'isReadonly c-form' : 'c-form', // 放在 $attrs 后面可自动合并 放在 $attrs 前面会被 $attrs.class 覆盖, h函数渲染的是标签就会覆盖 是组件就会合并不用管顺序
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
default: () => renderRow(),
|
|
57
|
+
},
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 返回渲染函数
|
|
64
|
+
return () => renderForm()
|
|
65
|
+
},
|
|
66
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="xxx">
|
|
3
|
+
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
<script setup lang="ts">
|
|
7
|
+
import { ref, computed, useAttrs, useSlots, defineModel } from 'vue'
|
|
8
|
+
import { ArrowUpBold } from '@element-plus/icons-vue'
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
formOptions: {
|
|
11
|
+
type: Array,
|
|
12
|
+
default: () => []
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
const emit = defineEmits(['search', 'reset', 'close'])
|
|
16
|
+
|
|
17
|
+
</script>
|
|
18
|
+
<style scoped lang="scss"></style>
|
package/index.ts
ADDED
package/package.json
CHANGED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import vue from "@vitejs/plugin-vue";
|
|
3
|
+
import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
4
|
+
// import dts from 'vite-plugin-dts'
|
|
5
|
+
// import { resolve } from 'path'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [
|
|
9
|
+
vue(),
|
|
10
|
+
vueJsx(),
|
|
11
|
+
// dts({
|
|
12
|
+
// rollupTypes: false,
|
|
13
|
+
// tsconfigPath: './tsconfig.json',
|
|
14
|
+
// }),
|
|
15
|
+
],
|
|
16
|
+
build: {
|
|
17
|
+
// 指定打包输出目录名称,替换成你想要的名字
|
|
18
|
+
outDir: "dist",
|
|
19
|
+
lib: {
|
|
20
|
+
entry: "components/index.ts",
|
|
21
|
+
name: "ElementPlusKit",
|
|
22
|
+
fileName: "index",
|
|
23
|
+
// fileName: (format) => `my-utils.${format}.js`,
|
|
24
|
+
},
|
|
25
|
+
rollupOptions: {
|
|
26
|
+
external: ["vue", "element-plus", "lodash-es", "@element-plus/icons-vue"],
|
|
27
|
+
},
|
|
28
|
+
emptyOutDir: true,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { FullScreen, Close } from '@element-plus/icons-vue'
|
|
3
|
+
|
|
4
|
+
const emits = defineEmits(['afterClose', 'beforeOpen', 'afterOpen', 'beforeClose', 'innerOutput'])
|
|
5
|
+
|
|
6
|
+
// 子组件属性
|
|
7
|
+
const innerComponentOptions = ref({})
|
|
8
|
+
|
|
9
|
+
// 子组件
|
|
10
|
+
const innerComponent = shallowRef()
|
|
11
|
+
|
|
12
|
+
// 弹窗显示隐藏关键属性
|
|
13
|
+
const dialogShow = ref(false)
|
|
14
|
+
|
|
15
|
+
// 弹窗组件基本属性
|
|
16
|
+
const dialogOptions = ref({
|
|
17
|
+
title: '',
|
|
18
|
+
appendToBody: true,
|
|
19
|
+
destroyOnClose: true,
|
|
20
|
+
fullscreen: false,
|
|
21
|
+
closeOnClickModal: false,
|
|
22
|
+
closeOnPressEscape: false,
|
|
23
|
+
showClose: false
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 源方法打开弹窗
|
|
28
|
+
*/
|
|
29
|
+
const handleOpenDialog = () => {
|
|
30
|
+
dialogShow.value = true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 源方法关闭弹窗
|
|
35
|
+
*/
|
|
36
|
+
const handleCloseDialog = () => {
|
|
37
|
+
dialogShow.value = false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 监听方法,监听来自子组件的事件
|
|
42
|
+
* @param e
|
|
43
|
+
*/
|
|
44
|
+
const handleCatchInnerOutput = (e: any) => {
|
|
45
|
+
emits('innerOutput', e)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 来自子组件的关闭请求处理
|
|
50
|
+
* @param e
|
|
51
|
+
*/
|
|
52
|
+
const handleInnerCommandClose = (e: any = false) => {
|
|
53
|
+
emits('beforeClose', [e, innerComponentOptions, dialogOptions])
|
|
54
|
+
handleCloseDialog()
|
|
55
|
+
emits('afterClose', e)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 来自弹窗组件自身的关闭回调处理
|
|
60
|
+
* @param e
|
|
61
|
+
*/
|
|
62
|
+
const handleWarpCommandClose = (e: any = false) => {
|
|
63
|
+
emits('beforeClose', [e, innerComponentOptions, dialogOptions])
|
|
64
|
+
handleCloseDialog()
|
|
65
|
+
emits('afterClose', e)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 全屏切换功能
|
|
70
|
+
*/
|
|
71
|
+
const handleToggleFullscreen = () => {
|
|
72
|
+
dialogOptions.value.fullscreen = !dialogOptions.value.fullscreen
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 打开弹窗
|
|
77
|
+
* @param v
|
|
78
|
+
* @param data
|
|
79
|
+
* @param dialogOption
|
|
80
|
+
*/
|
|
81
|
+
const open = async (v: any, data: any, dialogOption: any) => {
|
|
82
|
+
innerComponent.value = v
|
|
83
|
+
innerComponentOptions.value = data
|
|
84
|
+
if (dialogOption) {
|
|
85
|
+
dialogOptions.value = Object.assign(dialogOptions.value, dialogOption)
|
|
86
|
+
}
|
|
87
|
+
emits('beforeOpen', [innerComponentOptions.value, dialogOptions.value])
|
|
88
|
+
handleOpenDialog()
|
|
89
|
+
await nextTick()
|
|
90
|
+
emits('afterOpen', [innerComponentOptions.value, dialogOptions.value])
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 关闭弹窗
|
|
95
|
+
* @param e
|
|
96
|
+
*/
|
|
97
|
+
const close = (e: any = false) => {
|
|
98
|
+
emits('beforeClose', e)
|
|
99
|
+
handleCloseDialog()
|
|
100
|
+
emits('afterClose', e)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
defineExpose({
|
|
104
|
+
open,
|
|
105
|
+
close
|
|
106
|
+
})
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<template>
|
|
110
|
+
<el-dialog v-bind="dialogOptions" v-model="dialogShow" @close="handleWarpCommandClose">
|
|
111
|
+
<template #header>
|
|
112
|
+
<div class="dialog-header">
|
|
113
|
+
<div class="title">{{ dialogOptions.title }}</div>
|
|
114
|
+
<div class="operator-bar">
|
|
115
|
+
<el-tooltip content="切换全屏" effect="dark">
|
|
116
|
+
<el-icon class="operator-bar-item" @click="handleToggleFullscreen">
|
|
117
|
+
<FullScreen />
|
|
118
|
+
</el-icon>
|
|
119
|
+
</el-tooltip>
|
|
120
|
+
<el-tooltip content="关闭弹窗" effect="dark">
|
|
121
|
+
<el-icon class="operator-bar-item" @click="handleWarpCommandClose(false)">
|
|
122
|
+
<Close />
|
|
123
|
+
</el-icon>
|
|
124
|
+
</el-tooltip>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</template>
|
|
128
|
+
<component
|
|
129
|
+
:is="innerComponent"
|
|
130
|
+
v-bind="innerComponentOptions"
|
|
131
|
+
@inner-output="handleCatchInnerOutput"
|
|
132
|
+
@close="handleInnerCommandClose"
|
|
133
|
+
/>
|
|
134
|
+
</el-dialog>
|
|
135
|
+
</template>
|
|
136
|
+
|
|
137
|
+
<style scoped lang="scss">
|
|
138
|
+
.dialog-header {
|
|
139
|
+
display: flex;
|
|
140
|
+
flex-direction: row;
|
|
141
|
+
align-items: center;
|
|
142
|
+
justify-content: space-between;
|
|
143
|
+
|
|
144
|
+
.operator-bar {
|
|
145
|
+
.operator-bar-item {
|
|
146
|
+
margin: 0 5px;
|
|
147
|
+
cursor: pointer;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {formRender} from './formRender.ts';
|
|
2
|
+
import {cloneDeep} from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
props: ['schema', 'modelValue'],
|
|
6
|
+
emits: ['update:modelValue'],
|
|
7
|
+
setup(props: any, {emit, slots}) {
|
|
8
|
+
|
|
9
|
+
const privateModelValue = cloneDeep(props.modelValue);
|
|
10
|
+
|
|
11
|
+
return () => {
|
|
12
|
+
return formRender(props.schema, privateModelValue, emit, slots);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
// form-warp
|
|
3
|
+
import { FieldSchema } from '../../pageSchema/fieldSchema.ts'
|
|
4
|
+
import { formRender } from '@/core/form/elementPlus/formRender.ts'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
schema: FieldSchema[]
|
|
8
|
+
modelValue?: any
|
|
9
|
+
}>()
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<component :is="formRender(props.schema, modelValue)" />
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<style lang="scss" scoped></style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {FieldSchema, FIELD_TYPE} from "@/core/pageSchema/fieldSchema.ts";
|
|
2
|
+
|
|
3
|
+
import {h} from 'vue';
|
|
4
|
+
|
|
5
|
+
import {ElInput, ElInputNumber, ElFormItem, ElForm} from 'element-plus';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* input渲染器
|
|
9
|
+
* @param sc
|
|
10
|
+
* @param modelValue
|
|
11
|
+
* @param emit
|
|
12
|
+
*/
|
|
13
|
+
export const formInputRender = (sc: FieldSchema, modelValue: any, emit: any) => {
|
|
14
|
+
let props = {
|
|
15
|
+
modelValue,
|
|
16
|
+
'onUpdate:modelValues': (value: any) => {
|
|
17
|
+
emit('update:modelValues', value);
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
switch (sc.fieldType) {
|
|
22
|
+
case FIELD_TYPE.STRING:
|
|
23
|
+
return h(ElInput, props, []);
|
|
24
|
+
case FIELD_TYPE.NUMBER:
|
|
25
|
+
return h(ElInputNumber, props, []);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* formItem渲染器
|
|
31
|
+
* @param sc
|
|
32
|
+
* @param modelValue
|
|
33
|
+
* @param emit
|
|
34
|
+
*/
|
|
35
|
+
export const formItemRender = (sc: FieldSchema, modelValue: any, emit: any) => {
|
|
36
|
+
let innerInput = formInputRender(sc, modelValue, emit);
|
|
37
|
+
let props = {...sc}
|
|
38
|
+
return h(ElFormItem, props, [innerInput]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* form渲染器
|
|
43
|
+
* @param schema 表单描述
|
|
44
|
+
* @param modelValues v-model值绑定
|
|
45
|
+
* @param emit 事件触发器
|
|
46
|
+
* @param slots 插槽
|
|
47
|
+
*/
|
|
48
|
+
export const formRender = (schema: FieldSchema[], modelValues: any, emit: any, slots: any) => {
|
|
49
|
+
let formItems = schema.map(sc => {
|
|
50
|
+
return formItemRender(sc, modelValues[sc.prop], emit);
|
|
51
|
+
})
|
|
52
|
+
let props = {}
|
|
53
|
+
let children = [...formItems, slots.default({model: modelValues})]
|
|
54
|
+
return h(ElForm, props, children);
|
|
55
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ElTable, ElTableColumn } from 'element-plus'
|
|
2
|
+
import _ from 'lodash-es'
|
|
3
|
+
import { TABLE_CONFIG } from './config.ts'
|
|
4
|
+
|
|
5
|
+
function render(schema: any, data: any, emit: any, slots: any) {
|
|
6
|
+
const renderSlots = {
|
|
7
|
+
default: () => {
|
|
8
|
+
return buildSlots(schema, slots)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return h(ElTable, { data, emit }, renderSlots)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function buildSlots(schema: any, slots: any) {
|
|
15
|
+
const children: any[] = []
|
|
16
|
+
// 渲染表格列子组件
|
|
17
|
+
let columnsKeys = Object.keys(schema)
|
|
18
|
+
if (_.isObject(schema)) {
|
|
19
|
+
columnsKeys.forEach((columnKey) => {
|
|
20
|
+
let colSchema = schema[columnKey]
|
|
21
|
+
let colSlots = slots[columnKey]
|
|
22
|
+
children.push(buildColumns(columnKey, colSchema, colSlots, slots))
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 额外插槽处理
|
|
27
|
+
// 增加插槽式操作栏
|
|
28
|
+
if (slots[TABLE_CONFIG.OPERATION_SLOT_NAME]) {
|
|
29
|
+
let scopeProp = { label: TABLE_CONFIG.OPERATION_COL_LABEL }
|
|
30
|
+
let scopeSlots = {
|
|
31
|
+
default: (scope: any) => {
|
|
32
|
+
return [slots[TABLE_CONFIG.OPERATION_SLOT_NAME](scope)]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
children.push(h(ElTableColumn, scopeProp, scopeSlots))
|
|
36
|
+
}
|
|
37
|
+
return children
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildColumns(columnKey: any, option: any, slots: any, globalSlots: any) {
|
|
41
|
+
// 组装props
|
|
42
|
+
let props = buildColumnProps(columnKey, option)
|
|
43
|
+
let renderSlotsArr = []
|
|
44
|
+
|
|
45
|
+
// 多级表头组合
|
|
46
|
+
if (option[TABLE_CONFIG.CHILDREN_SLOT_KEY] && _.isObject(option[TABLE_CONFIG.CHILDREN_SLOT_KEY])) {
|
|
47
|
+
let scopeOption = option[TABLE_CONFIG.CHILDREN_SLOT_KEY]
|
|
48
|
+
let columnsKeys = Object.keys(scopeOption)
|
|
49
|
+
if (_.isObject(scopeOption)) {
|
|
50
|
+
columnsKeys.forEach((columnKey) => {
|
|
51
|
+
let colSchema = scopeOption[columnKey]
|
|
52
|
+
let colSlots = globalSlots[columnKey]
|
|
53
|
+
renderSlotsArr.push(buildColumns(columnKey, colSchema, colSlots, globalSlots))
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let renderSlots = () => []
|
|
59
|
+
|
|
60
|
+
if (slots) {
|
|
61
|
+
renderSlots = {
|
|
62
|
+
default: (scope) => {
|
|
63
|
+
return [...renderSlotsArr, slots(scope)]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
renderSlots = {
|
|
68
|
+
default: () => {
|
|
69
|
+
return [...renderSlotsArr]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return h(ElTableColumn, props, renderSlots)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function buildColumnProps(key: string, option: any) {
|
|
78
|
+
if (_.isString(option)) {
|
|
79
|
+
return {
|
|
80
|
+
prop: key,
|
|
81
|
+
label: option
|
|
82
|
+
}
|
|
83
|
+
} else if (_.isObject(option)) {
|
|
84
|
+
return {
|
|
85
|
+
prop: key,
|
|
86
|
+
...option
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default render
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import request from '@/config/axios'
|
|
2
|
+
|
|
3
|
+
const defaultFetchRule = {
|
|
4
|
+
page: {
|
|
5
|
+
method: 'get',
|
|
6
|
+
template: `/:path/:model/page`
|
|
7
|
+
},
|
|
8
|
+
detail: {
|
|
9
|
+
method: 'get',
|
|
10
|
+
template: `/:path/:model/get`
|
|
11
|
+
},
|
|
12
|
+
create: {
|
|
13
|
+
method: 'post',
|
|
14
|
+
template: `/:path/:model/create`
|
|
15
|
+
},
|
|
16
|
+
delete: {
|
|
17
|
+
method: 'delete',
|
|
18
|
+
template: `/:path/:model/delete`
|
|
19
|
+
},
|
|
20
|
+
update: {
|
|
21
|
+
method: 'put',
|
|
22
|
+
template: `/:path/:model/update`,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function schemaFetch(values: any, rule = defaultFetchRule) {
|
|
27
|
+
let apis = {}
|
|
28
|
+
rule = { ...defaultFetchRule, ...rule }
|
|
29
|
+
Object.keys(rule).forEach((key) => {
|
|
30
|
+
let url = ''
|
|
31
|
+
if (rule[key].url) {
|
|
32
|
+
url = rule[key].url
|
|
33
|
+
} else {
|
|
34
|
+
url = replaceParams(rule[key].template, values)
|
|
35
|
+
}
|
|
36
|
+
apis[key] = async (params: any, ...args: any) => {
|
|
37
|
+
let method = rule[key].method
|
|
38
|
+
switch (method) {
|
|
39
|
+
case 'get':
|
|
40
|
+
return await request[method]({ url, params }, ...args)
|
|
41
|
+
case 'post':
|
|
42
|
+
return await request[method]({ url, data: params }, ...args)
|
|
43
|
+
case 'put':
|
|
44
|
+
return await request[method]({ url, data: params }, ...args)
|
|
45
|
+
case 'delete':
|
|
46
|
+
return await request[method]({ url, params }, ...args)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
return apis
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function replaceParams(template, values) {
|
|
54
|
+
const regexp = /:(\w+)/g
|
|
55
|
+
return template.replace(regexp, (_, key) => {
|
|
56
|
+
return values[key] || `${key}`
|
|
57
|
+
})
|
|
58
|
+
}
|