Skip to content

Update uni-data-select.vue #1018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@
<view class="uni-select__selector-empty" v-if="mixinDatacomResData.length === 0">
<text>{{emptyTips}}</text>
</view>
<view v-else class="uni-select__selector-item" v-for="(item,index) in mixinDatacomResData" :key="index"
@click="change(item)">
<text :class="{'uni-select__selector__disabled': item.disable}">{{formatItemName(item)}}</text>
<view
v-else
class="uni-select__selector-item"
:class="{ 'uni-select_selector-item_active': item[dataKey] == current }"
style="display: flex; justify-content: space-between; align-items: center"
v-for="(item, index) in mixinDatacomResData"
:key="index"
@click="change(item)">
<text :class="{ 'uni-select__selector__disabled': item.disable }">{{
formatItemName(item)
}}</text>
<uni-icons v-if="item[dataKey] == current" type="checkmarkempty" color="#007aff" />
</view>
</scroll-view>
</view>
Expand All @@ -44,6 +53,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 选中发生变化触发
Expand Down Expand Up @@ -99,6 +110,14 @@
placement: {
type: String,
default: 'bottom'
},
dataKey: {
type: [String],
default: "text"
},
dataValue: {
type: [String],
default: "value"
}
},
data() {
Expand Down Expand Up @@ -211,15 +230,15 @@
} 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
}
if (defValue || defValue === 0) {
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) : ''
},

Expand All @@ -231,7 +250,7 @@
let isDisabled = false;

this.mixinDatacomResData.forEach(item => {
if (item.value === value) {
if (item[this.dataValue] === value) {
isDisabled = item.disable
}
})
Expand Down Expand Up @@ -269,11 +288,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) {
Expand Down Expand Up @@ -349,7 +369,7 @@
box-sizing: border-box;
}

.uni-stat-box {
.uni-stat-box {
background-color: #fff;
width: 100%;
flex: 1;
Expand Down Expand Up @@ -403,15 +423,15 @@
}

.uni-select__input-box {
height: 35px;
height: 35px;
width: 0px;
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex: 1;
flex-direction: row;
align-items: center;
align-items: center;
}

.uni-select__input {
Expand Down Expand Up @@ -559,4 +579,10 @@
left: 0;
z-index: 2;
}

.uni-select_selector-item_active {
color: #409eff;
font-weight: bold;
background-color: #f5f7fa;
}
</style>