| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <template>
- <view class="u-select" @click="close" :class="{ disabled: disabled }">
- <view class="u-select__content">
- <view class="u-select__label" @click.stop="openSelect">
- <slot name="text">
- <trans class="u-select__text" :_t="label" />
- </slot>
- <slot name="icon" v-if="!icon">
- <u-icon
- name="arrow-down"
- :size="iconSize"
- :color="iconColor"
- ></u-icon>
- </slot>
- </view>
- <view class="u-select__options" :style="{ zIndex: zIndex }" v-if="isOpen">
- <slot name="options">
- <view class="options" v-if="options.length">
- <view
- class="u-select__options_item"
- :class="current == index ? 'active' : ''"
- :key="index"
- v-for="(item, index) in options"
- @click.stop="selectItem(item, index)"
- >
- <slot name="optionItem" :item="item">
- <trans
- class="u-select__item_text"
- :style="{ color: itemColor }"
- :_t="item[keyName]"
- v-if="!isTran"
- />
- <text
- class="u-select__item_text"
- :style="{ color: itemColor }"
- v-else
- >
- {{ item[keyName] }}
- </text>
- </slot>
- </view>
- </view>
- <view class="_no" v-else>
- <trans class="no_text" _t="无数据" />
- </view>
- </slot>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: "up-select",
- emits: ["update:current", "select", "selectClick"],
- props: {
- label: {
- type: String,
- default: "选项",
- },
- options: {
- type: Array,
- default: () => {
- return [];
- },
- },
- keyName: {
- type: String,
- default: "name",
- },
- current: {
- type: [String, Number],
- default: "",
- },
- zIndex: {
- type: Number,
- default: 10,
- },
- itemColor: {
- type: String,
- default: "#333333",
- },
- iconColor: {
- type: String,
- default: "",
- },
- iconSize: {
- type: [String],
- default: "13px",
- },
- icon: Boolean,
- isTran: Boolean,
- disabled: {
- // 新增的禁用属性
- type: Boolean,
- default: false,
- },
- },
- data() {
- return {
- isOpen: false,
- };
- },
- methods: {
- openSelect() {
- this.isOpen = !this.isOpen;
- this.$emit("selectClick");
- },
- close() {
- this.isOpen = false;
- },
- selectItem(item, index) {
- this.isOpen = false;
- this.$emit("update:current", index);
- this.$emit("select", item);
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .u-select__content {
- position: relative;
- .u-select__label {
- display: flex;
- font-size: 28rpx;
- font-weight: 500;
- line-height: 60rpx;
- margin: 0 8rpx;
- color: var(--text-02);
- /* #ifdef H5 */
- &:hover {
- cursor: pointer;
- }
- /* #endif */
- }
- .u-select__text {
- margin-right: 2px;
- }
- .u-select__options {
- min-width: 300rpx;
- box-sizing: border-box;
- border-radius: 4px;
- border: 1px solid #f1f1f1;
- background-color: #fff;
- position: absolute;
- top: auto;
- left: -10px;
- padding: 10rpx 0;
- box-shadow: 0px 0px 12px #0000001f;
- margin-top: 18rpx;
- overflow: hidden scroll;
- .options {
- max-height: 274px;
- overflow: hidden scroll;
- }
- .u-select__options_item {
- box-sizing: border-box;
- width: 100%;
- min-width: 300rpx;
- &:hover {
- background-color: #f7f7f7;
- }
- /* #ifdef H5 */
- &:hover {
- cursor: pointer;
- }
- .u-select__item_text {
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- &:hover {
- cursor: pointer;
- }
- }
- /* #endif */
- }
- }
- .u-select__options::after {
- content: "";
- position: absolute;
- left: 60rpx;
- top: -12rpx;
- // transform: translateX(-30%);
- border-left: 14rpx solid transparent;
- border-right: 14rpx solid transparent;
- border-bottom: 14rpx solid var(--light);
- z-index: 10;
- }
- }
- ._no {
- text-align: center;
- .no_text {
- padding: 20rpx 0;
- text-align: center;
- font-size: 24rpx;
- color: #909399;
- }
- }
- .disabled {
- pointer-events: none;
- border: 2rpx solid #dadbde !important;
- background-color: rgb(245, 247, 250) !important;
- box-shadow: 0 0 0 1px var(--borderColor) inset;
- color: #606266;
- }
- </style>
|