update: 优化场景联动 DropdownMenus布尔值
This commit is contained in:
parent
b583fa77a9
commit
7427301495
|
@ -135,11 +135,10 @@ const timeSelect = (v: string) => {
|
|||
emit('select', v)
|
||||
}
|
||||
|
||||
const menuSelect = (v: any) => {
|
||||
const option = getOption(props.options, props.value, props.valueName)
|
||||
selectValue.value = v.key
|
||||
const menuSelect = (v: string, option: any) => {
|
||||
selectValue.value = v
|
||||
visible.value = false
|
||||
emit('update:value', v.key)
|
||||
emit('update:value', v)
|
||||
emit('select', option)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
</template>
|
||||
|
||||
<script lang='ts' setup name='DropdownMenus'>
|
||||
import { isBoolean } from 'lodash-es'
|
||||
import { isBoolean, isUndefined } from 'lodash-es'
|
||||
import { getOption } from '../DropdownButton/util'
|
||||
|
||||
type ValueType = string| number | boolean
|
||||
type Emits = {
|
||||
(e: 'update:value', value: ValueType): void
|
||||
(e: 'click', data: any): void
|
||||
(e: 'click', value: string, data: any): void
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
|
@ -32,25 +32,32 @@ const emit = defineEmits<Emits>()
|
|||
const myOptions = computed(() => {
|
||||
return props.options.map((item: any) => {
|
||||
let _label = item.label || item.name
|
||||
if (isBoolean(item.value)) {
|
||||
_label = item.value === true ? '是' : '否'
|
||||
let _value = isUndefined(item.value) ? item.id : item.value
|
||||
if (isBoolean(_value)) {
|
||||
_label = _value === true ? '是' : '否'
|
||||
_value = String(_value)
|
||||
}
|
||||
return {
|
||||
...item,
|
||||
label: _label,
|
||||
value: item.value || item.id,
|
||||
value: _value
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const myValue = ref(props.value)
|
||||
|
||||
const handleBoolean = (key: string) => {
|
||||
return key === 'false' ? false : true
|
||||
}
|
||||
|
||||
const click = (e: any) => {
|
||||
const option = getOption(myOptions.value, e.key)
|
||||
myValue.value = e.key
|
||||
emit('update:value', e.key)
|
||||
emit('click', {
|
||||
key: e.key,
|
||||
const _key = ['true', 'false'].includes(e.key) ? handleBoolean(e.key) : e.key
|
||||
const option = getOption(myOptions.value, _key)
|
||||
myValue.value = _key
|
||||
emit('update:value', _key)
|
||||
emit('click', _key, {
|
||||
key: _key,
|
||||
...option
|
||||
})
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export const getComponent = (type: string): string => {
|
|||
|
||||
export const getOption = (data: any[], value?: string | number | boolean, key: string = 'name'): DropdownButtonOptions | any => {
|
||||
let option
|
||||
if (!value) return option
|
||||
if (value === undefined && value === null) return option
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const item = data[i]
|
||||
if (item[key] === value) {
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
v-model:visible='visible'
|
||||
@visibleChange='visibleChange'
|
||||
>
|
||||
<div>
|
||||
<div @click.prevent='visible = true'>
|
||||
<slot :label='label'>
|
||||
<div class='dropdown-button value' @click.prevent='visible = true'>
|
||||
<div class='dropdown-button value'>
|
||||
<AIcon v-if='!!icon' :type='icon' />
|
||||
{{ label }}
|
||||
</div>
|
||||
|
@ -30,7 +30,7 @@
|
|||
<DropdownMenus
|
||||
v-if='["select","enum", "boolean"].includes(item.component)'
|
||||
:options='["metric", "upper"].includes(item.key) ? metricOption : options'
|
||||
@change='onSelect'
|
||||
@click='onSelect'
|
||||
/>
|
||||
<div
|
||||
v-else-if='item.component === "tree"'
|
||||
|
@ -122,7 +122,8 @@ const valueItemChange = (e: string) => {
|
|||
emit('select', e)
|
||||
}
|
||||
|
||||
const sonSelect = (e: string, option: any) => {
|
||||
const onSelect = (e: string, option: any) => {
|
||||
console.log(e, option)
|
||||
visible.value = false
|
||||
label.value = option.label
|
||||
emit('update:value', e)
|
||||
|
|
|
@ -82,6 +82,7 @@ const handleParamsData = (data: any[]): any[] => {
|
|||
return {
|
||||
...item,
|
||||
key: item.column,
|
||||
disabled: !!item.children,
|
||||
children: handleParamsData(item.children)
|
||||
}
|
||||
}) || []
|
||||
|
|
Loading…
Reference in New Issue