uview-plus 3.4.9 → 3.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md
CHANGED
|
@@ -1,93 +1,165 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-select">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
<view class="u-select__content">
|
|
4
|
+
<view class="u-select__label" @click="openSelect">
|
|
5
|
+
<slot name="text">
|
|
6
|
+
<text class="u-select__text" v-if="showOptionsLabel">
|
|
7
|
+
{{ currentLabel }}
|
|
8
|
+
</text>
|
|
9
|
+
<text class="u-select__text" v-else>
|
|
10
|
+
{{ label }}
|
|
11
|
+
</text>
|
|
12
|
+
</slot>
|
|
13
|
+
<slot name="icon">
|
|
14
|
+
<u-icon name="arrow-down" :size="iconSize" :color="iconColor"></u-icon>
|
|
15
|
+
</slot>
|
|
16
|
+
</view>
|
|
17
|
+
<u-overlay
|
|
18
|
+
:show="isOpen"
|
|
19
|
+
@click="overlayClick"
|
|
20
|
+
v-if="overlay"
|
|
21
|
+
:zIndex="zIndex"
|
|
22
|
+
:duration="duration + 50"
|
|
23
|
+
:customStyle="overlayStyle"
|
|
24
|
+
:opacity="overlayOpacity"
|
|
25
|
+
></u-overlay>
|
|
26
|
+
<view class="u-select__options__wrap"
|
|
27
|
+
:style="{ zIndex: zIndex + 1, left: optionsWrapLeft, right: optionsWrapRight }">
|
|
28
|
+
<view class="u-select__options" v-if="isOpen">
|
|
29
|
+
<slot name="options">
|
|
30
|
+
<view class="u-select__options_item"
|
|
31
|
+
:class="current == item[keyName] ? 'active': ''"
|
|
32
|
+
:key="index" v-for="(item, index) in options"
|
|
33
|
+
@click="selectItem(item)">
|
|
34
|
+
<slot name="optionItem" :item="item">
|
|
35
|
+
<text class="u-select__item_text" :style="{color: itemColor}">
|
|
36
|
+
{{item[labelName]}}
|
|
37
|
+
</text>
|
|
38
|
+
</slot>
|
|
39
|
+
</view>
|
|
40
|
+
</slot>
|
|
41
|
+
</view>
|
|
42
|
+
</view>
|
|
43
|
+
</view>
|
|
30
44
|
</view>
|
|
31
45
|
</template>
|
|
32
46
|
|
|
33
47
|
<script>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
type: String,
|
|
66
|
-
default: ''
|
|
67
|
-
},
|
|
68
|
-
iconSize: {
|
|
69
|
-
type: [String],
|
|
70
|
-
default: '13px'
|
|
71
|
-
}
|
|
72
|
-
} ,
|
|
73
|
-
data() {
|
|
74
|
-
return {
|
|
75
|
-
isOpen: false
|
|
48
|
+
import { getWindowInfo } from '../../libs/function/index';
|
|
49
|
+
export default {
|
|
50
|
+
name:"up-select",
|
|
51
|
+
emits: ['update:current', 'select'],
|
|
52
|
+
props: {
|
|
53
|
+
overlay: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: true
|
|
56
|
+
},
|
|
57
|
+
overlayOpacity: {
|
|
58
|
+
type: Number,
|
|
59
|
+
default: 0.01
|
|
60
|
+
},
|
|
61
|
+
overlayStyle: {
|
|
62
|
+
type: Object,
|
|
63
|
+
default: () => {
|
|
64
|
+
return {}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
duration: {
|
|
68
|
+
type: Number,
|
|
69
|
+
default: 300
|
|
70
|
+
},
|
|
71
|
+
label: {
|
|
72
|
+
type: String,
|
|
73
|
+
default: '选项'
|
|
74
|
+
},
|
|
75
|
+
options: {
|
|
76
|
+
type: Array,
|
|
77
|
+
default: () => {
|
|
78
|
+
return []
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
|
-
|
|
81
|
+
keyName: {
|
|
82
|
+
type: String,
|
|
83
|
+
default: 'id'
|
|
84
|
+
},
|
|
85
|
+
labelName: {
|
|
86
|
+
type: String,
|
|
87
|
+
default: 'name'
|
|
88
|
+
},
|
|
89
|
+
showOptionsLabel: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: false
|
|
92
|
+
},
|
|
93
|
+
current: {
|
|
94
|
+
type: [String, Number],
|
|
95
|
+
default: ''
|
|
96
|
+
},
|
|
97
|
+
zIndex: {
|
|
98
|
+
type: Number,
|
|
99
|
+
default: 11000
|
|
100
|
+
},
|
|
101
|
+
itemColor: {
|
|
102
|
+
type: String,
|
|
103
|
+
default: '#333333'
|
|
104
|
+
},
|
|
105
|
+
iconColor: {
|
|
106
|
+
type: String,
|
|
107
|
+
default: ''
|
|
108
|
+
},
|
|
109
|
+
iconSize: {
|
|
110
|
+
type: [String],
|
|
111
|
+
default: '13px'
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
data() {
|
|
115
|
+
return {
|
|
116
|
+
isOpen: false,
|
|
117
|
+
optionsWrapLeft: 'auto',
|
|
118
|
+
optionsWrapRight: 'auto'
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
computed: {
|
|
122
|
+
currentLabel() {
|
|
123
|
+
let name = '';
|
|
124
|
+
this.options.forEach((ele) => {
|
|
125
|
+
if (ele[this.keyName] === this.current) {
|
|
126
|
+
name = ele[this.labelName];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return name;
|
|
130
|
+
}
|
|
79
131
|
},
|
|
80
132
|
methods: {
|
|
81
133
|
openSelect() {
|
|
82
|
-
this.isOpen =
|
|
134
|
+
this.isOpen = true;
|
|
135
|
+
this.$nextTick(() => {
|
|
136
|
+
if (this.isOpen) {
|
|
137
|
+
this.adjustOptionsWrapPosition();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
83
140
|
},
|
|
141
|
+
overlayClick() {
|
|
142
|
+
this.isOpen = false;
|
|
143
|
+
},
|
|
84
144
|
selectItem(item) {
|
|
85
|
-
this.isOpen = false
|
|
86
|
-
this.$emit('update:current', item[this.keyName])
|
|
87
|
-
this.$emit('select', item)
|
|
88
|
-
}
|
|
145
|
+
this.isOpen = false;
|
|
146
|
+
this.$emit('update:current', item[this.keyName]);
|
|
147
|
+
this.$emit('select', item);
|
|
148
|
+
},
|
|
149
|
+
adjustOptionsWrapPosition() {
|
|
150
|
+
let wi = getWindowInfo();
|
|
151
|
+
let windowWidth = wi.windowWidth;
|
|
152
|
+
this.$uGetRect('.u-select__options__wrap').then(rect => {
|
|
153
|
+
console.log(rect)
|
|
154
|
+
if (rect.left + rect.width > windowWidth) {
|
|
155
|
+
// 如果右侧被遮挡,则调整到左侧
|
|
156
|
+
this.optionsWrapLeft = 'auto';
|
|
157
|
+
this.optionsWrapRight = `0px`;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
89
161
|
}
|
|
90
|
-
|
|
162
|
+
}
|
|
91
163
|
</script>
|
|
92
164
|
|
|
93
165
|
<style lang="scss" scoped>
|
|
@@ -95,6 +167,7 @@
|
|
|
95
167
|
position: relative;
|
|
96
168
|
.u-select__label {
|
|
97
169
|
display: flex;
|
|
170
|
+
justify-content: space-between;
|
|
98
171
|
/* #ifdef H5 */
|
|
99
172
|
&:hover {
|
|
100
173
|
cursor: pointer;
|
|
@@ -104,17 +177,20 @@
|
|
|
104
177
|
.u-select__text {
|
|
105
178
|
margin-right: 2px;
|
|
106
179
|
}
|
|
180
|
+
.u-select__options__wrap {
|
|
181
|
+
margin-bottom: 46px;
|
|
182
|
+
position: absolute;
|
|
183
|
+
top: 20px;
|
|
184
|
+
left: 0;
|
|
185
|
+
}
|
|
107
186
|
.u-select__options {
|
|
108
|
-
min-width: 100px;
|
|
187
|
+
min-width: 100px;
|
|
109
188
|
box-sizing: border-box;
|
|
110
189
|
border-radius: 4px;
|
|
111
190
|
border: 1px solid #f1f1f1;
|
|
112
191
|
background-color: #fff;
|
|
113
|
-
position: absolute;
|
|
114
|
-
top: 20px;
|
|
115
|
-
left: 0;
|
|
116
192
|
.u-select__options_item {
|
|
117
|
-
padding: 10px 12px;
|
|
193
|
+
padding: 10px 12px;
|
|
118
194
|
box-sizing: border-box;
|
|
119
195
|
width: 100%;
|
|
120
196
|
height: 100%;
|
package/package.json
CHANGED