@vue-start/pro 0.1.0 → 0.3.1
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/CHANGELOG.md +37 -0
- package/dist/index.d.ts +1130 -63
- package/dist/index.es.js +1568 -367
- package/dist/index.js +1574 -360
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -7,42 +7,123 @@ var lodash = require('lodash');
|
|
|
7
7
|
var rxjs = require('rxjs');
|
|
8
8
|
var hooks = require('@vue-start/hooks');
|
|
9
9
|
var request = require('@vue-start/request');
|
|
10
|
+
var vueRouter = require('vue-router');
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
function ownKeys(object, enumerableOnly) {
|
|
13
|
+
var keys = Object.keys(object);
|
|
14
|
+
|
|
15
|
+
if (Object.getOwnPropertySymbols) {
|
|
16
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
17
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
18
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
19
|
+
})), keys.push.apply(keys, symbols);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return keys;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _objectSpread2(target) {
|
|
26
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
28
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
29
|
+
_defineProperty(target, key, source[key]);
|
|
30
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
31
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return target;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function _defineProperty(obj, key, value) {
|
|
39
|
+
if (key in obj) {
|
|
40
|
+
Object.defineProperty(obj, key, {
|
|
41
|
+
value: value,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
obj[key] = value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return obj;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function _toConsumableArray(arr) {
|
|
54
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function _arrayWithoutHoles(arr) {
|
|
58
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function _iterableToArray(iter) {
|
|
62
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
66
|
+
if (!o) return;
|
|
67
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
68
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
69
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
70
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
71
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _arrayLikeToArray(arr, len) {
|
|
75
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
76
|
+
|
|
77
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
78
|
+
|
|
79
|
+
return arr2;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function _nonIterableSpread() {
|
|
83
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var createUseRequestActor = function createUseRequestActor(filterFun) {
|
|
87
|
+
return function (actors, callback) {
|
|
88
|
+
var _useRequestProvide = request.useRequestProvide(),
|
|
89
|
+
requestSubject$ = _useRequestProvide.requestSubject$;
|
|
90
|
+
|
|
91
|
+
var nameSet = new Set(lodash.map(actors, function (actor) {
|
|
92
|
+
return lodash.isString(actor) ? actor : actor.name;
|
|
93
|
+
}));
|
|
94
|
+
hooks.useEffect(function () {
|
|
95
|
+
var sub = requestSubject$.pipe(rxjs.filter(filterFun), rxjs.tap(function (actor) {
|
|
96
|
+
if (nameSet.has(actor.name)) {
|
|
97
|
+
callback(actor);
|
|
98
|
+
}
|
|
99
|
+
})).subscribe();
|
|
100
|
+
return function () {
|
|
101
|
+
sub.unsubscribe();
|
|
102
|
+
};
|
|
103
|
+
}, []);
|
|
104
|
+
};
|
|
26
105
|
};
|
|
27
106
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
107
|
+
var useDoneRequestActor = createUseRequestActor(request.isDoneRequestActor);
|
|
108
|
+
var useFailedRequestActor = createUseRequestActor(request.isFailedRequestActor);
|
|
109
|
+
var useComposeRequestActor = function useComposeRequestActor(actors, options, cancelWhileUnmount) {
|
|
110
|
+
var _useRequestProvide2 = request.useRequestProvide(),
|
|
111
|
+
requestSubject$ = _useRequestProvide2.requestSubject$,
|
|
112
|
+
dispatchRequest = _useRequestProvide2.dispatchRequest;
|
|
113
|
+
|
|
114
|
+
var nameSet = new Set(lodash.map(actors, function (actor) {
|
|
115
|
+
return lodash.isString(actor) ? actor : actor.name;
|
|
116
|
+
}));
|
|
117
|
+
var lastRequestActors = {};
|
|
118
|
+
hooks.useEffect(function () {
|
|
119
|
+
var sub = rxjs.merge(requestSubject$.pipe(rxjs.filter(request.isPreRequestActor), rxjs.tap(function (actor) {
|
|
39
120
|
if (nameSet.has(actor.name)) {
|
|
40
121
|
var _options$onStart;
|
|
41
122
|
|
|
42
123
|
(_options$onStart = options.onStart) === null || _options$onStart === void 0 ? void 0 : _options$onStart.call(options, actor);
|
|
43
124
|
lastRequestActors[actor.name] = actor;
|
|
44
125
|
}
|
|
45
|
-
})), requestSubject$.pipe(rxjs.filter(request.isDoneRequestActor), rxjs.tap(actor
|
|
126
|
+
})), requestSubject$.pipe(rxjs.filter(request.isDoneRequestActor), rxjs.tap(function (actor) {
|
|
46
127
|
if (nameSet.has(actor.name)) {
|
|
47
128
|
var _options$onSuccess, _options$onFinish;
|
|
48
129
|
|
|
@@ -50,7 +131,7 @@ const useComposeRequestActor = (actors, options, cancelWhileUnmount) => {
|
|
|
50
131
|
(_options$onFinish = options.onFinish) === null || _options$onFinish === void 0 ? void 0 : _options$onFinish.call(options, actor);
|
|
51
132
|
lastRequestActors[actor.name] = undefined;
|
|
52
133
|
}
|
|
53
|
-
})), requestSubject$.pipe(rxjs.filter(request.isFailedRequestActor), rxjs.tap(actor
|
|
134
|
+
})), requestSubject$.pipe(rxjs.filter(request.isFailedRequestActor), rxjs.tap(function (actor) {
|
|
54
135
|
if (nameSet.has(actor.name)) {
|
|
55
136
|
var _options$onFailed, _options$onFinish2;
|
|
56
137
|
|
|
@@ -59,197 +140,273 @@ const useComposeRequestActor = (actors, options, cancelWhileUnmount) => {
|
|
|
59
140
|
lastRequestActors[actor.name] = undefined;
|
|
60
141
|
}
|
|
61
142
|
}))).subscribe();
|
|
62
|
-
return ()
|
|
143
|
+
return function () {
|
|
63
144
|
sub.unsubscribe();
|
|
64
145
|
|
|
65
146
|
if (cancelWhileUnmount) {
|
|
66
147
|
//组件销毁的时候cancel请求
|
|
67
|
-
lodash.forEach(lastRequestActors, actor
|
|
68
|
-
actor && dispatchRequest({
|
|
148
|
+
lodash.forEach(lastRequestActors, function (actor) {
|
|
149
|
+
actor && dispatchRequest(_objectSpread2(_objectSpread2({}, actor), {}, {
|
|
69
150
|
stage: "CANCEL"
|
|
70
|
-
});
|
|
151
|
+
}));
|
|
71
152
|
});
|
|
72
153
|
}
|
|
73
154
|
};
|
|
74
155
|
}, []);
|
|
75
156
|
};
|
|
76
157
|
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
158
|
+
/**
|
|
159
|
+
* 剔除showState或showStateRules规则为!true的值
|
|
160
|
+
* @param values
|
|
161
|
+
* @param showState
|
|
162
|
+
* @param showStateRules
|
|
80
163
|
*/
|
|
164
|
+
var getValidValues = function getValidValues(values, showState, showStateRules) {
|
|
165
|
+
if (showState) {
|
|
166
|
+
var invalidKeys = lodash.filter(lodash.keys(showState), function (key) {
|
|
167
|
+
return !showState[key];
|
|
168
|
+
});
|
|
169
|
+
return lodash.omit(values, invalidKeys);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (showStateRules) {
|
|
173
|
+
var _invalidKeys = lodash.filter(lodash.keys(showStateRules), function (key) {
|
|
174
|
+
return !showStateRules[key](values);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return lodash.omit(values, _invalidKeys);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return values;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* string类型的path转为arr
|
|
184
|
+
* @param path
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
var convertPathToList = function convertPathToList(path) {
|
|
188
|
+
if (!path) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (lodash.isArray(path)) {
|
|
193
|
+
return path;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (path && lodash.isString(path) && path.indexOf(".") > 0) {
|
|
197
|
+
return lodash.split(path, ".");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return [path];
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* 唯一id
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
var generateId = function generateId() {
|
|
207
|
+
return Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36);
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* 将listState 中的数据通过id merge到 list item中
|
|
211
|
+
* ps:数组会替换
|
|
212
|
+
* @param list
|
|
213
|
+
* @param listState
|
|
214
|
+
* @param id
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
var mergeStateToList = function mergeStateToList(list, listState, id) {
|
|
218
|
+
if (!listState || !id) {
|
|
219
|
+
return list;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return lodash.map(list, function (item) {
|
|
223
|
+
var idName = lodash.isFunction(id) ? id(item) : id; //如果listState中有值,merge处理
|
|
81
224
|
|
|
82
|
-
|
|
225
|
+
var stateData = lodash.get(listState, idName);
|
|
226
|
+
|
|
227
|
+
if (!stateData || lodash.isEmpty(stateData) || lodash.isFunction(stateData) || !lodash.isObject(stateData)) {
|
|
228
|
+
return item;
|
|
229
|
+
} //只有是对象(键值对)才合并
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
return lodash.mergeWith(item, stateData, function (objValue, srcValue) {
|
|
233
|
+
//如果是数组,替换
|
|
234
|
+
if (lodash.isArray(objValue) || lodash.isArray(srcValue)) {
|
|
235
|
+
return srcValue;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 获取Column的valueType,默认"text"
|
|
243
|
+
* @param column
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
var getColumnValueType = function getColumnValueType(column) {
|
|
83
247
|
return column.formValueType || column.valueType || "text";
|
|
84
248
|
};
|
|
85
|
-
/**
|
|
86
|
-
*获取Column的FormItem name
|
|
87
|
-
* @param column
|
|
249
|
+
/**
|
|
250
|
+
*获取Column的FormItem name
|
|
251
|
+
* @param column
|
|
88
252
|
*/
|
|
89
253
|
|
|
90
|
-
|
|
254
|
+
var getColumnFormItemName = function getColumnFormItemName(column) {
|
|
91
255
|
var _column$formItemProps;
|
|
92
256
|
|
|
93
257
|
return ((_column$formItemProps = column.formItemProps) === null || _column$formItemProps === void 0 ? void 0 : _column$formItemProps.name) || column.dataIndex;
|
|
94
258
|
};
|
|
95
|
-
/**
|
|
96
|
-
* 根据Column生成FormItem VNode
|
|
97
|
-
* formFieldProps中的slots参数会以v-slots的形式传递到FormItem的录入组件(子组件)中
|
|
98
|
-
* @param formElementMap
|
|
99
|
-
* @param column
|
|
100
|
-
* @param needRules
|
|
259
|
+
/**
|
|
260
|
+
* 根据Column生成FormItem VNode
|
|
261
|
+
* formFieldProps中的slots参数会以v-slots的形式传递到FormItem的录入组件(子组件)中
|
|
262
|
+
* @param formElementMap
|
|
263
|
+
* @param column
|
|
264
|
+
* @param needRules
|
|
101
265
|
*/
|
|
102
266
|
|
|
103
|
-
|
|
267
|
+
var getFormItemEl = function getFormItemEl(formElementMap, column) {
|
|
104
268
|
var _column$formFieldProp;
|
|
105
269
|
|
|
106
|
-
|
|
107
|
-
|
|
270
|
+
var needRules = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
271
|
+
var valueType = getColumnValueType(column);
|
|
272
|
+
var Comp = lodash.get(formElementMap, valueType);
|
|
108
273
|
|
|
109
274
|
if (!Comp) {
|
|
110
275
|
return null;
|
|
111
276
|
}
|
|
112
277
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return vue.h(Comp, {
|
|
278
|
+
var name = getColumnFormItemName(column);
|
|
279
|
+
var itemProps = needRules ? column.formItemProps : lodash.omit(column.formItemProps, "rules");
|
|
280
|
+
return vue.h(Comp, _objectSpread2(_objectSpread2({
|
|
116
281
|
key: name,
|
|
117
|
-
name,
|
|
118
|
-
label: column.title
|
|
119
|
-
|
|
282
|
+
name: name,
|
|
283
|
+
label: column.title
|
|
284
|
+
}, itemProps), {}, {
|
|
120
285
|
fieldProps: lodash.omit(column.formFieldProps, "slots"),
|
|
121
286
|
showProps: column.showProps
|
|
122
|
-
}, (_column$formFieldProp = column.formFieldProps) === null || _column$formFieldProp === void 0 ? void 0 : _column$formFieldProp.slots);
|
|
287
|
+
}), (_column$formFieldProp = column.formFieldProps) === null || _column$formFieldProp === void 0 ? void 0 : _column$formFieldProp.slots);
|
|
123
288
|
};
|
|
124
|
-
/**
|
|
125
|
-
* 根据Column生成Item VNode
|
|
126
|
-
* @param elementMap
|
|
127
|
-
* @param column
|
|
128
|
-
* @param value
|
|
289
|
+
/**
|
|
290
|
+
* 根据Column生成Item VNode
|
|
291
|
+
* @param elementMap
|
|
292
|
+
* @param column
|
|
293
|
+
* @param value
|
|
129
294
|
*/
|
|
130
295
|
|
|
131
|
-
|
|
296
|
+
var getItemEl = function getItemEl(elementMap, column, value) {
|
|
132
297
|
var _column$formFieldProp2;
|
|
133
298
|
|
|
134
|
-
|
|
135
|
-
|
|
299
|
+
var valueType = column.valueType || "text";
|
|
300
|
+
var Comp = lodash.get(elementMap, valueType);
|
|
136
301
|
|
|
137
302
|
if (!Comp) {
|
|
138
303
|
return null;
|
|
139
304
|
}
|
|
140
305
|
|
|
141
|
-
return vue.h(Comp, {
|
|
306
|
+
return vue.h(Comp, _objectSpread2(_objectSpread2({}, lodash.omit(column.formFieldProps, "slots")), {}, {
|
|
142
307
|
showProps: column.showProps,
|
|
143
|
-
value
|
|
144
|
-
}, (_column$formFieldProp2 = column.formFieldProps) === null || _column$formFieldProp2 === void 0 ? void 0 : _column$formFieldProp2.slots);
|
|
308
|
+
value: value
|
|
309
|
+
}), (_column$formFieldProp2 = column.formFieldProps) === null || _column$formFieldProp2 === void 0 ? void 0 : _column$formFieldProp2.slots);
|
|
310
|
+
};
|
|
311
|
+
var ProModuleKey = Symbol("pro-module");
|
|
312
|
+
var useProModule = function useProModule() {
|
|
313
|
+
return vue.inject(ProModuleKey);
|
|
145
314
|
};
|
|
146
|
-
|
|
147
|
-
const useProModule = () => vue.inject(ProModuleKey);
|
|
148
|
-
const provideProModule = ctx => {
|
|
315
|
+
var provideProModule = function provideProModule(ctx) {
|
|
149
316
|
vue.provide(ProModuleKey, ctx);
|
|
150
317
|
};
|
|
151
|
-
|
|
318
|
+
var RequestAction = {
|
|
152
319
|
Success: "request-success$",
|
|
153
320
|
Fail: "request-fail$"
|
|
154
321
|
};
|
|
155
322
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
323
|
+
var proModuleProps = function proModuleProps() {
|
|
324
|
+
return {
|
|
325
|
+
/**
|
|
326
|
+
* module状态
|
|
327
|
+
*/
|
|
328
|
+
state: {
|
|
329
|
+
type: Object
|
|
330
|
+
},
|
|
163
331
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
332
|
+
/**
|
|
333
|
+
* 配置(静态)
|
|
334
|
+
*/
|
|
335
|
+
columns: {
|
|
336
|
+
type: Array
|
|
337
|
+
},
|
|
170
338
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
339
|
+
/**
|
|
340
|
+
* 配置(动态)
|
|
341
|
+
* columns动态属性兼容
|
|
342
|
+
*/
|
|
343
|
+
columnState: {
|
|
344
|
+
type: Object
|
|
345
|
+
},
|
|
178
346
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
347
|
+
/**
|
|
348
|
+
* 展示组件集
|
|
349
|
+
*/
|
|
350
|
+
elementMap: {
|
|
351
|
+
type: Object
|
|
352
|
+
},
|
|
185
353
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
354
|
+
/**
|
|
355
|
+
* 录入组件集
|
|
356
|
+
*/
|
|
357
|
+
formElementMap: {
|
|
358
|
+
type: Object
|
|
359
|
+
},
|
|
192
360
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
361
|
+
/**
|
|
362
|
+
* requests
|
|
363
|
+
*/
|
|
364
|
+
requests: {
|
|
365
|
+
type: Array
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
200
369
|
|
|
201
|
-
|
|
202
|
-
props: {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}) => {
|
|
207
|
-
/**
|
|
208
|
-
* columns columnState 合并
|
|
209
|
-
*/
|
|
210
|
-
const columns = vue.computed(() => {
|
|
211
|
-
return lodash.map(props.columns, item => {
|
|
212
|
-
//如果columnState中有值,merge处理
|
|
213
|
-
const mapData = lodash.get(props.columnState, getColumnFormItemName(item));
|
|
214
|
-
|
|
215
|
-
if (lodash.isObject(mapData) && !lodash.isEmpty(mapData) && !lodash.isArray(mapData) && !lodash.isFunction(mapData)) {
|
|
216
|
-
//合并
|
|
217
|
-
return lodash.mergeWith(item, mapData, (objValue, srcValue) => {
|
|
218
|
-
//如果是数组,替换
|
|
219
|
-
if (lodash.isArray(objValue) || lodash.isArray(srcValue)) {
|
|
220
|
-
return srcValue;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
370
|
+
var ProModule = vue.defineComponent({
|
|
371
|
+
props: _objectSpread2({}, proModuleProps()),
|
|
372
|
+
setup: function setup(props, _ref) {
|
|
373
|
+
var slots = _ref.slots,
|
|
374
|
+
expose = _ref.expose;
|
|
224
375
|
|
|
225
|
-
|
|
376
|
+
/**
|
|
377
|
+
* columns columnState 合并
|
|
378
|
+
*/
|
|
379
|
+
var columns = vue.computed(function () {
|
|
380
|
+
return mergeStateToList(props.columns, props.columnState, function (item) {
|
|
381
|
+
return getColumnFormItemName(item);
|
|
226
382
|
});
|
|
227
383
|
});
|
|
228
384
|
/*********************************** 渲染组件 ***************************************/
|
|
229
385
|
// 获取FormItem VNode
|
|
230
386
|
|
|
231
|
-
|
|
387
|
+
var getFormItemVNode = function getFormItemVNode(column) {
|
|
388
|
+
var needRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
232
389
|
return getFormItemEl(props.formElementMap, column, needRules);
|
|
233
390
|
}; // 获取Item VNode
|
|
234
391
|
|
|
235
392
|
|
|
236
|
-
|
|
393
|
+
var getItemVNode = function getItemVNode(column, value) {
|
|
237
394
|
return getItemEl(props.elementMap, column, value);
|
|
238
395
|
};
|
|
239
396
|
/*********************************** 事件处理 ***************************************/
|
|
240
397
|
|
|
241
398
|
|
|
242
|
-
|
|
399
|
+
var subject$ = new rxjs.Subject(); //发送Module事件
|
|
243
400
|
|
|
244
|
-
|
|
401
|
+
var sendEvent = function sendEvent(action) {
|
|
245
402
|
subject$.next(action);
|
|
246
403
|
};
|
|
247
404
|
/*********************************** 页面状态 ***************************************/
|
|
248
405
|
|
|
249
406
|
|
|
250
|
-
|
|
407
|
+
var state = props.state || vue.reactive({});
|
|
251
408
|
|
|
252
|
-
|
|
409
|
+
var dispatch = function dispatch(action) {
|
|
253
410
|
//如果要更新的属性值是 object ,执行覆盖操作
|
|
254
411
|
if (lodash.isObject(state[action.type])) {
|
|
255
412
|
hooks.setReactiveValue(state[action.type], action.payload);
|
|
@@ -261,27 +418,33 @@ const ProModule = vue.defineComponent({
|
|
|
261
418
|
/*********************************** request ***************************************/
|
|
262
419
|
|
|
263
420
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}), {});
|
|
270
|
-
const actionMap = lodash.reduce(props.requests, (pair, item) => ({ ...pair,
|
|
271
|
-
[item.action]: item
|
|
272
|
-
}), {}); //发送请求
|
|
421
|
+
var _useRequestProvide = request.useRequestProvide(),
|
|
422
|
+
dispatchRequest = _useRequestProvide.dispatchRequest;
|
|
423
|
+
|
|
424
|
+
var requestMap = lodash.reduce(props.requests, function (pair, item) {
|
|
425
|
+
var _item$actor;
|
|
273
426
|
|
|
274
|
-
|
|
275
|
-
|
|
427
|
+
return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, (_item$actor = item.actor) === null || _item$actor === void 0 ? void 0 : _item$actor.name, item));
|
|
428
|
+
}, {});
|
|
429
|
+
var actionMap = lodash.reduce(props.requests, function (pair, item) {
|
|
430
|
+
return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, item.action, item));
|
|
431
|
+
}, {}); //发送请求
|
|
432
|
+
|
|
433
|
+
var sendRequest = function sendRequest(requestNameOrAction) {
|
|
434
|
+
var requestOpts = lodash.get(requestMap, requestNameOrAction) || lodash.get(actionMap, requestNameOrAction);
|
|
276
435
|
|
|
277
436
|
if (!requestOpts) {
|
|
278
437
|
return;
|
|
279
438
|
}
|
|
280
439
|
|
|
281
|
-
|
|
440
|
+
var nextParams;
|
|
441
|
+
|
|
442
|
+
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
443
|
+
params[_key - 1] = arguments[_key];
|
|
444
|
+
}
|
|
282
445
|
|
|
283
446
|
if (requestOpts.convertParams) {
|
|
284
|
-
nextParams = requestOpts.convertParams(
|
|
447
|
+
nextParams = requestOpts.convertParams.apply(requestOpts, params);
|
|
285
448
|
} else {
|
|
286
449
|
nextParams = lodash.get(params, 0);
|
|
287
450
|
}
|
|
@@ -290,9 +453,9 @@ const ProModule = vue.defineComponent({
|
|
|
290
453
|
};
|
|
291
454
|
|
|
292
455
|
useComposeRequestActor(lodash.keys(requestMap), {
|
|
293
|
-
onStart: actor
|
|
456
|
+
onStart: function onStart(actor) {
|
|
294
457
|
//如果设置了loading,将请求状态维护到state中
|
|
295
|
-
|
|
458
|
+
var loadingName = lodash.get(requestMap, [actor.name, "loadingName"]);
|
|
296
459
|
|
|
297
460
|
if (loadingName) {
|
|
298
461
|
dispatch({
|
|
@@ -301,15 +464,15 @@ const ProModule = vue.defineComponent({
|
|
|
301
464
|
});
|
|
302
465
|
}
|
|
303
466
|
},
|
|
304
|
-
onSuccess: actor
|
|
467
|
+
onSuccess: function onSuccess(actor) {
|
|
305
468
|
var _requestOpts$onSucces;
|
|
306
469
|
|
|
307
|
-
|
|
470
|
+
var requestOpts = lodash.get(requestMap, actor.name); //如果设置了stateName,将结果维护到state中
|
|
308
471
|
|
|
309
472
|
if (requestOpts !== null && requestOpts !== void 0 && requestOpts.stateName) {
|
|
310
473
|
var _actor$res;
|
|
311
474
|
|
|
312
|
-
|
|
475
|
+
var data = requestOpts.convertData ? requestOpts.convertData(actor) : (_actor$res = actor.res) === null || _actor$res === void 0 ? void 0 : _actor$res.data;
|
|
313
476
|
dispatch({
|
|
314
477
|
type: requestOpts.stateName,
|
|
315
478
|
payload: data
|
|
@@ -320,28 +483,30 @@ const ProModule = vue.defineComponent({
|
|
|
320
483
|
sendEvent({
|
|
321
484
|
type: RequestAction.Success,
|
|
322
485
|
payload: {
|
|
323
|
-
actor
|
|
486
|
+
actor: actor,
|
|
487
|
+
requestOpts: requestOpts
|
|
324
488
|
}
|
|
325
489
|
}); //回调事件
|
|
326
490
|
|
|
327
491
|
(_requestOpts$onSucces = requestOpts.onSuccess) === null || _requestOpts$onSucces === void 0 ? void 0 : _requestOpts$onSucces.call(requestOpts, actor);
|
|
328
492
|
},
|
|
329
|
-
onFailed: actor
|
|
493
|
+
onFailed: function onFailed(actor) {
|
|
330
494
|
var _requestOpts$onFailed;
|
|
331
495
|
|
|
332
|
-
|
|
496
|
+
var requestOpts = lodash.get(requestMap, actor.name); //发送失败事件
|
|
333
497
|
|
|
334
498
|
sendEvent({
|
|
335
499
|
type: RequestAction.Fail,
|
|
336
500
|
payload: {
|
|
337
|
-
actor
|
|
501
|
+
actor: actor,
|
|
502
|
+
requestOpts: requestOpts
|
|
338
503
|
}
|
|
339
504
|
}); //回调事件
|
|
340
505
|
|
|
341
506
|
(_requestOpts$onFailed = requestOpts.onFailed) === null || _requestOpts$onFailed === void 0 ? void 0 : _requestOpts$onFailed.call(requestOpts, actor);
|
|
342
507
|
},
|
|
343
|
-
onFinish: actor
|
|
344
|
-
|
|
508
|
+
onFinish: function onFinish(actor) {
|
|
509
|
+
var loadingName = lodash.get(requestMap, [actor.name, "loadingName"]);
|
|
345
510
|
|
|
346
511
|
if (loadingName) {
|
|
347
512
|
dispatch({
|
|
@@ -352,53 +517,61 @@ const ProModule = vue.defineComponent({
|
|
|
352
517
|
}
|
|
353
518
|
}, true);
|
|
354
519
|
provideProModule({
|
|
355
|
-
columns,
|
|
356
|
-
getFormItemVNode,
|
|
357
|
-
getItemVNode,
|
|
520
|
+
columns: columns,
|
|
521
|
+
getFormItemVNode: getFormItemVNode,
|
|
522
|
+
getItemVNode: getItemVNode,
|
|
358
523
|
elementMap: props.elementMap,
|
|
359
524
|
formElementMap: props.formElementMap,
|
|
360
525
|
//
|
|
361
|
-
subject$,
|
|
362
|
-
sendEvent,
|
|
526
|
+
subject$: subject$,
|
|
527
|
+
sendEvent: sendEvent,
|
|
363
528
|
//
|
|
364
|
-
state,
|
|
365
|
-
dispatch,
|
|
529
|
+
state: state,
|
|
530
|
+
dispatch: dispatch,
|
|
366
531
|
//
|
|
367
532
|
requests: props.requests,
|
|
368
|
-
sendRequest
|
|
533
|
+
sendRequest: sendRequest
|
|
534
|
+
});
|
|
535
|
+
expose({
|
|
536
|
+
sendEvent: sendEvent,
|
|
537
|
+
sendRequest: sendRequest
|
|
369
538
|
});
|
|
370
|
-
return ()
|
|
539
|
+
return function () {
|
|
371
540
|
var _slots$default;
|
|
372
541
|
|
|
373
|
-
return (_slots$default = slots
|
|
542
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
374
543
|
};
|
|
375
544
|
}
|
|
376
545
|
});
|
|
377
546
|
|
|
378
547
|
//订阅module事件
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
hooks.useEffect(()
|
|
384
|
-
|
|
385
|
-
next: action
|
|
548
|
+
var useModuleEvent = function useModuleEvent(cb) {
|
|
549
|
+
var _useProModule = useProModule(),
|
|
550
|
+
subject$ = _useProModule.subject$;
|
|
551
|
+
|
|
552
|
+
hooks.useEffect(function () {
|
|
553
|
+
var sub = subject$.subscribe({
|
|
554
|
+
next: function next(action) {
|
|
386
555
|
cb(action);
|
|
387
556
|
}
|
|
388
557
|
});
|
|
389
|
-
return ()
|
|
558
|
+
return function () {
|
|
390
559
|
return sub.unsubscribe();
|
|
391
560
|
};
|
|
392
561
|
}, []);
|
|
393
562
|
};
|
|
394
563
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
564
|
+
var ProCurdKey = Symbol("pro-curd");
|
|
565
|
+
var useProCurd = function useProCurd() {
|
|
566
|
+
return vue.inject(ProCurdKey);
|
|
567
|
+
};
|
|
568
|
+
var provideProCurd = function provideProCurd(ctx) {
|
|
569
|
+
return vue.provide(ProCurdKey, ctx);
|
|
570
|
+
};
|
|
398
571
|
/************************************ 常量 *************************************/
|
|
399
572
|
|
|
400
573
|
/**
|
|
401
|
-
* curd 5种
|
|
574
|
+
* curd 5种Action
|
|
402
575
|
*/
|
|
403
576
|
|
|
404
577
|
exports.CurdAction = void 0;
|
|
@@ -411,6 +584,19 @@ exports.CurdAction = void 0;
|
|
|
411
584
|
CurdAction["DELETE"] = "DELETE";
|
|
412
585
|
})(exports.CurdAction || (exports.CurdAction = {}));
|
|
413
586
|
|
|
587
|
+
/**
|
|
588
|
+
* 5种Action 的子事件
|
|
589
|
+
*/
|
|
590
|
+
exports.CurdSubAction = void 0;
|
|
591
|
+
|
|
592
|
+
(function (CurdSubAction) {
|
|
593
|
+
CurdSubAction["EMIT"] = "EMIT";
|
|
594
|
+
CurdSubAction["EXECUTE"] = "EXECUTE";
|
|
595
|
+
CurdSubAction["PAGE"] = "PAGE";
|
|
596
|
+
CurdSubAction["SUCCESS"] = "SUCCESS";
|
|
597
|
+
CurdSubAction["FAIL"] = "FAIL";
|
|
598
|
+
})(exports.CurdSubAction || (exports.CurdSubAction = {}));
|
|
599
|
+
|
|
414
600
|
/**
|
|
415
601
|
* curd 操作模式
|
|
416
602
|
*/
|
|
@@ -432,124 +618,138 @@ exports.CurdAddAction = void 0;
|
|
|
432
618
|
CurdAddAction["CONTINUE"] = "CONTINUE";
|
|
433
619
|
})(exports.CurdAddAction || (exports.CurdAddAction = {}));
|
|
434
620
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
rowKey: {
|
|
440
|
-
type: String,
|
|
441
|
-
default: "id"
|
|
442
|
-
},
|
|
621
|
+
var defaultPage = {
|
|
622
|
+
page: 1,
|
|
623
|
+
pageSize: 10
|
|
624
|
+
};
|
|
443
625
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
626
|
+
var proCurdProps = function proCurdProps() {
|
|
627
|
+
return {
|
|
628
|
+
/**
|
|
629
|
+
* 列表 或 详情 的唯一标识
|
|
630
|
+
*/
|
|
631
|
+
rowKey: {
|
|
632
|
+
type: String,
|
|
633
|
+
"default": "id"
|
|
634
|
+
},
|
|
450
635
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
636
|
+
/**
|
|
637
|
+
* operates
|
|
638
|
+
*/
|
|
639
|
+
operates: {
|
|
640
|
+
type: Array
|
|
641
|
+
},
|
|
642
|
+
|
|
643
|
+
/************************* 子组件props *******************************/
|
|
644
|
+
listProps: {
|
|
645
|
+
type: Object
|
|
646
|
+
},
|
|
647
|
+
formProps: {
|
|
648
|
+
type: Object
|
|
649
|
+
},
|
|
650
|
+
descProps: {
|
|
651
|
+
type: Object
|
|
652
|
+
},
|
|
653
|
+
modalProps: {
|
|
654
|
+
type: Object
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
};
|
|
465
658
|
|
|
466
|
-
|
|
467
|
-
props: {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
} = useProModule();
|
|
659
|
+
var Curd = vue.defineComponent({
|
|
660
|
+
props: _objectSpread2({}, proCurdProps()),
|
|
661
|
+
setup: function setup(props, _ref) {
|
|
662
|
+
var slots = _ref.slots,
|
|
663
|
+
expose = _ref.expose;
|
|
664
|
+
|
|
665
|
+
var _ref2 = useProModule(),
|
|
666
|
+
columns = _ref2.columns,
|
|
667
|
+
state = _ref2.state,
|
|
668
|
+
sendEvent = _ref2.sendEvent,
|
|
669
|
+
sendRequest = _ref2.sendRequest;
|
|
478
670
|
/**
|
|
479
671
|
* 排序
|
|
480
672
|
* @param list
|
|
481
673
|
* @param propName
|
|
482
674
|
*/
|
|
483
675
|
|
|
484
|
-
|
|
485
|
-
|
|
676
|
+
|
|
677
|
+
var dealSort = function dealSort(list, propName) {
|
|
678
|
+
return lodash.sortBy(list, function (item) {
|
|
679
|
+
return lodash.get(item, propName);
|
|
680
|
+
});
|
|
486
681
|
};
|
|
487
682
|
/**
|
|
488
683
|
* 非 hideInForm columns
|
|
489
684
|
*/
|
|
490
685
|
|
|
491
686
|
|
|
492
|
-
|
|
493
|
-
return dealSort(lodash.filter(columns.value,
|
|
687
|
+
var formColumns = vue.computed(function () {
|
|
688
|
+
return dealSort(lodash.filter(columns.value, function (item) {
|
|
689
|
+
return !item.hideInForm;
|
|
690
|
+
}), "formSort");
|
|
494
691
|
});
|
|
495
692
|
/**
|
|
496
693
|
* 非 hideInDetail columns
|
|
497
694
|
*/
|
|
498
695
|
|
|
499
|
-
|
|
500
|
-
return dealSort(lodash.filter(columns.value,
|
|
696
|
+
var descColumns = vue.computed(function () {
|
|
697
|
+
return dealSort(lodash.filter(columns.value, function (item) {
|
|
698
|
+
return !item.hideInDetail;
|
|
699
|
+
}), "descSort");
|
|
501
700
|
});
|
|
502
701
|
/**
|
|
503
702
|
* 非 hideInTable columns
|
|
504
703
|
*/
|
|
505
704
|
|
|
506
|
-
|
|
507
|
-
return dealSort(lodash.filter(columns.value,
|
|
705
|
+
var tableColumns = vue.computed(function () {
|
|
706
|
+
return dealSort(lodash.filter(columns.value, function (item) {
|
|
707
|
+
return !item.hideInTable;
|
|
708
|
+
}), "tableSort");
|
|
508
709
|
});
|
|
509
710
|
/**
|
|
510
711
|
* search columns
|
|
511
712
|
*/
|
|
512
713
|
|
|
513
|
-
|
|
514
|
-
return dealSort(lodash.filter(columns.value,
|
|
714
|
+
var searchColumns = vue.computed(function () {
|
|
715
|
+
return dealSort(lodash.filter(columns.value, function (item) {
|
|
716
|
+
return !!item.search;
|
|
717
|
+
}), "searchSort");
|
|
515
718
|
});
|
|
516
719
|
/******************************** 逻辑 *************************************/
|
|
517
720
|
//上一次发起列表请求的参数
|
|
518
721
|
|
|
519
|
-
|
|
722
|
+
var prevListParams; //刷新列表
|
|
520
723
|
|
|
521
|
-
|
|
522
|
-
sendRequest(exports.CurdAction.LIST, {
|
|
523
|
-
...extra
|
|
524
|
-
});
|
|
724
|
+
var handleSearch = function handleSearch(extra) {
|
|
725
|
+
sendRequest(exports.CurdAction.LIST, _objectSpread2(_objectSpread2({}, prevListParams), extra));
|
|
525
726
|
}; //发送事件
|
|
526
727
|
|
|
527
728
|
|
|
528
|
-
|
|
729
|
+
var sendCurdEvent = function sendCurdEvent(event) {
|
|
529
730
|
sendEvent({
|
|
530
731
|
type: event.action,
|
|
531
|
-
payload: lodash.omit(event, "action")
|
|
732
|
+
payload: lodash.omit(event, "action", "source"),
|
|
733
|
+
source: event.source
|
|
532
734
|
});
|
|
533
735
|
}; //事件订阅
|
|
534
736
|
|
|
535
737
|
|
|
536
|
-
useModuleEvent(event
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
} else if (event.type === RequestAction.Fail) {
|
|
738
|
+
useModuleEvent(function (event) {
|
|
739
|
+
//如果当前event存在source 不处理
|
|
740
|
+
if (event.source) {
|
|
540
741
|
return;
|
|
541
742
|
}
|
|
542
743
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
} = event.payload;
|
|
744
|
+
var action = event.type;
|
|
745
|
+
var _ref3 = event.payload,
|
|
746
|
+
type = _ref3.type,
|
|
747
|
+
values = _ref3.values,
|
|
748
|
+
record = _ref3.record;
|
|
549
749
|
|
|
550
750
|
switch (action) {
|
|
551
751
|
case exports.CurdAction.LIST:
|
|
552
|
-
if (type ===
|
|
752
|
+
if (type === exports.CurdSubAction.EMIT) {
|
|
553
753
|
prevListParams = values;
|
|
554
754
|
handleSearch();
|
|
555
755
|
}
|
|
@@ -557,187 +757,1198 @@ const Curd = vue.defineComponent({
|
|
|
557
757
|
return;
|
|
558
758
|
|
|
559
759
|
case exports.CurdAction.ADD:
|
|
560
|
-
if (type ===
|
|
760
|
+
if (type === exports.CurdSubAction.EXECUTE) {
|
|
561
761
|
sendRequest(exports.CurdAction.ADD, values, state.detailData);
|
|
562
762
|
}
|
|
563
763
|
|
|
564
764
|
return;
|
|
565
765
|
|
|
566
766
|
case exports.CurdAction.EDIT:
|
|
567
|
-
if (type ===
|
|
767
|
+
if (type === exports.CurdSubAction.EXECUTE) {
|
|
568
768
|
sendRequest(exports.CurdAction.EDIT, values, state.detailData);
|
|
569
769
|
}
|
|
570
770
|
|
|
571
771
|
return;
|
|
572
772
|
|
|
573
773
|
case exports.CurdAction.DELETE:
|
|
574
|
-
if (type ===
|
|
774
|
+
if (type === exports.CurdSubAction.EMIT) {
|
|
575
775
|
sendRequest(exports.CurdAction.DELETE, record, props.rowKey);
|
|
576
776
|
}
|
|
577
777
|
|
|
578
778
|
return;
|
|
579
779
|
}
|
|
580
780
|
});
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
781
|
+
var operateMap = lodash.reduce(props.operates, function (pair, item) {
|
|
782
|
+
return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, item.action, item));
|
|
783
|
+
}, {}); //根据Action获取ICurdOperateOpts
|
|
584
784
|
|
|
585
|
-
|
|
785
|
+
var getOperate = function getOperate(action) {
|
|
586
786
|
return lodash.get(operateMap, action);
|
|
587
787
|
};
|
|
588
788
|
|
|
789
|
+
var listProps = vue.computed(function () {
|
|
790
|
+
return props.listProps;
|
|
791
|
+
});
|
|
792
|
+
var formProps = vue.computed(function () {
|
|
793
|
+
return props.formProps;
|
|
794
|
+
});
|
|
795
|
+
var descProps = vue.computed(function () {
|
|
796
|
+
return props.descProps;
|
|
797
|
+
});
|
|
798
|
+
var modalProps = vue.computed(function () {
|
|
799
|
+
return props.modalProps;
|
|
800
|
+
});
|
|
589
801
|
provideProCurd({
|
|
590
802
|
rowKey: props.rowKey,
|
|
591
803
|
curdState: state,
|
|
592
|
-
formColumns,
|
|
593
|
-
descColumns,
|
|
594
|
-
tableColumns,
|
|
595
|
-
searchColumns,
|
|
804
|
+
formColumns: formColumns,
|
|
805
|
+
descColumns: descColumns,
|
|
806
|
+
tableColumns: tableColumns,
|
|
807
|
+
searchColumns: searchColumns,
|
|
808
|
+
//
|
|
809
|
+
sendCurdEvent: sendCurdEvent,
|
|
596
810
|
//
|
|
597
|
-
|
|
811
|
+
getOperate: getOperate,
|
|
598
812
|
//
|
|
599
|
-
|
|
813
|
+
refreshList: handleSearch,
|
|
600
814
|
//
|
|
601
|
-
listProps:
|
|
602
|
-
formProps:
|
|
603
|
-
descProps:
|
|
604
|
-
modalProps:
|
|
815
|
+
listProps: listProps,
|
|
816
|
+
formProps: formProps,
|
|
817
|
+
descProps: descProps,
|
|
818
|
+
modalProps: modalProps
|
|
605
819
|
});
|
|
606
|
-
|
|
820
|
+
expose({
|
|
821
|
+
sendCurdEvent: sendCurdEvent,
|
|
822
|
+
getOperate: getOperate,
|
|
823
|
+
refreshList: handleSearch
|
|
824
|
+
});
|
|
825
|
+
return function () {
|
|
607
826
|
var _slots$default;
|
|
608
827
|
|
|
609
|
-
return (_slots$default = slots
|
|
828
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
610
829
|
};
|
|
611
830
|
}
|
|
612
831
|
});
|
|
613
|
-
|
|
614
|
-
props: {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
832
|
+
var ProCurd = vue.defineComponent({
|
|
833
|
+
props: _objectSpread2(_objectSpread2(_objectSpread2({}, lodash.omit(ProModule.props, "state", "requests")), Curd.props), {}, {
|
|
834
|
+
curdState: {
|
|
835
|
+
type: Object
|
|
836
|
+
}
|
|
837
|
+
}),
|
|
838
|
+
setup: function setup(props, _ref4) {
|
|
839
|
+
var _curdOperateOpts;
|
|
840
|
+
|
|
841
|
+
var slots = _ref4.slots,
|
|
842
|
+
expose = _ref4.expose;
|
|
843
|
+
var moduleRef = vue.ref();
|
|
844
|
+
var curdRef = vue.ref();
|
|
845
|
+
var curdState = props.curdState || vue.reactive({
|
|
621
846
|
detailData: {}
|
|
622
847
|
});
|
|
623
848
|
/****************** 请求处理 **********************/
|
|
624
849
|
//curd默认网络属性
|
|
625
850
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
851
|
+
var curdOperateOpts = (_curdOperateOpts = {}, _defineProperty(_curdOperateOpts, exports.CurdAction.LIST, {
|
|
852
|
+
convertParams: function convertParams(values) {
|
|
853
|
+
return values;
|
|
854
|
+
},
|
|
855
|
+
convertData: function convertData(actor) {
|
|
856
|
+
var _actor$res;
|
|
631
857
|
|
|
632
|
-
|
|
633
|
-
},
|
|
634
|
-
loadingName: "listLoading",
|
|
635
|
-
stateName: "listData"
|
|
858
|
+
return (_actor$res = actor.res) === null || _actor$res === void 0 ? void 0 : _actor$res.data;
|
|
636
859
|
},
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
return (_actor$res2 = actor.res) === null || _actor$res2 === void 0 ? void 0 : _actor$res2.data;
|
|
643
|
-
},
|
|
644
|
-
loadingName: "detailLoading",
|
|
645
|
-
stateName: "detailData",
|
|
646
|
-
label: "详情"
|
|
860
|
+
loadingName: "listLoading",
|
|
861
|
+
stateName: "listData"
|
|
862
|
+
}), _defineProperty(_curdOperateOpts, exports.CurdAction.DETAIL, {
|
|
863
|
+
convertParams: function convertParams(record, rowKey) {
|
|
864
|
+
return lodash.pick(record, rowKey);
|
|
647
865
|
},
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
}),
|
|
654
|
-
loadingName: "operateLoading",
|
|
655
|
-
label: "添加"
|
|
866
|
+
convertData: function convertData(actor) {
|
|
867
|
+
var _actor$res2;
|
|
868
|
+
|
|
869
|
+
return (_actor$res2 = actor.res) === null || _actor$res2 === void 0 ? void 0 : _actor$res2.data;
|
|
656
870
|
},
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
871
|
+
loadingName: "detailLoading",
|
|
872
|
+
stateName: "detailData",
|
|
873
|
+
label: "详情"
|
|
874
|
+
}), _defineProperty(_curdOperateOpts, exports.CurdAction.ADD, {
|
|
875
|
+
convertParams: function convertParams(values, record) {
|
|
876
|
+
return {
|
|
877
|
+
body: _objectSpread2(_objectSpread2({}, record), values)
|
|
878
|
+
};
|
|
665
879
|
},
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
880
|
+
loadingName: "operateLoading",
|
|
881
|
+
label: "添加"
|
|
882
|
+
}), _defineProperty(_curdOperateOpts, exports.CurdAction.EDIT, {
|
|
883
|
+
convertParams: function convertParams(values, record) {
|
|
884
|
+
return {
|
|
885
|
+
body: _objectSpread2(_objectSpread2({}, record), values)
|
|
886
|
+
};
|
|
887
|
+
},
|
|
888
|
+
loadingName: "operateLoading",
|
|
889
|
+
label: "编辑"
|
|
890
|
+
}), _defineProperty(_curdOperateOpts, exports.CurdAction.DELETE, {
|
|
891
|
+
convertParams: function convertParams(record, rowKey) {
|
|
892
|
+
return lodash.pick(record, rowKey);
|
|
893
|
+
},
|
|
894
|
+
label: "删除"
|
|
895
|
+
}), _curdOperateOpts);
|
|
896
|
+
/****************************** columns分类 *************************************/
|
|
897
|
+
|
|
898
|
+
var requests = lodash.map(props.operates, function (item) {
|
|
899
|
+
var curdOpts = lodash.get(curdOperateOpts, item.action);
|
|
900
|
+
return _objectSpread2(_objectSpread2({}, curdOpts), item);
|
|
901
|
+
});
|
|
902
|
+
var moduleKeys = lodash.keys(lodash.omit(ProModule.props, "state", "requests"));
|
|
903
|
+
expose({
|
|
904
|
+
moduleRef: moduleRef,
|
|
905
|
+
curdRef: curdRef
|
|
906
|
+
});
|
|
907
|
+
return function () {
|
|
908
|
+
return vue.createVNode(ProModule, vue.mergeProps({
|
|
909
|
+
"ref": moduleRef
|
|
910
|
+
}, lodash.pick(props, moduleKeys), {
|
|
911
|
+
"state": curdState,
|
|
912
|
+
"requests": requests
|
|
913
|
+
}), {
|
|
914
|
+
"default": function _default() {
|
|
915
|
+
return [vue.createVNode(Curd, vue.mergeProps({
|
|
916
|
+
"ref": curdRef
|
|
917
|
+
}, lodash.omit.apply(void 0, [props].concat(_toConsumableArray(moduleKeys), ["curdState", "operates"])), {
|
|
918
|
+
"operates": requests
|
|
919
|
+
}), slots)];
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
var modalCurdProps = function modalCurdProps() {
|
|
927
|
+
return {
|
|
928
|
+
defaultAddRecord: {
|
|
929
|
+
type: Object
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* 事件处理
|
|
936
|
+
*/
|
|
937
|
+
var ModalCurd = vue.defineComponent({
|
|
938
|
+
props: _objectSpread2({}, modalCurdProps()),
|
|
939
|
+
setup: function setup(props) {
|
|
940
|
+
var _listProps$value;
|
|
941
|
+
|
|
942
|
+
var _useProModule = useProModule(),
|
|
943
|
+
dispatch = _useProModule.dispatch,
|
|
944
|
+
sendRequest = _useProModule.sendRequest;
|
|
945
|
+
|
|
946
|
+
var _useProCurd = useProCurd(),
|
|
947
|
+
rowKey = _useProCurd.rowKey,
|
|
948
|
+
curdState = _useProCurd.curdState,
|
|
949
|
+
listProps = _useProCurd.listProps,
|
|
950
|
+
getOperate = _useProCurd.getOperate,
|
|
951
|
+
refreshList = _useProCurd.refreshList;
|
|
952
|
+
|
|
953
|
+
var pageState = (listProps === null || listProps === void 0 ? void 0 : (_listProps$value = listProps.value) === null || _listProps$value === void 0 ? void 0 : _listProps$value.pageState) || vue.reactive(_objectSpread2({}, defaultPage)); //发送详情接口
|
|
954
|
+
|
|
955
|
+
var sendDetailRequest = function sendDetailRequest(record) {
|
|
956
|
+
var operateOpts = getOperate(exports.CurdAction.DETAIL);
|
|
957
|
+
|
|
958
|
+
if (operateOpts !== null && operateOpts !== void 0 && operateOpts.actor) {
|
|
959
|
+
//如果注册了详情接口 发起请求
|
|
960
|
+
sendRequest(exports.CurdAction.DETAIL, record, rowKey);
|
|
961
|
+
} else {
|
|
962
|
+
//直接使用当前record作为详情数据
|
|
963
|
+
dispatch({
|
|
964
|
+
type: "detailData",
|
|
965
|
+
payload: record
|
|
966
|
+
});
|
|
673
967
|
}
|
|
674
968
|
};
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
969
|
+
|
|
970
|
+
var dealDetail = function dealDetail(subAction, _ref) {
|
|
971
|
+
var record = _ref.record;
|
|
972
|
+
|
|
973
|
+
if (subAction === exports.CurdSubAction.EMIT) {
|
|
974
|
+
dispatch({
|
|
975
|
+
type: "mode",
|
|
976
|
+
payload: exports.CurdCurrentMode.DETAIL
|
|
977
|
+
});
|
|
978
|
+
sendDetailRequest(record);
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
var dealAdd = function dealAdd(subAction) {
|
|
983
|
+
if (subAction === exports.CurdSubAction.EMIT) {
|
|
984
|
+
dispatch({
|
|
985
|
+
type: "mode",
|
|
986
|
+
payload: exports.CurdCurrentMode.ADD
|
|
987
|
+
});
|
|
988
|
+
dispatch({
|
|
989
|
+
type: "detailData",
|
|
990
|
+
payload: props.defaultAddRecord || {}
|
|
991
|
+
});
|
|
992
|
+
} else if (subAction === exports.CurdSubAction.SUCCESS) {
|
|
993
|
+
//添加成功
|
|
994
|
+
pageState.page = 1; //重置当前页数
|
|
995
|
+
//刷新List
|
|
996
|
+
|
|
997
|
+
refreshList({
|
|
998
|
+
page: 1
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
if (curdState.addAction === exports.CurdAddAction.CONTINUE) {
|
|
1002
|
+
dispatch({
|
|
1003
|
+
type: "detailData",
|
|
1004
|
+
payload: props.defaultAddRecord || {}
|
|
1005
|
+
});
|
|
1006
|
+
} else {
|
|
1007
|
+
dispatch({
|
|
1008
|
+
type: "mode",
|
|
1009
|
+
payload: undefined
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
var dealEdit = function dealEdit(subAction, _ref2) {
|
|
1016
|
+
var record = _ref2.record;
|
|
1017
|
+
|
|
1018
|
+
if (subAction === exports.CurdSubAction.EMIT) {
|
|
1019
|
+
dispatch({
|
|
1020
|
+
type: "mode",
|
|
1021
|
+
payload: exports.CurdCurrentMode.EDIT
|
|
1022
|
+
});
|
|
1023
|
+
sendDetailRequest(record);
|
|
1024
|
+
} else if (subAction === exports.CurdSubAction.SUCCESS) {
|
|
1025
|
+
// 编辑成功
|
|
1026
|
+
dispatch({
|
|
1027
|
+
type: "mode",
|
|
1028
|
+
payload: undefined
|
|
1029
|
+
}); //刷新列表
|
|
1030
|
+
|
|
1031
|
+
refreshList();
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
var dealDelete = function dealDelete(subAction) {
|
|
1036
|
+
if (subAction === exports.CurdSubAction.SUCCESS) {
|
|
1037
|
+
//刷新列表
|
|
1038
|
+
refreshList();
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
useModuleEvent(function (_ref3) {
|
|
1043
|
+
var type = _ref3.type,
|
|
1044
|
+
payload = _ref3.payload,
|
|
1045
|
+
source = _ref3.source;
|
|
1046
|
+
|
|
1047
|
+
if (source) {
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
var action = type;
|
|
1052
|
+
var subAction = payload === null || payload === void 0 ? void 0 : payload.type;
|
|
1053
|
+
var record = payload === null || payload === void 0 ? void 0 : payload.record;
|
|
1054
|
+
|
|
1055
|
+
if (action === RequestAction.Success) {
|
|
1056
|
+
//覆盖
|
|
1057
|
+
action = lodash.get(payload, ["requestOpts", "action"]);
|
|
1058
|
+
subAction = exports.CurdSubAction.SUCCESS;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
switch (action) {
|
|
1062
|
+
case exports.CurdAction.DETAIL:
|
|
1063
|
+
dealDetail(subAction, {
|
|
1064
|
+
record: record
|
|
1065
|
+
});
|
|
1066
|
+
break;
|
|
1067
|
+
|
|
1068
|
+
case exports.CurdAction.ADD:
|
|
1069
|
+
dealAdd(subAction);
|
|
1070
|
+
break;
|
|
1071
|
+
|
|
1072
|
+
case exports.CurdAction.EDIT:
|
|
1073
|
+
dealEdit(subAction, {
|
|
1074
|
+
record: record
|
|
1075
|
+
});
|
|
1076
|
+
break;
|
|
1077
|
+
|
|
1078
|
+
case exports.CurdAction.DELETE:
|
|
1079
|
+
dealDelete(subAction);
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
680
1082
|
});
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
return vue.h(ProModule, { ...lodash.pick(props, moduleKeys),
|
|
684
|
-
state: curdState,
|
|
685
|
-
requests
|
|
686
|
-
}, vue.h(Curd, { ...lodash.omit(props, ...moduleKeys, "curdState")
|
|
687
|
-
}, slots));
|
|
1083
|
+
return function () {
|
|
1084
|
+
return null;
|
|
688
1085
|
};
|
|
689
1086
|
}
|
|
690
1087
|
});
|
|
1088
|
+
var ProModalCurd = vue.defineComponent({
|
|
1089
|
+
props: _objectSpread2(_objectSpread2({}, ProCurd.props), ModalCurd.props),
|
|
1090
|
+
setup: function setup(props, _ref4) {
|
|
1091
|
+
var slots = _ref4.slots;
|
|
1092
|
+
var invalidKeys = lodash.keys(ModalCurd.props);
|
|
1093
|
+
return function () {
|
|
1094
|
+
var _slots$default;
|
|
691
1095
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
const getValidValues = (values, showState, showStateRules) => {
|
|
699
|
-
if (showState) {
|
|
700
|
-
const invalidKeys = lodash.filter(lodash.keys(showState), key => !showState[key]);
|
|
701
|
-
return lodash.omit(values, invalidKeys);
|
|
1096
|
+
return vue.createVNode(ProCurd, lodash.omit(props, invalidKeys), {
|
|
1097
|
+
"default": function _default() {
|
|
1098
|
+
return [vue.createVNode(ModalCurd, lodash.pick(props, invalidKeys), null), (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
};
|
|
702
1102
|
}
|
|
1103
|
+
});
|
|
703
1104
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
1105
|
+
var pageCurdProps = function pageCurdProps() {
|
|
1106
|
+
return {
|
|
1107
|
+
defaultAddRecord: {
|
|
1108
|
+
type: Object
|
|
1109
|
+
},
|
|
1110
|
+
routeBack: {
|
|
1111
|
+
type: Function
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
var PageCurd = vue.defineComponent({
|
|
1117
|
+
props: _objectSpread2({}, pageCurdProps()),
|
|
1118
|
+
setup: function setup(props) {
|
|
1119
|
+
var router = vueRouter.useRouter();
|
|
1120
|
+
var route = vueRouter.useRoute();
|
|
1121
|
+
|
|
1122
|
+
var _useProModule = useProModule(),
|
|
1123
|
+
dispatch = _useProModule.dispatch,
|
|
1124
|
+
sendRequest = _useProModule.sendRequest;
|
|
1125
|
+
|
|
1126
|
+
var _useProCurd = useProCurd(),
|
|
1127
|
+
rowKey = _useProCurd.rowKey,
|
|
1128
|
+
curdState = _useProCurd.curdState;
|
|
1129
|
+
|
|
1130
|
+
var dealList = function dealList(subAction) {
|
|
1131
|
+
if (subAction === exports.CurdSubAction.PAGE) {
|
|
1132
|
+
//其实就是个重置过程
|
|
1133
|
+
dispatch({
|
|
1134
|
+
type: "mode",
|
|
1135
|
+
payload: undefined
|
|
1136
|
+
});
|
|
1137
|
+
dispatch({
|
|
1138
|
+
type: "detailData",
|
|
1139
|
+
payload: {}
|
|
1140
|
+
});
|
|
1141
|
+
dispatch({
|
|
1142
|
+
type: "detailLoading",
|
|
1143
|
+
payload: false
|
|
1144
|
+
});
|
|
1145
|
+
dispatch({
|
|
1146
|
+
type: "addAction",
|
|
1147
|
+
payload: undefined
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
var dealDetail = function dealDetail(subAction, _ref) {
|
|
1153
|
+
var record = _ref.record;
|
|
1154
|
+
|
|
1155
|
+
if (subAction === exports.CurdSubAction.EMIT) {
|
|
1156
|
+
router.push({
|
|
1157
|
+
path: "".concat(route.path, "/detail"),
|
|
1158
|
+
query: lodash.pick(record, rowKey)
|
|
1159
|
+
});
|
|
1160
|
+
} else if (subAction === exports.CurdSubAction.PAGE) {
|
|
1161
|
+
dispatch({
|
|
1162
|
+
type: "mode",
|
|
1163
|
+
payload: exports.CurdCurrentMode.DETAIL
|
|
1164
|
+
});
|
|
1165
|
+
sendRequest(exports.CurdAction.DETAIL, route.query, rowKey);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
var dealAdd = function dealAdd(subAction) {
|
|
1170
|
+
if (subAction === exports.CurdSubAction.EMIT) {
|
|
1171
|
+
router.push({
|
|
1172
|
+
path: "".concat(route.path, "/add")
|
|
1173
|
+
});
|
|
1174
|
+
} else if (subAction === exports.CurdSubAction.PAGE) {
|
|
1175
|
+
dispatch({
|
|
1176
|
+
type: "mode",
|
|
1177
|
+
payload: exports.CurdCurrentMode.ADD
|
|
1178
|
+
});
|
|
1179
|
+
dispatch({
|
|
1180
|
+
type: "detailData",
|
|
1181
|
+
payload: props.defaultAddRecord || {}
|
|
1182
|
+
});
|
|
1183
|
+
} else if (subAction === exports.CurdSubAction.SUCCESS) {
|
|
1184
|
+
if (curdState.addAction === exports.CurdAddAction.CONTINUE) {
|
|
1185
|
+
dispatch({
|
|
1186
|
+
type: "detailData",
|
|
1187
|
+
payload: props.defaultAddRecord || {}
|
|
1188
|
+
});
|
|
1189
|
+
} else {
|
|
1190
|
+
props.routeBack ? props.routeBack(exports.CurdAction.ADD) : router.go(-1);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
|
|
1195
|
+
var dealEdit = function dealEdit(subAction, _ref2) {
|
|
1196
|
+
var record = _ref2.record;
|
|
1197
|
+
|
|
1198
|
+
if (subAction === exports.CurdSubAction.EMIT) {
|
|
1199
|
+
router.push({
|
|
1200
|
+
path: "".concat(route.path, "/edit"),
|
|
1201
|
+
query: lodash.pick(record, rowKey)
|
|
1202
|
+
});
|
|
1203
|
+
} else if (subAction === exports.CurdSubAction.PAGE) {
|
|
1204
|
+
dispatch({
|
|
1205
|
+
type: "mode",
|
|
1206
|
+
payload: exports.CurdCurrentMode.EDIT
|
|
1207
|
+
});
|
|
1208
|
+
sendRequest(exports.CurdAction.DETAIL, route.query, rowKey);
|
|
1209
|
+
} else if (subAction === exports.CurdSubAction.SUCCESS) {
|
|
1210
|
+
props.routeBack ? props.routeBack(exports.CurdAction.EDIT) : router.go(-1);
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
useModuleEvent(function (_ref3) {
|
|
1215
|
+
var type = _ref3.type,
|
|
1216
|
+
payload = _ref3.payload,
|
|
1217
|
+
source = _ref3.source;
|
|
1218
|
+
|
|
1219
|
+
if (source) {
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
var action = type;
|
|
1224
|
+
var subAction = payload === null || payload === void 0 ? void 0 : payload.type;
|
|
1225
|
+
var record = payload === null || payload === void 0 ? void 0 : payload.record;
|
|
1226
|
+
|
|
1227
|
+
if (action === RequestAction.Success) {
|
|
1228
|
+
//覆盖
|
|
1229
|
+
action = lodash.get(payload, ["requestOpts", "action"]);
|
|
1230
|
+
subAction = exports.CurdSubAction.SUCCESS;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
switch (action) {
|
|
1234
|
+
case exports.CurdAction.LIST:
|
|
1235
|
+
dealList(subAction);
|
|
1236
|
+
break;
|
|
1237
|
+
|
|
1238
|
+
case exports.CurdAction.DETAIL:
|
|
1239
|
+
dealDetail(subAction, {
|
|
1240
|
+
record: record
|
|
1241
|
+
});
|
|
1242
|
+
break;
|
|
1243
|
+
|
|
1244
|
+
case exports.CurdAction.ADD:
|
|
1245
|
+
dealAdd(subAction);
|
|
1246
|
+
break;
|
|
1247
|
+
|
|
1248
|
+
case exports.CurdAction.EDIT:
|
|
1249
|
+
dealEdit(subAction, {
|
|
1250
|
+
record: record
|
|
1251
|
+
});
|
|
1252
|
+
break;
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
return function () {
|
|
1256
|
+
return null;
|
|
1257
|
+
};
|
|
707
1258
|
}
|
|
1259
|
+
});
|
|
1260
|
+
var ProPageCurd = vue.defineComponent({
|
|
1261
|
+
props: _objectSpread2(_objectSpread2({}, ProCurd.props), PageCurd.props),
|
|
1262
|
+
setup: function setup(props, _ref4) {
|
|
1263
|
+
var slots = _ref4.slots;
|
|
1264
|
+
var invalidKeys = lodash.keys(PageCurd.props);
|
|
1265
|
+
return function () {
|
|
1266
|
+
var _slots$default;
|
|
708
1267
|
|
|
709
|
-
|
|
1268
|
+
return vue.createVNode(ProCurd, lodash.omit(props, invalidKeys), {
|
|
1269
|
+
"default": function _default() {
|
|
1270
|
+
return [vue.createVNode(PageCurd, lodash.pick(props, invalidKeys), null), (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
|
|
1271
|
+
}
|
|
1272
|
+
});
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
|
|
1277
|
+
var ProFormKey = Symbol("pro-form");
|
|
1278
|
+
var useProForm = function useProForm() {
|
|
1279
|
+
return vue.inject(ProFormKey);
|
|
710
1280
|
};
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
1281
|
+
|
|
1282
|
+
var provideProForm = function provideProForm(ctx) {
|
|
1283
|
+
vue.provide(ProFormKey, ctx);
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
var proFormProps = function proFormProps() {
|
|
1287
|
+
return {
|
|
1288
|
+
/**
|
|
1289
|
+
* 同 antd 或 element form中的model
|
|
1290
|
+
*/
|
|
1291
|
+
model: {
|
|
1292
|
+
type: Object
|
|
1293
|
+
},
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* 子组件是否只读样式
|
|
1297
|
+
*/
|
|
1298
|
+
readonly: {
|
|
1299
|
+
type: Boolean,
|
|
1300
|
+
"default": undefined
|
|
1301
|
+
},
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* FormComponent 根据此项来确定组件是否显示
|
|
1305
|
+
* rules 根据rules中方法生成showState对象
|
|
1306
|
+
*/
|
|
1307
|
+
showState: {
|
|
1308
|
+
type: Object
|
|
1309
|
+
},
|
|
1310
|
+
showStateRules: {
|
|
1311
|
+
type: Object
|
|
1312
|
+
},
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* 是否只读
|
|
1316
|
+
*/
|
|
1317
|
+
readonlyState: {
|
|
1318
|
+
type: Object
|
|
1319
|
+
},
|
|
1320
|
+
readonlyStateRules: {
|
|
1321
|
+
type: Object
|
|
1322
|
+
},
|
|
1323
|
+
|
|
1324
|
+
/**
|
|
1325
|
+
* 是否disabled
|
|
1326
|
+
*/
|
|
1327
|
+
disableState: {
|
|
1328
|
+
type: Object
|
|
1329
|
+
},
|
|
1330
|
+
disableStateRules: {
|
|
1331
|
+
type: Object
|
|
1332
|
+
},
|
|
1333
|
+
|
|
1334
|
+
/**
|
|
1335
|
+
*
|
|
1336
|
+
*/
|
|
1337
|
+
columns: {
|
|
1338
|
+
type: Array
|
|
1339
|
+
},
|
|
1340
|
+
columnState: {
|
|
1341
|
+
type: Object
|
|
1342
|
+
},
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* 展示控件集合,readonly模式下使用这些组件渲染
|
|
1346
|
+
*/
|
|
1347
|
+
elementMap: {
|
|
1348
|
+
type: Object
|
|
1349
|
+
},
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* 录入控件集合
|
|
1353
|
+
*/
|
|
1354
|
+
formElementMap: {
|
|
1355
|
+
type: Object
|
|
1356
|
+
},
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* 是否启用rules验证
|
|
1360
|
+
*/
|
|
1361
|
+
needRules: {
|
|
1362
|
+
type: Boolean,
|
|
1363
|
+
"default": true
|
|
1364
|
+
},
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* provide传递
|
|
1368
|
+
*/
|
|
1369
|
+
provideExtra: {
|
|
1370
|
+
type: Object
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
var ProForm = vue.defineComponent({
|
|
1376
|
+
props: _objectSpread2({}, proFormProps()),
|
|
1377
|
+
setup: function setup(props, _ref) {
|
|
1378
|
+
var slots = _ref.slots;
|
|
1379
|
+
var formState = props.model || vue.reactive({}); //组件状态相关
|
|
1380
|
+
|
|
1381
|
+
var showState = props.showState || vue.reactive({});
|
|
1382
|
+
var readonlyState = props.readonlyState || vue.reactive({});
|
|
1383
|
+
var disableState = props.disableState || vue.reactive({}); //formState改变情况下,更新 showState,readonlyState,disableState状态
|
|
1384
|
+
|
|
1385
|
+
hooks.useEffect(function () {
|
|
1386
|
+
if (props.showStateRules) {
|
|
1387
|
+
lodash.forEach(props.showStateRules, function (fn, key) {
|
|
1388
|
+
showState[key] = fn(formState);
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
if (props.readonlyStateRules) {
|
|
1393
|
+
lodash.forEach(props.readonlyStateRules, function (fn, key) {
|
|
1394
|
+
readonlyState[key] = fn(formState);
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
if (props.disableStateRules) {
|
|
1399
|
+
lodash.forEach(props.disableStateRules, function (fn, key) {
|
|
1400
|
+
disableState[key] = fn(formState);
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
}, formState); //转换为ref对象
|
|
1404
|
+
|
|
1405
|
+
var readonly = vue.computed(function () {
|
|
1406
|
+
return props.readonly;
|
|
1407
|
+
});
|
|
1408
|
+
var columns = vue.computed(function () {
|
|
1409
|
+
return mergeStateToList(props.columns, props.columnState, function (item) {
|
|
1410
|
+
return getColumnFormItemName(item);
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1413
|
+
provideProForm(_objectSpread2({
|
|
1414
|
+
formState: formState,
|
|
1415
|
+
showState: showState,
|
|
1416
|
+
readonlyState: readonlyState,
|
|
1417
|
+
disableState: disableState,
|
|
1418
|
+
//
|
|
1419
|
+
elementMap: props.elementMap,
|
|
1420
|
+
formElementMap: props.formElementMap,
|
|
1421
|
+
//
|
|
1422
|
+
readonly: readonly,
|
|
1423
|
+
//
|
|
1424
|
+
columns: columns
|
|
1425
|
+
}, props.provideExtra));
|
|
1426
|
+
return function () {
|
|
1427
|
+
var _slots$default;
|
|
1428
|
+
|
|
1429
|
+
// console.log("########", columns.value, props.columns, props.columnState);
|
|
1430
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
exports.SearchMode = void 0;
|
|
1436
|
+
|
|
1437
|
+
(function (SearchMode) {
|
|
1438
|
+
SearchMode["AUTO"] = "AUTO";
|
|
1439
|
+
SearchMode["MANUAL"] = "MANUAL";
|
|
1440
|
+
})(exports.SearchMode || (exports.SearchMode = {}));
|
|
1441
|
+
|
|
1442
|
+
var proSearchFormProps = function proSearchFormProps() {
|
|
1443
|
+
return {
|
|
1444
|
+
/**
|
|
1445
|
+
* 需要监听的对象
|
|
1446
|
+
*/
|
|
1447
|
+
model: {
|
|
1448
|
+
type: Object,
|
|
1449
|
+
required: true
|
|
1450
|
+
},
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* 初始化触发 onFinish
|
|
1454
|
+
*/
|
|
1455
|
+
initEmit: {
|
|
1456
|
+
type: Boolean,
|
|
1457
|
+
"default": true
|
|
1458
|
+
},
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* 模式 自动触发或者手动触发 onFinish
|
|
1462
|
+
*/
|
|
1463
|
+
searchMode: {
|
|
1464
|
+
type: String,
|
|
1465
|
+
"default": exports.SearchMode.AUTO
|
|
1466
|
+
},
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* 配置 同ProForm中的columns
|
|
1470
|
+
* 可以根据column中valueType计算出默认的debounceKeys
|
|
1471
|
+
*/
|
|
1472
|
+
columns: {
|
|
1473
|
+
type: Array
|
|
1474
|
+
},
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* 需要debounce处理的字段
|
|
1478
|
+
*/
|
|
1479
|
+
debounceKeys: {
|
|
1480
|
+
type: Array
|
|
1481
|
+
},
|
|
1482
|
+
debounceTime: {
|
|
1483
|
+
type: Number,
|
|
1484
|
+
"default": 800
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* 该组件只是个模式,最终返回null,不做任何渲染,应配合着ProForm的包装类一起使用
|
|
1491
|
+
* 针对传入的model(监听对象)做相应的finish(回调)处理
|
|
714
1492
|
*/
|
|
1493
|
+
var ProSearchForm = vue.defineComponent({
|
|
1494
|
+
props: _objectSpread2({}, proSearchFormProps()),
|
|
1495
|
+
setup: function setup(props, _ref) {
|
|
1496
|
+
var emit = _ref.emit;
|
|
1497
|
+
//根据column valueType 算出默认需要debounce处理的属性集合
|
|
1498
|
+
var defaultDebounceKeys = lodash.map(lodash.filter(props.columns, function (column) {
|
|
1499
|
+
var valueType = getColumnValueType(column); //默认input组件的触发事件需要debounce处理
|
|
1500
|
+
|
|
1501
|
+
return valueType === "text";
|
|
1502
|
+
}), function (column) {
|
|
1503
|
+
return getColumnFormItemName(column);
|
|
1504
|
+
});
|
|
715
1505
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
1506
|
+
var handleFinish = function handleFinish() {
|
|
1507
|
+
emit("finish");
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
var debounceFinish = lodash.debounce(function () {
|
|
1511
|
+
handleFinish();
|
|
1512
|
+
}, props.debounceTime); //初始化
|
|
1513
|
+
|
|
1514
|
+
hooks.useEffect(function () {
|
|
1515
|
+
if (props.initEmit) {
|
|
1516
|
+
handleFinish();
|
|
1517
|
+
}
|
|
1518
|
+
}, []);
|
|
1519
|
+
|
|
1520
|
+
var isDebounceDataChange = function isDebounceDataChange(state, prevState, debounceKeys) {
|
|
1521
|
+
return lodash.some(debounceKeys, function (key) {
|
|
1522
|
+
return lodash.get(state, key) !== lodash.get(prevState, key);
|
|
1523
|
+
});
|
|
1524
|
+
}; //监听
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
hooks.useWatch(function (state, prevState) {
|
|
1528
|
+
if (props.searchMode !== exports.SearchMode.AUTO) {
|
|
1529
|
+
return;
|
|
1530
|
+
} //如果改变的值中包括debounceKeys中注册的 延时触发
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
var debounceKeys = lodash.size(props.debounceKeys) > 0 ? props.debounceKeys : defaultDebounceKeys;
|
|
1534
|
+
|
|
1535
|
+
if (lodash.size(debounceKeys) > 0 && isDebounceDataChange(state, prevState, debounceKeys)) {
|
|
1536
|
+
debounceFinish();
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
handleFinish();
|
|
1541
|
+
}, function () {
|
|
1542
|
+
return lodash.clone(props.model);
|
|
1543
|
+
});
|
|
1544
|
+
return function () {
|
|
1545
|
+
return null;
|
|
1546
|
+
};
|
|
719
1547
|
}
|
|
1548
|
+
});
|
|
720
1549
|
|
|
721
|
-
|
|
722
|
-
|
|
1550
|
+
/**
|
|
1551
|
+
* ProFormList ctx
|
|
1552
|
+
*/
|
|
1553
|
+
|
|
1554
|
+
var ProFormListKey = Symbol("pro-form-list");
|
|
1555
|
+
var useProFormList = function useProFormList() {
|
|
1556
|
+
return vue.inject(ProFormListKey);
|
|
1557
|
+
};
|
|
1558
|
+
|
|
1559
|
+
var provideProFormList = function provideProFormList(ctx) {
|
|
1560
|
+
vue.provide(ProFormListKey, ctx);
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
var FormListProvider = vue.defineComponent({
|
|
1564
|
+
props: {
|
|
1565
|
+
pathList: {
|
|
1566
|
+
type: Array
|
|
1567
|
+
}
|
|
1568
|
+
},
|
|
1569
|
+
setup: function setup(props, _ref) {
|
|
1570
|
+
var slots = _ref.slots;
|
|
1571
|
+
provideProFormList({
|
|
1572
|
+
pathList: props.pathList
|
|
1573
|
+
});
|
|
1574
|
+
return function () {
|
|
1575
|
+
var _slots$default;
|
|
1576
|
+
|
|
1577
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
1578
|
+
};
|
|
723
1579
|
}
|
|
1580
|
+
});
|
|
724
1581
|
|
|
725
|
-
|
|
726
|
-
|
|
1582
|
+
var proFormListProps = function proFormListProps() {
|
|
1583
|
+
return {
|
|
1584
|
+
//每行默认id
|
|
1585
|
+
rowKey: {
|
|
1586
|
+
type: String,
|
|
1587
|
+
"default": "id"
|
|
1588
|
+
},
|
|
1589
|
+
//name
|
|
1590
|
+
name: {
|
|
1591
|
+
type: [String, Number, Array],
|
|
1592
|
+
required: true
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1597
|
+
var ProFormList = vue.defineComponent({
|
|
1598
|
+
props: _objectSpread2({}, proFormListProps()),
|
|
1599
|
+
setup: function setup(props, _ref2) {
|
|
1600
|
+
var slots = _ref2.slots;
|
|
1601
|
+
|
|
1602
|
+
var _useProForm = useProForm(),
|
|
1603
|
+
formState = _useProForm.formState,
|
|
1604
|
+
readonly = _useProForm.readonly;
|
|
1605
|
+
|
|
1606
|
+
var formListCtx = useProFormList();
|
|
1607
|
+
var nameList = convertPathToList(props.name);
|
|
1608
|
+
var path = formListCtx !== null && formListCtx !== void 0 && formListCtx.pathList ? [].concat(_toConsumableArray(formListCtx.pathList), _toConsumableArray(nameList)) : nameList;
|
|
1609
|
+
|
|
1610
|
+
var handleAdd = function handleAdd() {
|
|
1611
|
+
var targetList = lodash.get(formState, path);
|
|
1612
|
+
|
|
1613
|
+
if (!lodash.isArray(targetList)) {
|
|
1614
|
+
targetList = [];
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
targetList.push(_defineProperty({}, props.rowKey, new Date().valueOf()));
|
|
1618
|
+
lodash.set(formState, path, targetList);
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1621
|
+
var handleRemove = function handleRemove(index) {
|
|
1622
|
+
var targetList = lodash.get(formState, path);
|
|
1623
|
+
|
|
1624
|
+
if (lodash.size(targetList) <= 0) {
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
targetList.splice(index, 1);
|
|
1629
|
+
};
|
|
1630
|
+
|
|
1631
|
+
return function () {
|
|
1632
|
+
var _slots$add;
|
|
1633
|
+
|
|
1634
|
+
return vue.createVNode(vue.Fragment, null, [lodash.map(lodash.get(formState, path), function (item, index) {
|
|
1635
|
+
var _slots$default2, _slots$itemAdd, _slots$itemMinus;
|
|
1636
|
+
|
|
1637
|
+
return vue.createVNode(FormListProvider, {
|
|
1638
|
+
"key": index,
|
|
1639
|
+
"pathList": [].concat(_toConsumableArray(path), [index])
|
|
1640
|
+
}, {
|
|
1641
|
+
"default": function _default() {
|
|
1642
|
+
return [vue.createVNode("div", {
|
|
1643
|
+
"class": "pro-form-list-item"
|
|
1644
|
+
}, [(_slots$default2 = slots["default"]) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots), !readonly.value && vue.createVNode(vue.Fragment, null, [vue.createVNode("div", {
|
|
1645
|
+
"class": "pro-form-list-item-add",
|
|
1646
|
+
"onClick": handleAdd
|
|
1647
|
+
}, [(_slots$itemAdd = slots.itemAdd) === null || _slots$itemAdd === void 0 ? void 0 : _slots$itemAdd.call(slots)]), vue.createVNode("div", {
|
|
1648
|
+
"class": "pro-form-list-item-minus",
|
|
1649
|
+
"onClick": function onClick() {
|
|
1650
|
+
return handleRemove(index);
|
|
1651
|
+
}
|
|
1652
|
+
}, [(_slots$itemMinus = slots.itemMinus) === null || _slots$itemMinus === void 0 ? void 0 : _slots$itemMinus.call(slots)])])])];
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
}), !readonly.value && vue.createVNode("div", {
|
|
1656
|
+
"class": "pro-form-list-add",
|
|
1657
|
+
"onClick": handleAdd
|
|
1658
|
+
}, [(_slots$add = slots.add) === null || _slots$add === void 0 ? void 0 : _slots$add.call(slots)])]);
|
|
1659
|
+
};
|
|
727
1660
|
}
|
|
1661
|
+
});
|
|
728
1662
|
|
|
729
|
-
|
|
1663
|
+
var proFormItemProps = function proFormItemProps() {
|
|
1664
|
+
return {
|
|
1665
|
+
readonly: {
|
|
1666
|
+
type: Boolean,
|
|
1667
|
+
"default": undefined
|
|
1668
|
+
},
|
|
1669
|
+
fieldProps: {
|
|
1670
|
+
type: Object
|
|
1671
|
+
},
|
|
1672
|
+
showProps: {
|
|
1673
|
+
type: Object
|
|
1674
|
+
},
|
|
1675
|
+
slots: {
|
|
1676
|
+
type: Object
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
730
1679
|
};
|
|
731
1680
|
|
|
1681
|
+
var createFormItemCompFn = function createFormItemCompFn(FormItem, convertInputCompProps) {
|
|
1682
|
+
return function (_ref) {
|
|
1683
|
+
var InputComp = _ref.InputComp,
|
|
1684
|
+
valueType = _ref.valueType,
|
|
1685
|
+
name = _ref.name;
|
|
1686
|
+
return vue.defineComponent({
|
|
1687
|
+
name: name,
|
|
1688
|
+
props: _objectSpread2(_objectSpread2({}, FormItem.props), proFormItemProps()),
|
|
1689
|
+
setup: function setup(props, _ref2) {
|
|
1690
|
+
var slots = _ref2.slots;
|
|
1691
|
+
|
|
1692
|
+
var _useProForm = useProForm(),
|
|
1693
|
+
formState = _useProForm.formState,
|
|
1694
|
+
showState = _useProForm.showState,
|
|
1695
|
+
readonlyState = _useProForm.readonlyState,
|
|
1696
|
+
disableState = _useProForm.disableState,
|
|
1697
|
+
formReadonly = _useProForm.readonly,
|
|
1698
|
+
elementMap = _useProForm.elementMap;
|
|
1699
|
+
|
|
1700
|
+
var formListCtx = useProFormList(); //优先级 props.readonly > readonlyState > formContext.readonly
|
|
1701
|
+
|
|
1702
|
+
var readonly = vue.computed(function () {
|
|
1703
|
+
if (lodash.isBoolean(props.readonly)) {
|
|
1704
|
+
return props.readonly;
|
|
1705
|
+
} else if (lodash.isBoolean(readonlyState[props.name])) {
|
|
1706
|
+
return readonlyState[props.name];
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
return formReadonly.value;
|
|
1710
|
+
});
|
|
1711
|
+
var nameList = convertPathToList(props.name);
|
|
1712
|
+
var path = formListCtx !== null && formListCtx !== void 0 && formListCtx.pathList ? [].concat(_toConsumableArray(formListCtx.pathList), _toConsumableArray(nameList)) : nameList;
|
|
1713
|
+
|
|
1714
|
+
var setValue = function setValue(v) {
|
|
1715
|
+
lodash.set(formState, path, v);
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
var invalidKeys = lodash.keys(proFormItemProps());
|
|
1719
|
+
return function () {
|
|
1720
|
+
var show = lodash.get(showState, path);
|
|
1721
|
+
|
|
1722
|
+
if (lodash.isBoolean(show) && !show) {
|
|
1723
|
+
return null;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
var value = lodash.get(formState, path); //valueType对应的展示组件
|
|
1727
|
+
|
|
1728
|
+
var ShowComp = lodash.get(elementMap, valueType);
|
|
1729
|
+
return vue.createVNode(FormItem, vue.mergeProps(lodash.omit.apply(void 0, [props].concat(_toConsumableArray(invalidKeys), ["name", "slots"])), {
|
|
1730
|
+
"name": path
|
|
1731
|
+
}), _objectSpread2({
|
|
1732
|
+
"default": function _default() {
|
|
1733
|
+
return [readonly.value ? vue.createVNode(vue.Fragment, null, [ShowComp ? vue.createVNode(ShowComp, vue.mergeProps({
|
|
1734
|
+
"value": value
|
|
1735
|
+
}, props.fieldProps, {
|
|
1736
|
+
"showProps": props.showProps
|
|
1737
|
+
}), slots) : vue.createVNode("span", null, [value])]) : vue.createVNode(InputComp, vue.mergeProps(convertInputCompProps(value, setValue, lodash.get(disableState, path)), props.fieldProps), slots)];
|
|
1738
|
+
}
|
|
1739
|
+
}, props.slots));
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
};
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
var ProTableKey = Symbol("pro-table");
|
|
1747
|
+
var useProTable = function useProTable() {
|
|
1748
|
+
return vue.inject(ProTableKey);
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
var provideProTable = function provideProTable(ctx) {
|
|
1752
|
+
vue.provide(ProTableKey, ctx);
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
var proTableProps = function proTableProps() {
|
|
1756
|
+
return {
|
|
1757
|
+
//操作栏
|
|
1758
|
+
operate: {
|
|
1759
|
+
type: Object
|
|
1760
|
+
},
|
|
1761
|
+
//默认空字符串
|
|
1762
|
+
columnEmptyText: {
|
|
1763
|
+
type: String
|
|
1764
|
+
},
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* 公共column,会merge到columns item中
|
|
1768
|
+
*/
|
|
1769
|
+
column: {
|
|
1770
|
+
type: Object
|
|
1771
|
+
},
|
|
1772
|
+
//
|
|
1773
|
+
columns: {
|
|
1774
|
+
type: Array
|
|
1775
|
+
},
|
|
1776
|
+
columnState: {
|
|
1777
|
+
type: Object
|
|
1778
|
+
},
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* 展示控件集合,readonly模式下使用这些组件渲染
|
|
1782
|
+
*/
|
|
1783
|
+
elementMap: {
|
|
1784
|
+
type: Object
|
|
1785
|
+
},
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* loading
|
|
1789
|
+
*/
|
|
1790
|
+
loading: {
|
|
1791
|
+
type: Boolean
|
|
1792
|
+
},
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* 序号
|
|
1796
|
+
*/
|
|
1797
|
+
serialNumber: {
|
|
1798
|
+
type: Boolean
|
|
1799
|
+
},
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* 分页
|
|
1803
|
+
*/
|
|
1804
|
+
pagination: {
|
|
1805
|
+
type: Object
|
|
1806
|
+
},
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* provide传递
|
|
1810
|
+
*/
|
|
1811
|
+
provideExtra: {
|
|
1812
|
+
type: Object
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
};
|
|
1816
|
+
|
|
1817
|
+
var ProTable = vue.defineComponent({
|
|
1818
|
+
props: _objectSpread2({}, proTableProps()),
|
|
1819
|
+
setup: function setup(props, _ref) {
|
|
1820
|
+
var slots = _ref.slots;
|
|
1821
|
+
var columns = vue.computed(function () {
|
|
1822
|
+
var mergeColumns = mergeStateToList(props.columns, props.columnState, function (item) {
|
|
1823
|
+
return item.dataIndex;
|
|
1824
|
+
}); //根据valueType选择对应的展示组件
|
|
1825
|
+
|
|
1826
|
+
var columns = lodash.map(mergeColumns, function (item) {
|
|
1827
|
+
//merge公共item
|
|
1828
|
+
var nextItem = _objectSpread2(_objectSpread2({}, props.column), item);
|
|
1829
|
+
|
|
1830
|
+
if (!item.customRender) {
|
|
1831
|
+
nextItem.customRender = function (_ref2) {
|
|
1832
|
+
var text = _ref2.text;
|
|
1833
|
+
var vn = getItemEl(props.elementMap, _objectSpread2(_objectSpread2({}, item), {}, {
|
|
1834
|
+
showProps: _objectSpread2(_objectSpread2({}, item.showProps), {}, {
|
|
1835
|
+
content: props.columnEmptyText
|
|
1836
|
+
})
|
|
1837
|
+
}), text); //如果找不到注册的组件,使用当前值 及 columnEmptyText
|
|
1838
|
+
|
|
1839
|
+
return vn || text || props.columnEmptyText;
|
|
1840
|
+
};
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
return nextItem;
|
|
1844
|
+
}); //处理序号
|
|
1845
|
+
|
|
1846
|
+
if (props.serialNumber) {
|
|
1847
|
+
columns.unshift(_objectSpread2(_objectSpread2({
|
|
1848
|
+
title: "序号",
|
|
1849
|
+
dataIndex: "serialNumber",
|
|
1850
|
+
width: 80
|
|
1851
|
+
}, props.column), {}, {
|
|
1852
|
+
// @ts-ignore
|
|
1853
|
+
customRender: function customRender(_ref3) {
|
|
1854
|
+
var _props$pagination, _props$pagination2;
|
|
1855
|
+
|
|
1856
|
+
var index = _ref3.index;
|
|
1857
|
+
|
|
1858
|
+
if ((_props$pagination = props.pagination) !== null && _props$pagination !== void 0 && _props$pagination.page && (_props$pagination2 = props.pagination) !== null && _props$pagination2 !== void 0 && _props$pagination2.pageSize) {
|
|
1859
|
+
return props.pagination.pageSize * (props.pagination.page - 1) + index + 1;
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
return index + 1;
|
|
1863
|
+
}
|
|
1864
|
+
}));
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
var operate = props.operate; //处理operate
|
|
1868
|
+
|
|
1869
|
+
if (operate && operate.items && lodash.some(operate.items, function (item) {
|
|
1870
|
+
return item.show;
|
|
1871
|
+
})) {
|
|
1872
|
+
//将itemState补充的信息拼到item中
|
|
1873
|
+
var items = lodash.map(operate.items, function (i) {
|
|
1874
|
+
return _objectSpread2(_objectSpread2({}, i), lodash.get(operate.itemState, i.value));
|
|
1875
|
+
}); //排序
|
|
1876
|
+
|
|
1877
|
+
var sortedItems = lodash.sortBy(items, function (item) {
|
|
1878
|
+
return item.sort;
|
|
1879
|
+
});
|
|
1880
|
+
columns.push(_objectSpread2(_objectSpread2({
|
|
1881
|
+
title: "操作",
|
|
1882
|
+
dataIndex: "operate",
|
|
1883
|
+
fixed: "right"
|
|
1884
|
+
}, props.column), {}, {
|
|
1885
|
+
customRender: function customRender(_ref4) {
|
|
1886
|
+
var record = _ref4.record;
|
|
1887
|
+
var validItems = lodash.filter(sortedItems, function (item) {
|
|
1888
|
+
if (item.show && lodash.isFunction(item.show)) {
|
|
1889
|
+
return item.show(record);
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
if (item.show === false) {
|
|
1893
|
+
return false;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
return true;
|
|
1897
|
+
});
|
|
1898
|
+
return vue.createVNode("div", {
|
|
1899
|
+
"class": "pro-table-operate"
|
|
1900
|
+
}, [lodash.map(validItems, function (item) {
|
|
1901
|
+
//自定义
|
|
1902
|
+
if (lodash.isFunction(item.element)) {
|
|
1903
|
+
return item.element(record, item);
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
return vue.createVNode("div", {
|
|
1907
|
+
"class": "pro-table-operate-item",
|
|
1908
|
+
"key": item.value,
|
|
1909
|
+
"onClick": function onClick() {
|
|
1910
|
+
var _item$onClick;
|
|
1911
|
+
|
|
1912
|
+
(_item$onClick = item.onClick) === null || _item$onClick === void 0 ? void 0 : _item$onClick.call(item, record);
|
|
1913
|
+
}
|
|
1914
|
+
}, [item.label]);
|
|
1915
|
+
})]);
|
|
1916
|
+
}
|
|
1917
|
+
}, operate.column));
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
return columns;
|
|
1921
|
+
});
|
|
1922
|
+
provideProTable(_objectSpread2({
|
|
1923
|
+
columns: columns
|
|
1924
|
+
}, props.provideExtra));
|
|
1925
|
+
return function () {
|
|
1926
|
+
var _slots$default;
|
|
1927
|
+
|
|
1928
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
|
|
732
1933
|
exports.ProCurd = ProCurd;
|
|
1934
|
+
exports.ProForm = ProForm;
|
|
1935
|
+
exports.ProFormList = ProFormList;
|
|
1936
|
+
exports.ProModalCurd = ProModalCurd;
|
|
733
1937
|
exports.ProModule = ProModule;
|
|
1938
|
+
exports.ProPageCurd = ProPageCurd;
|
|
1939
|
+
exports.ProSearchForm = ProSearchForm;
|
|
1940
|
+
exports.ProTable = ProTable;
|
|
734
1941
|
exports.RequestAction = RequestAction;
|
|
735
1942
|
exports.convertPathToList = convertPathToList;
|
|
1943
|
+
exports.createFormItemCompFn = createFormItemCompFn;
|
|
1944
|
+
exports.defaultPage = defaultPage;
|
|
1945
|
+
exports.generateId = generateId;
|
|
736
1946
|
exports.getColumnFormItemName = getColumnFormItemName;
|
|
737
1947
|
exports.getColumnValueType = getColumnValueType;
|
|
738
1948
|
exports.getFormItemEl = getFormItemEl;
|
|
739
1949
|
exports.getItemEl = getItemEl;
|
|
740
1950
|
exports.getValidValues = getValidValues;
|
|
1951
|
+
exports.mergeStateToList = mergeStateToList;
|
|
741
1952
|
exports.provideProCurd = provideProCurd;
|
|
742
1953
|
exports.provideProModule = provideProModule;
|
|
743
1954
|
exports.useComposeRequestActor = useComposeRequestActor;
|
|
@@ -745,4 +1956,7 @@ exports.useDoneRequestActor = useDoneRequestActor;
|
|
|
745
1956
|
exports.useFailedRequestActor = useFailedRequestActor;
|
|
746
1957
|
exports.useModuleEvent = useModuleEvent;
|
|
747
1958
|
exports.useProCurd = useProCurd;
|
|
1959
|
+
exports.useProForm = useProForm;
|
|
1960
|
+
exports.useProFormList = useProFormList;
|
|
748
1961
|
exports.useProModule = useProModule;
|
|
1962
|
+
exports.useProTable = useProTable;
|