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