From 557dbb313fdfaf1944732eaec737d1a20849e66a Mon Sep 17 00:00:00 2001 From: zhengliming Date: Sun, 21 Jan 2024 23:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90add=E3=80=91=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5list=20ob?= =?UTF-8?q?j=E5=AF=B9=E8=B1=A1=E5=88=97=E8=A1=A8=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=8C=87=E5=AE=9A=E6=98=BE=E7=A4=BA=E5=AF=B9=E5=BA=94?= =?UTF-8?q?keyValue=E5=AF=B9=E5=BA=94=E7=9A=84=E5=88=97=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=87=AA=E5=AE=9A=E4=B9=89key=E7=9A=84?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E9=80=9A=E8=BF=87:keyName=3D'key'=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=EF=BC=8C=E9=BB=98=E8=AE=A4=E6=98=AF=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E4=B8=BA=E2=80=98key=E2=80=99=EF=BC=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E6=98=BE=E7=A4=BA=E7=9A=84value=E7=9A=84?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=EF=BC=8C=E9=80=9A=E8=BF=87:valueName=3D'valu?= =?UTF-8?q?e'=20=E4=BC=A0=E5=85=A5=EF=BC=8C=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E5=90=8D=E7=A7=B0=E6=98=AFvalue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tn-notice-bar/tn-notice-bar.vue | 76 +++++++++++++++++-- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/tuniao-ui/components/tn-notice-bar/tn-notice-bar.vue b/tuniao-ui/components/tn-notice-bar/tn-notice-bar.vue index 22b1974..7bda1ac 100644 --- a/tuniao-ui/components/tn-notice-bar/tn-notice-bar.vue +++ b/tuniao-ui/components/tn-notice-bar/tn-notice-bar.vue @@ -12,7 +12,7 @@ :fontColor="fontColor" :fontSize="fontSize" :fontUnit="fontUnit" - :list="list" + :list="valueList" :show="show" :playStatus="playStatus" :leftIcon="leftIcon" @@ -38,7 +38,7 @@ :fontColor="fontColor" :fontSize="fontSize" :fontUnit="fontUnit" - :list="list" + :list="valueList" :show="show" :mode="mode" :playStatus="playStatus" @@ -76,6 +76,18 @@ return [] } }, + keyName:{ + type:String, + default: 'key' + }, + valueName:{ + type:String, + default: 'value' + }, + keyValue:{ + type:String, + default: undefined + }, // 是否显示 show: { type: Boolean, @@ -167,24 +179,61 @@ computed: { // 当设置了show为false,或者autoHidden为true且list为空时,不显示通知 showNotice() { - if (this.show === false || (this.autoHidden && this.list.length === 0)) return false - else return true + return !(this.show === false || (this.autoHidden && this.list.length === 0)) } }, + watch:{ + keyValue:{ + handler(value) { + this.loadList(); + }, + deep: true + }, + }, data() { return { - + //显示的值 + valueList:[], } }, + mounted() { + this.loadList(); + }, methods: { // 点击了通知栏 click(index) { - this.$emit('click', index) + let value = this.findValue(index); + //如果是对象,返回传入的对象 + if (this.isObj(value)){ + this.$emit('click', value) + }else { + this.$emit('click', index) + } }, + findValue(findIndex){ + let objList = [] + for (let index in this.list){ + let v = this.list[index]; + if (this.isObj(v)){ + //判断是否指定key显示,如果是则显示指定的列表,否则就返回所有列表 + if (this.keyValue == undefined || v[this.keyName] == this.keyValue){ + objList.push(v); + } + }else{ + //兼容旧的,旧的直接返回下表 + return findIndex; + } + } + return findIndex >= objList.length ? undefined : objList[findIndex]; + }, // 点击了关闭按钮 close() { this.$emit('close') }, + //判断元素是否是对象 + isObj(value){ + return typeof(value) === 'object'; + }, // 点击了左边图标 clickLeftIcon() { this.$emit('clickLeft') @@ -196,6 +245,21 @@ // 一个周期滚动结束 end() { this.$emit('end') + }, + loadList() { + let tmpList = []; + for (let index in this.list) { + let v = this.list[index]; + if (this.isObj(v)) { + //判断是否指定key显示,如果是则显示指定的列表,否则就返回所有列表 + if (this.keyValue == undefined || v[this.keyName] == this.keyValue) { + tmpList.push(v[this.valueName]); + } + } else { + tmpList.push(v); + } + } + this.valueList = tmpList; } } }