From 40dc1b51ed79d54a6be4f11ffd7e1777c8d13ee3 Mon Sep 17 00:00:00 2001 From: TianHeng2017 Date: Thu, 5 Jun 2025 10:44:18 +0800 Subject: [PATCH 1/2] Update uni-data-select.vue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增property:dataKey、dataValue,让数据格式更灵活,从固定的[{text:'',value:''}]形式改为可通过dataKey、dataValue自定义,比如[{name:'',value:''}] --- .../uni-data-select/uni-data-select.vue | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue b/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue index cad39e3c..45ed5e3f 100644 --- a/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue +++ b/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue @@ -44,6 +44,8 @@ * @property {String} placeholder 输入框的提示文字 * @property {Boolean} disabled 是否禁用 * @property {String} placement 弹出位置 + * @property {String} dataKey 作为 key 唯一标识的键名 + * @property {String} dataValue 作为 value 唯一标识的键名 * @value top 顶部弹出 * @value bottom 底部弹出(default) * @event {Function} change 选中发生变化触发 @@ -99,6 +101,14 @@ placement: { type: String, default: 'bottom' + }, + dataKey: { + type: [String], + default: "text" + }, + dataValue: { + type: [String], + default: "value" } }, data() { @@ -211,7 +221,7 @@ } else { let defItem = '' if (this.defItem > 0 && this.defItem <= this.mixinDatacomResData.length) { - defItem = this.mixinDatacomResData[this.defItem - 1].value + defItem = this.mixinDatacomResData[this.defItem - 1][this.dataValue] } defValue = defItem } @@ -219,7 +229,7 @@ this.emit(defValue) } } - const def = this.mixinDatacomResData.find(item => item.value === defValue) + const def = this.mixinDatacomResData.find(item => item[this.dataValue] === defValue) this.current = def ? this.formatItemName(def) : '' }, @@ -231,7 +241,7 @@ let isDisabled = false; this.mixinDatacomResData.forEach(item => { - if (item.value === value) { + if (item[this.dataValue] === value) { isDisabled = item.disable } }) @@ -269,11 +279,12 @@ this.showSelector = !this.showSelector }, formatItemName(item) { - let { - text, - value, - channel_code - } = item + if (!item) { + return "" + } + let text = item[this.dataKey] + let value = item[this.dataValue] + let { channel_code } = item channel_code = channel_code ? `(${channel_code})` : '' if (this.format) { @@ -349,7 +360,7 @@ box-sizing: border-box; } - .uni-stat-box { + .uni-stat-box { background-color: #fff; width: 100%; flex: 1; @@ -403,7 +414,7 @@ } .uni-select__input-box { - height: 35px; + height: 35px; width: 0px; position: relative; /* #ifndef APP-NVUE */ @@ -411,7 +422,7 @@ /* #endif */ flex: 1; flex-direction: row; - align-items: center; + align-items: center; } .uni-select__input { From 7e75840705fe8cb5b4d33c57126c73bef10ebc25 Mon Sep 17 00:00:00 2001 From: TianHeng2017 Date: Thu, 5 Jun 2025 11:17:07 +0800 Subject: [PATCH 2/2] Update uni-data-select.vue --- .../uni-data-select/uni-data-select.vue | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue b/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue index 45ed5e3f..ee70e0f4 100644 --- a/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue +++ b/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue @@ -20,9 +20,18 @@ {{emptyTips}} - - {{formatItemName(item)}} + + {{ + formatItemName(item) + }} + @@ -570,4 +579,10 @@ left: 0; z-index: 2; } + + .uni-select_selector-item_active { + color: #409eff; + font-weight: bold; + background-color: #f5f7fa; + }