@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,69 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="vro-el-tags">
|
|
3
|
+
<el-tag
|
|
4
|
+
v-for="(item, index) in modelValue"
|
|
5
|
+
:key="`${item}-${index}`"
|
|
6
|
+
class="vro-el-tag"
|
|
7
|
+
size="large"
|
|
8
|
+
:closable="!disabled"
|
|
9
|
+
:disable-transitions="false"
|
|
10
|
+
@close="handleClose(index)"
|
|
11
|
+
>
|
|
12
|
+
{{ item }}
|
|
13
|
+
</el-tag>
|
|
14
|
+
|
|
15
|
+
<el-input
|
|
16
|
+
v-if="inputVisible"
|
|
17
|
+
ref="inputRef"
|
|
18
|
+
v-model="inputValue"
|
|
19
|
+
class="vro-el-tag-input"
|
|
20
|
+
@keyup.enter="handleInputConfirm"
|
|
21
|
+
@blur="handleInputConfirm"
|
|
22
|
+
/>
|
|
23
|
+
<el-button v-else-if="!disabled" class="vro-el-tag-btn" :icon="Plus" @click="showInput">
|
|
24
|
+
{{ t('tags.addText') }}
|
|
25
|
+
</el-button>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import { Plus } from '@element-plus/icons-vue'
|
|
31
|
+
import { ElButton, ElInput, ElTag } from 'element-plus'
|
|
32
|
+
import { nextTick, ref } from 'vue'
|
|
33
|
+
|
|
34
|
+
import { useLocale } from '../locale'
|
|
35
|
+
import { vroElTagsProps } from './types'
|
|
36
|
+
|
|
37
|
+
defineOptions({ name: 'VroElTags' })
|
|
38
|
+
|
|
39
|
+
const emit = defineEmits(['update:modelValue'])
|
|
40
|
+
const props = defineProps(vroElTagsProps)
|
|
41
|
+
const { t } = useLocale()
|
|
42
|
+
|
|
43
|
+
const inputValue = ref('')
|
|
44
|
+
const inputVisible = ref(false)
|
|
45
|
+
const inputRef = ref<InstanceType<typeof ElInput>>()
|
|
46
|
+
|
|
47
|
+
const handleClose = (index: number) => {
|
|
48
|
+
const value = props.modelValue.filter((_, valueIndex) => valueIndex !== index)
|
|
49
|
+
emit('update:modelValue', value)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const showInput = () => {
|
|
53
|
+
inputVisible.value = true
|
|
54
|
+
nextTick(() => {
|
|
55
|
+
inputRef.value?.input?.focus()
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const handleInputConfirm = () => {
|
|
60
|
+
const value = [...props.modelValue]
|
|
61
|
+
const tag = inputValue.value.trim()
|
|
62
|
+
if (tag) {
|
|
63
|
+
value.push(tag)
|
|
64
|
+
}
|
|
65
|
+
emit('update:modelValue', value)
|
|
66
|
+
inputVisible.value = false
|
|
67
|
+
inputValue.value = ''
|
|
68
|
+
}
|
|
69
|
+
</script>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# VroElTree
|
|
2
|
+
|
|
3
|
+
### 介绍
|
|
4
|
+
|
|
5
|
+
基于 `ElTree` 的受控勾选封装。组件会把全选节点和半选节点一起同步到 `v-model`,适合权限树这类需要保存父子勾选链路的场景。
|
|
6
|
+
|
|
7
|
+
## 代码演示
|
|
8
|
+
|
|
9
|
+
### 基础用法
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<template>
|
|
13
|
+
<vro-el-tree
|
|
14
|
+
v-model="value"
|
|
15
|
+
show-checkbox
|
|
16
|
+
node-key="id"
|
|
17
|
+
default-expand-all
|
|
18
|
+
:options="options"
|
|
19
|
+
:props="{ label: 'label' }"
|
|
20
|
+
/>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import { ref } from 'vue'
|
|
25
|
+
|
|
26
|
+
const value = ref(['system'])
|
|
27
|
+
const options = [
|
|
28
|
+
{
|
|
29
|
+
id: 'system',
|
|
30
|
+
parentId: '-1',
|
|
31
|
+
label: '系统管理',
|
|
32
|
+
children: [
|
|
33
|
+
{ id: 'user', parentId: 'system', label: '用户管理' },
|
|
34
|
+
{ id: 'role', parentId: 'system', label: '角色管理' },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### 属性 Props
|
|
44
|
+
|
|
45
|
+
<table>
|
|
46
|
+
<tbody>
|
|
47
|
+
<tr>
|
|
48
|
+
<td>名称</td>
|
|
49
|
+
<td>类型</td>
|
|
50
|
+
<td>默认值</td>
|
|
51
|
+
</tr>
|
|
52
|
+
<tr v-for="(item, key) in vroElTreeProps" :key="key">
|
|
53
|
+
<td>{{ key }}</td>
|
|
54
|
+
<td>{{ parseType(item.type || item) }}</td>
|
|
55
|
+
<td>{{ reserve(item.default, '-') }}</td>
|
|
56
|
+
</tr>
|
|
57
|
+
</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
|
|
60
|
+
### 插槽 Slots
|
|
61
|
+
|
|
62
|
+
支持默认插槽,插槽参数同 `ElTree` 默认插槽。
|
|
63
|
+
|
|
64
|
+
### 事件 Events
|
|
65
|
+
|
|
66
|
+
<table>
|
|
67
|
+
<tbody>
|
|
68
|
+
<tr>
|
|
69
|
+
<td>名称</td>
|
|
70
|
+
<td>参数</td>
|
|
71
|
+
<td>说明</td>
|
|
72
|
+
</tr>
|
|
73
|
+
<tr>
|
|
74
|
+
<td>update:modelValue</td>
|
|
75
|
+
<td>value</td>
|
|
76
|
+
<td>勾选节点变化时触发,返回半选和全选节点 id</td>
|
|
77
|
+
</tr>
|
|
78
|
+
</tbody>
|
|
79
|
+
</table>
|
|
80
|
+
|
|
81
|
+
<script setup lang="ts">
|
|
82
|
+
import { reserve } from '@daysnap/utils'
|
|
83
|
+
import { VroElTree, vroElTreeProps } from '.'
|
|
84
|
+
import { parseType } from '../utils'
|
|
85
|
+
</script>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { withInstall } from '@vrojs/base'
|
|
2
|
+
|
|
3
|
+
import Component from './vro-el-tree.vue'
|
|
4
|
+
|
|
5
|
+
export * from './types'
|
|
6
|
+
|
|
7
|
+
export const VroElTree = withInstall<typeof Component>(Component)
|
|
8
|
+
export default VroElTree
|
|
9
|
+
|
|
10
|
+
export type VroElTreeInstance = InstanceType<typeof VroElTree>
|
|
11
|
+
|
|
12
|
+
declare module 'vue' {
|
|
13
|
+
export interface GlobalComponents {
|
|
14
|
+
VroElTree: typeof VroElTree
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'element-plus/es/components/tree/style/css'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ExtractPropTypes, PropType } from 'vue'
|
|
2
|
+
|
|
3
|
+
export type VroElTreeKey = string | number
|
|
4
|
+
|
|
5
|
+
export interface VroElTreeOption {
|
|
6
|
+
id: VroElTreeKey
|
|
7
|
+
parentId?: VroElTreeKey
|
|
8
|
+
children?: VroElTreeOption[]
|
|
9
|
+
[key: string]: any
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const vroElTreeProps = {
|
|
13
|
+
/**
|
|
14
|
+
* 选中的节点 id 列表,包含半选和全选节点。
|
|
15
|
+
*/
|
|
16
|
+
modelValue: {
|
|
17
|
+
type: Array as PropType<VroElTreeKey[]>,
|
|
18
|
+
default: () => [],
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 树节点数据,节点需要包含 id,可通过 parentId 表示父级关系。
|
|
23
|
+
*/
|
|
24
|
+
options: {
|
|
25
|
+
type: Array as PropType<VroElTreeOption[]>,
|
|
26
|
+
default: () => [],
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 根节点 id,用于判断顶层节点的选中链路。
|
|
31
|
+
*/
|
|
32
|
+
rootId: {
|
|
33
|
+
type: [String, Number],
|
|
34
|
+
default: '-1',
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type VroElTreeProps = ExtractPropTypes<typeof vroElTreeProps>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-tree
|
|
3
|
+
v-bind="$attrs"
|
|
4
|
+
class="vro-el-tree"
|
|
5
|
+
:data="options"
|
|
6
|
+
:default-checked-keys="checkedKeys"
|
|
7
|
+
@check="handleCheck"
|
|
8
|
+
>
|
|
9
|
+
<template v-if="$slots.default" #default="scope">
|
|
10
|
+
<slot v-bind="scope" />
|
|
11
|
+
</template>
|
|
12
|
+
</el-tree>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { isUndefined } from '@daysnap/utils'
|
|
17
|
+
import { ElTree } from 'element-plus'
|
|
18
|
+
import { computed } from 'vue'
|
|
19
|
+
|
|
20
|
+
import { type VroElTreeKey, type VroElTreeOption, vroElTreeProps } from './types'
|
|
21
|
+
|
|
22
|
+
defineOptions({ name: 'VroElTree' })
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits<{
|
|
25
|
+
(event: 'update:modelValue', value: VroElTreeKey[]): void
|
|
26
|
+
}>()
|
|
27
|
+
const props = defineProps(vroElTreeProps)
|
|
28
|
+
|
|
29
|
+
const checkedKeys = computed(() => {
|
|
30
|
+
const { modelValue, options, rootId } = props
|
|
31
|
+
const { childIds, mapping } = parseNodeIds(options)
|
|
32
|
+
const modelValueMap = modelValue.reduce(
|
|
33
|
+
(acc, id) => {
|
|
34
|
+
acc[id] = true
|
|
35
|
+
return acc
|
|
36
|
+
},
|
|
37
|
+
{} as Record<VroElTreeKey, boolean>,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const loop = (id: VroElTreeKey): boolean => {
|
|
41
|
+
if (id === rootId) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
if (!modelValueMap[id]) {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
const parentId = mapping[id]
|
|
48
|
+
return !isUndefined(parentId) && loop(parentId)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return childIds.filter(loop)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const handleCheck = (_: any, data: any) => {
|
|
55
|
+
const { checkedKeys, halfCheckedKeys } = data
|
|
56
|
+
emit('update:modelValue', [...halfCheckedKeys, ...checkedKeys])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseNodeIds(
|
|
60
|
+
data: VroElTreeOption[],
|
|
61
|
+
mapping: Partial<Record<VroElTreeKey, VroElTreeKey>> = {},
|
|
62
|
+
) {
|
|
63
|
+
const childIds: VroElTreeKey[] = []
|
|
64
|
+
|
|
65
|
+
data.forEach((item) => {
|
|
66
|
+
if (!isUndefined(item.parentId)) {
|
|
67
|
+
mapping[item.id] = item.parentId
|
|
68
|
+
}
|
|
69
|
+
if (item.children && item.children.length > 0) {
|
|
70
|
+
const res = parseNodeIds(item.children ?? [], mapping)
|
|
71
|
+
childIds.push(...res.childIds)
|
|
72
|
+
} else {
|
|
73
|
+
childIds.push(item.id)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
return { childIds, mapping }
|
|
77
|
+
}
|
|
78
|
+
</script>
|