easy3wui 4.0.33 → 4.0.34
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/lib/Easy3wModal/index.js +107 -62
- package/package.json +1 -1
package/lib/Easy3wModal/index.js
CHANGED
|
@@ -32,8 +32,6 @@ var _react = require('react');
|
|
|
32
32
|
|
|
33
33
|
var _react2 = _interopRequireDefault(_react);
|
|
34
34
|
|
|
35
|
-
var _dva = require('dva');
|
|
36
|
-
|
|
37
35
|
var _antd = require('antd');
|
|
38
36
|
|
|
39
37
|
var _modal = require('antd/lib/modal');
|
|
@@ -42,6 +40,8 @@ var _modal2 = _interopRequireDefault(_modal);
|
|
|
42
40
|
|
|
43
41
|
require('antd/lib/modal/style');
|
|
44
42
|
|
|
43
|
+
var _dva = require('dva');
|
|
44
|
+
|
|
45
45
|
var _button = require('antd/lib/button');
|
|
46
46
|
|
|
47
47
|
var _button2 = _interopRequireDefault(_button);
|
|
@@ -81,12 +81,12 @@ var Easy3wModal = function (_Component) {
|
|
|
81
81
|
return _react2['default'].createElement(
|
|
82
82
|
_button2['default'],
|
|
83
83
|
{
|
|
84
|
-
onClick: function onClick(e) {
|
|
85
|
-
return _this.onClickFunc(e, obj.func);
|
|
86
|
-
},
|
|
87
84
|
type: 'primary',
|
|
88
85
|
className: (0, _classnames2['default'])(['e3wFootBtn']),
|
|
89
|
-
loading: obj.loading
|
|
86
|
+
loading: obj.loading,
|
|
87
|
+
onClick: function onClick(e) {
|
|
88
|
+
return _this.onClickFunc(e, obj.func);
|
|
89
|
+
}
|
|
90
90
|
},
|
|
91
91
|
obj.cName
|
|
92
92
|
);
|
|
@@ -110,22 +110,25 @@ var Easy3wModal = function (_Component) {
|
|
|
110
110
|
Easy3wModal.setGetLoading = function setGetLoading(fn) {
|
|
111
111
|
Easy3wModal.getLoading = fn;
|
|
112
112
|
};
|
|
113
|
-
//
|
|
113
|
+
// 返回一个promise
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
Easy3wModal.
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
Easy3wModal.returnPromise = function returnPromise() {
|
|
117
|
+
var onOk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
|
118
|
+
|
|
119
|
+
return new Promise(function (resolve) {
|
|
120
|
+
try {
|
|
121
|
+
onOk();
|
|
122
|
+
setTimeout(function () {
|
|
123
|
+
resolve(); // 300ms 后关闭 Modal
|
|
124
|
+
document.body.style.overflow = '';
|
|
125
|
+
}, 300);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error('onOk 执行报错:', e);
|
|
128
|
+
resolve(); // 出错时不关闭
|
|
129
|
+
document.body.style.overflow = '';
|
|
130
|
+
}
|
|
131
|
+
});
|
|
129
132
|
};
|
|
130
133
|
// confirm
|
|
131
134
|
|
|
@@ -133,10 +136,18 @@ var Easy3wModal = function (_Component) {
|
|
|
133
136
|
Easy3wModal.confirm = function confirm() {
|
|
134
137
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
135
138
|
var _onOk = props.onOk,
|
|
136
|
-
|
|
139
|
+
_onCancel = props.onCancel,
|
|
140
|
+
restProps = (0, _objectWithoutProperties3['default'])(props, ['onOk', 'onCancel']);
|
|
137
141
|
|
|
138
142
|
return _modal2['default'].confirm((0, _extends3['default'])({}, restProps, {
|
|
143
|
+
onCancel: function onCancel() {
|
|
144
|
+
if (_onCancel) {
|
|
145
|
+
_onCancel();
|
|
146
|
+
}
|
|
147
|
+
document.body.style.overflow = '';
|
|
148
|
+
},
|
|
139
149
|
onOk: function onOk() {
|
|
150
|
+
// 1. 检查全局 loading 状态,阻止重复操作
|
|
140
151
|
var loadingFlag = Easy3wModal.getLoading();
|
|
141
152
|
if (loadingFlag) {
|
|
142
153
|
_notification3['default'].warning({
|
|
@@ -146,80 +157,113 @@ var Easy3wModal = function (_Component) {
|
|
|
146
157
|
});
|
|
147
158
|
return Promise.reject(); // 阻止 Modal 自动关闭
|
|
148
159
|
}
|
|
149
|
-
|
|
150
|
-
|
|
160
|
+
|
|
161
|
+
// 2. onOk不是函数,关闭
|
|
162
|
+
if (typeof _onOk !== 'function') {
|
|
163
|
+
return true; // 直接关闭 Modal
|
|
151
164
|
}
|
|
152
|
-
|
|
165
|
+
|
|
166
|
+
// 3. 执行onOk
|
|
167
|
+
return new Promise(function (resolve) {
|
|
168
|
+
try {
|
|
169
|
+
_onOk();
|
|
170
|
+
setTimeout(function () {
|
|
171
|
+
resolve(); // 300ms 后关闭 Modal
|
|
172
|
+
document.body.style.overflow = '';
|
|
173
|
+
}, 300);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.error('onOk 执行报错:', e);
|
|
176
|
+
resolve(); // 出错时不关闭
|
|
177
|
+
document.body.style.overflow = '';
|
|
178
|
+
}
|
|
179
|
+
});
|
|
153
180
|
}
|
|
154
181
|
}));
|
|
155
182
|
};
|
|
156
|
-
// info
|
|
157
183
|
|
|
184
|
+
// 展示modal
|
|
158
185
|
|
|
159
|
-
Easy3wModal.info = function info() {
|
|
160
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
161
186
|
|
|
162
|
-
|
|
187
|
+
Easy3wModal.showModal = function showModal(type) {
|
|
188
|
+
var _this2 = this;
|
|
189
|
+
|
|
190
|
+
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
191
|
+
|
|
192
|
+
// 1. 判断参数类型
|
|
163
193
|
var options = typeof props === 'string' || typeof props === 'number' ? { content: props } : props;
|
|
194
|
+
|
|
164
195
|
var _onOk2 = options.onOk,
|
|
165
|
-
|
|
196
|
+
_onCancel2 = options.onCancel,
|
|
197
|
+
restProps = (0, _objectWithoutProperties3['default'])(options, ['onOk', 'onCancel']);
|
|
166
198
|
|
|
167
|
-
|
|
199
|
+
// 2. 定义统一的关闭逻辑
|
|
200
|
+
|
|
201
|
+
var resetBodyOverflow = function resetBodyOverflow() {
|
|
202
|
+
document.body.style.overflow = '';
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// 3. 调用对应类型的 Modal 方法
|
|
206
|
+
return _modal2['default'][type]((0, _extends3['default'])({}, restProps, {
|
|
207
|
+
onCancel: function onCancel() {
|
|
208
|
+
if (_onCancel2) {
|
|
209
|
+
_onCancel2();
|
|
210
|
+
}
|
|
211
|
+
resetBodyOverflow();
|
|
212
|
+
},
|
|
168
213
|
onOk: function onOk() {
|
|
169
|
-
|
|
214
|
+
if (_onOk2) {
|
|
215
|
+
var loadingFlag = Easy3wModal.getLoading();
|
|
216
|
+
if (loadingFlag) {
|
|
217
|
+
_notification3['default'].warning({
|
|
218
|
+
message: '温馨提示',
|
|
219
|
+
description: '操作正在进行中,请稍后!',
|
|
220
|
+
duration: 3
|
|
221
|
+
});
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (typeof _onOk2 !== 'function') {
|
|
225
|
+
return true; // 直接关闭 Modal
|
|
226
|
+
}
|
|
227
|
+
_this2.returnPromise(_onOk2).then(function () {});
|
|
228
|
+
}
|
|
170
229
|
}
|
|
171
230
|
}));
|
|
172
231
|
};
|
|
232
|
+
|
|
233
|
+
// info
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
Easy3wModal.info = function info() {
|
|
237
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
238
|
+
|
|
239
|
+
return this.showModal('info', props);
|
|
240
|
+
};
|
|
241
|
+
|
|
173
242
|
// success
|
|
174
243
|
|
|
175
244
|
|
|
176
245
|
Easy3wModal.success = function success() {
|
|
177
246
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
178
247
|
|
|
179
|
-
|
|
180
|
-
var options = typeof props === 'string' || typeof props === 'number' ? { content: props } : props;
|
|
181
|
-
var _onOk3 = options.onOk,
|
|
182
|
-
restProps = (0, _objectWithoutProperties3['default'])(options, ['onOk']);
|
|
183
|
-
|
|
184
|
-
return _modal2['default'].success((0, _extends3['default'])({}, restProps, {
|
|
185
|
-
onOk: function onOk() {
|
|
186
|
-
return Easy3wModal.checkLoadingAndRun(_onOk3);
|
|
187
|
-
}
|
|
188
|
-
}));
|
|
248
|
+
return this.showModal('success', props);
|
|
189
249
|
};
|
|
250
|
+
|
|
190
251
|
// error
|
|
191
252
|
|
|
192
253
|
|
|
193
254
|
Easy3wModal.error = function error() {
|
|
194
255
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
195
256
|
|
|
196
|
-
|
|
197
|
-
var options = typeof props === 'string' || typeof props === 'number' ? { content: props } : props;
|
|
198
|
-
var _onOk4 = options.onOk,
|
|
199
|
-
restProps = (0, _objectWithoutProperties3['default'])(options, ['onOk']);
|
|
200
|
-
|
|
201
|
-
return _modal2['default'].error((0, _extends3['default'])({}, restProps, {
|
|
202
|
-
onOk: function onOk() {
|
|
203
|
-
return Easy3wModal.checkLoadingAndRun(_onOk4);
|
|
204
|
-
}
|
|
205
|
-
}));
|
|
257
|
+
return this.showModal('error', props);
|
|
206
258
|
};
|
|
259
|
+
|
|
207
260
|
// warning
|
|
208
261
|
|
|
209
262
|
|
|
210
263
|
Easy3wModal.warning = function warning() {
|
|
211
264
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
212
265
|
|
|
213
|
-
|
|
214
|
-
var options = typeof props === 'string' || typeof props === 'number' ? { content: props } : props;
|
|
215
|
-
var _onOk5 = options.onOk,
|
|
216
|
-
restProps = (0, _objectWithoutProperties3['default'])(options, ['onOk']);
|
|
217
|
-
|
|
218
|
-
return _modal2['default'].warning((0, _extends3['default'])({}, restProps, {
|
|
219
|
-
onOk: function onOk() {
|
|
220
|
-
return Easy3wModal.checkLoadingAndRun(_onOk5);
|
|
221
|
-
}
|
|
222
|
-
}));
|
|
266
|
+
return this.showModal('warning', props);
|
|
223
267
|
};
|
|
224
268
|
|
|
225
269
|
Easy3wModal.prototype.render = function render() {
|
|
@@ -231,9 +275,10 @@ var Easy3wModal = function (_Component) {
|
|
|
231
275
|
cancelHandler = _props.cancelHandler,
|
|
232
276
|
onOk = _props.onOk,
|
|
233
277
|
width = _props.width,
|
|
278
|
+
footer = _props.footer,
|
|
234
279
|
footBtnArr = _props.footBtnArr;
|
|
235
280
|
|
|
236
|
-
var btnObj = footBtnArr && footBtnArr.length ? this.getBtnObj() : null;
|
|
281
|
+
var btnObj = footer && footer.length ? footer : footBtnArr && footBtnArr.length ? this.getBtnObj() : null;
|
|
237
282
|
return _react2['default'].createElement(
|
|
238
283
|
_modal2['default'],
|
|
239
284
|
(0, _extends3['default'])({
|