@cloudbase/weda-ui-mp 3.15.8 → 3.16.0
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/components/form/select/dropdown-select/index.js +8 -0
- package/components/form/select/dropdown-select/index.wxml +1 -1
- package/components/form/selectMultiple/dropdown-select/index.js +15 -17
- package/components/form/selectMultiple/dropdown-select/index.wxml +1 -1
- package/components/form/selectMultiple/index.js +29 -7
- package/components/form/selectMultiple/index.wxml +2 -1
- package/components/richText/copy/index.wxss +45 -48
- package/components/wd-select/index.js +18 -14
- package/components/wd-select/index.wxml +7 -3
- package/components/wd-select/select/dropdown-select/index.js +192 -0
- package/components/wd-select/select/dropdown-select/index.json +4 -0
- package/components/wd-select/select/dropdown-select/index.wxml +37 -0
- package/components/wd-select/select/dropdown-select/index.wxss +329 -0
- package/components/wd-select/select/formats-util.js +12 -1
- package/components/wd-select/select/index.js +208 -344
- package/components/wd-select/select/index.json +1 -1
- package/components/wd-select/select/index.wxml +16 -16
- package/components/wd-select-multiple/index.js +16 -8
- package/components/wd-select-multiple/index.json +1 -1
- package/components/wd-select-multiple/index.wxml +6 -2
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<view wx:if="{{!focus}}" class="weda-ui-custom-picker__header">
|
|
5
5
|
<button class="weda-ui-custom-picker__header-btn" bindtap="cancelPicker" data-clear="false">取消</button>
|
|
6
6
|
</view>
|
|
7
|
-
<view class="weda-ui-custom-search {{focus?'is-focused':''}}" style="{{focus? 'margin: 34rpx 32rpx 16rpx 32rpx':'margin: 20rpx 32rpx'}}">
|
|
7
|
+
<view wx:if="{{searchable}}" class="weda-ui-custom-search {{focus?'is-focused':''}}" style="{{focus? 'margin: 34rpx 32rpx 16rpx 32rpx':'margin: 20rpx 32rpx'}}">
|
|
8
8
|
<view class="weda-ui-custom-search-box" bindtap="onFocus">
|
|
9
9
|
<input class="weda-ui-input" focus="{{focus}}" bindfocus="onFocus" bindblur="onBlur" bindinput="bindinput" value="{{searchValue}}" hold-keyboard="true" bindconfirm="bindconfirm" />
|
|
10
10
|
<view class="weda-ui-custom-search-box__label">
|
|
@@ -36,14 +36,18 @@ Component({
|
|
|
36
36
|
type: Boolean,
|
|
37
37
|
value: true,
|
|
38
38
|
},
|
|
39
|
-
staticSearchable: {
|
|
40
|
-
type: Boolean,
|
|
41
|
-
value: true,
|
|
42
|
-
},
|
|
43
39
|
selectedValue: {
|
|
44
40
|
type: Array,
|
|
45
41
|
value: [],
|
|
46
42
|
},
|
|
43
|
+
searchable: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
value: true,
|
|
46
|
+
},
|
|
47
|
+
filterable: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
value: false,
|
|
50
|
+
},
|
|
47
51
|
},
|
|
48
52
|
data: {
|
|
49
53
|
height: '390px',
|
|
@@ -53,18 +57,12 @@ Component({
|
|
|
53
57
|
status: 0,
|
|
54
58
|
showOption: [],
|
|
55
59
|
searchPageNo: 1,
|
|
56
|
-
timeId: '',
|
|
57
60
|
pageNo: 1,
|
|
58
61
|
selectedCache: [], // 缓存当前选中值
|
|
59
62
|
},
|
|
60
63
|
|
|
61
64
|
lifetimes: {
|
|
62
|
-
detached() {
|
|
63
|
-
const id = this.data.timeId;
|
|
64
|
-
if (id !== '') {
|
|
65
|
-
clearTimeout(id);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
65
|
+
detached() {},
|
|
68
66
|
},
|
|
69
67
|
methods: {
|
|
70
68
|
cancelPicker: function (e) {
|
|
@@ -179,9 +177,13 @@ Component({
|
|
|
179
177
|
},
|
|
180
178
|
},
|
|
181
179
|
observers: {
|
|
182
|
-
'option,searchValue,
|
|
180
|
+
'option,searchValue,filterable': function (option, searchValue, filterable) {
|
|
183
181
|
const { ignoreCase } = this.properties;
|
|
184
|
-
if (
|
|
182
|
+
if (filterable) {
|
|
183
|
+
this.setData({
|
|
184
|
+
showOption: option,
|
|
185
|
+
});
|
|
186
|
+
} else {
|
|
185
187
|
const searchRange = option.filter((item) => {
|
|
186
188
|
if (ignoreCase) {
|
|
187
189
|
return String(item.label).toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;
|
|
@@ -192,10 +194,6 @@ Component({
|
|
|
192
194
|
showOption: searchRange,
|
|
193
195
|
status: searchRange.length > 0 ? 0 : 3,
|
|
194
196
|
});
|
|
195
|
-
} else {
|
|
196
|
-
this.setData({
|
|
197
|
-
showOption: option,
|
|
198
|
-
});
|
|
199
197
|
}
|
|
200
198
|
},
|
|
201
199
|
selectedValue: function (selectedValue) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<button class="weda-ui-custom-picker__header-btn" bindtap="closeModal" data-clear="false">取消</button>
|
|
7
7
|
<button class="weda-ui-custom-picker__header-btn" bindtap="confirmModal">确定</button>
|
|
8
8
|
</view>
|
|
9
|
-
<view class="weda-ui-custom-search {{focus?'is-focused':''}}" style="{{focus? 'margin: 34rpx 32rpx 16rpx 32rpx':'margin: 20rpx 32rpx'}}">
|
|
9
|
+
<view wx:if="{{searchable}}" class="weda-ui-custom-search {{focus?'is-focused':''}}" style="{{focus? 'margin: 34rpx 32rpx 16rpx 32rpx':'margin: 20rpx 32rpx'}}">
|
|
10
10
|
<view class="weda-ui-custom-search-box" bindtap="onFocus">
|
|
11
11
|
<input class="weda-ui-input" focus="{{focus}}" bindfocus="onFocus" bindblur="onBlur" bindinput="bindinput" value="{{searchValue}}" hold-keyboard="true" bindconfirm="bindconfirm" />
|
|
12
12
|
<view class="weda-ui-custom-search-box__label multiple">
|
|
@@ -98,6 +98,26 @@ Component({
|
|
|
98
98
|
type: Array,
|
|
99
99
|
value: [],
|
|
100
100
|
},
|
|
101
|
+
supportManyRelated: {
|
|
102
|
+
type: Boolean,
|
|
103
|
+
value: false,
|
|
104
|
+
},
|
|
105
|
+
queryCondition: {
|
|
106
|
+
type: null,
|
|
107
|
+
value: [],
|
|
108
|
+
},
|
|
109
|
+
sorter: {
|
|
110
|
+
type: Array,
|
|
111
|
+
value: [],
|
|
112
|
+
},
|
|
113
|
+
searchable: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
value: true,
|
|
116
|
+
},
|
|
117
|
+
filterable: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
value: false,
|
|
120
|
+
},
|
|
101
121
|
},
|
|
102
122
|
data: {
|
|
103
123
|
cls: '',
|
|
@@ -112,15 +132,13 @@ Component({
|
|
|
112
132
|
searchOption: [],
|
|
113
133
|
width: '100%',
|
|
114
134
|
isEmpty: true,
|
|
115
|
-
preWhere: [], // 对比 where 监听
|
|
116
|
-
whereEffected: [], // 每次请求都加上
|
|
117
135
|
fetchTimed: null, // 防抖
|
|
118
136
|
queryParam: { select: { $master: true } },
|
|
119
|
-
|
|
137
|
+
_filterable: false,
|
|
120
138
|
},
|
|
121
139
|
lifetimes: {
|
|
122
140
|
attached() {
|
|
123
|
-
const { className, layout, disabled, range } = this.properties;
|
|
141
|
+
const { className, layout, disabled, range, filterable } = this.properties;
|
|
124
142
|
const isFlex = layout !== 'vertical';
|
|
125
143
|
const cls = classNames({
|
|
126
144
|
'weda-ui': true,
|
|
@@ -144,6 +162,7 @@ Component({
|
|
|
144
162
|
cls,
|
|
145
163
|
subCls,
|
|
146
164
|
displayValue,
|
|
165
|
+
_filterable: filterable,
|
|
147
166
|
});
|
|
148
167
|
},
|
|
149
168
|
ready() {
|
|
@@ -172,9 +191,12 @@ Component({
|
|
|
172
191
|
});
|
|
173
192
|
},
|
|
174
193
|
format: function (format) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
194
|
+
if (['many-many', 'one-many'].includes(format)) {
|
|
195
|
+
// 关联关系,自定义查询规则,不走前端过滤
|
|
196
|
+
this.setData({
|
|
197
|
+
_filterable: true,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
178
200
|
},
|
|
179
201
|
'value,range': function () {
|
|
180
202
|
const { range, format } = this.properties;
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
</view>
|
|
14
14
|
<block wx:if="{{allPickerShow}}">
|
|
15
15
|
<dropdownSelect
|
|
16
|
+
searchable="{{searchable}}"
|
|
17
|
+
filterable="{{_filterable}}"
|
|
16
18
|
class="weui-picker__group weui-input"
|
|
17
19
|
bindchange="onChange"
|
|
18
20
|
bind:_childFetchData="_childFetchData"
|
|
@@ -24,7 +26,6 @@
|
|
|
24
26
|
displayLabel="{{displayLabel}}"
|
|
25
27
|
selectedValue="{{value}}"
|
|
26
28
|
ignoreCase="{{ignoreCase}}"
|
|
27
|
-
staticSearchable="{{staticSearchable}}"
|
|
28
29
|
bind:search="onSearch"
|
|
29
30
|
/>
|
|
30
31
|
</block>
|
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
@font-face {
|
|
2
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
background: #eef1f4;
|
|
48
|
-
}
|
|
49
|
-
|
|
2
|
+
font-family: WdTd;
|
|
3
|
+
src: url('t.eot'), url('t_iefix.eot') format('embedded-opentype'), url('t.woff') format('woff'),
|
|
4
|
+
url('t.ttf') format('truetype'), url('t.svg') format('svg'),
|
|
5
|
+
url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.eot'),
|
|
6
|
+
url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t_iefix.eot')
|
|
7
|
+
format('embedded-opentype'),
|
|
8
|
+
url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.woff') format('woff'),
|
|
9
|
+
url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.ttf') format('truetype'),
|
|
10
|
+
url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.svg') format('svg');
|
|
11
|
+
font-weight: 400;
|
|
12
|
+
font-style: normal;
|
|
13
|
+
}
|
|
14
|
+
.wd-markdown {
|
|
15
|
+
padding: 1rem;
|
|
16
|
+
}
|
|
17
|
+
.markdown-it-code-wrap {
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
.markdown-it-code-copy {
|
|
21
|
+
font-family: WdTd !important;
|
|
22
|
+
vertical-align: middle;
|
|
23
|
+
font-size: 14px;
|
|
24
|
+
border: none;
|
|
25
|
+
background: transparent;
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 7.5px;
|
|
28
|
+
right: 6px;
|
|
29
|
+
outline: none;
|
|
30
|
+
}
|
|
31
|
+
i.markdown-it-code-copy {
|
|
32
|
+
font-style: normal;
|
|
33
|
+
}
|
|
34
|
+
.markdown-it-code-copy::before {
|
|
35
|
+
content: '\E1AC';
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
right: 0;
|
|
39
|
+
width: 20px;
|
|
40
|
+
height: 20px;
|
|
41
|
+
display: inline-block;
|
|
42
|
+
text-align: center;
|
|
43
|
+
}
|
|
44
|
+
.markdown-it-code-copy:hover::before {
|
|
45
|
+
background: #eef1f4;
|
|
46
|
+
}
|
|
@@ -3,10 +3,10 @@ import formFieldBehavior from '../form-field-behavior/form-field-behavior';
|
|
|
3
3
|
import itemBehavior from '../form-field-behavior/item-behavior';
|
|
4
4
|
import { convertFixedIcon, SELECT_ICON_H5 } from '../../utils/getFormLegacy';
|
|
5
5
|
import debounce from '../../utils/debounce';
|
|
6
|
-
import {
|
|
6
|
+
import { arrayToMap, getSelected } from '../../utils/tool';
|
|
7
7
|
|
|
8
8
|
Component({
|
|
9
|
-
options: { virtualHost: true },
|
|
9
|
+
options: { virtualHost: true, styleIsolation: 'shared' },
|
|
10
10
|
behaviors: [itemBehavior, commonCompBehavior, formFieldBehavior],
|
|
11
11
|
properties: {
|
|
12
12
|
classRoot: {
|
|
@@ -25,9 +25,16 @@ Component({
|
|
|
25
25
|
type: Array,
|
|
26
26
|
value: [],
|
|
27
27
|
},
|
|
28
|
+
searchable: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
value: true,
|
|
31
|
+
},
|
|
32
|
+
filterable: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
value: false,
|
|
35
|
+
},
|
|
28
36
|
},
|
|
29
37
|
data: {
|
|
30
|
-
options: [],
|
|
31
38
|
itemMap: {},
|
|
32
39
|
selectedLabel: null,
|
|
33
40
|
selectedItem: null,
|
|
@@ -45,16 +52,18 @@ Component({
|
|
|
45
52
|
});
|
|
46
53
|
this.updateWidgetAPI();
|
|
47
54
|
},
|
|
48
|
-
changeOptions: function (e) {
|
|
49
|
-
const { options } = safeObj(e.detail.value);
|
|
50
|
-
this.setData({ options });
|
|
51
|
-
},
|
|
52
55
|
search: function (e) {
|
|
53
56
|
this.debouncedTriggerSearchEvent(e.detail.value);
|
|
54
57
|
},
|
|
55
58
|
debouncedTriggerSearchEvent: debounce(function (value) {
|
|
56
59
|
this.triggerEvent('search', { value });
|
|
57
60
|
}),
|
|
61
|
+
updateSelect: function (e) {
|
|
62
|
+
const { value, option } = e.detail;
|
|
63
|
+
const itemMap = arrayToMap(option, 'value');
|
|
64
|
+
const { selectedLabel, selectedItem } = getSelected(itemMap, value, false);
|
|
65
|
+
this.setData({ selectedLabel, selectedItem });
|
|
66
|
+
},
|
|
58
67
|
},
|
|
59
68
|
observers: {
|
|
60
69
|
'name, value, label, required, visible, disabled, readOnly, before, after, primaryField, selectedLabel, selectedItem':
|
|
@@ -65,13 +74,8 @@ Component({
|
|
|
65
74
|
const [_suffixType, _suffixIcon] = convertFixedIcon(suffixType, suffixIcon, SELECT_ICON_H5);
|
|
66
75
|
this.setData({ _suffixType, _suffixIcon });
|
|
67
76
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.setData({ itemMap });
|
|
71
|
-
},
|
|
72
|
-
'itemMap, value': function (itemMap, value) {
|
|
73
|
-
const { selectedLabel, selectedItem } = getSelected(itemMap, value, false);
|
|
74
|
-
this.setData({ selectedLabel, selectedItem });
|
|
77
|
+
range: function (range) {
|
|
78
|
+
this.updateSelect({ detail: { value: this.data.value, option: range } });
|
|
75
79
|
},
|
|
76
80
|
},
|
|
77
81
|
lifetimes: {
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
<wd-input-group before="{{before}}" after="{{after}}" block="{{true}}" size="{{_size}}" classRoot="{{classRoot}}" readOnly="{{readOnly}}">
|
|
23
23
|
<wd-input-wrap block="{{block}}" classRoot="{{classRoot}}" before="{{before}}" after="{{after}}" disabled="{{disabled}}" prefixType="{{prefixType}}" prefixIcon="{{prefixIcon}}" prefixSrc="{{prefixSrc}}" suffixType="{{_suffixType}}" suffixIcon="{{_suffixIcon}}" suffixSrc="{{suffixSrc}}" hasClearIcon="{{hasClearIcon}}" bind:onClear="handleClear" readOnly="{{readOnly}}">
|
|
24
24
|
<old-select
|
|
25
|
+
multiple="{{false}}"
|
|
26
|
+
searchable="{{searchable}}"
|
|
27
|
+
filterable="{{filterable}}"
|
|
25
28
|
supportManyRelated="{{supportManyRelated}}"
|
|
26
29
|
queryCondition="{{queryCondition}}"
|
|
27
30
|
sorter="{{sorter}}"
|
|
@@ -30,7 +33,7 @@
|
|
|
30
33
|
label=""
|
|
31
34
|
defaultValue="{{value}}"
|
|
32
35
|
enumName="{{enumName}}"
|
|
33
|
-
format="{{format
|
|
36
|
+
format="{{format}}"
|
|
34
37
|
placeholder="{{placeholder}}"
|
|
35
38
|
primaryField="{{primaryField}}"
|
|
36
39
|
range="{{range}}"
|
|
@@ -44,10 +47,11 @@
|
|
|
44
47
|
version="wd"
|
|
45
48
|
mode="selector"
|
|
46
49
|
ignoreCase="{{ignoreCase}}"
|
|
47
|
-
staticSearchable="{{staticSearchable}}"
|
|
48
50
|
bind:change="handleChange"
|
|
49
|
-
bind:
|
|
51
|
+
bind:updateSelect="updateSelect"
|
|
50
52
|
bind:search="search"
|
|
53
|
+
bind:focus="handleEvent"
|
|
54
|
+
bind:blur="handleEvent"
|
|
51
55
|
/>
|
|
52
56
|
</wd-input-wrap>
|
|
53
57
|
</wd-input-group>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Component({
|
|
2
|
+
properties: {
|
|
3
|
+
isActive: {
|
|
4
|
+
type: Boolean,
|
|
5
|
+
value: true,
|
|
6
|
+
},
|
|
7
|
+
option: {
|
|
8
|
+
type: Array,
|
|
9
|
+
value: [],
|
|
10
|
+
},
|
|
11
|
+
searchStatus: {
|
|
12
|
+
type: Number,
|
|
13
|
+
value: 0,
|
|
14
|
+
},
|
|
15
|
+
loadStatus: {
|
|
16
|
+
type: Number,
|
|
17
|
+
value: 0,
|
|
18
|
+
},
|
|
19
|
+
disabled: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
value: false,
|
|
22
|
+
},
|
|
23
|
+
ignoreCase: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
value: true,
|
|
26
|
+
},
|
|
27
|
+
selectedValue: {
|
|
28
|
+
type: Array,
|
|
29
|
+
value: [],
|
|
30
|
+
},
|
|
31
|
+
searchable: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
value: true,
|
|
34
|
+
},
|
|
35
|
+
filterable: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
value: false,
|
|
38
|
+
},
|
|
39
|
+
multiple: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
value: false,
|
|
42
|
+
},
|
|
43
|
+
currentPageNo: {
|
|
44
|
+
type: Number,
|
|
45
|
+
value: 1,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
data: {
|
|
49
|
+
height: '390px',
|
|
50
|
+
focus: false,
|
|
51
|
+
searchValue: '',
|
|
52
|
+
index: -1,
|
|
53
|
+
status: 0,
|
|
54
|
+
showOption: [],
|
|
55
|
+
pageNo: 1,
|
|
56
|
+
selectedCache: [], // 缓存当前选中值
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
methods: {
|
|
60
|
+
cancelPicker: function (e) {
|
|
61
|
+
if (this.data.multiple) {
|
|
62
|
+
const { option } = this.properties;
|
|
63
|
+
this.setData({ selectedCache: option.filter((item) => item.check) });
|
|
64
|
+
}
|
|
65
|
+
this.triggerEvent('onClosePicker');
|
|
66
|
+
},
|
|
67
|
+
// 监听输入
|
|
68
|
+
bindinput: function (event) {
|
|
69
|
+
const value = event.detail.value;
|
|
70
|
+
this.setData({
|
|
71
|
+
searchValue: value,
|
|
72
|
+
pageNo: 1,
|
|
73
|
+
});
|
|
74
|
+
this.triggerEvent('search', { value });
|
|
75
|
+
},
|
|
76
|
+
// 清空输入
|
|
77
|
+
clear: function () {
|
|
78
|
+
this.setData({
|
|
79
|
+
searchValue: '',
|
|
80
|
+
showOption: this.properties.option,
|
|
81
|
+
pageNo: 1,
|
|
82
|
+
});
|
|
83
|
+
this.triggerEvent('search', { value: '' });
|
|
84
|
+
},
|
|
85
|
+
// 取消
|
|
86
|
+
shrink: function () {
|
|
87
|
+
this.setData({
|
|
88
|
+
height: '390px',
|
|
89
|
+
focus: false,
|
|
90
|
+
searchValue: '',
|
|
91
|
+
pageNo: 1,
|
|
92
|
+
showOption: this.properties.option,
|
|
93
|
+
});
|
|
94
|
+
this.triggerEvent('search', { value: '', noEvent: true });
|
|
95
|
+
},
|
|
96
|
+
confirmModal: function () {
|
|
97
|
+
const { selectedCache } = this.data;
|
|
98
|
+
this.triggerEvent('onSelectPicker', selectedCache);
|
|
99
|
+
},
|
|
100
|
+
// 获取焦点
|
|
101
|
+
onFocus: function () {
|
|
102
|
+
this.setData({
|
|
103
|
+
height: '550px',
|
|
104
|
+
focus: true,
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
// 处理当前选中值
|
|
108
|
+
dealSelectedValue(item) {
|
|
109
|
+
const { selectedCache } = this.data;
|
|
110
|
+
const index = selectedCache.findIndex((v) => v.value === item.value);
|
|
111
|
+
if (index > -1) {
|
|
112
|
+
return [...selectedCache.slice(0, index), ...selectedCache.slice(index + 1)];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return [...selectedCache, item];
|
|
116
|
+
},
|
|
117
|
+
// 选中项
|
|
118
|
+
onItemClick: function (e) {
|
|
119
|
+
const item = e.currentTarget.dataset.value;
|
|
120
|
+
if (item.disabled) return;
|
|
121
|
+
if (this.data.multiple) {
|
|
122
|
+
this.setData({
|
|
123
|
+
selectedCache: this.dealSelectedValue(item),
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
this.triggerEvent('onSelectPicker', item);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
// 滚动到底部
|
|
130
|
+
bindscrolltolower: function () {
|
|
131
|
+
if (this.properties.loadStatus === 0) {
|
|
132
|
+
const pageNo = this.data.pageNo + 1;
|
|
133
|
+
this.setData({ pageNo });
|
|
134
|
+
this.triggerEvent('_childFetchData', {
|
|
135
|
+
pageNo,
|
|
136
|
+
searchValue: this.data.searchValue,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
// 重试
|
|
141
|
+
onRetry: function () {
|
|
142
|
+
const { pageNo } = this.data;
|
|
143
|
+
if (this.properties.loadStatus === 2) {
|
|
144
|
+
this.setData({
|
|
145
|
+
status: 1,
|
|
146
|
+
});
|
|
147
|
+
this.triggerEvent('_childFetchData', {
|
|
148
|
+
pageNo: pageNo,
|
|
149
|
+
searchValue: this.data.searchValue,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
observers: {
|
|
155
|
+
'option,searchValue,filterable': function (option, searchValue, filterable) {
|
|
156
|
+
const { ignoreCase } = this.properties;
|
|
157
|
+
if (filterable) {
|
|
158
|
+
this.setData({
|
|
159
|
+
showOption: option,
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
const searchRange = option.filter((item) => {
|
|
163
|
+
if (ignoreCase) {
|
|
164
|
+
return String(item.label).toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;
|
|
165
|
+
}
|
|
166
|
+
return item.label.indexOf(searchValue) !== -1;
|
|
167
|
+
});
|
|
168
|
+
this.setData({
|
|
169
|
+
showOption: searchRange,
|
|
170
|
+
status: searchRange.length > 0 ? 0 : 3,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
'selectedValue,showOption': function (selectedValue, showOption) {
|
|
175
|
+
const data = Array.isArray(selectedValue) ? selectedValue : [selectedValue];
|
|
176
|
+
const optionMap = showOption.reduce((pre, cur) => {
|
|
177
|
+
pre[cur.value] = cur;
|
|
178
|
+
return pre;
|
|
179
|
+
}, {});
|
|
180
|
+
const selectedCache = data.map((d) => optionMap[d]).filter((item) => !!item);
|
|
181
|
+
this.setData({ selectedCache });
|
|
182
|
+
},
|
|
183
|
+
loadStatus: function (loadStatus) {
|
|
184
|
+
this.setData({
|
|
185
|
+
status: loadStatus,
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
currentPageNo: function (currentPageNo) {
|
|
189
|
+
this.setData({ pageNo: currentPageNo });
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<wxs module="tools"> function includes(array, item) { return array.map(function (v) { return v.value }).indexOf(item.value) !== -1 } module.exports = { includes: includes } </wxs>
|
|
2
|
+
<view class="weda-ui-custom-picker">
|
|
3
|
+
<view class="weda-ui-custom-mask" data-clear="false" bindtap="cancelPicker"></view>
|
|
4
|
+
<view class="weda-ui-custom-picker__inner" style="height: {{height}};">
|
|
5
|
+
<view wx:if="{{!focus}}" class="weda-ui-custom-picker__header">
|
|
6
|
+
<button class="weda-ui-custom-picker__header-btn" bindtap="cancelPicker" data-clear="false">取消</button>
|
|
7
|
+
<button wx:if="{{multiple}}" class="weda-ui-custom-picker__header-btn" bindtap="confirmModal">确定</button>
|
|
8
|
+
</view>
|
|
9
|
+
<view wx:if="{{searchable}}" class="weda-ui-custom-search {{focus?'is-focused':''}}" style="{{focus? 'margin: 34rpx 32rpx 16rpx 32rpx':'margin: 20rpx 32rpx'}}">
|
|
10
|
+
<view class="weda-ui-custom-search-box" bindtap="onFocus">
|
|
11
|
+
<input class="weda-ui-input" focus="{{focus}}" bindfocus="onFocus" bindblur="onBlur" bindinput="bindinput" value="{{searchValue}}" hold-keyboard="true" bindconfirm="bindconfirm" />
|
|
12
|
+
<view class="weda-ui-custom-search-box__label {{multiple?'multiple':''}}">
|
|
13
|
+
<span class="weda-ui-custom-search-box__search-icon"></span>
|
|
14
|
+
<span class="weda-ui-custom-search-box__search-placeholder"> 搜索 </span>
|
|
15
|
+
</view>
|
|
16
|
+
<span wx:if="{{focus && searchValue !== ''}}" class="weda-ui-custom-search-box__dismiss-icon" bindtap="clear"></span>
|
|
17
|
+
</view>
|
|
18
|
+
<text class="weda-ui-custom-search__btn-cancle" bindtap="shrink">取消</text>
|
|
19
|
+
</view>
|
|
20
|
+
<scroll-view wx:if="{{status !== -1}}" class="weda-ui-custom-picker__body" scroll-y="true" enhanced="true" bindscrolltolower="bindscrolltolower">
|
|
21
|
+
<view class="weda-ui-custom-picker__cloumns">
|
|
22
|
+
<view class="weda-ui-custom-picker__cloumn">
|
|
23
|
+
<view wx:for="{{showOption}}" wx:key="i" wx:for-index="i" class="weda-ui-custom-picker__cloumn-item {{multiple?'multiple':''}} {{ tools.includes(selectedCache, item) ? 'is-selected':''}} {{ (item.disabled) ? 'is-disabled':''}}" bindtap="onItemClick" data-value="{{item}}">
|
|
24
|
+
<text class="weda-ui-custom-picker__cloumn-item-text {{multiple?'multiple':''}}">{{item.label}}</text>
|
|
25
|
+
</view>
|
|
26
|
+
<view wx:if="{{status === 1}}" class="weda-ui-custom-picker__status weda-ui-custom-picker__status--loading"> <i class="weda-ui-custom-picker__loading-icon"></i>加载中... </view>
|
|
27
|
+
<view wx:if="{{status === 2}}" class="weda-ui-custom-picker__status">
|
|
28
|
+
加载失败
|
|
29
|
+
<text class="weda-ui-custom-picker__btn weda-ui-custom-picker__btn--link" bindtap="onRetry">重试</text>
|
|
30
|
+
</view>
|
|
31
|
+
<view wx:if="{{status === 3&&!showOption.length}}" class="weda-ui-custom-picker__status"> 暂无数据 </view>
|
|
32
|
+
</view>
|
|
33
|
+
</view>
|
|
34
|
+
</scroll-view>
|
|
35
|
+
<view wx:if="{{status === -1}}" class="weda-ui-custom-picker__empty">暂无数据</view>
|
|
36
|
+
</view>
|
|
37
|
+
</view>
|