@vrojs/element-plus 0.0.1 → 0.0.2
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/package.json +3 -3
- package/src/index.ts +5 -0
- package/src/locale/lang/zh-cn.ts +24 -0
- package/src/style/deps.ts +5 -0
- package/src/style/index.scss +5 -0
- package/src/vro-el-config-provider/types.ts +1 -1
- package/src/vro-el-radio-group/README.md +83 -0
- package/src/vro-el-radio-group/index.ts +16 -0
- package/src/vro-el-radio-group/style/css.ts +2 -0
- package/src/vro-el-radio-group/style/deps.ts +2 -0
- package/src/vro-el-radio-group/style/index.scss +1 -0
- package/src/vro-el-radio-group/style/index.ts +2 -0
- package/src/vro-el-radio-group/types.ts +29 -0
- package/src/vro-el-radio-group/vro-el-radio-group.vue +34 -0
- package/src/vro-el-schema-filter/README.md +146 -0
- package/src/vro-el-schema-filter/index.ts +16 -0
- package/src/vro-el-schema-filter/style/css.ts +3 -0
- package/src/vro-el-schema-filter/style/deps.ts +4 -0
- package/src/vro-el-schema-filter/style/index.scss +20 -0
- package/src/vro-el-schema-filter/style/index.ts +2 -0
- package/src/vro-el-schema-filter/types.ts +31 -0
- package/src/vro-el-schema-filter/vro-el-schema-filter.vue +64 -0
- package/src/vro-el-schema-form/README.md +207 -0
- package/src/vro-el-schema-form/defineVroElSchemaFormCreateField.ts +12 -0
- package/src/vro-el-schema-form/defineVroElSchemaFormFieldTrigger.ts +9 -0
- package/src/vro-el-schema-form/index.ts +20 -0
- package/src/vro-el-schema-form/style/css.ts +9 -0
- package/src/vro-el-schema-form/style/deps.ts +20 -0
- package/src/vro-el-schema-form/style/index.scss +4 -0
- package/src/vro-el-schema-form/style/index.ts +2 -0
- package/src/vro-el-schema-form/types.ts +171 -0
- package/src/vro-el-schema-form/useVroElSchemaForm.ts +48 -0
- package/src/vro-el-schema-form/vro-el-schema-form.vue +177 -0
- package/src/vro-el-schema-form/vroElSchemaFormFieldManager.ts +59 -0
- package/src/vro-el-schema-form-dialog/README.md +114 -5
- package/src/vro-el-schema-form-dialog/function-call.ts +11 -3
- package/src/vro-el-schema-form-dialog/index.ts +6 -1
- package/src/vro-el-schema-form-dialog/injection.ts +10 -0
- package/src/vro-el-schema-form-dialog/style/css.ts +2 -0
- package/src/vro-el-schema-form-dialog/style/deps.ts +4 -0
- package/src/vro-el-schema-form-dialog/style/index.scss +4 -1
- package/src/vro-el-schema-form-dialog/types.ts +70 -2
- package/src/vro-el-schema-form-dialog/useVroElSchemaFormDialog.ts +52 -0
- package/src/vro-el-schema-form-dialog/vro-el-schema-form-dialog.vue +119 -9
- package/src/vro-el-tags/README.md +73 -0
- package/src/vro-el-tags/index.ts +16 -0
- package/src/vro-el-tags/style/css.ts +2 -0
- package/src/vro-el-tags/style/deps.ts +3 -0
- package/src/vro-el-tags/style/index.scss +1 -0
- package/src/vro-el-tags/style/index.ts +2 -0
- package/src/vro-el-tags/types.ts +21 -0
- package/src/vro-el-tags/vro-el-tags.vue +69 -0
- package/src/vro-el-tree/README.md +85 -0
- package/src/vro-el-tree/index.ts +16 -0
- package/src/vro-el-tree/style/css.ts +2 -0
- package/src/vro-el-tree/style/deps.ts +1 -0
- package/src/vro-el-tree/style/index.scss +3 -0
- package/src/vro-el-tree/style/index.ts +2 -0
- package/src/vro-el-tree/types.ts +38 -0
- package/src/vro-el-tree/vro-el-tree.vue +78 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ComponentManager } from '@vrojs/base'
|
|
2
|
+
import {
|
|
3
|
+
ElCascader,
|
|
4
|
+
ElCheckboxGroup,
|
|
5
|
+
ElDatePicker,
|
|
6
|
+
ElDivider,
|
|
7
|
+
ElInput,
|
|
8
|
+
ElInputNumber,
|
|
9
|
+
ElRadioGroup,
|
|
10
|
+
ElSelect,
|
|
11
|
+
ElTreeSelect,
|
|
12
|
+
} from 'element-plus'
|
|
13
|
+
|
|
14
|
+
import { VroElCheckboxGroup } from '../vro-el-checkbox-group'
|
|
15
|
+
import { VroElFileUpload } from '../vro-el-file-upload'
|
|
16
|
+
import { VroElImageUpload } from '../vro-el-image-upload'
|
|
17
|
+
import { VroElRadioGroup } from '../vro-el-radio-group'
|
|
18
|
+
import { VroElSelect } from '../vro-el-select'
|
|
19
|
+
import { VroElTags } from '../vro-el-tags'
|
|
20
|
+
import { VroElTree } from '../vro-el-tree'
|
|
21
|
+
|
|
22
|
+
export const vroElSchemaFormFieldManager = new ComponentManager()
|
|
23
|
+
|
|
24
|
+
// 注册
|
|
25
|
+
vroElSchemaFormFieldManager
|
|
26
|
+
.add('ElInput', ElInput, {
|
|
27
|
+
clearable: true,
|
|
28
|
+
showWordLimit: true,
|
|
29
|
+
autosize: { minRows: 2 },
|
|
30
|
+
})
|
|
31
|
+
.add('ElSelect', ElSelect, {
|
|
32
|
+
clearable: true,
|
|
33
|
+
filterable: true,
|
|
34
|
+
})
|
|
35
|
+
.add('ElRadioGroup', ElRadioGroup)
|
|
36
|
+
.add('ElCheckboxGroup', ElCheckboxGroup)
|
|
37
|
+
.add('ElDatePicker', ElDatePicker, {
|
|
38
|
+
type: 'date',
|
|
39
|
+
clearable: true,
|
|
40
|
+
})
|
|
41
|
+
.add('ElInputNumber', ElInputNumber)
|
|
42
|
+
.add('ElTreeSelect', ElTreeSelect)
|
|
43
|
+
.add('ElCascader', ElCascader, {
|
|
44
|
+
clearable: true,
|
|
45
|
+
validateEvent: false,
|
|
46
|
+
})
|
|
47
|
+
.add('ElDivider', ElDivider, {
|
|
48
|
+
contentPosition: 'center',
|
|
49
|
+
})
|
|
50
|
+
.add('VroElSelect', VroElSelect, {
|
|
51
|
+
clearable: true,
|
|
52
|
+
filterable: true,
|
|
53
|
+
})
|
|
54
|
+
.add('VroElCheckboxGroup', VroElCheckboxGroup)
|
|
55
|
+
.add('VroElRadioGroup', VroElRadioGroup)
|
|
56
|
+
.add('VroElImageUpload', VroElImageUpload)
|
|
57
|
+
.add('VroElFileUpload', VroElFileUpload)
|
|
58
|
+
.add('VroElTags', VroElTags)
|
|
59
|
+
.add('VroElTree', VroElTree)
|
|
@@ -2,12 +2,76 @@
|
|
|
2
2
|
|
|
3
3
|
### 介绍
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
基于 `ElDialog` 和 `VroElSchemaForm` 的弹窗表单组件。组件内置校验、提交 loading、确认/取消按钮,适合编辑、新建等弹窗表单场景,也支持通过函数方式调用。
|
|
6
6
|
|
|
7
7
|
## 代码演示
|
|
8
8
|
|
|
9
9
|
### 基础用法
|
|
10
10
|
|
|
11
|
+
```html
|
|
12
|
+
<template>
|
|
13
|
+
<el-button type="primary" @click="openDialog">打开弹窗</el-button>
|
|
14
|
+
<vro-el-schema-form-dialog
|
|
15
|
+
ref="dialogRef"
|
|
16
|
+
title="编辑用户"
|
|
17
|
+
:schema="schema"
|
|
18
|
+
:request="handleRequest"
|
|
19
|
+
@confirm="handleConfirm"
|
|
20
|
+
/>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import { ref } from 'vue'
|
|
25
|
+
import type { VroElSchemaFormDialogInstance, VroElSchemaFormSchema } from '@vrojs/element-plus'
|
|
26
|
+
|
|
27
|
+
const dialogRef = ref<VroElSchemaFormDialogInstance>()
|
|
28
|
+
const schema = ref<VroElSchemaFormSchema>({
|
|
29
|
+
username: {
|
|
30
|
+
label: '用户名',
|
|
31
|
+
value: '',
|
|
32
|
+
is: 'ElInput',
|
|
33
|
+
rules: [{ required: true, message: '请填写用户名', trigger: 'blur' }],
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const openDialog = () => {
|
|
38
|
+
dialogRef.value?.show()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const handleRequest = async (data) => {
|
|
42
|
+
return data
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const handleConfirm = (data) => {
|
|
46
|
+
console.log(data)
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 函数调用
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { showVroElSchemaFormDialog } from '@vrojs/element-plus'
|
|
55
|
+
|
|
56
|
+
const data = await showVroElSchemaFormDialog({
|
|
57
|
+
title: '新建用户',
|
|
58
|
+
schema,
|
|
59
|
+
request: async (value) => value,
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 自定义底部按钮文本
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<vro-el-schema-form-dialog
|
|
67
|
+
ref="dialogRef"
|
|
68
|
+
title="编辑用户"
|
|
69
|
+
confirm-button-text="保存"
|
|
70
|
+
cancel-button-text="关闭"
|
|
71
|
+
:schema="schema"
|
|
72
|
+
/>
|
|
73
|
+
```
|
|
74
|
+
|
|
11
75
|
## API
|
|
12
76
|
|
|
13
77
|
### 属性 Props
|
|
@@ -36,8 +100,8 @@
|
|
|
36
100
|
<td>说明</td>
|
|
37
101
|
</tr>
|
|
38
102
|
<tr>
|
|
39
|
-
<td>
|
|
40
|
-
<td
|
|
103
|
+
<td>default</td>
|
|
104
|
+
<td>透传给内部 VroElSchemaForm 的默认插槽</td>
|
|
41
105
|
</tr>
|
|
42
106
|
</tbody>
|
|
43
107
|
</table>
|
|
@@ -51,8 +115,53 @@
|
|
|
51
115
|
<td>说明</td>
|
|
52
116
|
</tr>
|
|
53
117
|
<tr>
|
|
54
|
-
<td>
|
|
55
|
-
<td
|
|
118
|
+
<td>schemaFormInstance</td>
|
|
119
|
+
<td>内部 VroElSchemaForm 实例</td>
|
|
120
|
+
</tr>
|
|
121
|
+
<tr>
|
|
122
|
+
<td>show</td>
|
|
123
|
+
<td>打开弹窗,支持传入动态 props</td>
|
|
124
|
+
</tr>
|
|
125
|
+
<tr>
|
|
126
|
+
<td>hide</td>
|
|
127
|
+
<td>关闭弹窗</td>
|
|
128
|
+
</tr>
|
|
129
|
+
</tbody>
|
|
130
|
+
</table>
|
|
131
|
+
|
|
132
|
+
### 事件 Events
|
|
133
|
+
|
|
134
|
+
<table>
|
|
135
|
+
<tbody>
|
|
136
|
+
<tr>
|
|
137
|
+
<td>名称</td>
|
|
138
|
+
<td>参数</td>
|
|
139
|
+
<td>说明</td>
|
|
140
|
+
</tr>
|
|
141
|
+
<tr>
|
|
142
|
+
<td>confirm</td>
|
|
143
|
+
<td>data</td>
|
|
144
|
+
<td>确认成功后触发</td>
|
|
145
|
+
</tr>
|
|
146
|
+
<tr>
|
|
147
|
+
<td>cancel</td>
|
|
148
|
+
<td>reason</td>
|
|
149
|
+
<td>关闭弹窗时触发</td>
|
|
150
|
+
</tr>
|
|
151
|
+
<tr>
|
|
152
|
+
<td>closed</td>
|
|
153
|
+
<td>-</td>
|
|
154
|
+
<td>弹窗关闭动画结束后触发</td>
|
|
155
|
+
</tr>
|
|
156
|
+
<tr>
|
|
157
|
+
<td>change-field</td>
|
|
158
|
+
<td>{ key, value }</td>
|
|
159
|
+
<td>内部表单字段 change 时触发</td>
|
|
160
|
+
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td>input-field</td>
|
|
163
|
+
<td>{ key, value }</td>
|
|
164
|
+
<td>内部表单字段 input 时触发</td>
|
|
56
165
|
</tr>
|
|
57
166
|
</tbody>
|
|
58
167
|
</table>
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { showComponent } from '@vrojs/base'
|
|
2
|
-
import { AppContext } from 'vue'
|
|
2
|
+
import { type AppContext, markRaw } from 'vue'
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import VroElWithConfig from '../vro-el-with-config'
|
|
5
|
+
import type { VroElSchemaFormDialogProps } from './types'
|
|
5
6
|
import VroElSchemaFormDialog from './vro-el-schema-form-dialog.vue'
|
|
6
7
|
|
|
7
8
|
export function showVroElSchemaFormDialog<T = any>(
|
|
8
9
|
props: Partial<VroElSchemaFormDialogProps>,
|
|
9
10
|
appContext: AppContext | null = null,
|
|
10
11
|
): Promise<T> {
|
|
11
|
-
return showComponent(
|
|
12
|
+
return showComponent(
|
|
13
|
+
VroElWithConfig,
|
|
14
|
+
{
|
|
15
|
+
...props,
|
|
16
|
+
is: markRaw(VroElSchemaFormDialog),
|
|
17
|
+
},
|
|
18
|
+
appContext,
|
|
19
|
+
)
|
|
12
20
|
}
|
|
@@ -3,9 +3,14 @@ import { withInstall } from '@vrojs/base'
|
|
|
3
3
|
import Component from './vro-el-schema-form-dialog.vue'
|
|
4
4
|
|
|
5
5
|
export * from './function-call'
|
|
6
|
+
export * from './injection'
|
|
6
7
|
export * from './types'
|
|
8
|
+
export * from './useVroElSchemaFormDialog'
|
|
7
9
|
|
|
8
|
-
export const VroElSchemaFormDialog = withInstall<typeof Component>(Component)
|
|
10
|
+
export const VroElSchemaFormDialog = withInstall<typeof Component>(Component, (app) => {
|
|
11
|
+
app.component((Component as any).name, Component)
|
|
12
|
+
;(Component as any)._context = app._context
|
|
13
|
+
})
|
|
9
14
|
export default VroElSchemaFormDialog
|
|
10
15
|
|
|
11
16
|
export type VroElSchemaFormDialogInstance = InstanceType<typeof VroElSchemaFormDialog>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { inject, type InjectionKey } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const vroElSchemaFormDialogInjectionKey = Symbol() as InjectionKey<{
|
|
4
|
+
confirm: (...args: any[]) => Promise<void>
|
|
5
|
+
hide: (reason?: any) => Promise<void>
|
|
6
|
+
}>
|
|
7
|
+
|
|
8
|
+
export function useVroElSchemaFormDialogInstance() {
|
|
9
|
+
return inject(vroElSchemaFormDialogInjectionKey, null)
|
|
10
|
+
}
|
|
@@ -1,5 +1,73 @@
|
|
|
1
|
-
import type { ExtractPropTypes } from 'vue'
|
|
1
|
+
import type { CSSProperties, ExtractPropTypes, PropType } from 'vue'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { vroElSchemaFormProps, type VroElSchemaFormSchema } from '../vro-el-schema-form'
|
|
4
|
+
|
|
5
|
+
export interface VroElSchemaFormDialogRequest {
|
|
6
|
+
(data: any, schema: VroElSchemaFormSchema): Promise<any>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const vroElSchemaFormDialogProps = {
|
|
10
|
+
...vroElSchemaFormProps,
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 弹窗标题。
|
|
14
|
+
*/
|
|
15
|
+
title: String,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 弹窗样式。
|
|
19
|
+
*/
|
|
20
|
+
style: {
|
|
21
|
+
type: Object as PropType<CSSProperties>,
|
|
22
|
+
default: () => ({}),
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 确认前的提交请求,返回值会作为 confirm 事件参数。
|
|
27
|
+
*/
|
|
28
|
+
request: Function as PropType<VroElSchemaFormDialogRequest>,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 表单标签位置。
|
|
32
|
+
*/
|
|
33
|
+
labelPosition: {
|
|
34
|
+
type: String as PropType<'left' | 'right' | 'top'>,
|
|
35
|
+
default: 'top',
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 表单标签宽度。
|
|
40
|
+
*/
|
|
41
|
+
labelWidth: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: '120px',
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 是否显示取消按钮。
|
|
48
|
+
*/
|
|
49
|
+
showCancelButton: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: true,
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 是否显示确认按钮。
|
|
56
|
+
*/
|
|
57
|
+
showConfirmButton: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: true,
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 取消按钮文本。
|
|
64
|
+
*/
|
|
65
|
+
cancelButtonText: String,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 确认按钮文本。
|
|
69
|
+
*/
|
|
70
|
+
confirmButtonText: String,
|
|
71
|
+
}
|
|
4
72
|
|
|
5
73
|
export type VroElSchemaFormDialogProps = ExtractPropTypes<typeof vroElSchemaFormDialogProps>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import banana from '@daysnap/banana'
|
|
2
|
+
import { getCurrentInstance, type Ref, ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
import type { VroElSchemaFormSchema, VroElSchemaFormSchemaField } from '../vro-el-schema-form'
|
|
5
|
+
import { showVroElSchemaFormDialog } from './function-call'
|
|
6
|
+
|
|
7
|
+
export interface UseVroElSchemaFormDialogOptions<S extends VroElSchemaFormSchema> {
|
|
8
|
+
instanceRef?: Ref<any>
|
|
9
|
+
onGenerate?: (schema: S, ...args: any[]) => void
|
|
10
|
+
onSuccess?: (schema: S, ...args: any[]) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UseVroElSchemaFormDialogInstance {
|
|
14
|
+
show: typeof showVroElSchemaFormDialog
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useVroElSchemaFormDialog<
|
|
18
|
+
T extends VroElSchemaFormSchema,
|
|
19
|
+
S extends VroElSchemaFormSchema = { [P in keyof T]: VroElSchemaFormSchemaField },
|
|
20
|
+
>(
|
|
21
|
+
generator: () => T | Promise<T>,
|
|
22
|
+
task: (schema: S, instance: UseVroElSchemaFormDialogInstance, ...args: any[]) => Promise<any>,
|
|
23
|
+
options: UseVroElSchemaFormDialogOptions<S> = {},
|
|
24
|
+
) {
|
|
25
|
+
const { onGenerate, onSuccess, instanceRef } = options
|
|
26
|
+
|
|
27
|
+
const schema = ref<S>()
|
|
28
|
+
|
|
29
|
+
const instance = getCurrentInstance()
|
|
30
|
+
|
|
31
|
+
const trigger = async (...args: any[]) => {
|
|
32
|
+
schema.value = (await generator()) as unknown as S
|
|
33
|
+
if (args[0]) {
|
|
34
|
+
banana.assignment(args[0], schema.value as any)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
onGenerate?.(schema.value as any, ...args)
|
|
38
|
+
|
|
39
|
+
await task(
|
|
40
|
+
schema.value,
|
|
41
|
+
instanceRef?.value ?? {
|
|
42
|
+
show: (props, appContext) =>
|
|
43
|
+
showVroElSchemaFormDialog(props, appContext ?? instance?.appContext),
|
|
44
|
+
},
|
|
45
|
+
...args,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
onSuccess?.(schema.value as any, ...args)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [schema, trigger] as const
|
|
52
|
+
}
|
|
@@ -1,20 +1,77 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<el-dialog
|
|
3
|
-
|
|
2
|
+
<el-dialog
|
|
3
|
+
v-model="visible"
|
|
4
|
+
ref="containerRef"
|
|
5
|
+
class="vro-el-schema-form-dialog"
|
|
6
|
+
:class="[id]"
|
|
7
|
+
:title="computedProps.title"
|
|
8
|
+
destroy-on-close
|
|
9
|
+
append-to-body
|
|
10
|
+
:close-on-click-modal="false"
|
|
11
|
+
:style="computedProps.style"
|
|
12
|
+
@close="hide()"
|
|
13
|
+
@closed="$emit('closed')"
|
|
14
|
+
>
|
|
15
|
+
<vro-el-schema-form
|
|
16
|
+
v-bind="schemaFormProps"
|
|
17
|
+
ref="refVroElSchemaForm"
|
|
18
|
+
@change-field="$emit('change-field', $event)"
|
|
19
|
+
@input-field="$emit('input-field', $event)"
|
|
20
|
+
@submit.prevent="handleSubmit()"
|
|
21
|
+
>
|
|
22
|
+
<slot></slot>
|
|
23
|
+
</vro-el-schema-form>
|
|
24
|
+
|
|
25
|
+
<template v-if="computedProps.showCancelButton || computedProps.showConfirmButton" #footer>
|
|
26
|
+
<span class="dialog-footer">
|
|
27
|
+
<el-button v-if="computedProps.showCancelButton" @click="hide('cancel')">
|
|
28
|
+
{{ computedProps.cancelButtonText || t('schemaFormDialog.cancelText') }}
|
|
29
|
+
</el-button>
|
|
30
|
+
<el-button
|
|
31
|
+
v-if="computedProps.showConfirmButton"
|
|
32
|
+
type="primary"
|
|
33
|
+
@click="handleSubmit"
|
|
34
|
+
:loading="loading"
|
|
35
|
+
>
|
|
36
|
+
{{ computedProps.confirmButtonText || t('schemaFormDialog.confirmText') }}
|
|
37
|
+
</el-button>
|
|
38
|
+
</span>
|
|
39
|
+
</template>
|
|
4
40
|
</el-dialog>
|
|
5
41
|
</template>
|
|
6
42
|
|
|
7
43
|
<script setup lang="ts">
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
44
|
+
import { getRandom, pick } from '@daysnap/utils'
|
|
45
|
+
import { useAsyncTask, useVisible } from '@vrojs/use'
|
|
46
|
+
import { ElButton, ElDialog } from 'element-plus'
|
|
47
|
+
import { computed, nextTick, provide, ref, useTemplateRef, watch } from 'vue'
|
|
10
48
|
|
|
11
|
-
import {
|
|
49
|
+
import { useLocale } from '../locale'
|
|
50
|
+
import { VroElSchemaForm, vroElSchemaFormProps } from '../vro-el-schema-form'
|
|
51
|
+
import { vroElSchemaFormDialogInjectionKey } from './injection'
|
|
52
|
+
import { type VroElSchemaFormDialogProps, vroElSchemaFormDialogProps } from './types'
|
|
12
53
|
|
|
13
54
|
defineOptions({ name: 'VroElSchemaFormDialog' })
|
|
14
|
-
defineProps(vroElSchemaFormDialogProps)
|
|
15
|
-
const emit = defineEmits(['cancel', 'confirm'])
|
|
16
55
|
|
|
17
|
-
const
|
|
56
|
+
const emit = defineEmits(['change-field', 'input-field', 'cancel', 'confirm', 'closed'])
|
|
57
|
+
|
|
58
|
+
const props = defineProps(vroElSchemaFormDialogProps)
|
|
59
|
+
const { t } = useLocale()
|
|
60
|
+
const dynamicProps = ref<Partial<VroElSchemaFormDialogProps>>()
|
|
61
|
+
const computedProps = computed<VroElSchemaFormDialogProps>(() =>
|
|
62
|
+
Object.assign({}, props, dynamicProps.value),
|
|
63
|
+
)
|
|
64
|
+
const schemaFormProps = computed(() => {
|
|
65
|
+
const value = pick(computedProps.value, Object.keys(vroElSchemaFormProps) as any)
|
|
66
|
+
return {
|
|
67
|
+
...value,
|
|
68
|
+
formProps: {
|
|
69
|
+
labelPosition: computedProps.value.labelPosition,
|
|
70
|
+
labelWidth: computedProps.value.labelWidth,
|
|
71
|
+
...value.formProps,
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
})
|
|
18
75
|
|
|
19
76
|
const { show, hide, confirm, visible } = useVisible<Partial<VroElSchemaFormDialogProps>, any>({
|
|
20
77
|
showCallback: (options) => {
|
|
@@ -24,9 +81,62 @@
|
|
|
24
81
|
confirmCallback: (data) => emit('confirm', data),
|
|
25
82
|
})
|
|
26
83
|
|
|
84
|
+
const id = `id_${getRandom(10)}`
|
|
85
|
+
watch(visible, (v) => {
|
|
86
|
+
if (v) {
|
|
87
|
+
nextTick(() => {
|
|
88
|
+
const els = document.querySelectorAll(`.${id}`)
|
|
89
|
+
if (els.length) {
|
|
90
|
+
els.forEach((el) => (el.parentElement!.scrollTop = 0))
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const refVroElSchemaForm = useTemplateRef('refVroElSchemaForm')
|
|
97
|
+
const { loading, trigger: handleSubmit } = useAsyncTask(
|
|
98
|
+
async () => {
|
|
99
|
+
if (!refVroElSchemaForm.value) {
|
|
100
|
+
throw new Error('not fond VroElSchemaForm')
|
|
101
|
+
}
|
|
102
|
+
await refVroElSchemaForm.value.validate().catch(() => {
|
|
103
|
+
throw 'cancel'
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// 执行方法
|
|
107
|
+
let isBlock = false
|
|
108
|
+
await refVroElSchemaForm.value.trigger({
|
|
109
|
+
confirm,
|
|
110
|
+
hide,
|
|
111
|
+
block: () => {
|
|
112
|
+
isBlock = true
|
|
113
|
+
setTimeout(() => (isBlock = true))
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
if (visible.value && !isBlock) {
|
|
118
|
+
// 获取数据
|
|
119
|
+
const data = await refVroElSchemaForm.value.extractValues()
|
|
120
|
+
const result = (await computedProps.value.request?.(data, props.schema!)) ?? data
|
|
121
|
+
|
|
122
|
+
confirm(result)
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
throwError: true,
|
|
127
|
+
},
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
provide(vroElSchemaFormDialogInjectionKey, {
|
|
131
|
+
confirm,
|
|
132
|
+
hide,
|
|
133
|
+
})
|
|
134
|
+
|
|
27
135
|
defineExpose({
|
|
136
|
+
get schemaFormInstance() {
|
|
137
|
+
return refVroElSchemaForm.value!
|
|
138
|
+
},
|
|
28
139
|
show,
|
|
29
140
|
hide,
|
|
30
|
-
confirm,
|
|
31
141
|
})
|
|
32
142
|
</script>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# VroElTags
|
|
2
|
+
|
|
3
|
+
### 介绍
|
|
4
|
+
|
|
5
|
+
基于 `ElTag`、`ElInput` 和 `ElButton` 的标签编辑组件。支持通过 `v-model` 新增、删除标签,也可以设置为只读禁用状态。
|
|
6
|
+
|
|
7
|
+
## 代码演示
|
|
8
|
+
|
|
9
|
+
### 基础用法
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<template>
|
|
13
|
+
<vro-el-tags v-model="value" />
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import { ref } from 'vue'
|
|
18
|
+
|
|
19
|
+
const value = ref(['Vue', 'Element Plus'])
|
|
20
|
+
</script>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 禁用状态
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<vro-el-tags v-model="value" disabled />
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
### 属性 Props
|
|
32
|
+
|
|
33
|
+
<table>
|
|
34
|
+
<tbody>
|
|
35
|
+
<tr>
|
|
36
|
+
<td>名称</td>
|
|
37
|
+
<td>类型</td>
|
|
38
|
+
<td>默认值</td>
|
|
39
|
+
</tr>
|
|
40
|
+
<tr v-for="(item, key) in vroElTagsProps" :key="key">
|
|
41
|
+
<td>{{ key }}</td>
|
|
42
|
+
<td>{{ parseType(item.type || item) }}</td>
|
|
43
|
+
<td>{{ reserve(item.default, '-') }}</td>
|
|
44
|
+
</tr>
|
|
45
|
+
</tbody>
|
|
46
|
+
</table>
|
|
47
|
+
|
|
48
|
+
### 插槽 Slots
|
|
49
|
+
|
|
50
|
+
暂无。
|
|
51
|
+
|
|
52
|
+
### 事件 Events
|
|
53
|
+
|
|
54
|
+
<table>
|
|
55
|
+
<tbody>
|
|
56
|
+
<tr>
|
|
57
|
+
<td>名称</td>
|
|
58
|
+
<td>参数</td>
|
|
59
|
+
<td>说明</td>
|
|
60
|
+
</tr>
|
|
61
|
+
<tr>
|
|
62
|
+
<td>update:modelValue</td>
|
|
63
|
+
<td>value</td>
|
|
64
|
+
<td>标签列表变化时触发</td>
|
|
65
|
+
</tr>
|
|
66
|
+
</tbody>
|
|
67
|
+
</table>
|
|
68
|
+
|
|
69
|
+
<script setup lang="ts">
|
|
70
|
+
import { reserve } from '@daysnap/utils'
|
|
71
|
+
import { VroElTags, vroElTagsProps } from '.'
|
|
72
|
+
import { parseType } from '../utils'
|
|
73
|
+
</script>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { withInstall } from '@vrojs/base'
|
|
2
|
+
|
|
3
|
+
import Component from './vro-el-tags.vue'
|
|
4
|
+
|
|
5
|
+
export * from './types'
|
|
6
|
+
|
|
7
|
+
export const VroElTags = withInstall<typeof Component>(Component)
|
|
8
|
+
export default VroElTags
|
|
9
|
+
|
|
10
|
+
export type VroElTagsInstance = InstanceType<typeof VroElTags>
|
|
11
|
+
|
|
12
|
+
declare module 'vue' {
|
|
13
|
+
export interface GlobalComponents {
|
|
14
|
+
VroElTags: typeof VroElTags
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.vro-el-tags { }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ExtractPropTypes, PropType } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const vroElTagsProps = {
|
|
4
|
+
/**
|
|
5
|
+
* 标签列表。
|
|
6
|
+
*/
|
|
7
|
+
modelValue: {
|
|
8
|
+
type: Array as PropType<string[]>,
|
|
9
|
+
default: () => [],
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 是否禁用新增和删除标签。
|
|
14
|
+
*/
|
|
15
|
+
disabled: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: false,
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type VroElTagsProps = ExtractPropTypes<typeof vroElTagsProps>
|