@vue-start/pro 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.ts +1021 -61
- package/dist/index.es.js +1072 -326
- package/dist/index.js +1073 -319
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,44 +1,124 @@
|
|
|
1
|
-
import { defineComponent, computed, reactive, inject, h, provide } from 'vue';
|
|
2
|
-
import { map, isString, forEach, get, isObject, isEmpty, isArray, isFunction, mergeWith, reduce, keys, omit, filter as filter$1, sortBy, pick, split } from 'lodash';
|
|
1
|
+
import { defineComponent, computed, reactive, inject, h, provide, createVNode, Fragment, mergeProps } from 'vue';
|
|
2
|
+
import { map, isString, forEach, get, isObject, isEmpty, isArray, isFunction, mergeWith, reduce, keys, omit, filter as filter$1, sortBy, pick, size, debounce, some, clone, split, set, isBoolean, merge as merge$1 } 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
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
function ownKeys(object, enumerableOnly) {
|
|
8
|
+
var keys = Object.keys(object);
|
|
9
|
+
|
|
10
|
+
if (Object.getOwnPropertySymbols) {
|
|
11
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
12
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
13
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
14
|
+
})), keys.push.apply(keys, symbols);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _objectSpread2(target) {
|
|
21
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
22
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
23
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
26
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _defineProperty(obj, key, value) {
|
|
34
|
+
if (key in obj) {
|
|
35
|
+
Object.defineProperty(obj, key, {
|
|
36
|
+
value: value,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
obj[key] = value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _toConsumableArray(arr) {
|
|
49
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _arrayWithoutHoles(arr) {
|
|
53
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _iterableToArray(iter) {
|
|
57
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
61
|
+
if (!o) return;
|
|
62
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
63
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
64
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
65
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
66
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _arrayLikeToArray(arr, len) {
|
|
70
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
71
|
+
|
|
72
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
73
|
+
|
|
74
|
+
return arr2;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function _nonIterableSpread() {
|
|
78
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var createUseRequestActor = function createUseRequestActor(filterFun) {
|
|
82
|
+
return function (actors, callback) {
|
|
83
|
+
var _useRequestProvide = useRequestProvide(),
|
|
84
|
+
requestSubject$ = _useRequestProvide.requestSubject$;
|
|
85
|
+
|
|
86
|
+
var nameSet = new Set(map(actors, function (actor) {
|
|
87
|
+
return isString(actor) ? actor : actor.name;
|
|
88
|
+
}));
|
|
89
|
+
useEffect(function () {
|
|
90
|
+
var sub = requestSubject$.pipe(filter(filterFun), tap(function (actor) {
|
|
91
|
+
if (nameSet.has(actor.name)) {
|
|
92
|
+
callback(actor);
|
|
93
|
+
}
|
|
94
|
+
})).subscribe();
|
|
95
|
+
return function () {
|
|
96
|
+
sub.unsubscribe();
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
99
|
+
};
|
|
22
100
|
};
|
|
23
101
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
102
|
+
var useDoneRequestActor = createUseRequestActor(isDoneRequestActor);
|
|
103
|
+
var useFailedRequestActor = createUseRequestActor(isFailedRequestActor);
|
|
104
|
+
var useComposeRequestActor = function useComposeRequestActor(actors, options, cancelWhileUnmount) {
|
|
105
|
+
var _useRequestProvide2 = useRequestProvide(),
|
|
106
|
+
requestSubject$ = _useRequestProvide2.requestSubject$,
|
|
107
|
+
dispatchRequest = _useRequestProvide2.dispatchRequest;
|
|
108
|
+
|
|
109
|
+
var nameSet = new Set(map(actors, function (actor) {
|
|
110
|
+
return isString(actor) ? actor : actor.name;
|
|
111
|
+
}));
|
|
112
|
+
var lastRequestActors = {};
|
|
113
|
+
useEffect(function () {
|
|
114
|
+
var sub = merge(requestSubject$.pipe(filter(isPreRequestActor), tap(function (actor) {
|
|
35
115
|
if (nameSet.has(actor.name)) {
|
|
36
116
|
var _options$onStart;
|
|
37
117
|
|
|
38
118
|
(_options$onStart = options.onStart) === null || _options$onStart === void 0 ? void 0 : _options$onStart.call(options, actor);
|
|
39
119
|
lastRequestActors[actor.name] = actor;
|
|
40
120
|
}
|
|
41
|
-
})), requestSubject$.pipe(filter(isDoneRequestActor), tap(actor
|
|
121
|
+
})), requestSubject$.pipe(filter(isDoneRequestActor), tap(function (actor) {
|
|
42
122
|
if (nameSet.has(actor.name)) {
|
|
43
123
|
var _options$onSuccess, _options$onFinish;
|
|
44
124
|
|
|
@@ -46,7 +126,7 @@ const useComposeRequestActor = (actors, options, cancelWhileUnmount) => {
|
|
|
46
126
|
(_options$onFinish = options.onFinish) === null || _options$onFinish === void 0 ? void 0 : _options$onFinish.call(options, actor);
|
|
47
127
|
lastRequestActors[actor.name] = undefined;
|
|
48
128
|
}
|
|
49
|
-
})), requestSubject$.pipe(filter(isFailedRequestActor), tap(actor
|
|
129
|
+
})), requestSubject$.pipe(filter(isFailedRequestActor), tap(function (actor) {
|
|
50
130
|
if (nameSet.has(actor.name)) {
|
|
51
131
|
var _options$onFailed, _options$onFinish2;
|
|
52
132
|
|
|
@@ -55,15 +135,15 @@ const useComposeRequestActor = (actors, options, cancelWhileUnmount) => {
|
|
|
55
135
|
lastRequestActors[actor.name] = undefined;
|
|
56
136
|
}
|
|
57
137
|
}))).subscribe();
|
|
58
|
-
return ()
|
|
138
|
+
return function () {
|
|
59
139
|
sub.unsubscribe();
|
|
60
140
|
|
|
61
141
|
if (cancelWhileUnmount) {
|
|
62
142
|
//组件销毁的时候cancel请求
|
|
63
|
-
forEach(lastRequestActors, actor
|
|
64
|
-
actor && dispatchRequest({
|
|
143
|
+
forEach(lastRequestActors, function (actor) {
|
|
144
|
+
actor && dispatchRequest(_objectSpread2(_objectSpread2({}, actor), {}, {
|
|
65
145
|
stage: "CANCEL"
|
|
66
|
-
});
|
|
146
|
+
}));
|
|
67
147
|
});
|
|
68
148
|
}
|
|
69
149
|
};
|
|
@@ -75,7 +155,7 @@ const useComposeRequestActor = (actors, options, cancelWhileUnmount) => {
|
|
|
75
155
|
* @param column
|
|
76
156
|
*/
|
|
77
157
|
|
|
78
|
-
|
|
158
|
+
var getColumnValueType = function getColumnValueType(column) {
|
|
79
159
|
return column.formValueType || column.valueType || "text";
|
|
80
160
|
};
|
|
81
161
|
/**
|
|
@@ -83,7 +163,7 @@ const getColumnValueType = column => {
|
|
|
83
163
|
* @param column
|
|
84
164
|
*/
|
|
85
165
|
|
|
86
|
-
|
|
166
|
+
var getColumnFormItemName = function getColumnFormItemName(column) {
|
|
87
167
|
var _column$formItemProps;
|
|
88
168
|
|
|
89
169
|
return ((_column$formItemProps = column.formItemProps) === null || _column$formItemProps === void 0 ? void 0 : _column$formItemProps.name) || column.dataIndex;
|
|
@@ -96,26 +176,27 @@ const getColumnFormItemName = column => {
|
|
|
96
176
|
* @param needRules
|
|
97
177
|
*/
|
|
98
178
|
|
|
99
|
-
|
|
179
|
+
var getFormItemEl = function getFormItemEl(formElementMap, column) {
|
|
100
180
|
var _column$formFieldProp;
|
|
101
181
|
|
|
102
|
-
|
|
103
|
-
|
|
182
|
+
var needRules = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
183
|
+
var valueType = getColumnValueType(column);
|
|
184
|
+
var Comp = get(formElementMap, valueType);
|
|
104
185
|
|
|
105
186
|
if (!Comp) {
|
|
106
187
|
return null;
|
|
107
188
|
}
|
|
108
189
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return h(Comp, {
|
|
190
|
+
var name = getColumnFormItemName(column);
|
|
191
|
+
var itemProps = needRules ? column.formItemProps : omit(column.formItemProps, "rules");
|
|
192
|
+
return h(Comp, _objectSpread2(_objectSpread2({
|
|
112
193
|
key: name,
|
|
113
|
-
name,
|
|
114
|
-
label: column.title
|
|
115
|
-
|
|
194
|
+
name: name,
|
|
195
|
+
label: column.title
|
|
196
|
+
}, itemProps), {}, {
|
|
116
197
|
fieldProps: omit(column.formFieldProps, "slots"),
|
|
117
198
|
showProps: column.showProps
|
|
118
|
-
}, (_column$formFieldProp = column.formFieldProps) === null || _column$formFieldProp === void 0 ? void 0 : _column$formFieldProp.slots);
|
|
199
|
+
}), (_column$formFieldProp = column.formFieldProps) === null || _column$formFieldProp === void 0 ? void 0 : _column$formFieldProp.slots);
|
|
119
200
|
};
|
|
120
201
|
/**
|
|
121
202
|
* 根据Column生成Item VNode
|
|
@@ -124,93 +205,96 @@ const getFormItemEl = (formElementMap, column, needRules = true) => {
|
|
|
124
205
|
* @param value
|
|
125
206
|
*/
|
|
126
207
|
|
|
127
|
-
|
|
208
|
+
var getItemEl = function getItemEl(elementMap, column, value) {
|
|
128
209
|
var _column$formFieldProp2;
|
|
129
210
|
|
|
130
|
-
|
|
131
|
-
|
|
211
|
+
var valueType = column.valueType || "text";
|
|
212
|
+
var Comp = get(elementMap, valueType);
|
|
132
213
|
|
|
133
214
|
if (!Comp) {
|
|
134
215
|
return null;
|
|
135
216
|
}
|
|
136
217
|
|
|
137
|
-
return h(Comp, {
|
|
218
|
+
return h(Comp, _objectSpread2(_objectSpread2({}, omit(column.formFieldProps, "slots")), {}, {
|
|
138
219
|
showProps: column.showProps,
|
|
139
|
-
value
|
|
140
|
-
}, (_column$formFieldProp2 = column.formFieldProps) === null || _column$formFieldProp2 === void 0 ? void 0 : _column$formFieldProp2.slots);
|
|
220
|
+
value: value
|
|
221
|
+
}), (_column$formFieldProp2 = column.formFieldProps) === null || _column$formFieldProp2 === void 0 ? void 0 : _column$formFieldProp2.slots);
|
|
141
222
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
223
|
+
var ProModuleKey = Symbol("pro-module");
|
|
224
|
+
var useProModule = function useProModule() {
|
|
225
|
+
return inject(ProModuleKey);
|
|
226
|
+
};
|
|
227
|
+
var provideProModule = function provideProModule(ctx) {
|
|
145
228
|
provide(ProModuleKey, ctx);
|
|
146
229
|
};
|
|
147
|
-
|
|
230
|
+
var RequestAction = {
|
|
148
231
|
Success: "request-success$",
|
|
149
232
|
Fail: "request-fail$"
|
|
150
233
|
};
|
|
151
234
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
235
|
+
var proModuleProps = function proModuleProps() {
|
|
236
|
+
return {
|
|
237
|
+
/**
|
|
238
|
+
* module状态
|
|
239
|
+
*/
|
|
240
|
+
state: {
|
|
241
|
+
type: Object
|
|
242
|
+
},
|
|
159
243
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
244
|
+
/**
|
|
245
|
+
* 配置(静态)
|
|
246
|
+
*/
|
|
247
|
+
columns: {
|
|
248
|
+
type: Array
|
|
249
|
+
},
|
|
166
250
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
251
|
+
/**
|
|
252
|
+
* 配置(动态)
|
|
253
|
+
* columns动态属性兼容
|
|
254
|
+
*/
|
|
255
|
+
columnState: {
|
|
256
|
+
type: Object
|
|
257
|
+
},
|
|
174
258
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
259
|
+
/**
|
|
260
|
+
* 展示组件集
|
|
261
|
+
*/
|
|
262
|
+
elementMap: {
|
|
263
|
+
type: Object
|
|
264
|
+
},
|
|
181
265
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
266
|
+
/**
|
|
267
|
+
* 录入组件集
|
|
268
|
+
*/
|
|
269
|
+
formElementMap: {
|
|
270
|
+
type: Object
|
|
271
|
+
},
|
|
188
272
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
273
|
+
/**
|
|
274
|
+
* requests
|
|
275
|
+
*/
|
|
276
|
+
requests: {
|
|
277
|
+
type: Array
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
var ProModule = defineComponent({
|
|
283
|
+
props: _objectSpread2({}, proModuleProps()),
|
|
284
|
+
setup: function setup(props, _ref) {
|
|
285
|
+
var slots = _ref.slots;
|
|
196
286
|
|
|
197
|
-
const ProModule = defineComponent({
|
|
198
|
-
props: { ...proModuleProps()
|
|
199
|
-
},
|
|
200
|
-
setup: (props, {
|
|
201
|
-
slots
|
|
202
|
-
}) => {
|
|
203
287
|
/**
|
|
204
288
|
* columns columnState 合并
|
|
205
289
|
*/
|
|
206
|
-
|
|
207
|
-
return map(props.columns, item
|
|
290
|
+
var columns = computed(function () {
|
|
291
|
+
return map(props.columns, function (item) {
|
|
208
292
|
//如果columnState中有值,merge处理
|
|
209
|
-
|
|
293
|
+
var mapData = get(props.columnState, getColumnFormItemName(item));
|
|
210
294
|
|
|
211
295
|
if (isObject(mapData) && !isEmpty(mapData) && !isArray(mapData) && !isFunction(mapData)) {
|
|
212
296
|
//合并
|
|
213
|
-
return mergeWith(item, mapData, (objValue, srcValue)
|
|
297
|
+
return mergeWith(item, mapData, function (objValue, srcValue) {
|
|
214
298
|
//如果是数组,替换
|
|
215
299
|
if (isArray(objValue) || isArray(srcValue)) {
|
|
216
300
|
return srcValue;
|
|
@@ -224,28 +308,29 @@ const ProModule = defineComponent({
|
|
|
224
308
|
/*********************************** 渲染组件 ***************************************/
|
|
225
309
|
// 获取FormItem VNode
|
|
226
310
|
|
|
227
|
-
|
|
311
|
+
var getFormItemVNode = function getFormItemVNode(column) {
|
|
312
|
+
var needRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
228
313
|
return getFormItemEl(props.formElementMap, column, needRules);
|
|
229
314
|
}; // 获取Item VNode
|
|
230
315
|
|
|
231
316
|
|
|
232
|
-
|
|
317
|
+
var getItemVNode = function getItemVNode(column, value) {
|
|
233
318
|
return getItemEl(props.elementMap, column, value);
|
|
234
319
|
};
|
|
235
320
|
/*********************************** 事件处理 ***************************************/
|
|
236
321
|
|
|
237
322
|
|
|
238
|
-
|
|
323
|
+
var subject$ = new Subject(); //发送Module事件
|
|
239
324
|
|
|
240
|
-
|
|
325
|
+
var sendEvent = function sendEvent(action) {
|
|
241
326
|
subject$.next(action);
|
|
242
327
|
};
|
|
243
328
|
/*********************************** 页面状态 ***************************************/
|
|
244
329
|
|
|
245
330
|
|
|
246
|
-
|
|
331
|
+
var state = props.state || reactive({});
|
|
247
332
|
|
|
248
|
-
|
|
333
|
+
var dispatch = function dispatch(action) {
|
|
249
334
|
//如果要更新的属性值是 object ,执行覆盖操作
|
|
250
335
|
if (isObject(state[action.type])) {
|
|
251
336
|
setReactiveValue(state[action.type], action.payload);
|
|
@@ -257,27 +342,33 @@ const ProModule = defineComponent({
|
|
|
257
342
|
/*********************************** request ***************************************/
|
|
258
343
|
|
|
259
344
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
} = useRequestProvide();
|
|
263
|
-
const requestMap = reduce(props.requests, (pair, item) => ({ ...pair,
|
|
264
|
-
[item.actor.name]: item
|
|
265
|
-
}), {});
|
|
266
|
-
const actionMap = reduce(props.requests, (pair, item) => ({ ...pair,
|
|
267
|
-
[item.action]: item
|
|
268
|
-
}), {}); //发送请求
|
|
345
|
+
var _useRequestProvide = useRequestProvide(),
|
|
346
|
+
dispatchRequest = _useRequestProvide.dispatchRequest;
|
|
269
347
|
|
|
270
|
-
|
|
271
|
-
|
|
348
|
+
var requestMap = reduce(props.requests, function (pair, item) {
|
|
349
|
+
var _item$actor;
|
|
350
|
+
|
|
351
|
+
return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, (_item$actor = item.actor) === null || _item$actor === void 0 ? void 0 : _item$actor.name, item));
|
|
352
|
+
}, {});
|
|
353
|
+
var actionMap = reduce(props.requests, function (pair, item) {
|
|
354
|
+
return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, item.action, item));
|
|
355
|
+
}, {}); //发送请求
|
|
356
|
+
|
|
357
|
+
var sendRequest = function sendRequest(requestNameOrAction) {
|
|
358
|
+
var requestOpts = get(requestMap, requestNameOrAction) || get(actionMap, requestNameOrAction);
|
|
272
359
|
|
|
273
360
|
if (!requestOpts) {
|
|
274
361
|
return;
|
|
275
362
|
}
|
|
276
363
|
|
|
277
|
-
|
|
364
|
+
var nextParams;
|
|
365
|
+
|
|
366
|
+
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
367
|
+
params[_key - 1] = arguments[_key];
|
|
368
|
+
}
|
|
278
369
|
|
|
279
370
|
if (requestOpts.convertParams) {
|
|
280
|
-
nextParams = requestOpts.convertParams(
|
|
371
|
+
nextParams = requestOpts.convertParams.apply(requestOpts, params);
|
|
281
372
|
} else {
|
|
282
373
|
nextParams = get(params, 0);
|
|
283
374
|
}
|
|
@@ -286,9 +377,9 @@ const ProModule = defineComponent({
|
|
|
286
377
|
};
|
|
287
378
|
|
|
288
379
|
useComposeRequestActor(keys(requestMap), {
|
|
289
|
-
onStart: actor
|
|
380
|
+
onStart: function onStart(actor) {
|
|
290
381
|
//如果设置了loading,将请求状态维护到state中
|
|
291
|
-
|
|
382
|
+
var loadingName = get(requestMap, [actor.name, "loadingName"]);
|
|
292
383
|
|
|
293
384
|
if (loadingName) {
|
|
294
385
|
dispatch({
|
|
@@ -297,15 +388,15 @@ const ProModule = defineComponent({
|
|
|
297
388
|
});
|
|
298
389
|
}
|
|
299
390
|
},
|
|
300
|
-
onSuccess: actor
|
|
391
|
+
onSuccess: function onSuccess(actor) {
|
|
301
392
|
var _requestOpts$onSucces;
|
|
302
393
|
|
|
303
|
-
|
|
394
|
+
var requestOpts = get(requestMap, actor.name); //如果设置了stateName,将结果维护到state中
|
|
304
395
|
|
|
305
396
|
if (requestOpts !== null && requestOpts !== void 0 && requestOpts.stateName) {
|
|
306
397
|
var _actor$res;
|
|
307
398
|
|
|
308
|
-
|
|
399
|
+
var data = requestOpts.convertData ? requestOpts.convertData(actor) : (_actor$res = actor.res) === null || _actor$res === void 0 ? void 0 : _actor$res.data;
|
|
309
400
|
dispatch({
|
|
310
401
|
type: requestOpts.stateName,
|
|
311
402
|
payload: data
|
|
@@ -316,28 +407,30 @@ const ProModule = defineComponent({
|
|
|
316
407
|
sendEvent({
|
|
317
408
|
type: RequestAction.Success,
|
|
318
409
|
payload: {
|
|
319
|
-
actor
|
|
410
|
+
actor: actor,
|
|
411
|
+
requestOpts: requestOpts
|
|
320
412
|
}
|
|
321
413
|
}); //回调事件
|
|
322
414
|
|
|
323
415
|
(_requestOpts$onSucces = requestOpts.onSuccess) === null || _requestOpts$onSucces === void 0 ? void 0 : _requestOpts$onSucces.call(requestOpts, actor);
|
|
324
416
|
},
|
|
325
|
-
onFailed: actor
|
|
417
|
+
onFailed: function onFailed(actor) {
|
|
326
418
|
var _requestOpts$onFailed;
|
|
327
419
|
|
|
328
|
-
|
|
420
|
+
var requestOpts = get(requestMap, actor.name); //发送失败事件
|
|
329
421
|
|
|
330
422
|
sendEvent({
|
|
331
423
|
type: RequestAction.Fail,
|
|
332
424
|
payload: {
|
|
333
|
-
actor
|
|
425
|
+
actor: actor,
|
|
426
|
+
requestOpts: requestOpts
|
|
334
427
|
}
|
|
335
428
|
}); //回调事件
|
|
336
429
|
|
|
337
430
|
(_requestOpts$onFailed = requestOpts.onFailed) === null || _requestOpts$onFailed === void 0 ? void 0 : _requestOpts$onFailed.call(requestOpts, actor);
|
|
338
431
|
},
|
|
339
|
-
onFinish: actor
|
|
340
|
-
|
|
432
|
+
onFinish: function onFinish(actor) {
|
|
433
|
+
var loadingName = get(requestMap, [actor.name, "loadingName"]);
|
|
341
434
|
|
|
342
435
|
if (loadingName) {
|
|
343
436
|
dispatch({
|
|
@@ -348,56 +441,60 @@ const ProModule = defineComponent({
|
|
|
348
441
|
}
|
|
349
442
|
}, true);
|
|
350
443
|
provideProModule({
|
|
351
|
-
columns,
|
|
352
|
-
getFormItemVNode,
|
|
353
|
-
getItemVNode,
|
|
444
|
+
columns: columns,
|
|
445
|
+
getFormItemVNode: getFormItemVNode,
|
|
446
|
+
getItemVNode: getItemVNode,
|
|
354
447
|
elementMap: props.elementMap,
|
|
355
448
|
formElementMap: props.formElementMap,
|
|
356
449
|
//
|
|
357
|
-
subject$,
|
|
358
|
-
sendEvent,
|
|
450
|
+
subject$: subject$,
|
|
451
|
+
sendEvent: sendEvent,
|
|
359
452
|
//
|
|
360
|
-
state,
|
|
361
|
-
dispatch,
|
|
453
|
+
state: state,
|
|
454
|
+
dispatch: dispatch,
|
|
362
455
|
//
|
|
363
456
|
requests: props.requests,
|
|
364
|
-
sendRequest
|
|
457
|
+
sendRequest: sendRequest
|
|
365
458
|
});
|
|
366
|
-
return ()
|
|
459
|
+
return function () {
|
|
367
460
|
var _slots$default;
|
|
368
461
|
|
|
369
|
-
return (_slots$default = slots
|
|
462
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
370
463
|
};
|
|
371
464
|
}
|
|
372
465
|
});
|
|
373
466
|
|
|
374
467
|
//订阅module事件
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
useEffect(()
|
|
380
|
-
|
|
381
|
-
next: action
|
|
468
|
+
var useModuleEvent = function useModuleEvent(cb) {
|
|
469
|
+
var _useProModule = useProModule(),
|
|
470
|
+
subject$ = _useProModule.subject$;
|
|
471
|
+
|
|
472
|
+
useEffect(function () {
|
|
473
|
+
var sub = subject$.subscribe({
|
|
474
|
+
next: function next(action) {
|
|
382
475
|
cb(action);
|
|
383
476
|
}
|
|
384
477
|
});
|
|
385
|
-
return ()
|
|
478
|
+
return function () {
|
|
386
479
|
return sub.unsubscribe();
|
|
387
480
|
};
|
|
388
481
|
}, []);
|
|
389
482
|
};
|
|
390
483
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
484
|
+
var ProCurdKey = Symbol("pro-curd");
|
|
485
|
+
var useProCurd = function useProCurd() {
|
|
486
|
+
return inject(ProCurdKey);
|
|
487
|
+
};
|
|
488
|
+
var provideProCurd = function provideProCurd(ctx) {
|
|
489
|
+
return provide(ProCurdKey, ctx);
|
|
490
|
+
};
|
|
394
491
|
/************************************ 常量 *************************************/
|
|
395
492
|
|
|
396
493
|
/**
|
|
397
|
-
* curd 5种
|
|
494
|
+
* curd 5种Action
|
|
398
495
|
*/
|
|
399
496
|
|
|
400
|
-
|
|
497
|
+
var CurdAction;
|
|
401
498
|
|
|
402
499
|
(function (CurdAction) {
|
|
403
500
|
CurdAction["LIST"] = "LIST";
|
|
@@ -407,10 +504,23 @@ let CurdAction;
|
|
|
407
504
|
CurdAction["DELETE"] = "DELETE";
|
|
408
505
|
})(CurdAction || (CurdAction = {}));
|
|
409
506
|
|
|
507
|
+
/**
|
|
508
|
+
* 5种Action 的子事件
|
|
509
|
+
*/
|
|
510
|
+
var CurdSubAction;
|
|
511
|
+
|
|
512
|
+
(function (CurdSubAction) {
|
|
513
|
+
CurdSubAction["EMIT"] = "EMIT";
|
|
514
|
+
CurdSubAction["EXECUTE"] = "EXECUTE";
|
|
515
|
+
CurdSubAction["PAGE"] = "PAGE";
|
|
516
|
+
CurdSubAction["SUCCESS"] = "SUCCESS";
|
|
517
|
+
CurdSubAction["FAIL"] = "FAIL";
|
|
518
|
+
})(CurdSubAction || (CurdSubAction = {}));
|
|
519
|
+
|
|
410
520
|
/**
|
|
411
521
|
* curd 操作模式
|
|
412
522
|
*/
|
|
413
|
-
|
|
523
|
+
var CurdCurrentMode;
|
|
414
524
|
|
|
415
525
|
(function (CurdCurrentMode) {
|
|
416
526
|
CurdCurrentMode["ADD"] = "ADD";
|
|
@@ -421,107 +531,116 @@ let CurdCurrentMode;
|
|
|
421
531
|
/**
|
|
422
532
|
* curd add 模式下 标记 "确定" "确定并继续" 触发
|
|
423
533
|
*/
|
|
424
|
-
|
|
534
|
+
var CurdAddAction;
|
|
425
535
|
|
|
426
536
|
(function (CurdAddAction) {
|
|
427
537
|
CurdAddAction["NORMAL"] = "NORMAL";
|
|
428
538
|
CurdAddAction["CONTINUE"] = "CONTINUE";
|
|
429
539
|
})(CurdAddAction || (CurdAddAction = {}));
|
|
430
540
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
541
|
+
var proCurdProps = function proCurdProps() {
|
|
542
|
+
return {
|
|
543
|
+
/**
|
|
544
|
+
* 列表 或 详情 的唯一标识
|
|
545
|
+
*/
|
|
546
|
+
rowKey: {
|
|
547
|
+
type: String,
|
|
548
|
+
"default": "id"
|
|
549
|
+
},
|
|
439
550
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
551
|
+
/**
|
|
552
|
+
* operates
|
|
553
|
+
*/
|
|
554
|
+
operates: {
|
|
555
|
+
type: Array
|
|
556
|
+
},
|
|
557
|
+
|
|
558
|
+
/************************* 子组件props *******************************/
|
|
559
|
+
listProps: {
|
|
560
|
+
type: Object
|
|
561
|
+
},
|
|
562
|
+
formProps: {
|
|
563
|
+
type: Object
|
|
564
|
+
},
|
|
565
|
+
descProps: {
|
|
566
|
+
type: Object
|
|
567
|
+
},
|
|
568
|
+
modalProps: {
|
|
569
|
+
type: Object
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
};
|
|
446
573
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
formProps: {
|
|
452
|
-
type: Object
|
|
453
|
-
},
|
|
454
|
-
descProps: {
|
|
455
|
-
type: Object
|
|
456
|
-
},
|
|
457
|
-
modalProps: {
|
|
458
|
-
type: Object
|
|
459
|
-
}
|
|
460
|
-
});
|
|
574
|
+
var Curd = defineComponent({
|
|
575
|
+
props: _objectSpread2({}, proCurdProps()),
|
|
576
|
+
setup: function setup(props, _ref) {
|
|
577
|
+
var slots = _ref.slots;
|
|
461
578
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}) => {
|
|
468
|
-
const {
|
|
469
|
-
columns,
|
|
470
|
-
state,
|
|
471
|
-
sendEvent,
|
|
472
|
-
sendRequest
|
|
473
|
-
} = useProModule();
|
|
579
|
+
var _ref2 = useProModule(),
|
|
580
|
+
columns = _ref2.columns,
|
|
581
|
+
state = _ref2.state,
|
|
582
|
+
sendEvent = _ref2.sendEvent,
|
|
583
|
+
sendRequest = _ref2.sendRequest;
|
|
474
584
|
/**
|
|
475
585
|
* 排序
|
|
476
586
|
* @param list
|
|
477
587
|
* @param propName
|
|
478
588
|
*/
|
|
479
589
|
|
|
480
|
-
|
|
481
|
-
|
|
590
|
+
|
|
591
|
+
var dealSort = function dealSort(list, propName) {
|
|
592
|
+
return sortBy(list, function (item) {
|
|
593
|
+
return get(item, propName);
|
|
594
|
+
});
|
|
482
595
|
};
|
|
483
596
|
/**
|
|
484
597
|
* 非 hideInForm columns
|
|
485
598
|
*/
|
|
486
599
|
|
|
487
600
|
|
|
488
|
-
|
|
489
|
-
return dealSort(filter$1(columns.value,
|
|
601
|
+
var formColumns = computed(function () {
|
|
602
|
+
return dealSort(filter$1(columns.value, function (item) {
|
|
603
|
+
return !item.hideInForm;
|
|
604
|
+
}), "formSort");
|
|
490
605
|
});
|
|
491
606
|
/**
|
|
492
607
|
* 非 hideInDetail columns
|
|
493
608
|
*/
|
|
494
609
|
|
|
495
|
-
|
|
496
|
-
return dealSort(filter$1(columns.value,
|
|
610
|
+
var descColumns = computed(function () {
|
|
611
|
+
return dealSort(filter$1(columns.value, function (item) {
|
|
612
|
+
return !item.hideInDetail;
|
|
613
|
+
}), "descSort");
|
|
497
614
|
});
|
|
498
615
|
/**
|
|
499
616
|
* 非 hideInTable columns
|
|
500
617
|
*/
|
|
501
618
|
|
|
502
|
-
|
|
503
|
-
return dealSort(filter$1(columns.value,
|
|
619
|
+
var tableColumns = computed(function () {
|
|
620
|
+
return dealSort(filter$1(columns.value, function (item) {
|
|
621
|
+
return !item.hideInTable;
|
|
622
|
+
}), "tableSort");
|
|
504
623
|
});
|
|
505
624
|
/**
|
|
506
625
|
* search columns
|
|
507
626
|
*/
|
|
508
627
|
|
|
509
|
-
|
|
510
|
-
return dealSort(filter$1(columns.value,
|
|
628
|
+
var searchColumns = computed(function () {
|
|
629
|
+
return dealSort(filter$1(columns.value, function (item) {
|
|
630
|
+
return !!item.search;
|
|
631
|
+
}), "searchSort");
|
|
511
632
|
});
|
|
512
633
|
/******************************** 逻辑 *************************************/
|
|
513
634
|
//上一次发起列表请求的参数
|
|
514
635
|
|
|
515
|
-
|
|
636
|
+
var prevListParams; //刷新列表
|
|
516
637
|
|
|
517
|
-
|
|
518
|
-
sendRequest(CurdAction.LIST, {
|
|
519
|
-
...extra
|
|
520
|
-
});
|
|
638
|
+
var handleSearch = function handleSearch(extra) {
|
|
639
|
+
sendRequest(CurdAction.LIST, _objectSpread2(_objectSpread2({}, prevListParams), extra));
|
|
521
640
|
}; //发送事件
|
|
522
641
|
|
|
523
642
|
|
|
524
|
-
|
|
643
|
+
var sendCurdEvent = function sendCurdEvent(event) {
|
|
525
644
|
sendEvent({
|
|
526
645
|
type: event.action,
|
|
527
646
|
payload: omit(event, "action")
|
|
@@ -529,23 +648,16 @@ const Curd = defineComponent({
|
|
|
529
648
|
}; //事件订阅
|
|
530
649
|
|
|
531
650
|
|
|
532
|
-
useModuleEvent(event
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
const action = event.type;
|
|
540
|
-
const {
|
|
541
|
-
type,
|
|
542
|
-
values,
|
|
543
|
-
record
|
|
544
|
-
} = event.payload;
|
|
651
|
+
useModuleEvent(function (event) {
|
|
652
|
+
var action = event.type;
|
|
653
|
+
var _ref3 = event.payload,
|
|
654
|
+
type = _ref3.type,
|
|
655
|
+
values = _ref3.values,
|
|
656
|
+
record = _ref3.record;
|
|
545
657
|
|
|
546
658
|
switch (action) {
|
|
547
659
|
case CurdAction.LIST:
|
|
548
|
-
if (type ===
|
|
660
|
+
if (type === CurdSubAction.EMIT) {
|
|
549
661
|
prevListParams = values;
|
|
550
662
|
handleSearch();
|
|
551
663
|
}
|
|
@@ -553,163 +665,456 @@ const Curd = defineComponent({
|
|
|
553
665
|
return;
|
|
554
666
|
|
|
555
667
|
case CurdAction.ADD:
|
|
556
|
-
if (type ===
|
|
668
|
+
if (type === CurdSubAction.EXECUTE) {
|
|
557
669
|
sendRequest(CurdAction.ADD, values, state.detailData);
|
|
558
670
|
}
|
|
559
671
|
|
|
560
672
|
return;
|
|
561
673
|
|
|
562
674
|
case CurdAction.EDIT:
|
|
563
|
-
if (type ===
|
|
675
|
+
if (type === CurdSubAction.EXECUTE) {
|
|
564
676
|
sendRequest(CurdAction.EDIT, values, state.detailData);
|
|
565
677
|
}
|
|
566
678
|
|
|
567
679
|
return;
|
|
568
680
|
|
|
569
681
|
case CurdAction.DELETE:
|
|
570
|
-
if (type ===
|
|
682
|
+
if (type === CurdSubAction.EMIT) {
|
|
571
683
|
sendRequest(CurdAction.DELETE, record, props.rowKey);
|
|
572
684
|
}
|
|
573
685
|
|
|
574
686
|
return;
|
|
575
687
|
}
|
|
576
688
|
});
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
689
|
+
var operateMap = reduce(props.operates, function (pair, item) {
|
|
690
|
+
return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, item.action, item));
|
|
691
|
+
}, {}); //根据Action获取ICurdOperateOpts
|
|
580
692
|
|
|
581
|
-
|
|
693
|
+
var getOperate = function getOperate(action) {
|
|
582
694
|
return get(operateMap, action);
|
|
583
695
|
};
|
|
584
696
|
|
|
697
|
+
var listProps = computed(function () {
|
|
698
|
+
return props.listProps;
|
|
699
|
+
});
|
|
700
|
+
var formProps = computed(function () {
|
|
701
|
+
return props.formProps;
|
|
702
|
+
});
|
|
703
|
+
var descProps = computed(function () {
|
|
704
|
+
return props.descProps;
|
|
705
|
+
});
|
|
706
|
+
var modalProps = computed(function () {
|
|
707
|
+
return props.modalProps;
|
|
708
|
+
});
|
|
585
709
|
provideProCurd({
|
|
586
710
|
rowKey: props.rowKey,
|
|
587
711
|
curdState: state,
|
|
588
|
-
formColumns,
|
|
589
|
-
descColumns,
|
|
590
|
-
tableColumns,
|
|
591
|
-
searchColumns,
|
|
712
|
+
formColumns: formColumns,
|
|
713
|
+
descColumns: descColumns,
|
|
714
|
+
tableColumns: tableColumns,
|
|
715
|
+
searchColumns: searchColumns,
|
|
592
716
|
//
|
|
593
|
-
sendCurdEvent,
|
|
717
|
+
sendCurdEvent: sendCurdEvent,
|
|
594
718
|
//
|
|
595
|
-
getOperate,
|
|
719
|
+
getOperate: getOperate,
|
|
596
720
|
//
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
721
|
+
refreshList: handleSearch,
|
|
722
|
+
//
|
|
723
|
+
listProps: listProps,
|
|
724
|
+
formProps: formProps,
|
|
725
|
+
descProps: descProps,
|
|
726
|
+
modalProps: modalProps
|
|
601
727
|
});
|
|
602
|
-
return ()
|
|
728
|
+
return function () {
|
|
603
729
|
var _slots$default;
|
|
604
730
|
|
|
605
|
-
return (_slots$default = slots
|
|
731
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
606
732
|
};
|
|
607
733
|
}
|
|
608
734
|
});
|
|
609
|
-
|
|
610
|
-
props: {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
735
|
+
var ProCurd = defineComponent({
|
|
736
|
+
props: _objectSpread2(_objectSpread2(_objectSpread2({}, omit(ProModule.props, "state", "requests")), Curd.props), {}, {
|
|
737
|
+
curdState: {
|
|
738
|
+
type: Object
|
|
739
|
+
}
|
|
740
|
+
}),
|
|
741
|
+
setup: function setup(props, _ref4) {
|
|
742
|
+
var _curdOperateOpts;
|
|
743
|
+
|
|
744
|
+
var slots = _ref4.slots;
|
|
745
|
+
var curdState = props.curdState || reactive({
|
|
617
746
|
detailData: {}
|
|
618
747
|
});
|
|
619
748
|
/****************** 请求处理 **********************/
|
|
620
749
|
//curd默认网络属性
|
|
621
750
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
751
|
+
var curdOperateOpts = (_curdOperateOpts = {}, _defineProperty(_curdOperateOpts, CurdAction.LIST, {
|
|
752
|
+
convertParams: function convertParams(values) {
|
|
753
|
+
return values;
|
|
754
|
+
},
|
|
755
|
+
convertData: function convertData(actor) {
|
|
756
|
+
var _actor$res;
|
|
627
757
|
|
|
628
|
-
|
|
629
|
-
},
|
|
630
|
-
loadingName: "listLoading",
|
|
631
|
-
stateName: "listData"
|
|
758
|
+
return (_actor$res = actor.res) === null || _actor$res === void 0 ? void 0 : _actor$res.data;
|
|
632
759
|
},
|
|
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: "详情"
|
|
760
|
+
loadingName: "listLoading",
|
|
761
|
+
stateName: "listData"
|
|
762
|
+
}), _defineProperty(_curdOperateOpts, CurdAction.DETAIL, {
|
|
763
|
+
convertParams: function convertParams(record, rowKey) {
|
|
764
|
+
return pick(record, rowKey);
|
|
643
765
|
},
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
649
|
-
}),
|
|
650
|
-
loadingName: "operateLoading",
|
|
651
|
-
label: "添加"
|
|
766
|
+
convertData: function convertData(actor) {
|
|
767
|
+
var _actor$res2;
|
|
768
|
+
|
|
769
|
+
return (_actor$res2 = actor.res) === null || _actor$res2 === void 0 ? void 0 : _actor$res2.data;
|
|
652
770
|
},
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
771
|
+
loadingName: "detailLoading",
|
|
772
|
+
stateName: "detailData",
|
|
773
|
+
label: "详情"
|
|
774
|
+
}), _defineProperty(_curdOperateOpts, CurdAction.ADD, {
|
|
775
|
+
convertParams: function convertParams(values, record) {
|
|
776
|
+
return {
|
|
777
|
+
body: _objectSpread2(_objectSpread2({}, record), values)
|
|
778
|
+
};
|
|
661
779
|
},
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
780
|
+
loadingName: "operateLoading",
|
|
781
|
+
label: "添加"
|
|
782
|
+
}), _defineProperty(_curdOperateOpts, CurdAction.EDIT, {
|
|
783
|
+
convertParams: function convertParams(values, record) {
|
|
784
|
+
return {
|
|
785
|
+
body: _objectSpread2(_objectSpread2({}, record), values)
|
|
786
|
+
};
|
|
787
|
+
},
|
|
788
|
+
loadingName: "operateLoading",
|
|
789
|
+
label: "编辑"
|
|
790
|
+
}), _defineProperty(_curdOperateOpts, CurdAction.DELETE, {
|
|
791
|
+
convertParams: function convertParams(record, rowKey) {
|
|
792
|
+
return pick(record, rowKey);
|
|
793
|
+
},
|
|
794
|
+
label: "删除"
|
|
795
|
+
}), _curdOperateOpts);
|
|
796
|
+
var requests = map(props.operates, function (item) {
|
|
797
|
+
var curdOpts = get(curdOperateOpts, item.action);
|
|
798
|
+
return _objectSpread2(_objectSpread2({}, curdOpts), item);
|
|
799
|
+
});
|
|
800
|
+
var moduleKeys = keys(omit(ProModule.props, "state", "requests"));
|
|
801
|
+
return function () {
|
|
802
|
+
return h(ProModule, _objectSpread2(_objectSpread2({}, pick(props, moduleKeys)), {}, {
|
|
803
|
+
state: curdState,
|
|
804
|
+
requests: requests
|
|
805
|
+
}), h(Curd, _objectSpread2(_objectSpread2({}, omit.apply(void 0, [props].concat(_toConsumableArray(moduleKeys), ["curdState", "operates"]))), {}, {
|
|
806
|
+
operates: requests
|
|
807
|
+
}), slots));
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
var ProFormKey = Symbol("pro-form");
|
|
813
|
+
var useProForm = function useProForm() {
|
|
814
|
+
return inject(ProFormKey);
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
var provideProForm = function provideProForm(ctx) {
|
|
818
|
+
provide(ProFormKey, ctx);
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
var proFormProps = function proFormProps() {
|
|
822
|
+
return {
|
|
823
|
+
/**
|
|
824
|
+
* 同 antd 或 element form中的model
|
|
825
|
+
*/
|
|
826
|
+
model: {
|
|
827
|
+
type: Object
|
|
828
|
+
},
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* 子组件是否只读样式
|
|
832
|
+
*/
|
|
833
|
+
readonly: {
|
|
834
|
+
type: Boolean,
|
|
835
|
+
"default": undefined
|
|
836
|
+
},
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* FormComponent 根据此项来确定组件是否显示
|
|
840
|
+
* rules 根据rules中方法生成showState对象
|
|
841
|
+
*/
|
|
842
|
+
showState: {
|
|
843
|
+
type: Object
|
|
844
|
+
},
|
|
845
|
+
showStateRules: {
|
|
846
|
+
type: Object
|
|
847
|
+
},
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* 是否只读
|
|
851
|
+
*/
|
|
852
|
+
readonlyState: {
|
|
853
|
+
type: Object
|
|
854
|
+
},
|
|
855
|
+
readonlyStateRules: {
|
|
856
|
+
type: Object
|
|
857
|
+
},
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* 是否disabled
|
|
861
|
+
*/
|
|
862
|
+
disableState: {
|
|
863
|
+
type: Object
|
|
864
|
+
},
|
|
865
|
+
disableStateRules: {
|
|
866
|
+
type: Object
|
|
867
|
+
},
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
*
|
|
871
|
+
*/
|
|
872
|
+
columns: {
|
|
873
|
+
type: Array
|
|
874
|
+
},
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* 展示控件集合,readonly模式下使用这些组件渲染
|
|
878
|
+
*/
|
|
879
|
+
elementMap: {
|
|
880
|
+
type: Object
|
|
881
|
+
},
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* 录入控件集合
|
|
885
|
+
*/
|
|
886
|
+
formElementMap: {
|
|
887
|
+
type: Object
|
|
888
|
+
},
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* 是否启用rules验证
|
|
892
|
+
*/
|
|
893
|
+
needRules: {
|
|
894
|
+
type: Boolean,
|
|
895
|
+
"default": true
|
|
896
|
+
},
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* provide传递
|
|
900
|
+
*/
|
|
901
|
+
provideExtra: {
|
|
902
|
+
type: Object
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
var ProForm = defineComponent({
|
|
908
|
+
props: _objectSpread2({}, proFormProps()),
|
|
909
|
+
setup: function setup(props, _ref) {
|
|
910
|
+
var slots = _ref.slots;
|
|
911
|
+
var formState = props.model || reactive({}); //组件状态相关
|
|
912
|
+
|
|
913
|
+
var showState = props.showState || reactive({});
|
|
914
|
+
var readonlyState = props.readonlyState || reactive({});
|
|
915
|
+
var disableState = props.disableState || reactive({}); //formState改变情况下,更新 showState,readonlyState,disableState状态
|
|
916
|
+
|
|
917
|
+
useEffect(function () {
|
|
918
|
+
if (props.showStateRules) {
|
|
919
|
+
forEach(props.showStateRules, function (fn, key) {
|
|
920
|
+
showState[key] = fn(formState);
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
if (props.readonlyStateRules) {
|
|
925
|
+
forEach(props.readonlyStateRules, function (fn, key) {
|
|
926
|
+
readonlyState[key] = fn(formState);
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
if (props.disableStateRules) {
|
|
931
|
+
forEach(props.disableStateRules, function (fn, key) {
|
|
932
|
+
disableState[key] = fn(formState);
|
|
933
|
+
});
|
|
669
934
|
}
|
|
935
|
+
}, formState); //转换为ref对象
|
|
936
|
+
|
|
937
|
+
var readonly = computed(function () {
|
|
938
|
+
return props.readonly;
|
|
939
|
+
});
|
|
940
|
+
/**
|
|
941
|
+
* 将columns 转化为FormItem VNode对象
|
|
942
|
+
*/
|
|
943
|
+
|
|
944
|
+
var formItemVNodes = computed(function () {
|
|
945
|
+
if (size(props.formElementMap) <= 0) {
|
|
946
|
+
return [];
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
return map(props.columns, function (item) {
|
|
950
|
+
return getFormItemEl(props.formElementMap, item, props.needRules);
|
|
951
|
+
});
|
|
952
|
+
});
|
|
953
|
+
provideProForm(_objectSpread2({
|
|
954
|
+
formState: formState,
|
|
955
|
+
showState: showState,
|
|
956
|
+
readonlyState: readonlyState,
|
|
957
|
+
disableState: disableState,
|
|
958
|
+
//
|
|
959
|
+
elementMap: props.elementMap,
|
|
960
|
+
//
|
|
961
|
+
readonly: readonly,
|
|
962
|
+
//
|
|
963
|
+
formItemVNodes: formItemVNodes
|
|
964
|
+
}, props.provideExtra));
|
|
965
|
+
return function () {
|
|
966
|
+
var _slots$default;
|
|
967
|
+
|
|
968
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
670
969
|
};
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
var SearchMode;
|
|
974
|
+
|
|
975
|
+
(function (SearchMode) {
|
|
976
|
+
SearchMode["AUTO"] = "AUTO";
|
|
977
|
+
SearchMode["MANUAL"] = "MANUAL";
|
|
978
|
+
})(SearchMode || (SearchMode = {}));
|
|
979
|
+
|
|
980
|
+
var proSearchFormProps = function proSearchFormProps() {
|
|
981
|
+
return {
|
|
982
|
+
/**
|
|
983
|
+
* 需要监听的对象
|
|
984
|
+
*/
|
|
985
|
+
model: {
|
|
986
|
+
type: Object,
|
|
987
|
+
required: true
|
|
988
|
+
},
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* 初始化触发 onFinish
|
|
992
|
+
*/
|
|
993
|
+
initEmit: {
|
|
994
|
+
type: Boolean,
|
|
995
|
+
"default": true
|
|
996
|
+
},
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* 模式 自动触发或者手动触发 onFinish
|
|
1000
|
+
*/
|
|
1001
|
+
searchMode: {
|
|
1002
|
+
type: String,
|
|
1003
|
+
"default": SearchMode.AUTO
|
|
1004
|
+
},
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* 配置 同ProForm中的columns
|
|
1008
|
+
* 可以根据column中valueType计算出默认的debounceKeys
|
|
1009
|
+
*/
|
|
1010
|
+
columns: {
|
|
1011
|
+
type: Array
|
|
1012
|
+
},
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* 需要debounce处理的字段
|
|
1016
|
+
*/
|
|
1017
|
+
debounceKeys: {
|
|
1018
|
+
type: Array
|
|
1019
|
+
},
|
|
1020
|
+
debounceTime: {
|
|
1021
|
+
type: Number,
|
|
1022
|
+
"default": 800
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* 该组件只是个模式,最终返回null,不做任何渲染,应配合着ProForm的包装类一起使用
|
|
1029
|
+
* 针对传入的model(监听对象)做相应的finish(回调)处理
|
|
1030
|
+
*/
|
|
1031
|
+
var ProSearchForm = defineComponent({
|
|
1032
|
+
props: _objectSpread2({}, proSearchFormProps()),
|
|
1033
|
+
setup: function setup(props, _ref) {
|
|
1034
|
+
var emit = _ref.emit;
|
|
1035
|
+
//根据column valueType 算出默认需要debounce处理的属性集合
|
|
1036
|
+
var defaultDebounceKeys = map(filter$1(props.columns, function (column) {
|
|
1037
|
+
var valueType = getColumnValueType(column); //默认input组件的触发事件需要debounce处理
|
|
1038
|
+
|
|
1039
|
+
return valueType === "text";
|
|
1040
|
+
}), function (column) {
|
|
1041
|
+
return getColumnFormItemName(column);
|
|
676
1042
|
});
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
1043
|
+
|
|
1044
|
+
var handleFinish = function handleFinish() {
|
|
1045
|
+
emit("finish");
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
var debounceFinish = debounce(function () {
|
|
1049
|
+
handleFinish();
|
|
1050
|
+
}, props.debounceTime); //初始化
|
|
1051
|
+
|
|
1052
|
+
useEffect(function () {
|
|
1053
|
+
if (props.initEmit) {
|
|
1054
|
+
handleFinish();
|
|
1055
|
+
}
|
|
1056
|
+
}, []);
|
|
1057
|
+
|
|
1058
|
+
var isDebounceDataChange = function isDebounceDataChange(state, prevState, debounceKeys) {
|
|
1059
|
+
return some(debounceKeys, function (key) {
|
|
1060
|
+
return get(state, key) !== get(prevState, key);
|
|
1061
|
+
});
|
|
1062
|
+
}; //监听
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
useWatch(function (state, prevState) {
|
|
1066
|
+
if (props.searchMode !== SearchMode.AUTO) {
|
|
1067
|
+
return;
|
|
1068
|
+
} //如果改变的值中包括debounceKeys中注册的 延时触发
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
var debounceKeys = size(props.debounceKeys) > 0 ? props.debounceKeys : defaultDebounceKeys;
|
|
1072
|
+
|
|
1073
|
+
if (size(debounceKeys) > 0 && isDebounceDataChange(state, prevState, debounceKeys)) {
|
|
1074
|
+
debounceFinish();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
handleFinish();
|
|
1079
|
+
}, function () {
|
|
1080
|
+
return clone(props.model);
|
|
1081
|
+
});
|
|
1082
|
+
return function () {
|
|
1083
|
+
return null;
|
|
684
1084
|
};
|
|
685
1085
|
}
|
|
686
1086
|
});
|
|
687
1087
|
|
|
688
|
-
/**
|
|
689
|
-
* 剔除showState或showStateRules规则为!true的值
|
|
690
|
-
* @param values
|
|
691
|
-
* @param showState
|
|
692
|
-
* @param showStateRules
|
|
1088
|
+
/**
|
|
1089
|
+
* 剔除showState或showStateRules规则为!true的值
|
|
1090
|
+
* @param values
|
|
1091
|
+
* @param showState
|
|
1092
|
+
* @param showStateRules
|
|
693
1093
|
*/
|
|
694
|
-
|
|
1094
|
+
var getValidValues = function getValidValues(values, showState, showStateRules) {
|
|
695
1095
|
if (showState) {
|
|
696
|
-
|
|
1096
|
+
var invalidKeys = filter$1(keys(showState), function (key) {
|
|
1097
|
+
return !showState[key];
|
|
1098
|
+
});
|
|
697
1099
|
return omit(values, invalidKeys);
|
|
698
1100
|
}
|
|
699
1101
|
|
|
700
1102
|
if (showStateRules) {
|
|
701
|
-
|
|
702
|
-
|
|
1103
|
+
var _invalidKeys = filter$1(keys(showStateRules), function (key) {
|
|
1104
|
+
return !showStateRules[key](values);
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
return omit(values, _invalidKeys);
|
|
703
1108
|
}
|
|
704
1109
|
|
|
705
1110
|
return values;
|
|
706
1111
|
};
|
|
707
|
-
/**
|
|
708
|
-
* string类型的path转为arr
|
|
709
|
-
* @param path
|
|
1112
|
+
/**
|
|
1113
|
+
* string类型的path转为arr
|
|
1114
|
+
* @param path
|
|
710
1115
|
*/
|
|
711
1116
|
|
|
712
|
-
|
|
1117
|
+
var convertPathToList = function convertPathToList(path) {
|
|
713
1118
|
if (!path) {
|
|
714
1119
|
return undefined;
|
|
715
1120
|
}
|
|
@@ -725,4 +1130,345 @@ const convertPathToList = path => {
|
|
|
725
1130
|
return [path];
|
|
726
1131
|
};
|
|
727
1132
|
|
|
728
|
-
|
|
1133
|
+
/**
|
|
1134
|
+
* ProFormList ctx
|
|
1135
|
+
*/
|
|
1136
|
+
|
|
1137
|
+
var ProFormListKey = Symbol("pro-form-list");
|
|
1138
|
+
var useProFormList = function useProFormList() {
|
|
1139
|
+
return inject(ProFormListKey);
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
var provideProFormList = function provideProFormList(ctx) {
|
|
1143
|
+
provide(ProFormListKey, ctx);
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
var FormListProvider = defineComponent({
|
|
1147
|
+
props: {
|
|
1148
|
+
pathList: {
|
|
1149
|
+
type: Array
|
|
1150
|
+
}
|
|
1151
|
+
},
|
|
1152
|
+
setup: function setup(props, _ref) {
|
|
1153
|
+
var slots = _ref.slots;
|
|
1154
|
+
provideProFormList({
|
|
1155
|
+
pathList: props.pathList
|
|
1156
|
+
});
|
|
1157
|
+
return function () {
|
|
1158
|
+
var _slots$default;
|
|
1159
|
+
|
|
1160
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
var proFormListProps = function proFormListProps() {
|
|
1166
|
+
return {
|
|
1167
|
+
//每行默认id
|
|
1168
|
+
rowKey: {
|
|
1169
|
+
type: String,
|
|
1170
|
+
"default": "id"
|
|
1171
|
+
},
|
|
1172
|
+
//name
|
|
1173
|
+
name: {
|
|
1174
|
+
type: [String, Number, Array],
|
|
1175
|
+
required: true
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
var ProFormList = defineComponent({
|
|
1181
|
+
props: _objectSpread2({}, proFormListProps()),
|
|
1182
|
+
setup: function setup(props, _ref2) {
|
|
1183
|
+
var slots = _ref2.slots;
|
|
1184
|
+
|
|
1185
|
+
var _useProForm = useProForm(),
|
|
1186
|
+
formState = _useProForm.formState,
|
|
1187
|
+
readonly = _useProForm.readonly;
|
|
1188
|
+
|
|
1189
|
+
var formListCtx = useProFormList();
|
|
1190
|
+
var nameList = convertPathToList(props.name);
|
|
1191
|
+
var path = formListCtx !== null && formListCtx !== void 0 && formListCtx.pathList ? [].concat(_toConsumableArray(formListCtx.pathList), _toConsumableArray(nameList)) : nameList;
|
|
1192
|
+
|
|
1193
|
+
var handleAdd = function handleAdd() {
|
|
1194
|
+
var targetList = get(formState, path);
|
|
1195
|
+
|
|
1196
|
+
if (!isArray(targetList)) {
|
|
1197
|
+
targetList = [];
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
targetList.push(_defineProperty({}, props.rowKey, new Date().valueOf()));
|
|
1201
|
+
set(formState, path, targetList);
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
var handleRemove = function handleRemove(index) {
|
|
1205
|
+
var targetList = get(formState, path);
|
|
1206
|
+
|
|
1207
|
+
if (size(targetList) <= 0) {
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
targetList.splice(index, 1);
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
return function () {
|
|
1215
|
+
var _slots$add;
|
|
1216
|
+
|
|
1217
|
+
return createVNode(Fragment, null, [map(get(formState, path), function (item, index) {
|
|
1218
|
+
var _slots$default2, _slots$itemAdd, _slots$itemMinus;
|
|
1219
|
+
|
|
1220
|
+
return createVNode(FormListProvider, {
|
|
1221
|
+
"key": index,
|
|
1222
|
+
"pathList": [].concat(_toConsumableArray(path), [index])
|
|
1223
|
+
}, {
|
|
1224
|
+
"default": function _default() {
|
|
1225
|
+
return [createVNode("div", {
|
|
1226
|
+
"class": "pro-form-list-item"
|
|
1227
|
+
}, [(_slots$default2 = slots["default"]) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots), !readonly.value && createVNode(Fragment, null, [createVNode("div", {
|
|
1228
|
+
"class": "pro-form-list-item-add",
|
|
1229
|
+
"onClick": handleAdd
|
|
1230
|
+
}, [(_slots$itemAdd = slots.itemAdd) === null || _slots$itemAdd === void 0 ? void 0 : _slots$itemAdd.call(slots)]), createVNode("div", {
|
|
1231
|
+
"class": "pro-form-list-item-minus",
|
|
1232
|
+
"onClick": function onClick() {
|
|
1233
|
+
return handleRemove(index);
|
|
1234
|
+
}
|
|
1235
|
+
}, [(_slots$itemMinus = slots.itemMinus) === null || _slots$itemMinus === void 0 ? void 0 : _slots$itemMinus.call(slots)])])])];
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
}), !readonly.value && createVNode("div", {
|
|
1239
|
+
"class": "pro-form-list-add",
|
|
1240
|
+
"onClick": handleAdd
|
|
1241
|
+
}, [(_slots$add = slots.add) === null || _slots$add === void 0 ? void 0 : _slots$add.call(slots)])]);
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
var proFormItemProps = function proFormItemProps() {
|
|
1247
|
+
return {
|
|
1248
|
+
readonly: {
|
|
1249
|
+
type: Boolean,
|
|
1250
|
+
"default": undefined
|
|
1251
|
+
},
|
|
1252
|
+
fieldProps: {
|
|
1253
|
+
type: Object
|
|
1254
|
+
},
|
|
1255
|
+
showProps: {
|
|
1256
|
+
type: Object
|
|
1257
|
+
},
|
|
1258
|
+
slots: {
|
|
1259
|
+
type: Object
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
var createFormItemCompFn = function createFormItemCompFn(FormItem, convertInputCompProps) {
|
|
1265
|
+
return function (_ref) {
|
|
1266
|
+
var InputComp = _ref.InputComp,
|
|
1267
|
+
valueType = _ref.valueType,
|
|
1268
|
+
name = _ref.name;
|
|
1269
|
+
return defineComponent({
|
|
1270
|
+
name: name,
|
|
1271
|
+
props: _objectSpread2(_objectSpread2({}, FormItem.props), proFormItemProps()),
|
|
1272
|
+
setup: function setup(props, _ref2) {
|
|
1273
|
+
var slots = _ref2.slots;
|
|
1274
|
+
|
|
1275
|
+
var _useProForm = useProForm(),
|
|
1276
|
+
formState = _useProForm.formState,
|
|
1277
|
+
showState = _useProForm.showState,
|
|
1278
|
+
readonlyState = _useProForm.readonlyState,
|
|
1279
|
+
disableState = _useProForm.disableState,
|
|
1280
|
+
formReadonly = _useProForm.readonly,
|
|
1281
|
+
elementMap = _useProForm.elementMap;
|
|
1282
|
+
|
|
1283
|
+
var formListCtx = useProFormList(); //优先级 props.readonly > readonlyState > formContext.readonly
|
|
1284
|
+
|
|
1285
|
+
var readonly = computed(function () {
|
|
1286
|
+
if (isBoolean(props.readonly)) {
|
|
1287
|
+
return props.readonly;
|
|
1288
|
+
} else if (isBoolean(readonlyState[props.name])) {
|
|
1289
|
+
return readonlyState[props.name];
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
return formReadonly.value;
|
|
1293
|
+
});
|
|
1294
|
+
var nameList = convertPathToList(props.name);
|
|
1295
|
+
var path = formListCtx !== null && formListCtx !== void 0 && formListCtx.pathList ? [].concat(_toConsumableArray(formListCtx.pathList), _toConsumableArray(nameList)) : nameList;
|
|
1296
|
+
|
|
1297
|
+
var setValue = function setValue(v) {
|
|
1298
|
+
set(formState, path, v);
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
var invalidKeys = keys(proFormItemProps());
|
|
1302
|
+
return function () {
|
|
1303
|
+
var show = get(showState, path);
|
|
1304
|
+
|
|
1305
|
+
if (isBoolean(show) && !show) {
|
|
1306
|
+
return null;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
var value = get(formState, path); //valueType对应的展示组件
|
|
1310
|
+
|
|
1311
|
+
var ShowComp = get(elementMap, valueType);
|
|
1312
|
+
return createVNode(FormItem, mergeProps(omit.apply(void 0, [props].concat(_toConsumableArray(invalidKeys), ["name", "slots"])), {
|
|
1313
|
+
"name": path
|
|
1314
|
+
}), _objectSpread2({
|
|
1315
|
+
"default": function _default() {
|
|
1316
|
+
return [readonly.value ? createVNode(Fragment, null, [ShowComp ? createVNode(ShowComp, mergeProps({
|
|
1317
|
+
"value": value
|
|
1318
|
+
}, props.fieldProps, {
|
|
1319
|
+
"showProps": props.showProps
|
|
1320
|
+
}), slots) : createVNode("span", null, [value])]) : createVNode(InputComp, mergeProps(convertInputCompProps(value, setValue, get(disableState, path)), props.fieldProps), slots)];
|
|
1321
|
+
}
|
|
1322
|
+
}, props.slots));
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
};
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
var ProTableKey = Symbol("pro-table");
|
|
1330
|
+
var useProTable = function useProTable() {
|
|
1331
|
+
return inject(ProTableKey);
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
var provideProTable = function provideProTable(ctx) {
|
|
1335
|
+
provide(ProTableKey, ctx);
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
var proTableProps = function proTableProps() {
|
|
1339
|
+
return {
|
|
1340
|
+
//操作栏
|
|
1341
|
+
operate: {
|
|
1342
|
+
type: Object
|
|
1343
|
+
},
|
|
1344
|
+
//默认空字符串
|
|
1345
|
+
columnEmptyText: {
|
|
1346
|
+
type: String
|
|
1347
|
+
},
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* 公共column,会merge到columns item中
|
|
1351
|
+
*/
|
|
1352
|
+
column: {
|
|
1353
|
+
type: Object
|
|
1354
|
+
},
|
|
1355
|
+
//
|
|
1356
|
+
columns: {
|
|
1357
|
+
type: Array
|
|
1358
|
+
},
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* 展示控件集合,readonly模式下使用这些组件渲染
|
|
1362
|
+
*/
|
|
1363
|
+
elementMap: {
|
|
1364
|
+
type: Object
|
|
1365
|
+
},
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* loading
|
|
1369
|
+
*/
|
|
1370
|
+
loading: {
|
|
1371
|
+
type: Boolean
|
|
1372
|
+
},
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* provide传递
|
|
1376
|
+
*/
|
|
1377
|
+
provideExtra: {
|
|
1378
|
+
type: Object
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
var ProTable = defineComponent({
|
|
1384
|
+
props: _objectSpread2({}, proTableProps()),
|
|
1385
|
+
setup: function setup(props, _ref) {
|
|
1386
|
+
var slots = _ref.slots;
|
|
1387
|
+
var columns = computed(function () {
|
|
1388
|
+
//根据valueType选择对应的展示组件
|
|
1389
|
+
var columns = map(props.columns, function (item) {
|
|
1390
|
+
//merge公共item
|
|
1391
|
+
var nextItem = merge$1(props.column, item);
|
|
1392
|
+
|
|
1393
|
+
if (!item.customRender) {
|
|
1394
|
+
nextItem.customRender = function (_ref2) {
|
|
1395
|
+
var text = _ref2.text;
|
|
1396
|
+
var vn = getItemEl(props.elementMap, _objectSpread2(_objectSpread2({}, item), {}, {
|
|
1397
|
+
showProps: _objectSpread2(_objectSpread2({}, item.showProps), {}, {
|
|
1398
|
+
content: props.columnEmptyText
|
|
1399
|
+
})
|
|
1400
|
+
}), text); //如果找不到注册的组件,使用当前值 及 columnEmptyText
|
|
1401
|
+
|
|
1402
|
+
return vn || text || props.columnEmptyText;
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
return nextItem;
|
|
1407
|
+
});
|
|
1408
|
+
var operate = props.operate; //处理operate
|
|
1409
|
+
|
|
1410
|
+
if (operate && operate.items && some(operate.items, function (item) {
|
|
1411
|
+
return item.show;
|
|
1412
|
+
})) {
|
|
1413
|
+
//将itemState补充的信息拼到item中
|
|
1414
|
+
var items = map(operate.items, function (i) {
|
|
1415
|
+
return _objectSpread2(_objectSpread2({}, i), get(operate.itemState, i.value));
|
|
1416
|
+
}); //排序
|
|
1417
|
+
|
|
1418
|
+
var sortedItems = sortBy(items, function (item) {
|
|
1419
|
+
return item.sort;
|
|
1420
|
+
});
|
|
1421
|
+
columns.push(_objectSpread2(_objectSpread2({
|
|
1422
|
+
title: "操作",
|
|
1423
|
+
dataIndex: "operate",
|
|
1424
|
+
fixed: "right"
|
|
1425
|
+
}, props.column), {}, {
|
|
1426
|
+
customRender: function customRender(_ref3) {
|
|
1427
|
+
var record = _ref3.record;
|
|
1428
|
+
var validItems = filter$1(sortedItems, function (item) {
|
|
1429
|
+
if (item.show && isFunction(item.show)) {
|
|
1430
|
+
return item.show(record);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
if (item.show === false) {
|
|
1434
|
+
return false;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
return true;
|
|
1438
|
+
});
|
|
1439
|
+
return createVNode("div", {
|
|
1440
|
+
"class": "pro-table-operate"
|
|
1441
|
+
}, [map(validItems, function (item) {
|
|
1442
|
+
//自定义
|
|
1443
|
+
if (isFunction(item.element)) {
|
|
1444
|
+
return item.element(record, item);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
return createVNode("div", {
|
|
1448
|
+
"class": "pro-table-operate-item",
|
|
1449
|
+
"key": item.value,
|
|
1450
|
+
"onClick": function onClick() {
|
|
1451
|
+
var _item$onClick;
|
|
1452
|
+
|
|
1453
|
+
(_item$onClick = item.onClick) === null || _item$onClick === void 0 ? void 0 : _item$onClick.call(item, record);
|
|
1454
|
+
}
|
|
1455
|
+
}, [item.label]);
|
|
1456
|
+
})]);
|
|
1457
|
+
}
|
|
1458
|
+
}, operate.column));
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
return columns;
|
|
1462
|
+
});
|
|
1463
|
+
provideProTable(_objectSpread2({
|
|
1464
|
+
columns: columns
|
|
1465
|
+
}, props.provideExtra));
|
|
1466
|
+
return function () {
|
|
1467
|
+
var _slots$default;
|
|
1468
|
+
|
|
1469
|
+
return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots, columns.value);
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
|
|
1474
|
+
export { CurdAction, CurdAddAction, CurdCurrentMode, CurdSubAction, ProCurd, ProForm, ProFormList, ProModule, ProSearchForm, ProTable, RequestAction, SearchMode, convertPathToList, createFormItemCompFn, getColumnFormItemName, getColumnValueType, getFormItemEl, getItemEl, getValidValues, provideProCurd, provideProModule, useComposeRequestActor, useDoneRequestActor, useFailedRequestActor, useModuleEvent, useProCurd, useProForm, useProFormList, useProModule, useProTable };
|