mirror of
https://gitee.com/JavaLionLi/plus-ui.git
synced 2025-12-30 09:52:27 +00:00
update 优化 字典组件值宽松匹配
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<template v-for="(item, index) in options">
|
<template v-for="(item, index) in options">
|
||||||
<template v-if="values.includes(item.value)">
|
<template v-if="isValueMatch(item.value)">
|
||||||
<span
|
<span
|
||||||
v-if="(item.elTagType === 'default' || item.elTagType === '') && (item.elTagClass === '' || item.elTagClass == null)"
|
v-if="(item.elTagType === 'default' || item.elTagType === '') && (item.elTagClass === '' || item.elTagClass == null)"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
@@ -50,6 +50,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
|
|
||||||
const values = computed(() => {
|
const values = computed(() => {
|
||||||
if (props.value === '' || props.value === null || typeof props.value === 'undefined') return [];
|
if (props.value === '' || props.value === null || typeof props.value === 'undefined') return [];
|
||||||
|
if (typeof props.value === 'number' || typeof props.value === 'boolean') return [props.value]
|
||||||
return Array.isArray(props.value) ? props.value.map((item) => '' + item) : String(props.value).split(props.separator);
|
return Array.isArray(props.value) ? props.value.map((item) => '' + item) : String(props.value).split(props.separator);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ const unmatch = computed(() => {
|
|||||||
// 传入值为非数组
|
// 传入值为非数组
|
||||||
let unmatch = false; // 添加一个标志来判断是否有未匹配项
|
let unmatch = false; // 添加一个标志来判断是否有未匹配项
|
||||||
values.value.forEach((item) => {
|
values.value.forEach((item) => {
|
||||||
if (!props.options.some((v) => v.value === item)) {
|
if (!props.options.some((v) => v.value == item)) {
|
||||||
unmatch = true; // 如果有未匹配项,将标志设置为true
|
unmatch = true; // 如果有未匹配项,将标志设置为true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -85,6 +86,10 @@ const handleArray = (array: Array<string | number>) => {
|
|||||||
return pre + ' ' + cur;
|
return pre + ' ' + cur;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isValueMatch = (itemValue: any) => {
|
||||||
|
return this.values.some(val => val == itemValue)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user