el-plus-crud 0.1.37 → 0.1.39
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/CHANGELOG.md +4 -0
- package/dist/el-plus-crud.mjs +2129 -2099
- package/lib/components/el-plus-form/ElPlusForm.vue +2 -1
- package/lib/components/el-plus-form/components/ElPlusFormSelect.vue +12 -8
- package/lib/components/el-plus-form/components/ElPlusFormTree.vue +69 -11
- package/lib/components/el-plus-table/ElPlusTable.vue +1 -1
- package/package.json +1 -1
|
@@ -260,6 +260,7 @@ const computedRules = computed(() => {
|
|
|
260
260
|
case 'link':
|
|
261
261
|
case 'radio':
|
|
262
262
|
case 'checkbox':
|
|
263
|
+
case 'tree':
|
|
263
264
|
rules = 'select'
|
|
264
265
|
break
|
|
265
266
|
case 'daterange':
|
|
@@ -852,7 +853,7 @@ onMounted(async () => {
|
|
|
852
853
|
})
|
|
853
854
|
|
|
854
855
|
// 暴露对外方法
|
|
855
|
-
defineExpose({ fid: props.fid, submit: handleSubmitForm, getData: getFormData, validate: validateForm, reset, clearValid, clear, changeValidImg, refresh, init })
|
|
856
|
+
defineExpose({ fid: props.fid, formRef: refElPlusForm, submit: handleSubmitForm, getData: getFormData, validate: validateForm, reset, clearValid, clear, changeValidImg, refresh, init })
|
|
856
857
|
</script>
|
|
857
858
|
<style lang="scss">
|
|
858
859
|
.el-plus-form-panel {
|
|
@@ -131,7 +131,7 @@ async function queryOptionsFn(query: string) {
|
|
|
131
131
|
* 初始化默认项
|
|
132
132
|
*/
|
|
133
133
|
function initDefault() {
|
|
134
|
-
if (props.desc.defaultKey) {
|
|
134
|
+
if (oldQuery.value === null && props.desc.defaultKey) {
|
|
135
135
|
let defaultValue = props.formData[props.desc.defaultKey.value]
|
|
136
136
|
if (!Array.isArray(defaultValue)) defaultValue = [defaultValue]
|
|
137
137
|
let defaultLabel = props.formData[props.desc.defaultKey.label]
|
|
@@ -140,12 +140,15 @@ function initDefault() {
|
|
|
140
140
|
if (defaultValue.length <= 0 || defaultValue.length !== defaultLabel.length) return
|
|
141
141
|
// 遍历
|
|
142
142
|
defaultValue.map((val: any, i: number) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
if (val) {
|
|
144
|
+
// 这里需要判断下默认值是否已经出现在了options中,如果存在,则需要删除
|
|
145
|
+
const index = options.findIndex((item) => item.value === val)
|
|
146
|
+
if (index >= 0) {
|
|
147
|
+
options.splice(index, 1)
|
|
148
|
+
}
|
|
149
|
+
options.unshift({ value: val, label: defaultLabel[i], dataItem: cloneDeep(props.formData) })
|
|
150
|
+
}
|
|
147
151
|
})
|
|
148
|
-
console.log('options: ', options)
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
@@ -164,7 +167,6 @@ onBeforeMount(async () => {
|
|
|
164
167
|
attrs.value = await getAttrs(props, tempAttr)
|
|
165
168
|
attrs.value.remote = !!props.desc.remote
|
|
166
169
|
delete attrs.value.disabled
|
|
167
|
-
initDefault()
|
|
168
170
|
isInit.value = true
|
|
169
171
|
})
|
|
170
172
|
|
|
@@ -201,8 +203,10 @@ watch(
|
|
|
201
203
|
currentValue.value = (val as Array<string>).filter((item) => typeof item !== 'string' || item.length <= (defaultConf.form?.leng?.input || 20))
|
|
202
204
|
}
|
|
203
205
|
}
|
|
206
|
+
// 处理一下默认值
|
|
207
|
+
initDefault()
|
|
204
208
|
},
|
|
205
|
-
{ immediate: true
|
|
209
|
+
{ immediate: true }
|
|
206
210
|
)
|
|
207
211
|
|
|
208
212
|
defineExpose({ field: props.field, clear })
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<div class="el-plus-form-tree">
|
|
3
|
+
<template v-if="attrs.showCheckbox && !attrs.noSelectAll">
|
|
4
|
+
<div class="btns">
|
|
5
|
+
<el-checkbox v-model="selectAll" @change="handelSelectAll" label="全部勾选" border />
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
<el-tree ref="treeRef" v-if="isInit" :class="desc.class" :style="desc.style" v-bind="attrs" :disabled="disabled" :default-checked-keys="currentValue" :loading="loading" node-key="id" :data="options" v-on="onEvents" class="el-plus-form-tree" @check-change="handelCheckChange" />
|
|
9
|
+
</div>
|
|
3
10
|
</template>
|
|
4
11
|
<script lang="ts">
|
|
5
12
|
export default {
|
|
@@ -11,13 +18,15 @@ export default {
|
|
|
11
18
|
</script>
|
|
12
19
|
<script lang="ts" setup>
|
|
13
20
|
import { isEqual } from '../../../util'
|
|
14
|
-
import { ref, reactive, useAttrs, onBeforeMount, watch, inject } from 'vue'
|
|
21
|
+
import { ref, reactive, useAttrs, onBeforeMount, watch, inject, nextTick } from 'vue'
|
|
15
22
|
import { getAttrs, getEvents } from '../mixins'
|
|
23
|
+
import { useVModel } from '@vueuse/core'
|
|
24
|
+
import { cloneDeep } from 'lodash'
|
|
16
25
|
|
|
17
26
|
const globalData = inject('globalData') as any
|
|
18
27
|
|
|
19
28
|
const props = defineProps<{
|
|
20
|
-
modelValue?: string
|
|
29
|
+
modelValue?: Array<string>
|
|
21
30
|
field?: string
|
|
22
31
|
loading?: boolean
|
|
23
32
|
desc: { [key: string]: any }
|
|
@@ -25,8 +34,8 @@ const props = defineProps<{
|
|
|
25
34
|
disabled?: boolean
|
|
26
35
|
}>()
|
|
27
36
|
|
|
28
|
-
const emits = defineEmits(['update:modelValue'])
|
|
29
|
-
const currentValue =
|
|
37
|
+
const emits = defineEmits(['update:modelValue', 'validateThis'])
|
|
38
|
+
const currentValue = useVModel(props, 'modelValue', emits)
|
|
30
39
|
|
|
31
40
|
const options = reactive([] as any[])
|
|
32
41
|
const isInit = ref(false)
|
|
@@ -34,14 +43,54 @@ const attrs = ref({} as any)
|
|
|
34
43
|
const onEvents = ref(getEvents(props))
|
|
35
44
|
|
|
36
45
|
const treeRef = ref()
|
|
46
|
+
const selectAll = ref(false)
|
|
47
|
+
const allIds = ref([] as any[])
|
|
37
48
|
|
|
38
49
|
onBeforeMount(async () => {
|
|
39
|
-
attrs.value = await getAttrs(props, { checkStrictly: true, showCheckbox: true, accordion: true, props: { label: 'label', children: 'children' }, ...useAttrs() })
|
|
50
|
+
attrs.value = await getAttrs(props, { checkStrictly: true, showCheckbox: true, accordion: true, noSelectAll: false, props: { label: 'label', children: 'children' }, ...useAttrs() })
|
|
51
|
+
if (attrs.value.showCheckbox && !attrs.value.noSelectAll && options.length) {
|
|
52
|
+
allIds.value = getLoopIds(options)
|
|
53
|
+
}
|
|
40
54
|
isInit.value = true
|
|
41
55
|
})
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
/**
|
|
58
|
+
* 处理单个checkbox改变
|
|
59
|
+
*/
|
|
60
|
+
function handelCheckChange(item: any, isSelect: boolean) {
|
|
61
|
+
currentValue.value = treeRef.value!.getCheckedKeys(!(props.desc.isPId ?? true))
|
|
62
|
+
nextTick(() => {
|
|
63
|
+
// 这里判断一下全选状态
|
|
64
|
+
selectAll.value = isSelect && allIds.value.length === currentValue.value?.length
|
|
65
|
+
emits('validateThis')
|
|
66
|
+
console.log('validateThis******************')
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 处理权限
|
|
72
|
+
*/
|
|
73
|
+
function handelSelectAll() {
|
|
74
|
+
let selectIds = [] as any[]
|
|
75
|
+
if (selectAll.value) selectIds = cloneDeep(allIds.value)
|
|
76
|
+
currentValue.value = selectIds
|
|
77
|
+
treeRef.value!.setCheckedKeys(currentValue.value)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 递归获取id
|
|
82
|
+
*/
|
|
83
|
+
function getLoopIds(list: Array<any>) {
|
|
84
|
+
const tempIds = [] as any[]
|
|
85
|
+
if (list?.length) {
|
|
86
|
+
list.map((item) => {
|
|
87
|
+
if (item[attrs.value.props.children]?.length) {
|
|
88
|
+
tempIds.push(...getLoopIds(item[attrs.value.props.children]))
|
|
89
|
+
}
|
|
90
|
+
tempIds.push(item.id)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
return tempIds
|
|
45
94
|
}
|
|
46
95
|
|
|
47
96
|
watch(
|
|
@@ -59,6 +108,10 @@ watch(
|
|
|
59
108
|
} else {
|
|
60
109
|
options.splice(0, options.length)
|
|
61
110
|
}
|
|
111
|
+
// 如果是复选,这里重新获取下所有IDs
|
|
112
|
+
if (attrs.value.showCheckbox && !attrs.value.noSelectAll) {
|
|
113
|
+
allIds.value = getLoopIds(options)
|
|
114
|
+
}
|
|
62
115
|
},
|
|
63
116
|
{ immediate: true }
|
|
64
117
|
)
|
|
@@ -66,14 +119,19 @@ watch(
|
|
|
66
119
|
watch(
|
|
67
120
|
() => props.modelValue,
|
|
68
121
|
(val) => {
|
|
69
|
-
|
|
70
|
-
treeRef.value!.setCheckedKeys(currentValue.value)
|
|
122
|
+
treeRef.value!.setCheckedKeys(val || [])
|
|
71
123
|
}
|
|
72
124
|
)
|
|
73
125
|
</script>
|
|
74
126
|
<style lang="scss" scoped>
|
|
75
127
|
.el-plus-form-tree {
|
|
76
128
|
width: 100%;
|
|
129
|
+
display: flex;
|
|
130
|
+
flex-direction: column;
|
|
131
|
+
.btns {
|
|
132
|
+
width: 100%;
|
|
133
|
+
padding-left: 12px;
|
|
134
|
+
margin-bottom: 8px;
|
|
135
|
+
}
|
|
77
136
|
}
|
|
78
137
|
</style>
|
|
79
|
-
../util/aaaaa
|
|
@@ -816,7 +816,7 @@ onMounted(() => {
|
|
|
816
816
|
}
|
|
817
817
|
})
|
|
818
818
|
|
|
819
|
-
defineExpose({ reload, tableData, changeSelect, resetSelect, initCol })
|
|
819
|
+
defineExpose({ tableRef: elPlusTableRef, reload, tableData, changeSelect, resetSelect, initCol })
|
|
820
820
|
</script>
|
|
821
821
|
<style lang="scss">
|
|
822
822
|
.dark .el-plus-table-content {
|