fmui-base 2.3.58 → 2.3.60

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.
@@ -0,0 +1,509 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = undefined;
7
+
8
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
9
+
10
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
11
+
12
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
13
+
14
+ var _react = require('react');
15
+
16
+ var _react2 = _interopRequireDefault(_react);
17
+
18
+ var _SearchBar = require('saltui/lib/SearchBar');
19
+
20
+ var _SearchBar2 = _interopRequireDefault(_SearchBar);
21
+
22
+ var _Button = require('saltui/lib/Button');
23
+
24
+ var _Button2 = _interopRequireDefault(_Button);
25
+
26
+ var _Toast = require('saltui/lib/Toast');
27
+
28
+ var _Toast2 = _interopRequireDefault(_Toast);
29
+
30
+ var _Boxs = require('saltui/lib/Boxs');
31
+
32
+ var _Boxs2 = _interopRequireDefault(_Boxs);
33
+
34
+ var _db = require('../db/db');
35
+
36
+ var _db2 = _interopRequireDefault(_db);
37
+
38
+ var _variables = require('../db/variables');
39
+
40
+ var _variables2 = _interopRequireDefault(_variables);
41
+
42
+ var _ScrollList = require('../ScrollList/ScrollList');
43
+
44
+ var _ScrollList2 = _interopRequireDefault(_ScrollList);
45
+
46
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
+
48
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
49
+
50
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
51
+
52
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
53
+
54
+ var HBox = _Boxs2.default.HBox,
55
+ Box = _Boxs2.default.Box;
56
+
57
+
58
+ var PAGE_SIZE = 10;
59
+
60
+ /** 列表项:已关联则禁用多选框,但仍展示 */
61
+ function RelationPickItem(props) {
62
+ var item = props.data || props;
63
+ if (item._hidden) {
64
+ return null;
65
+ }
66
+ var pid = String(item.processInstanceId || item.id || '');
67
+ var disabled = !!item._relatedDisabled;
68
+ var checked = !!props.isChecked;
69
+ var createTime = item.createTime || item.startTime || '';
70
+ return _react2.default.createElement(
71
+ HBox,
72
+ {
73
+ className: 't-BCf t-P16 t-PR12 dd-bottom-border' + (disabled ? ' relation-pick-item-disabled' : ''),
74
+ vAlign: 'center',
75
+ onClick: function onClick() {
76
+ if (disabled) {
77
+ return;
78
+ }
79
+ if (typeof props.onToggle === 'function') {
80
+ props.onToggle(item);
81
+ }
82
+ }
83
+ },
84
+ _react2.default.createElement(
85
+ Box,
86
+ {
87
+ className: disabled ? 't-checkbox-field-icon-list un-checked disabled' : checked ? 't-checkbox-field-icon checked t-checkbox-field-icon-list' : 't-checkbox-field-icon-list un-checked',
88
+ style: disabled ? { opacity: 0.4, background: 'rgba(31,56,88,.15)' } : undefined
89
+ },
90
+ _react2.default.createElement('i', { className: 'iconfont icon-checked t-FCf t-FS14' })
91
+ ),
92
+ _react2.default.createElement(
93
+ Box,
94
+ { flex: 1, className: 't-PL12', style: { minWidth: 0 } },
95
+ _react2.default.createElement(
96
+ 'div',
97
+ { className: 't-omit t-FS16 t-LH1_3 ' + (disabled ? 't-FCc' : 't-FC3') },
98
+ item.title || '',
99
+ disabled ? _react2.default.createElement(
100
+ 'span',
101
+ { className: 't-FS12 t-ML8 t-FCc' },
102
+ '\uFF08\u5DF2\u5173\u8054\uFF09'
103
+ ) : null
104
+ ),
105
+ _react2.default.createElement(
106
+ HBox,
107
+ { className: 't-FCddfontblue-40 t-LH1_3 t-PT8 t-FS14', vAlign: 'center' },
108
+ _react2.default.createElement(
109
+ Box,
110
+ null,
111
+ _react2.default.createElement(
112
+ 'span',
113
+ { className: 't-omit t-MR16' },
114
+ item.startUserName || ''
115
+ )
116
+ ),
117
+ _react2.default.createElement(
118
+ Box,
119
+ { flex: 1, style: { minWidth: 0 } },
120
+ _react2.default.createElement(
121
+ 'span',
122
+ { className: 't-omit' },
123
+ createTime
124
+ )
125
+ )
126
+ )
127
+ )
128
+ );
129
+ }
130
+
131
+ /**
132
+ * 移动端关联流程选择:标题搜索 + ScrollList 触底分页
133
+ * 已关联:展示但禁用勾选;分页按服务端 count 判断,避免过滤后误判「没有更多了」
134
+ */
135
+
136
+ var RelationProcessPicker = function (_React$Component) {
137
+ _inherits(RelationProcessPicker, _React$Component);
138
+
139
+ function RelationProcessPicker(props) {
140
+ _classCallCheck(this, RelationProcessPicker);
141
+
142
+ var _this = _possibleConstructorReturn(this, (RelationProcessPicker.__proto__ || Object.getPrototypeOf(RelationProcessPicker)).call(this, props));
143
+
144
+ _this.state = {
145
+ title: '',
146
+ selectedMap: {},
147
+ list: [],
148
+ page: 1,
149
+ total: 0,
150
+ fetchedCount: 0,
151
+ loading: false,
152
+ refreshing: false,
153
+ dataGetted: false,
154
+ noMore: false,
155
+ hasError: false
156
+ };
157
+ _this.searchTimer = null;
158
+ return _this;
159
+ }
160
+
161
+ _createClass(RelationProcessPicker, [{
162
+ key: 'componentDidMount',
163
+ value: function componentDidMount() {
164
+ this.fetchPage(1, true);
165
+ }
166
+ }, {
167
+ key: 'componentWillUnmount',
168
+ value: function componentWillUnmount() {
169
+ if (this.searchTimer) {
170
+ clearTimeout(this.searchTimer);
171
+ }
172
+ }
173
+ }, {
174
+ key: 'getExcludeIdSet',
175
+ value: function getExcludeIdSet() {
176
+ var excludeIds = this.props.excludeIds || [];
177
+ var set = {};
178
+ for (var i = 0; i < excludeIds.length; i++) {
179
+ if (excludeIds[i]) {
180
+ set[String(excludeIds[i])] = true;
181
+ }
182
+ }
183
+ var currentId = this.props.processInstanceId;
184
+ if (currentId) {
185
+ set[String(currentId)] = true;
186
+ }
187
+ return set;
188
+ }
189
+ }, {
190
+ key: 'isRelated',
191
+ value: function isRelated(item) {
192
+ var excludeSet = this.getExcludeIdSet();
193
+ var pid = item.processInstanceId || item.id;
194
+ return !!(pid && excludeSet[String(pid)]);
195
+ }
196
+ }, {
197
+ key: 'markList',
198
+ value: function markList(rawList) {
199
+ var selfId = String(this.props.processInstanceId || '');
200
+ var marked = [];
201
+ if (!rawList || !rawList.length) {
202
+ return marked;
203
+ }
204
+ for (var i = 0; i < rawList.length; i++) {
205
+ var row = Object.assign({}, rawList[i]);
206
+ var pid = String(row.processInstanceId || row.id || '');
207
+ // 当前流程标记隐藏(不删数组项,避免影响分页长度判断;渲染时跳过)
208
+ if (pid && selfId && pid === selfId) {
209
+ row._hidden = true;
210
+ }
211
+ row._relatedDisabled = this.isRelated(row);
212
+ marked.push(row);
213
+ }
214
+ return marked;
215
+ }
216
+ }, {
217
+ key: 'parsePayload',
218
+ value: function parsePayload(content) {
219
+ var payload = content;
220
+ // 兼容 DB 解包后 / 未解包 / 再包一层 content
221
+ if (content && content.content && _typeof(content.content) === 'object' && !Array.isArray(content.content)) {
222
+ var inner = content.content;
223
+ if (inner.data || inner.count != null || inner.content) {
224
+ payload = inner;
225
+ }
226
+ }
227
+ if (payload && payload.content && _typeof(payload.content) === 'object' && !Array.isArray(payload.content) && (payload.content.data || payload.content.count != null)) {
228
+ payload = payload.content;
229
+ }
230
+ var list = [];
231
+ if (payload && Array.isArray(payload.data)) {
232
+ list = payload.data;
233
+ } else if (Array.isArray(payload)) {
234
+ list = payload;
235
+ }
236
+ var total = 0;
237
+ if (payload && payload.count != null && payload.count !== '') {
238
+ total = Number(payload.count);
239
+ } else if (payload && payload.totalElements != null) {
240
+ total = Number(payload.totalElements);
241
+ } else if (payload && payload.total != null) {
242
+ total = Number(payload.total);
243
+ }
244
+ if (isNaN(total) || total < 0) {
245
+ total = 0;
246
+ }
247
+ return { list: list, total: total };
248
+ }
249
+ }, {
250
+ key: 'fetchPage',
251
+ value: function fetchPage(page, replace) {
252
+ var t = this;
253
+ if (t.state.loading) {
254
+ return;
255
+ }
256
+ t.setState(replace ? { refreshing: true, loading: true } : { loading: true, hasError: false });
257
+ _db2.default.FlowModuleAPI.getRelationProcessList({
258
+ title: t.state.title || '',
259
+ page: page,
260
+ limit: PAGE_SIZE,
261
+ pageSize: PAGE_SIZE
262
+ }).then(function (content) {
263
+ var parsed = t.parsePayload(content);
264
+ var marked = t.markList(parsed.list);
265
+ // 累计「原始返回条数」判断是否还有下一页;隐藏当前流程不缩短累计长度
266
+ var fetchedLen = (replace ? 0 : t.state.fetchedCount || 0) + parsed.list.length;
267
+ var nextList = replace ? marked : t.state.list.concat(marked);
268
+ var total = parsed.total;
269
+ // 仅按服务端 count 判断;绝不能用过滤/隐藏后的 list.length < pageSize
270
+ var noMore = false;
271
+ if (total > 0) {
272
+ noMore = fetchedLen >= total;
273
+ } else {
274
+ noMore = parsed.list.length === 0;
275
+ }
276
+ t.setState({
277
+ list: nextList,
278
+ page: page,
279
+ total: total,
280
+ fetchedCount: fetchedLen,
281
+ loading: false,
282
+ refreshing: false,
283
+ dataGetted: true,
284
+ noMore: noMore,
285
+ hasError: false
286
+ });
287
+ }).catch(function () {
288
+ t.setState({
289
+ loading: false,
290
+ refreshing: false,
291
+ dataGetted: true,
292
+ hasError: true
293
+ });
294
+ _Toast2.default.show({
295
+ type: 'error',
296
+ content: '加载可选流程失败'
297
+ });
298
+ });
299
+ }
300
+ }, {
301
+ key: 'onSearchChange',
302
+ value: function onSearchChange(value) {
303
+ var t = this;
304
+ t.setState({ title: value });
305
+ if (t.searchTimer) {
306
+ clearTimeout(t.searchTimer);
307
+ }
308
+ t.searchTimer = setTimeout(function () {
309
+ t.fetchPage(1, true);
310
+ }, 400);
311
+ }
312
+ }, {
313
+ key: 'onSearch',
314
+ value: function onSearch(value) {
315
+ var _this2 = this;
316
+
317
+ this.setState({ title: value }, function () {
318
+ _this2.fetchPage(1, true);
319
+ });
320
+ }
321
+ }, {
322
+ key: 'onRefresh',
323
+ value: function onRefresh() {
324
+ this.fetchPage(1, true);
325
+ }
326
+ }, {
327
+ key: 'onLoad',
328
+ value: function onLoad() {
329
+ if (this.state.noMore || this.state.loading) {
330
+ return;
331
+ }
332
+ this.fetchPage(this.state.page + 1, false);
333
+ }
334
+ }, {
335
+ key: 'toggleSelect',
336
+ value: function toggleSelect(item) {
337
+ if (!item || item._hidden || item._relatedDisabled || this.isRelated(item)) {
338
+ return;
339
+ }
340
+ var pid = String(item.processInstanceId || item.id || '');
341
+ if (!pid) {
342
+ return;
343
+ }
344
+ var selectedMap = Object.assign({}, this.state.selectedMap);
345
+ if (selectedMap[pid]) {
346
+ delete selectedMap[pid];
347
+ } else {
348
+ selectedMap[pid] = item;
349
+ }
350
+ this.setState({ selectedMap: selectedMap });
351
+ }
352
+ }, {
353
+ key: 'closePage',
354
+ value: function closePage() {
355
+ if (typeof this.props.onClose === 'function') {
356
+ this.props.onClose();
357
+ return;
358
+ }
359
+ if (typeof this.props.onCancel === 'function') {
360
+ this.props.onCancel();
361
+ }
362
+ }
363
+ }, {
364
+ key: 'handleCancel',
365
+ value: function handleCancel() {
366
+ this.closePage();
367
+ }
368
+ }, {
369
+ key: 'handleConfirm',
370
+ value: function handleConfirm() {
371
+ var t = this;
372
+ var keys = Object.keys(t.state.selectedMap);
373
+ if (!keys.length) {
374
+ _Toast2.default.show({
375
+ type: 'error',
376
+ content: '请选择记录'
377
+ });
378
+ return;
379
+ }
380
+ var processInstanceId = t.props.processInstanceId;
381
+ if (!processInstanceId) {
382
+ _Toast2.default.show({
383
+ type: 'error',
384
+ content: '请先保存/提交生成流程后再关联'
385
+ });
386
+ return;
387
+ }
388
+ _db2.default.FlowModuleAPI.insertBatchRelation({
389
+ processInstanceId: processInstanceId,
390
+ relationIds: keys.join(','),
391
+ activityId: t.props.activityId || '',
392
+ dataInherit: ''
393
+ }).then(function () {
394
+ _Toast2.default.show({
395
+ type: 'success',
396
+ content: '关联成功'
397
+ });
398
+ t.closePage();
399
+ if (typeof t.props.onSuccess === 'function') {
400
+ t.props.onSuccess();
401
+ }
402
+ }).catch(function () {
403
+ _Toast2.default.show({
404
+ type: 'error',
405
+ content: '关联失败'
406
+ });
407
+ });
408
+ }
409
+ }, {
410
+ key: 'render',
411
+ value: function render() {
412
+ var t = this;
413
+ var selectedMap = t.state.selectedMap;
414
+ var selectedCount = Object.keys(selectedMap).length;
415
+ var searchBarProps = {
416
+ locale: 'zh_CN',
417
+ placeholder: '搜索流程标题',
418
+ instantSearch: true,
419
+ hasHistory: false,
420
+ searchDelay: 400,
421
+ onChange: t.onSearchChange.bind(t),
422
+ onSearch: t.onSearch.bind(t)
423
+ };
424
+ var winH = typeof window !== 'undefined' && window.innerHeight ? window.innerHeight : 600;
425
+ var listH = Math.max(winH - 160, 240);
426
+ return _react2.default.createElement(
427
+ 'div',
428
+ {
429
+ className: 't-W100 t-BCf relation-process-picker',
430
+ style: {
431
+ width: '100%',
432
+ height: winH + 'px',
433
+ display: 'flex',
434
+ flexDirection: 'column',
435
+ boxSizing: 'border-box'
436
+ }
437
+ },
438
+ _react2.default.createElement(
439
+ HBox,
440
+ { vAlign: 'center', className: 't-PL16 t-PR16 t-PT12 t-PB12 t-BB1', style: { flexShrink: 0 } },
441
+ _react2.default.createElement(
442
+ Box,
443
+ { flex: 1, className: 't-FS16 t-FAC' },
444
+ '\u5173\u8054\u6D41\u7A0B'
445
+ )
446
+ ),
447
+ _react2.default.createElement(
448
+ 'div',
449
+ { className: 't-BCf', style: { flexShrink: 0 } },
450
+ _react2.default.createElement(_SearchBar2.default, _extends({}, searchBarProps, { value: t.state.title }))
451
+ ),
452
+ _react2.default.createElement(
453
+ 'div',
454
+ { style: { flex: 1, minHeight: 0, height: listH + 'px' }, className: 'relation-process-picker-scroll' },
455
+ _react2.default.createElement(
456
+ _ScrollList2.default,
457
+ {
458
+ dataGetted: t.state.dataGetted,
459
+ data: t.state.list,
460
+ loading: t.state.loading,
461
+ refreshing: t.state.refreshing,
462
+ noMore: t.state.noMore,
463
+ hasError: t.state.hasError,
464
+ onRefresh: t.onRefresh.bind(t),
465
+ onLoad: t.onLoad.bind(t),
466
+ scrollLoad: true,
467
+ scrollRefresh: true,
468
+ noDataImage: _variables2.default.nodataIcon,
469
+ noDataTip: '\u6682\u65E0\u6570\u636E',
470
+ noMoreDataTip: '\u6CA1\u6709\u66F4\u591A\u4E86'
471
+ },
472
+ function (item, i) {
473
+ var pid = String(item.processInstanceId || item.id || '');
474
+ return _react2.default.createElement(RelationPickItem, {
475
+ key: pid + '_' + i,
476
+ data: item,
477
+ isChecked: !!selectedMap[pid],
478
+ onToggle: t.toggleSelect.bind(t)
479
+ });
480
+ }
481
+ )
482
+ ),
483
+ _react2.default.createElement(
484
+ 'div',
485
+ { className: 't-P0', style: { flexShrink: 0 } },
486
+ _react2.default.createElement(
487
+ _Button2.default.Group,
488
+ null,
489
+ _react2.default.createElement(
490
+ _Button2.default,
491
+ { type: 'secondary', display: 'banner', onClick: t.handleCancel.bind(t) },
492
+ '\u53D6\u6D88'
493
+ ),
494
+ _react2.default.createElement(
495
+ _Button2.default,
496
+ { type: 'primary', display: 'banner', onClick: t.handleConfirm.bind(t) },
497
+ '\u786E\u5B9A',
498
+ selectedCount > 0 ? '(' + selectedCount + ')' : ''
499
+ )
500
+ )
501
+ )
502
+ );
503
+ }
504
+ }]);
505
+
506
+ return RelationProcessPicker;
507
+ }(_react2.default.Component);
508
+
509
+ exports.default = RelationProcessPicker;