@cloudbase/weda-ui 0.2.17 → 1.0.21
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/README.md +3 -0
- package/package.json +6 -3
- package/src/configs/components/calendar.json +4 -1
- package/src/configs/components/chart/bar.json +19 -6
- package/src/configs/components/chart/line.json +19 -6
- package/src/configs/components/chart/pie.json +14 -4
- package/src/configs/components/chart/statisticsCard.json +61 -13
- package/src/configs/components/container.json +7 -2
- package/src/configs/components/dataView.json +21 -6
- package/src/configs/components/form/checkbox.json +97 -5
- package/src/configs/components/form/radio.json +96 -4
- package/src/configs/components/form/select.json +245 -11
- package/src/configs/components/graphicCard.json +84 -73
- package/src/configs/components/image.json +7 -2
- package/src/configs/components/link.json +19 -3
- package/src/configs/components/listView.json +63 -17
- package/src/configs/components/modal.json +37 -5
- package/src/configs/components/navLayout.json +87 -75
- package/src/configs/components/navigationBar.json +59 -0
- package/src/configs/components/richtextview.json +4 -1
- package/src/configs/components/scrollVeiw.json +74 -22
- package/src/configs/components/swiper.json +4 -1
- package/src/configs/components/tabs.json +51 -8
- package/src/configs/components/text.json +33 -25
- package/src/configs/components/wxOpenApi/phone.json +141 -0
- package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
- package/src/configs/components/wxOpenApi/share.json +167 -0
- package/src/configs/components/wxOpenApi/userInfo.json +174 -0
- package/src/configs/index.js +11 -0
- package/src/mp/components/chart/bar/index.js +6 -2
- package/src/mp/components/chart/common/core/eChartBar.js +9 -8
- package/src/mp/components/chart/common/core/eChartBase.js +20 -16
- package/src/mp/components/chart/common/core/eChartLine.js +6 -5
- package/src/mp/components/chart/line/index.js +10 -6
- package/src/mp/components/chart/pie/index.js +6 -2
- package/src/mp/components/chart/statisticsCard/index.js +33 -6
- package/src/mp/components/dataView/index.json +1 -1
- package/src/mp/components/form/checkbox/index.js +41 -2
- package/src/mp/components/form/checkbox/index.wxml +1 -1
- package/src/mp/components/form/input/index.js +1 -1
- package/src/mp/components/form/location/index.js +43 -2
- package/src/mp/components/form/radio/index.js +34 -1
- package/src/mp/components/form/select/index.js +360 -40
- package/src/mp/components/form/select/index.wxml +17 -2
- package/src/mp/components/form/select/region/index.js +98 -0
- package/src/mp/components/form/uploader/index.js +39 -27
- package/src/mp/components/form/uploaderFile/index.js +10 -6
- package/src/mp/components/listView/index.js +33 -27
- package/src/mp/components/listView/index.wxml +1 -1
- package/src/mp/components/listView/index.wxss +5 -0
- package/src/mp/components/navigationBar/index.js +193 -0
- package/src/mp/components/navigationBar/index.json +6 -0
- package/src/mp/components/navigationBar/index.wxml +88 -0
- package/src/mp/components/navigationBar/index.wxss +1257 -0
- package/src/mp/components/tabs/index.js +7 -2
- package/src/mp/components/tabs/index.wxml +2 -1
- package/src/mp/components/text/index.js +0 -25
- package/src/mp/components/text/index.wxml +3 -3
- package/src/mp/components/wxOpenApi/phone/index.js +117 -0
- package/src/mp/components/{internals/listView → wxOpenApi/phone}/index.json +0 -0
- package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/share/index.js +117 -0
- package/src/mp/components/wxOpenApi/share/index.json +4 -0
- package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
- package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
- package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
- package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
- package/src/mp/index.json +7 -2
- package/src/mp/style/weda-ui.wxss +2 -0
- package/src/mp/utils/destr.js +48 -0
- package/src/mp/utils/platform.js +10 -0
- package/src/mp/utils/tcb.js +44 -0
- package/src/web/components/button/index.css +8 -1
- package/src/web/components/button/index.tsx +3 -2
- package/src/web/components/chart/bar/index.tsx +40 -39
- package/src/web/components/chart/common/core/eChartBar.js +7 -6
- package/src/web/components/chart/common/core/eChartBase.ts +20 -16
- package/src/web/components/chart/common/core/eChartLine.js +8 -6
- package/src/web/components/chart/line/index.tsx +40 -39
- package/src/web/components/chart/statisticsCard/index.tsx +29 -8
- package/src/web/components/form/checkbox/index.tsx +55 -23
- package/src/web/components/form/radio/index.tsx +84 -53
- package/src/web/components/form/select/h5.tsx +388 -72
- package/src/web/components/form/select/index.css +10 -0
- package/src/web/components/form/select/index.tsx +404 -144
- package/src/web/components/form/select/region/index.ts +122 -31
- package/src/web/components/form/select/time.jsx +89 -0
- package/src/web/components/form/select/year.tsx +170 -0
- package/src/web/components/form/uploader/uploader.h5.tsx +9 -2
- package/src/web/components/form/uploader/uploader.pc.tsx +4 -4
- package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +13 -7
- package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +13 -5
- package/src/web/components/image/image.tsx +1 -1
- package/src/web/components/image/index.tsx +1 -1
- package/src/web/components/index.js +7 -0
- package/src/web/components/link/index.tsx +6 -3
- package/src/web/components/listView/index.css +4 -0
- package/src/web/components/listView/index.tsx +6 -1
- package/src/web/components/modal/index.tsx +3 -1
- package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
- package/src/web/components/navigationBar/common.tsx +198 -0
- package/src/web/components/navigationBar/h5Menu.tsx +179 -0
- package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
- package/src/web/components/navigationBar/index.css +762 -0
- package/src/web/components/navigationBar/index.tsx +231 -0
- package/src/web/components/navigationBar/type.d.ts +111 -0
- package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
- package/src/web/components/phone/index.css +0 -0
- package/src/web/components/phone/index.tsx +22 -0
- package/src/web/components/phoneCode/index.css +0 -0
- package/src/web/components/phoneCode/index.tsx +22 -0
- package/src/web/components/richTextView/index.tsx +3 -5
- package/src/web/components/share/index.css +0 -0
- package/src/web/components/share/index.tsx +38 -0
- package/src/web/components/tabs/index.tsx +2 -0
- package/src/web/components/tabs/tabs.h5.tsx +43 -33
- package/src/web/components/tabs/tabs.pc.tsx +23 -10
- package/src/web/components/text/index.tsx +6 -14
- package/src/web/components/userInfo/index.css +0 -0
- package/src/web/components/userInfo/index.tsx +30 -0
- package/src/web/utils/platform.js +9 -0
- package/src/web/utils/tcb.js +26 -0
- package/src/web/weda-ui.css +2 -0
- package/src/mp/components/internals/listView/arrow-right-line.svg +0 -3
- package/src/mp/components/internals/listView/index.js +0 -286
- package/src/mp/components/internals/listView/index.wxml +0 -40
- package/src/mp/components/internals/listView/index.wxss +0 -150
- package/src/mp/components/internals/listView/more-line.svg +0 -3
- package/src/web/components/form/select/region/cities.ts +0 -2410
- package/src/web/components/form/select/region/provinces.ts +0 -240
- package/src/web/components/form/select/region/regions.ts +0 -20645
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
import classNames from '../../../utils/classnames';
|
|
2
2
|
import dayjs from '../../../utils/dayjs.min.js';
|
|
3
|
+
import { getRegionTree, buildDisplayValue } from './region/index';
|
|
4
|
+
import { provinces, cities, regions } from './region/index';
|
|
5
|
+
import destr from '../../../utils/destr';
|
|
6
|
+
import { callDataSourceApi, callWedaApi } from '../../../utils/tcb';
|
|
7
|
+
|
|
8
|
+
// 处理where筛选条件
|
|
9
|
+
const isNull = (val) => [undefined, null].includes(val);
|
|
10
|
+
const REL_DICT = {
|
|
11
|
+
equal: 'eq', // 等于
|
|
12
|
+
unequal: 'neq', // 不等于
|
|
13
|
+
include: 'search', // 包含
|
|
14
|
+
exclude: '_exclude', // 不包含
|
|
15
|
+
begin_with: '_begin_with', // 开头是
|
|
16
|
+
greater: 'gt', // 大于
|
|
17
|
+
greater_or_equal: 'gte', // 大于等于
|
|
18
|
+
bigger_or_equal: 'gte', //大于等于
|
|
19
|
+
less: 'lt', // 小于
|
|
20
|
+
less_or_equal: 'lte', // 小于等于
|
|
21
|
+
in: 'in', // 多选值
|
|
22
|
+
not_in: 'nin', // 不在多选值
|
|
23
|
+
};
|
|
24
|
+
const getWhereList = (where) => {
|
|
25
|
+
let result = [];
|
|
26
|
+
Array.isArray(where) &&
|
|
27
|
+
where.forEach((item1) => {
|
|
28
|
+
if (item1?.groupLogic !== 'or' && Array.isArray(item1?.logicData)) {
|
|
29
|
+
item1?.logicData.forEach((item2) => {
|
|
30
|
+
let [rel, val] = [REL_DICT[item2?.rel], item2?.value];
|
|
31
|
+
if ('_begin_with' === rel) {
|
|
32
|
+
rel = 'regex';
|
|
33
|
+
val = `^${val}`;
|
|
34
|
+
}
|
|
35
|
+
if ('_exclude' === rel) {
|
|
36
|
+
rel = 'regex';
|
|
37
|
+
val = `^((?!${val}).)*$`;
|
|
38
|
+
}
|
|
39
|
+
if (item2?.logic !== 'or' && item2?.key && rel && !isNull(val)) {
|
|
40
|
+
result.push({ key: item2.key, rel, val });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
3
47
|
|
|
4
48
|
Component({
|
|
5
49
|
options: {
|
|
@@ -34,10 +78,18 @@ Component({
|
|
|
34
78
|
type: String,
|
|
35
79
|
value: 'selector',
|
|
36
80
|
},
|
|
81
|
+
dateMode: {
|
|
82
|
+
type: String,
|
|
83
|
+
value: 'day',
|
|
84
|
+
},
|
|
37
85
|
disabled: {
|
|
38
86
|
type: Boolean,
|
|
39
87
|
value: false,
|
|
40
88
|
},
|
|
89
|
+
regionType: {
|
|
90
|
+
type: String,
|
|
91
|
+
value: ''
|
|
92
|
+
},
|
|
41
93
|
range: {
|
|
42
94
|
type: Array,
|
|
43
95
|
value: [
|
|
@@ -81,6 +133,10 @@ Component({
|
|
|
81
133
|
defaultRegion: {
|
|
82
134
|
type: Array,
|
|
83
135
|
},
|
|
136
|
+
defaultMutiRegion: {
|
|
137
|
+
type: String,
|
|
138
|
+
value: ''
|
|
139
|
+
},
|
|
84
140
|
separator: {
|
|
85
141
|
type: String,
|
|
86
142
|
value: ',',
|
|
@@ -89,6 +145,30 @@ Component({
|
|
|
89
145
|
type: Boolean,
|
|
90
146
|
value: false,
|
|
91
147
|
},
|
|
148
|
+
format: {
|
|
149
|
+
type: String,
|
|
150
|
+
value: '',
|
|
151
|
+
},
|
|
152
|
+
dataSourceName: {
|
|
153
|
+
type: String,
|
|
154
|
+
value: '',
|
|
155
|
+
},
|
|
156
|
+
viewId: {
|
|
157
|
+
type: String,
|
|
158
|
+
value: '',
|
|
159
|
+
},
|
|
160
|
+
primaryField: {
|
|
161
|
+
type: String,
|
|
162
|
+
value: '',
|
|
163
|
+
},
|
|
164
|
+
enumName: {
|
|
165
|
+
type: String,
|
|
166
|
+
value: '',
|
|
167
|
+
},
|
|
168
|
+
where: {
|
|
169
|
+
type: Array,
|
|
170
|
+
value: []
|
|
171
|
+
}
|
|
92
172
|
},
|
|
93
173
|
data: {
|
|
94
174
|
cls: '',
|
|
@@ -99,6 +179,12 @@ Component({
|
|
|
99
179
|
value: '',
|
|
100
180
|
displayValue: '',
|
|
101
181
|
displayCls: '',
|
|
182
|
+
//省市级联动数据
|
|
183
|
+
multiArray: [[{ value: '地区数据加载中,请关闭弹窗后重试' }]],
|
|
184
|
+
multiIndex: [0, 0, 0], // 默认的下标
|
|
185
|
+
records: [],
|
|
186
|
+
option: [{ label: '', value: '' }],
|
|
187
|
+
whereEffected: []
|
|
102
188
|
},
|
|
103
189
|
lifetimes: {
|
|
104
190
|
attached() {
|
|
@@ -112,6 +198,9 @@ Component({
|
|
|
112
198
|
endTime,
|
|
113
199
|
startDate,
|
|
114
200
|
endDate,
|
|
201
|
+
dateMode,
|
|
202
|
+
defaultDate,
|
|
203
|
+
format,
|
|
115
204
|
} = this.properties;
|
|
116
205
|
const isFlex = layout !== 'vertical';
|
|
117
206
|
const cls = classNames({
|
|
@@ -127,11 +216,15 @@ Component({
|
|
|
127
216
|
'weui-cell_disabled': disabled,
|
|
128
217
|
});
|
|
129
218
|
|
|
130
|
-
let selectRange, start, end;
|
|
219
|
+
let selectRange, start, end, displayValue;
|
|
131
220
|
|
|
132
221
|
switch (mode) {
|
|
133
222
|
case 'selector': {
|
|
134
|
-
|
|
223
|
+
if (format === 'related' || format === 'father-son' || format === 'x-enum') {
|
|
224
|
+
selectRange = this.data.option.map((item) => item.label);
|
|
225
|
+
} else {
|
|
226
|
+
selectRange = range.map((item) => item.label);
|
|
227
|
+
}
|
|
135
228
|
break;
|
|
136
229
|
}
|
|
137
230
|
case 'time': {
|
|
@@ -144,52 +237,58 @@ Component({
|
|
|
144
237
|
break;
|
|
145
238
|
}
|
|
146
239
|
case 'date': {
|
|
147
|
-
start = startDate
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
end = endDate
|
|
151
|
-
? this.converDate2Dayjs(endDate).format('YYYY-MM-DD')
|
|
152
|
-
: undefined;
|
|
240
|
+
start = this._coverNumber2Date(startDate, dateMode);
|
|
241
|
+
end = this._coverNumber2Date(endDate, dateMode);
|
|
242
|
+
displayValue = this._coverNumber2Date(defaultDate, dateMode);
|
|
153
243
|
break;
|
|
154
244
|
}
|
|
155
245
|
case 'region': {
|
|
156
246
|
break;
|
|
157
247
|
}
|
|
248
|
+
case 'mutiRegion': {
|
|
249
|
+
this.getProvince();
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
158
252
|
default: {
|
|
159
253
|
break;
|
|
160
254
|
}
|
|
161
255
|
}
|
|
162
|
-
|
|
163
256
|
this.setData({
|
|
164
257
|
cls,
|
|
165
258
|
subCls,
|
|
166
259
|
selectRange,
|
|
167
260
|
start,
|
|
168
261
|
end,
|
|
262
|
+
displayValue,
|
|
169
263
|
});
|
|
170
264
|
},
|
|
171
265
|
},
|
|
172
266
|
observers: {
|
|
173
|
-
'defaultValue, defaultTime,
|
|
267
|
+
'defaultValue, defaultTime, defaultRegion,defaultMutiRegion': function (
|
|
174
268
|
defaultValue,
|
|
175
269
|
defaultTime,
|
|
176
|
-
defaultDate,
|
|
177
270
|
defaultRegion
|
|
178
271
|
) {
|
|
179
|
-
const { range, mode, separator, placeholder } =
|
|
272
|
+
const { range, mode, separator, placeholder, dateMode, defaultDate, format, option, defaultMutiRegion } =
|
|
273
|
+
this.properties;
|
|
180
274
|
let value, displayValue;
|
|
181
275
|
switch (mode) {
|
|
182
276
|
case 'selector': {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
277
|
+
// TODO: == 故意的
|
|
278
|
+
if (format !== 'father-son' && format !== 'related' && format !== 'x-enum') {
|
|
279
|
+
const index = range.findIndex((item) => item.value == defaultValue);
|
|
280
|
+
value = index < 0 ? '' : defaultValue;
|
|
281
|
+
displayValue = index < 0 ? '' : range[index].label;
|
|
282
|
+
} else {
|
|
283
|
+
const index = option.findIndex((item) => item.value == defaultValue);
|
|
284
|
+
value = index < 0 ? '' : defaultValue;
|
|
285
|
+
displayValue = index < 0 ? '' : option[index].label;
|
|
286
|
+
}
|
|
186
287
|
break;
|
|
187
288
|
}
|
|
188
289
|
case 'date': {
|
|
189
|
-
value = defaultDate
|
|
190
|
-
|
|
191
|
-
: undefined;
|
|
192
|
-
displayValue = value;
|
|
290
|
+
value = this._coverNumber2Date(defaultDate, dateMode);
|
|
291
|
+
displayValue = this._coverNumber2Date(defaultDate, dateMode, true);
|
|
193
292
|
break;
|
|
194
293
|
}
|
|
195
294
|
case 'time': {
|
|
@@ -202,6 +301,10 @@ Component({
|
|
|
202
301
|
displayValue = defaultRegion.join(separator);
|
|
203
302
|
break;
|
|
204
303
|
}
|
|
304
|
+
case 'mutiRegion': {
|
|
305
|
+
displayValue = defaultMutiRegion || '';
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
205
308
|
default: {
|
|
206
309
|
break;
|
|
207
310
|
}
|
|
@@ -213,11 +316,13 @@ Component({
|
|
|
213
316
|
});
|
|
214
317
|
},
|
|
215
318
|
range: function (range) {
|
|
216
|
-
const { mode } = this.properties;
|
|
319
|
+
const { mode, format } = this.properties;
|
|
217
320
|
let selectRange = '';
|
|
218
321
|
switch (mode) {
|
|
219
322
|
case 'selector': {
|
|
220
|
-
|
|
323
|
+
if (format !== 'father-son' && format !== 'related' && format !== 'x-enum') {
|
|
324
|
+
selectRange = range.map((item) => item.label);
|
|
325
|
+
}
|
|
221
326
|
break;
|
|
222
327
|
}
|
|
223
328
|
default: {
|
|
@@ -230,32 +335,212 @@ Component({
|
|
|
230
335
|
});
|
|
231
336
|
}
|
|
232
337
|
},
|
|
338
|
+
enumName: function (enumName) {
|
|
339
|
+
if (this.properties.format === 'x-enum' && enumName) {
|
|
340
|
+
this._fetchEnumData();
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
where: function (where) {
|
|
344
|
+
const whereEffected = [].concat(getWhereList(where));
|
|
345
|
+
this.setData({ whereEffected });
|
|
346
|
+
const { format, dataSourceName, viewId } = this.properties;
|
|
347
|
+
if ((format === 'father-son' || format === 'related') && dataSourceName && viewId) {
|
|
348
|
+
this._fetchData(whereEffected);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
'records': function (records) {
|
|
352
|
+
const { primaryField } = this.properties;
|
|
353
|
+
if (records && records.length !== 0 && primaryField) {
|
|
354
|
+
const option = records.map(item => {
|
|
355
|
+
return {
|
|
356
|
+
label: item[primaryField],
|
|
357
|
+
value: item._id,
|
|
358
|
+
name: item[primaryField]
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
this.setData({ selectRange: option.map((item) => item.label), option });
|
|
362
|
+
}
|
|
363
|
+
},
|
|
233
364
|
},
|
|
234
365
|
methods: {
|
|
366
|
+
// 获取数据列表
|
|
367
|
+
_fetchData: async function (param) {
|
|
368
|
+
const { dataSourceName, viewId } = this.properties;
|
|
369
|
+
let pageNo = 1;
|
|
370
|
+
let pageSize = 200;
|
|
371
|
+
let records = [];
|
|
372
|
+
let total = 99999;
|
|
373
|
+
for (let index = 0; index < Math.floor(total / pageSize) + 1; index++) {
|
|
374
|
+
let data = await callDataSourceApi({
|
|
375
|
+
dataSourceName: dataSourceName,
|
|
376
|
+
viewId: viewId,
|
|
377
|
+
methodName: 'wedaGetRecords',
|
|
378
|
+
params: {
|
|
379
|
+
where: param,
|
|
380
|
+
pageNo: pageNo,
|
|
381
|
+
pageSize: pageSize
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
pageNo = pageNo + 1;
|
|
385
|
+
if (data?.records) {
|
|
386
|
+
total = data?.total || 0;
|
|
387
|
+
records = records.concat(data?.records);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (records) {
|
|
393
|
+
this.setData({ records });
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
//获取省
|
|
397
|
+
async getProvince() {
|
|
398
|
+
const { regionType, defaultMutiRegion } = this.properties;
|
|
399
|
+
const changeData = await getRegionTree(defaultMutiRegion || '');
|
|
400
|
+
this.triggerEvent('change', changeData);
|
|
401
|
+
var provinceList = [...provinces];
|
|
402
|
+
var provinceArr = provinces.map((item) => { return { value: item.Value, code: item.Code }; }); //保存省级名称
|
|
403
|
+
this.setData({
|
|
404
|
+
multiArray: JSON.parse(JSON.stringify(provinceArr)),
|
|
405
|
+
provinceList,//保存省级原始数据
|
|
406
|
+
provinceArr, //省级所有的名称
|
|
407
|
+
});
|
|
408
|
+
var defaultCode = this.data.provinceList[0].Code; // 使用第一项当作参数获取市级数据
|
|
409
|
+
this.setData({
|
|
410
|
+
currnetProvinceKey: defaultCode // 保存在当前的省级key
|
|
411
|
+
});
|
|
412
|
+
if (regionType != 'levelOne') {
|
|
413
|
+
this.getCity(this.data.provinceList[0]); // 获取市级数据
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
getCity(provinceInfo) { // 获取市级数据
|
|
417
|
+
const { regionType } = this.properties;
|
|
418
|
+
const code = provinceInfo.Code;
|
|
419
|
+
this.setData({
|
|
420
|
+
currnetProvinceKey: code // 保存当前选择的市级code
|
|
421
|
+
});
|
|
422
|
+
var cityArr = [];
|
|
423
|
+
var cityList = [];
|
|
424
|
+
cities.forEach((item) => {
|
|
425
|
+
if (item.Code.substr(0, 2) == code.substr(0, 2)) {
|
|
426
|
+
cityArr.push({ value: item.Value, code: item.Code });
|
|
427
|
+
cityList.push(item);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
this.setData({
|
|
431
|
+
cityList, // 保存下市级原始数据
|
|
432
|
+
cityArr // 市级所有的名称
|
|
433
|
+
});
|
|
434
|
+
if (regionType == 'levelTwo') {
|
|
435
|
+
const cityData = [this.data.provinceArr, cityArr];
|
|
436
|
+
this.setData({
|
|
437
|
+
multiArray: JSON.parse(JSON.stringify(cityData)),
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
var defaultCode = cityList[0]?.Code;
|
|
441
|
+
this.setData({
|
|
442
|
+
currnetCityKey: defaultCode // 存下当前选择的城市key
|
|
443
|
+
});
|
|
444
|
+
if (regionType == 'levelThree') {
|
|
445
|
+
this.getRegion(cityList[0]);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
getRegion(cityInfo) {
|
|
449
|
+
const code = cityInfo.Code;
|
|
450
|
+
this.setData({
|
|
451
|
+
currnetCityKey: code // 更新当前选择的市级key
|
|
452
|
+
});
|
|
453
|
+
var regionList = [];
|
|
454
|
+
var regionArr = [];
|
|
455
|
+
regions.forEach((item) => {
|
|
456
|
+
if (cityInfo.Type == 1 && cityInfo.CentralCity) {
|
|
457
|
+
if (item.Code.substr(0, 2) == code.substr(0, 2)) {
|
|
458
|
+
regionArr.push({ value: item.Value, code: item.Code });
|
|
459
|
+
regionList.push(item);
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
if (item.Code.substr(0, 4) == code.substr(0, 4)) {
|
|
463
|
+
regionArr.push({ value: item.Value, code: item.Code });
|
|
464
|
+
regionList.push(item);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
const threeRegion = [this.data.provinceArr, this.data.cityArr, regionArr];
|
|
469
|
+
this.setData({
|
|
470
|
+
multiArray: JSON.parse(JSON.stringify(threeRegion)),
|
|
471
|
+
regionList,
|
|
472
|
+
regionArr
|
|
473
|
+
});
|
|
474
|
+
var defaultCode = regionList[0]?.Code;
|
|
475
|
+
this.setData({
|
|
476
|
+
currnetRegionKey: defaultCode // 存下当前选择的城市key
|
|
477
|
+
});
|
|
478
|
+
},
|
|
479
|
+
columnchange(e) { // 滚动选择器 触发的事件
|
|
480
|
+
const { regionType } = this.properties;
|
|
481
|
+
var column = e.detail.column; // 当前改变的列
|
|
482
|
+
var data = {
|
|
483
|
+
multiIndex: JSON.parse(JSON.stringify(this.data.multiIndex)),
|
|
484
|
+
multiArray: JSON.parse(JSON.stringify(this.data.multiArray))
|
|
485
|
+
};
|
|
486
|
+
data.multiIndex[column] = e.detail.value; // 第几列改变了就是对应multiIndex的第几个,更新它
|
|
487
|
+
switch (column) { // 处理不同的逻辑
|
|
488
|
+
case 0: // 第一列更改 就是省级的更改
|
|
489
|
+
if (regionType != 'levelOne')
|
|
490
|
+
this.getCity(this.data.provinceList[e.detail.value]); // 获取当前key下面的市级数据
|
|
491
|
+
data.multiIndex[1] = 0; // 将市默认选择第一个
|
|
492
|
+
break;
|
|
493
|
+
case 1: // 市发生变化
|
|
494
|
+
this.getRegion(this.data.cityList[e.detail.value]); // 获取区
|
|
495
|
+
// }
|
|
496
|
+
data.multiIndex[2] = 0; // 区默认为第一个
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
// 获取通用选项集列表
|
|
501
|
+
_fetchEnumData: async function () {
|
|
502
|
+
let data = await callWedaApi({
|
|
503
|
+
action: 'DescribeGeneralOptionsDetailList',
|
|
504
|
+
data: { OptNameList: [this.properties.enumName], PageIndex: 1, PageSize: 10 },
|
|
505
|
+
});
|
|
506
|
+
const config = destr(data?.Items?.[0]?.Config) ?? [];
|
|
507
|
+
const option = config.map(item => {
|
|
508
|
+
return {
|
|
509
|
+
label: item.value,
|
|
510
|
+
value: item.key,
|
|
511
|
+
name: item.value
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
this.setData({ selectRange: option.map((item) => item.label), option });
|
|
515
|
+
},
|
|
516
|
+
|
|
235
517
|
onChange(e) {
|
|
236
|
-
const { range, mode, separator, placeholder } = this.properties;
|
|
518
|
+
const { range, mode, separator, placeholder, regionType, dateMode, format, option } = this.properties;
|
|
237
519
|
let displayValue;
|
|
238
520
|
switch (mode) {
|
|
239
521
|
case 'selector': {
|
|
240
|
-
|
|
241
|
-
|
|
522
|
+
if (format !== 'father-son' && format !== 'related' && format !== 'x-enum') {
|
|
523
|
+
this.triggerEvent('change', range[e.detail.value]);
|
|
524
|
+
displayValue = range[e.detail.value].label;
|
|
525
|
+
} else {
|
|
526
|
+
this.triggerEvent('change', option[e.detail.value]);
|
|
527
|
+
displayValue = option[e.detail.value].label;
|
|
528
|
+
}
|
|
242
529
|
break;
|
|
243
530
|
}
|
|
244
531
|
case 'date':
|
|
245
532
|
case 'time': {
|
|
246
533
|
const value = e.detail.value;
|
|
247
|
-
let day
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.triggerEvent('change', {
|
|
257
|
-
value: timeSnap,
|
|
258
|
-
});
|
|
534
|
+
let day, timeSnap;
|
|
535
|
+
if (mode === 'date') {
|
|
536
|
+
const dateValue = this._coverDateModeValue(value, dateMode);
|
|
537
|
+
day = this.converDate2Dayjs(dateValue);
|
|
538
|
+
timeSnap = day.valueOf();
|
|
539
|
+
} else {
|
|
540
|
+
day = this.converTime2Dayjs(value);
|
|
541
|
+
timeSnap = (day.hour() * 60 * 60 + day.minute() * 60) * 1000;
|
|
542
|
+
}
|
|
543
|
+
this.triggerEvent('change', { value: timeSnap });
|
|
259
544
|
displayValue = e.detail.value;
|
|
260
545
|
break;
|
|
261
546
|
}
|
|
@@ -264,6 +549,16 @@ Component({
|
|
|
264
549
|
displayValue = e.detail.value.join(separator);
|
|
265
550
|
break;
|
|
266
551
|
}
|
|
552
|
+
case 'mutiRegion': {
|
|
553
|
+
this.setData({
|
|
554
|
+
step: 1,
|
|
555
|
+
multiIndex: e.detail.value // 更新下标字段
|
|
556
|
+
});
|
|
557
|
+
const value = buildDisplayValue(this.data.multiArray, this.data.multiIndex, regionType);
|
|
558
|
+
displayValue = value?.value;
|
|
559
|
+
this.triggerEvent('change', value);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
267
562
|
default: {
|
|
268
563
|
break;
|
|
269
564
|
}
|
|
@@ -298,11 +593,36 @@ Component({
|
|
|
298
593
|
return dayjs(time);
|
|
299
594
|
}
|
|
300
595
|
},
|
|
301
|
-
converDate2Dayjs(
|
|
302
|
-
if (typeof
|
|
303
|
-
return dayjs(Number(
|
|
596
|
+
converDate2Dayjs(d) {
|
|
597
|
+
if (typeof d === 'string' && /^-?[0-9]*$/.test(d)) {
|
|
598
|
+
return dayjs(Number(d));
|
|
599
|
+
}
|
|
600
|
+
return dayjs(d);
|
|
601
|
+
},
|
|
602
|
+
// 将原始 number 类型值转成 YYYY-MM-DD 格式
|
|
603
|
+
_coverNumber2Date(d, dateMode = 'day', isDisplay = false) {
|
|
604
|
+
const day = d && this.converDate2Dayjs(d);
|
|
605
|
+
if (!day) return undefined;
|
|
606
|
+
let dayStr;
|
|
607
|
+
if (dateMode === 'year') {
|
|
608
|
+
dayStr = day.format('YYYY') + (isDisplay ? '' : '-01-01');
|
|
609
|
+
} else if (dateMode === 'month') {
|
|
610
|
+
dayStr = day.format('YYYY-MM') + (isDisplay ? '' : '-01');
|
|
611
|
+
} else {
|
|
612
|
+
dayStr = day.format('YYYY-MM-DD');
|
|
613
|
+
}
|
|
614
|
+
return dayStr;
|
|
615
|
+
},
|
|
616
|
+
// 将组件 onChange 返回的值,根据年/月/日模式,补齐返回 YYYY-MM-DD 格式
|
|
617
|
+
_coverDateModeValue(d, dateMode = 'day') {
|
|
618
|
+
if (dateMode === 'year' && /^\d{4}$/.test(d)) {
|
|
619
|
+
return `${d}-01-01`;
|
|
620
|
+
} else if (dateMode === 'month' && /^\d{4}-\d{2}$/.test(d)) {
|
|
621
|
+
return `${d}-01`;
|
|
622
|
+
} else {
|
|
623
|
+
return d;
|
|
304
624
|
}
|
|
305
|
-
return dayjs(date);
|
|
306
625
|
},
|
|
626
|
+
|
|
307
627
|
},
|
|
308
628
|
});
|
|
@@ -6,20 +6,35 @@
|
|
|
6
6
|
multiCell="{{false}}"
|
|
7
7
|
requiredFlag="{{requiredFlag}}"
|
|
8
8
|
>
|
|
9
|
-
|
|
9
|
+
<view class="{{subCls}}">
|
|
10
10
|
<view class="weui-cell__bd">
|
|
11
11
|
<picker
|
|
12
|
+
wx:if="{{mode!='mutiRegion'}}"
|
|
12
13
|
class="weui-picker__group weui-input"
|
|
13
14
|
bindchange="onChange"
|
|
14
15
|
bindcancel="onCancel"
|
|
15
16
|
mode="{{mode}}"
|
|
16
17
|
range="{{selectRange}}"
|
|
18
|
+
disabled="{{disabled}}"
|
|
17
19
|
start="{{start}}"
|
|
18
20
|
end="{{end}}"
|
|
21
|
+
disabled="{{disabled}}"
|
|
19
22
|
value="{{value}}"
|
|
23
|
+
fields="{{dateMode}}"
|
|
20
24
|
>
|
|
25
|
+
<label class="{{displayCls}}">{{displayValue}}</label>
|
|
26
|
+
</picker>
|
|
27
|
+
<picker wx:if="{{mode=='mutiRegion'}}"
|
|
28
|
+
mode="multiSelector"
|
|
29
|
+
disabled="{{disabled}}"
|
|
30
|
+
range="{{multiArray}}"
|
|
31
|
+
range-key='value'
|
|
32
|
+
bindcolumnchange="columnchange"
|
|
33
|
+
value="{{multiIndex}}"
|
|
34
|
+
bindchange='onChange'
|
|
35
|
+
class="weui-picker__group weui-input">
|
|
21
36
|
<label class="{{displayCls}}">{{displayValue}}</label>
|
|
22
37
|
</picker>
|
|
23
38
|
</view>
|
|
24
|
-
|
|
39
|
+
</view>
|
|
25
40
|
</formcell>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { callWedaApi } from '../../../../utils/tcb';
|
|
2
|
+
|
|
3
|
+
export const provinces = [];
|
|
4
|
+
export const cities = [];
|
|
5
|
+
export const regions = [];
|
|
6
|
+
export let regionData = [];
|
|
7
|
+
/**
|
|
8
|
+
* 获取运行态地区数据
|
|
9
|
+
* 查询所有的省市区数据https://iwiki.woa.com/pages/viewpage.action?pageId=1582408865
|
|
10
|
+
*/
|
|
11
|
+
export async function getAreaCode() {
|
|
12
|
+
try {
|
|
13
|
+
const res = await callWedaApi({
|
|
14
|
+
action: 'QueryRuntimeAreaCode',
|
|
15
|
+
data: { Mask: "11100" },
|
|
16
|
+
});
|
|
17
|
+
return res?.AreaCodeList;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('错误', error);
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const getRegionTree = async function (defaultValue) {
|
|
24
|
+
regionData = await getAreaCode();
|
|
25
|
+
splitAreaData(regionData, regionData);
|
|
26
|
+
return changeResult(defaultValue, regionData);
|
|
27
|
+
};
|
|
28
|
+
export const splitAreaData = (areaData) => {
|
|
29
|
+
areaData.forEach(item => {
|
|
30
|
+
if (!item.Deprecated) {
|
|
31
|
+
if (item?.Type == 1) {
|
|
32
|
+
provinces.push(item);
|
|
33
|
+
} if (item?.Type == 2 || (item?.Type == 1 && item.CentralCity)) {
|
|
34
|
+
cities.push(item);
|
|
35
|
+
} else if (item?.Type == 3) {
|
|
36
|
+
regions.push(item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
/***
|
|
42
|
+
* 用于构建change事件result返回值
|
|
43
|
+
*/
|
|
44
|
+
export const changeResult = (regionValue, areaData) => {
|
|
45
|
+
const defaultValue = regionValue ? regionValue.split(',') : null;
|
|
46
|
+
const changeValue = [];
|
|
47
|
+
const defaultIndex = [];
|
|
48
|
+
if (defaultValue && defaultValue.length > 0) {
|
|
49
|
+
defaultValue.forEach((element, index) => {
|
|
50
|
+
areaData.map((item, id) => {
|
|
51
|
+
//区级判重
|
|
52
|
+
if ((item?.Value == element && index != 2) || (item?.Value == element && item.Code.substr(0, 2) == changeValue[0].code.substr(0, 2) && index == 2)) {
|
|
53
|
+
changeValue.push({
|
|
54
|
+
value: item?.Value,
|
|
55
|
+
code: item?.Code
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
defaultIndex.push(id);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return { value: regionValue, result: changeValue };
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 拼接地区选择默认值显示规则
|
|
67
|
+
*/
|
|
68
|
+
export const buildDisplayValue = (data, indexList, type) => {
|
|
69
|
+
let provinceItem = [];
|
|
70
|
+
let cityItem;
|
|
71
|
+
let regionItem;
|
|
72
|
+
switch (type) {
|
|
73
|
+
case 'levelOne': {
|
|
74
|
+
provinceItem = data[0][indexList[0]];
|
|
75
|
+
return {
|
|
76
|
+
value: provinceItem.value,
|
|
77
|
+
result: [provinceItem]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
case 'levelTwo': {
|
|
81
|
+
provinceItem = data[0][indexList[0]];
|
|
82
|
+
cityItem = data[1][indexList[1]];
|
|
83
|
+
return {
|
|
84
|
+
value: provinceItem.value + "," + cityItem.value,
|
|
85
|
+
result: [provinceItem, cityItem]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
case 'levelThree': {
|
|
89
|
+
provinceItem = data[0][indexList[0]];
|
|
90
|
+
cityItem = data[1][indexList[1]];
|
|
91
|
+
regionItem = data[2][indexList[2]];
|
|
92
|
+
return {
|
|
93
|
+
value: provinceItem.value + "," + cityItem.value + "," + regionItem.value,
|
|
94
|
+
result: [provinceItem, cityItem, regionItem]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|