@cloudbase/weda-ui-mp 3.7.13 → 3.8.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.
@@ -40,6 +40,10 @@ Component({
40
40
  type: Boolean,
41
41
  value: true,
42
42
  },
43
+ selectedValue: {
44
+ type: Array,
45
+ value: [],
46
+ },
43
47
  },
44
48
  data: {
45
49
  height: '390px',
@@ -74,6 +78,7 @@ Component({
74
78
  const value = event.detail.value;
75
79
  this.setData({
76
80
  searchValue: value,
81
+ pageNo: 1,
77
82
  });
78
83
  this.triggerEvent('search', { value });
79
84
  },
@@ -82,6 +87,7 @@ Component({
82
87
  this.setData({
83
88
  searchValue: '',
84
89
  showOption: this.properties.option,
90
+ pageNo: 1,
85
91
  });
86
92
  this.triggerEvent('search', { value: '' });
87
93
  },
@@ -91,8 +97,10 @@ Component({
91
97
  height: '390px',
92
98
  focus: false,
93
99
  searchValue: '',
100
+ pageNo: 1,
94
101
  showOption: this.properties.option,
95
102
  });
103
+ this.triggerEvent('search', { value: '', noEvent: true });
96
104
  },
97
105
  closeModal: function () {
98
106
  const { option } = this.properties;
@@ -151,12 +159,11 @@ Component({
151
159
  // 滚动到底部
152
160
  bindscrolltolower: function () {
153
161
  if (this.properties.loadStatus === 0) {
154
- const pgNum = this.data.pageNo;
155
- this.setData({
156
- pageNo: pgNum + 1,
157
- });
162
+ const pageNo = this.data.pageNo + 1;
163
+ this.setData({ pageNo });
158
164
  this.triggerEvent('_childFetchData', {
159
- pageNo: this.data.pageNo,
165
+ pageNo,
166
+ searchValue: this.data.searchValue,
160
167
  });
161
168
  }
162
169
  },
@@ -169,6 +176,7 @@ Component({
169
176
  });
170
177
  this.triggerEvent('_childFetchData', {
171
178
  pageNo: pageNo,
179
+ searchValue: this.data.searchValue,
172
180
  });
173
181
  }
174
182
  },
@@ -206,8 +214,17 @@ Component({
206
214
  });
207
215
  }
208
216
  },
209
- option: function (option) {
210
- const selectedCache = option.filter((item) => item.check);
217
+ selectedValue: function (selectedValue) {
218
+ const data = Array.isArray(selectedValue)
219
+ ? selectedValue
220
+ : [selectedValue];
221
+ const optionMap = this.properties.option.reduce((pre, cur) => {
222
+ pre[cur.value] = cur;
223
+ return pre;
224
+ }, {});
225
+ const selectedCache = data
226
+ .map((d) => optionMap[d])
227
+ .filter((item) => !!item);
211
228
  this.setData({ selectedCache });
212
229
  },
213
230
  },
@@ -3,6 +3,8 @@ import { isNil } from '../../../utils/lodash';
3
3
  import { callDataSourceApi } from '../../../utils/tcb';
4
4
  import { arrayToMap } from '../../../utils/tool';
5
5
  import lodashGet from 'lodash.get';
6
+ import deepEqual from '../../../utils/deepEqual';
7
+ import { getWhereList } from '../../../utils/platform';
6
8
 
7
9
  // 判断值为空,展示placeholder
8
10
  export const isEmpty = (v) => {
@@ -95,6 +97,10 @@ Component({
95
97
  type: Boolean,
96
98
  value: true,
97
99
  },
100
+ where: {
101
+ type: Array,
102
+ value: [],
103
+ },
98
104
  },
99
105
  data: {
100
106
  cls: '',
@@ -109,6 +115,9 @@ Component({
109
115
  searchOption: [],
110
116
  width: '100%',
111
117
  isEmpty: true,
118
+ preWhere: [], // 对比 where 监听
119
+ whereEffected: [], // 每次请求都加上
120
+ fetchTimed: null, // 防抖
112
121
  },
113
122
  lifetimes: {
114
123
  attached() {
@@ -181,19 +190,7 @@ Component({
181
190
  });
182
191
  },
183
192
  dataSourceName: function () {
184
- const { format, dataSourceName, primaryField } = this.properties;
185
- if (
186
- (format === 'one-many' || format === 'many-many') &&
187
- dataSourceName &&
188
- primaryField
189
- ) {
190
- this.setData({
191
- records: [],
192
- option: [],
193
- pageNo: 1,
194
- });
195
- this._fetchData(1);
196
- }
193
+ this._initFetchData();
197
194
  },
198
195
  displayLabel: function (displayLabel) {
199
196
  this.setData({ isEmpty: isEmpty(displayLabel) });
@@ -201,6 +198,13 @@ Component({
201
198
  option: function (options) {
202
199
  this.triggerEvent('changeOptions', { value: { options } });
203
200
  },
201
+ where: function (where) {
202
+ if (deepEqual(where, this.data.preWhere)) return;
203
+ const whereEffected = [].concat(getWhereList(where));
204
+ this.setData({ preWhere: where, whereEffected }, () => {
205
+ this._initFetchData();
206
+ });
207
+ },
204
208
  },
205
209
  methods: {
206
210
  onClosePicker: function () {
@@ -243,28 +247,44 @@ Component({
243
247
  onChange(e) {
244
248
  this.triggerEvent('change', e.detail);
245
249
  },
250
+ // 初始化搜索数据,包括属性变化/搜索值变化
251
+ _initFetchData: function (_where = []) {
252
+ clearTimeout(this.data.fetchTimed);
253
+ // eslint-disable-next-line rulesdir/no-timer
254
+ this.data.fetchTimed = setTimeout(() => {
255
+ const { format, dataSourceName, primaryField } = this.properties;
256
+ if (
257
+ ['many-many', 'one-many'].concat(format) &&
258
+ dataSourceName &&
259
+ primaryField
260
+ ) {
261
+ this.setData({ records: [], option: [], pageNo: 1 });
262
+ this._fetchData(1, _where, true);
263
+ }
264
+ }, 300);
265
+ },
246
266
  // 获取数据列表:一对多,多对多
247
- _fetchData: async function (pageNo) {
267
+ _fetchData: async function (_pageNo, _where = [], _init = false) {
248
268
  const { dataSourceName, primaryField } = this.properties;
249
269
  if (!dataSourceName) return;
250
270
 
251
- const { records } = this.data;
252
- let pageSize = 200;
253
- let data = await callDataSourceApi({
271
+ const records = _init ? [] : this.data.records;
272
+ const pageSize = 200;
273
+ const res = await callDataSourceApi({
254
274
  dataSourceName: dataSourceName,
255
275
  methodName: 'wedaGetRecords',
256
276
  params: {
257
- pageNo: pageNo,
258
- pageSize: pageSize,
277
+ where: [{ $and: [...this.data.whereEffected, ..._where] }],
278
+ _pageNo,
279
+ pageSize,
259
280
  },
260
281
  });
261
- const results = data?.records.map((item) => {
262
- return {
263
- ...item,
264
- label: item[primaryField],
265
- value: item._id,
266
- };
267
- });
282
+
283
+ const results = res?.records.map((item) => ({
284
+ ...item,
285
+ label: item[primaryField],
286
+ value: item._id,
287
+ }));
268
288
  if (this.data.records.length === 0 && results?.length === 0) {
269
289
  // 当异常的时候,主要为了不引起records的observer变化变化设置默认值
270
290
  this.setData({
@@ -300,8 +320,11 @@ Component({
300
320
  }
301
321
  },
302
322
  _childFetchData: function (e) {
303
- const { pageNo } = e.detail;
304
- this._fetchData(pageNo);
323
+ const { pageNo, searchValue } = e.detail;
324
+ const _where = searchValue
325
+ ? [{ [this.properties.primaryField]: { $search: searchValue } }]
326
+ : [];
327
+ this._fetchData(pageNo, _where);
305
328
  },
306
329
  getLabels: function (values, options) {
307
330
  let labels = values;
@@ -326,7 +349,18 @@ Component({
326
349
  return stringRange;
327
350
  },
328
351
  onSearch(event) {
329
- this.triggerEvent('search', { value: event.detail.value });
352
+ const { noEvent, value: searchValue } = event.detail;
353
+
354
+ // 取消不触发搜索事件
355
+ if (!noEvent) {
356
+ this.triggerEvent('search', { value: searchValue });
357
+ }
358
+
359
+ // 接口搜索
360
+ const _where = searchValue
361
+ ? [{ [this.properties.primaryField]: { $search: searchValue } }]
362
+ : [];
363
+ this._initFetchData(_where);
330
364
  },
331
365
  },
332
366
  });
@@ -129,7 +129,8 @@ export default Behavior({
129
129
  const isPass = _rules.some((item) => {
130
130
  if (!item.format && !item.pattern && !item.func) {
131
131
  // console.log(item)
132
- throw new Error('验证规则必须配置 format/pattern');
132
+ // throw new Error('验证规则必须配置 format/pattern');
133
+ return true;
133
134
  }
134
135
  if (item.format) {
135
136
  const typeFunc = validType[item.format];
@@ -435,6 +435,12 @@ export default Behavior({
435
435
  after,
436
436
  });
437
437
  },
438
+ // 点击前后缀文字/图标
439
+ inputAdornmentClick: function (e) {
440
+ this.triggerEvent('inputAdornmentClick', {
441
+ type: e.currentTarget.dataset.type,
442
+ });
443
+ },
438
444
  },
439
445
  observers: {
440
446
  'clearable,disabled,value': function (clearable, disabled, value) {
@@ -54,4 +54,5 @@
54
54
  template="{{template}}"
55
55
  cursorSpacing="{{cursorSpacing}}"
56
56
  isConvert="{{isConvert}}"
57
+ bind:inputAdornmentClick="handleEvent"
57
58
  ></inner-input>
@@ -24,11 +24,11 @@
24
24
  after="{{after}}"
25
25
  readBeforeAfter="{{!isUnionValue}}"
26
26
  >
27
- <wd-input-group before="{{before}}" after="{{after}}" block="{{true}}" size="{{_size}}" classRoot="{{classRoot}}">
27
+ <wd-input-group before="{{before}}" after="{{after}}" block="{{true}}" size="{{_size}}" classRoot="{{classRoot}}" bind:inputAdornmentClick="handleEvent">
28
28
  <view class="{{cls}} {{template === 'greySearchBox'?'wd-input-input-search template search-box color-grey is-pc-bordered is-h5-borderless':''}} {{template === 'whiteSearchBox'?'wd-input-input-search template search-box color-white is-pc-bordered is-h5-borderless':''}}">
29
29
  <!-- 前缀图标 -->
30
30
  <block wx:if="{{prefixType}}">
31
- <view class="{{inputWrap}}__before">
31
+ <view class="{{inputWrap}}__before" data-type="prefix" bind:tap="inputAdornmentClick">
32
32
  <wd-icon name="{{prefixIcon}}" type="{{prefixType}}" src="{{prefixSrc}}" size="{{iconSize}}" className="{{root}}__icon-before"></wd-icon>
33
33
  </view>
34
34
  </block>
@@ -64,7 +64,7 @@
64
64
 
65
65
  <!-- 后缀图标 -->
66
66
  <block wx:if="{{!hasClearIcon && suffixType}}">
67
- <view class="{{inputWrap}}__after">
67
+ <view class="{{inputWrap}}__after" data-type="suffix" bind:tap="inputAdornmentClick">
68
68
  <wd-icon name="{{suffixIcon}}" type="{{suffixType}}" src="{{suffixSrc}}" size="{{iconSize}}" className="{{root}}__icon-after"></wd-icon>
69
69
  </view>
70
70
  </block>
@@ -44,6 +44,7 @@
44
44
  bind:clear="handleEvent"
45
45
  bind:confirm="handleEvent"
46
46
  bind:changeForm="changeForm"
47
+ bind:inputAdornmentClick="handleEvent"
47
48
  classRoot="{{classRoot}}"
48
49
  visible="{{visible}}"
49
50
  validateState="{{validateState}}"
@@ -54,4 +54,12 @@ Component({
54
54
  this.setData({ inputGroupCls, root });
55
55
  },
56
56
  },
57
+ methods: {
58
+ // 点击前后缀文字/图标
59
+ inputAdornmentClick: function (e) {
60
+ this.triggerEvent('inputAdornmentClick', {
61
+ type: e.currentTarget.dataset.type,
62
+ });
63
+ },
64
+ },
57
65
  });
@@ -1,13 +1,13 @@
1
1
  <block wx:if="{{!readOnly && (!!before || !!after)}}">
2
2
  <view class="{{inputGroupCls}}">
3
3
  <block wx:if="{{before}}">
4
- <view class="{{inputGroup}}__addon {{inputGroup}}__addon-left {{root}}__text-before">{{before}}</view>
4
+ <view class="{{inputGroup}}__addon {{inputGroup}}__addon-left {{root}}__text-before" data-type="beforeText" bind:tap="inputAdornmentClick">{{before}}</view>
5
5
  </block>
6
6
  <view class="{{inputGroup}}__content">
7
7
  <slot></slot>
8
8
  </view>
9
9
  <block wx:if="{{after}}">
10
- <view class="{{inputGroup}}__addon {{inputGroup}}__addon-right {{root}}__text-after">{{after}}</view>
10
+ <view class="{{inputGroup}}__addon {{inputGroup}}__addon-right {{root}}__text-after" data-type="afterText" bind:tap="inputAdornmentClick">{{after}}</view>
11
11
  </block>
12
12
  </view>
13
13
  </block>
@@ -44,6 +44,7 @@
44
44
  bind:clear="handleEvent"
45
45
  bind:confirm="handleEvent"
46
46
  bind:changeForm="changeForm"
47
+ bind:inputAdornmentClick="handleEvent"
47
48
  classRoot="{{classRoot}}"
48
49
  visible="{{visible}}"
49
50
  validateState="{{validateState}}"
@@ -43,6 +43,7 @@
43
43
  bind:change="handleEvent"
44
44
  bind:clear="handleEvent"
45
45
  bind:confirm="handleEvent"
46
+ bind:inputAdornmentClick="handleEvent"
46
47
  bind:changeForm="changeForm"
47
48
  classRoot="{{classRoot}}"
48
49
  visible="{{visible}}"
@@ -22,7 +22,6 @@
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
- name="{{name}}"
26
25
  labelVisible="{{false}}"
27
26
  label=""
28
27
  readOnly="{{readOnly}}"
@@ -36,6 +35,7 @@
36
35
  size="full"
37
36
  tipBlock="{{tipBlock}}"
38
37
  viewId="{{viewId}}"
38
+ where="{{where}}"
39
39
  dataSourceName="{{dataSourceName}}"
40
40
  mode="selector"
41
41
  version="wd"
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.7.13",
6
+ "version": "3.8.0",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"
package/utils/enum.js CHANGED
@@ -978,6 +978,8 @@ export const WD_SELECT_FORMAT = [
978
978
  { label: 'related', value: 'related' },
979
979
  { label: 'x-enum', value: 'x-enum' },
980
980
  { label: 'many-one', value: 'many-one' },
981
+ { label: 'one-one', value: 'one-one' },
982
+ { label: 'one-one-r', value: 'one-one-r' },
981
983
  ];
982
984
 
983
985
  // 地区选择
@@ -1252,6 +1254,8 @@ export const WD_CODE_EDITOR_LANGUAGE = [
1252
1254
  { label: 'MongoDB', value: 'mongodb' },
1253
1255
  { label: 'SQL', value: 'sql' },
1254
1256
  { label: 'MySQL', value: 'mysql' },
1257
+ { label: 'JSON', value: 'json' },
1258
+ { label: 'Markdown', value: 'markdown' },
1255
1259
  ];
1256
1260
 
1257
1261
  export const WD_CODE_EDITOR_THEME = [