From f2200df15a02721126de2bc9ab665c0508554ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 8 Sep 2023 17:41:14 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20!pr417=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81vue3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/DictTag/index.vue | 36 +++++++++---------- ruoyi-ui/src/components/DictTag/index.vue | 4 +-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/ruoyi-ui-vue3/src/components/DictTag/index.vue b/ruoyi-ui-vue3/src/components/DictTag/index.vue index 3b9511796..e2b40f5ec 100644 --- a/ruoyi-ui-vue3/src/components/DictTag/index.vue +++ b/ruoyi-ui-vue3/src/components/DictTag/index.vue @@ -41,34 +41,30 @@ const props = defineProps({ type: Boolean, default: true, }, + separator: { + type: String, + default: ",", + } }); const values = computed(() => { - if (props.value !== null && typeof props.value !== 'undefined') { - return Array.isArray(props.value) ? props.value : [String(props.value)]; - } else { - return []; - } + if (props.value === null || typeof props.value === 'undefined' || props.value === '') return []; + return Array.isArray(props.value) ? props.value.map(item => '' + item) : String(props.value).split(props.separator); }); const unmatch = computed(() => { unmatchArray.value = []; - if (props.value !== null && typeof props.value !== "undefined") { - // 传入值为非数组 - if (!Array.isArray(props.value)) { - if (props.options.some((v) => v.value == props.value)) return false; - unmatchArray.value.push(props.value); - return true; - } - // 传入值为Array - props.value.forEach((item) => { - if (!props.options.some((v) => v.value == item)) - unmatchArray.value.push(item); - }); - return true; - } // 没有value不显示 - return false; + if (props.value === null || typeof props.value === 'undefined' || props.value === '' || props.options.length === 0) return false + // 传入值为数组 + let unmatch = false // 添加一个标志来判断是否有未匹配项 + values.value.forEach(item => { + if (!props.options.some(v => v.value === item)) { + unmatchArray.value.push(item) + unmatch = true // 如果有未匹配项,将标志设置为true + } + }) + return unmatch // 返回标志的值 }); function handleArray(array) { diff --git a/ruoyi-ui/src/components/DictTag/index.vue b/ruoyi-ui/src/components/DictTag/index.vue index c3429e559..417b97aa4 100644 --- a/ruoyi-ui/src/components/DictTag/index.vue +++ b/ruoyi-ui/src/components/DictTag/index.vue @@ -53,13 +53,13 @@ export default { }, computed: { values() { - if (this.value === null || typeof this.value !== 'undefined' || this.value === '') return [] + if (this.value === null || typeof this.value === 'undefined' || this.value === '') return [] return Array.isArray(this.value) ? this.value.map(item => '' + item) : String(this.value).split(this.separator) }, unmatch() { this.unmatchArray = [] // 没有value不显示 - if (this.value === null || typeof this.value !== 'undefined' || this.value === '' || this.options.length === 0) return false + if (this.value === null || typeof this.value === 'undefined' || this.value === '' || this.options.length === 0) return false // 传入值为数组 let unmatch = false // 添加一个标志来判断是否有未匹配项 this.values.forEach(item => {