@hzab/list-render 0.0.11 → 0.0.12
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/README.md +80 -1
- package/example/app.tsx +19 -0
- package/example/components/anbao-router/index.tsx +47 -0
- package/example/index.less +3 -0
- package/example/index.tsx +8 -0
- package/example/pages/index/grid-empty.schema.json +201 -0
- package/example/pages/index/grid.schema.json +94 -0
- package/example/pages/index/index.less +5 -0
- package/example/pages/index/index.tsx +72 -0
- package/example/pages/index/test.schema.json +413 -0
- package/example/router.ts +3 -0
- package/example/typings.d.ts +16 -0
- package/lib/data-model.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +7 -3
- package/src/common/utils.js +17 -0
- package/src/data-model.js +11 -3
- package/src/form-dialog/index.jsx +0 -1
- package/src/index.js +1 -5
- package/src/list-render.jsx +3 -6
- package/src/query-render/index.jsx +3 -6
- package/CHANGELOG +0 -27
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/list-render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "webpack serve -c ./config/webpack.config.js --env development",
|
|
8
|
-
"build": "webpack -c ./config/webpack.config.js --env production"
|
|
8
|
+
"build": "webpack -c ./config/webpack.config.js --env production",
|
|
9
|
+
"publish-patch": "npm run build && npm version patch && npm publish --access public",
|
|
10
|
+
"publish-minor": "npm run build && npm version minor && npm publish --access public",
|
|
11
|
+
"publish-major": "npm run build && npm version major && npm publish --access public"
|
|
9
12
|
},
|
|
10
13
|
"files": [
|
|
11
14
|
"lib",
|
|
12
|
-
"src"
|
|
15
|
+
"src",
|
|
16
|
+
"example"
|
|
13
17
|
],
|
|
14
18
|
"keywords": [],
|
|
15
19
|
"author": "CaiYansong",
|
package/src/common/utils.js
CHANGED
|
@@ -94,3 +94,20 @@ export function getFieldList(_schema, fieldList = []) {
|
|
|
94
94
|
});
|
|
95
95
|
return fieldList;
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
export function getFieldMap(_schema, fieldMap = {}) {
|
|
99
|
+
// const fieldMap = _.keyBy(getFieldList(_schema), "name");
|
|
100
|
+
const schema = _schema?.schema || _schema;
|
|
101
|
+
schema?.properties &&
|
|
102
|
+
Object.keys(schema?.properties).forEach((key) => {
|
|
103
|
+
const field = schema?.properties[key];
|
|
104
|
+
if (field["x-component"] === "FormGrid") {
|
|
105
|
+
getFieldMap(field, fieldMap);
|
|
106
|
+
} else if (field["x-component"] === "FormGrid.GridColumn") {
|
|
107
|
+
getFieldMap(field, fieldMap);
|
|
108
|
+
} else {
|
|
109
|
+
fieldMap[key] = field;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return fieldMap;
|
|
113
|
+
}
|
package/src/data-model.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
|
|
4
|
+
const _$Temp = {};
|
|
5
|
+
|
|
4
6
|
class DataModel {
|
|
5
7
|
constructor(params) {
|
|
6
8
|
const {
|
|
@@ -23,7 +25,7 @@ class DataModel {
|
|
|
23
25
|
|
|
24
26
|
this.ctx = ctx || {};
|
|
25
27
|
this.query = query || {};
|
|
26
|
-
this.axios = as || axios;
|
|
28
|
+
this.axios = as || _$Temp.axios || axios;
|
|
27
29
|
this.axiosConf = axiosConf || {};
|
|
28
30
|
|
|
29
31
|
this.createApi = createApi;
|
|
@@ -41,7 +43,7 @@ class DataModel {
|
|
|
41
43
|
|
|
42
44
|
getApiUrl(api, record, ctx = this.ctx) {
|
|
43
45
|
if (!api) {
|
|
44
|
-
throw new Error("Error
|
|
46
|
+
throw new Error("Error api 不能为空", api, record, ctx);
|
|
45
47
|
}
|
|
46
48
|
let apiUrl = api;
|
|
47
49
|
const params = _.merge({}, record, ctx);
|
|
@@ -215,6 +217,12 @@ class DataModel {
|
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
219
|
|
|
218
|
-
|
|
220
|
+
function setDefaultAxios(ax) {
|
|
221
|
+
if (ax) {
|
|
222
|
+
_$Temp.axios = ax;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export { axios, DataModel, setDefaultAxios };
|
|
219
227
|
|
|
220
228
|
export default DataModel;
|
|
@@ -27,7 +27,6 @@ function FormDialog(props, parentRef) {
|
|
|
27
27
|
} else {
|
|
28
28
|
_formData = formData;
|
|
29
29
|
}
|
|
30
|
-
console.log("formRef.current?.formRender", formRef.current?.formRender);
|
|
31
30
|
setTitle(title || "新增");
|
|
32
31
|
return new Promise((resolve, reject) => {
|
|
33
32
|
resolveCB.current = resolve;
|
package/src/index.js
CHANGED
package/src/list-render.jsx
CHANGED
|
@@ -72,14 +72,13 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
72
72
|
model
|
|
73
73
|
?.getList(_q)
|
|
74
74
|
.then((res) => {
|
|
75
|
-
console.log("list res", res);
|
|
76
75
|
setList(res.list);
|
|
77
76
|
setTotal(res.pagination?.total);
|
|
78
77
|
props.onGetListEnd && props.onGetListEnd(res);
|
|
79
78
|
setListLoading(false);
|
|
80
79
|
})
|
|
81
80
|
.catch((err) => {
|
|
82
|
-
console.
|
|
81
|
+
console.error(err);
|
|
83
82
|
message.error(err._message || "未知错误");
|
|
84
83
|
setListLoading(false);
|
|
85
84
|
});
|
|
@@ -111,11 +110,9 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
function onCreate() {
|
|
114
|
-
console.log("onCreate");
|
|
115
113
|
formDialogRef.current
|
|
116
114
|
.show()
|
|
117
115
|
.then(async (form) => {
|
|
118
|
-
console.log("onCreate", form);
|
|
119
116
|
const data = form;
|
|
120
117
|
|
|
121
118
|
model
|
|
@@ -130,7 +127,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
130
127
|
});
|
|
131
128
|
})
|
|
132
129
|
.catch((e) => {
|
|
133
|
-
console.
|
|
130
|
+
console.warn("Dialog close");
|
|
134
131
|
});
|
|
135
132
|
}
|
|
136
133
|
|
|
@@ -173,7 +170,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
173
170
|
});
|
|
174
171
|
})
|
|
175
172
|
.catch((e) => {
|
|
176
|
-
console.
|
|
173
|
+
console.warn("Dialog close");
|
|
177
174
|
});
|
|
178
175
|
}
|
|
179
176
|
|
|
@@ -4,6 +4,7 @@ import dayjs from "dayjs";
|
|
|
4
4
|
import _ from "lodash";
|
|
5
5
|
|
|
6
6
|
import FormRender from "@hzab/form-render";
|
|
7
|
+
import { getFieldMap } from "../common/utils";
|
|
7
8
|
|
|
8
9
|
import "./index.less";
|
|
9
10
|
|
|
@@ -36,10 +37,9 @@ function QueryRender(props, parentRef) {
|
|
|
36
37
|
index += 1;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
-
console.log("props.filters", props.filters);
|
|
40
|
+
const fieldMap = getFieldMap(props.schema);
|
|
41
41
|
props.filters?.forEach((key) => {
|
|
42
|
-
const item =
|
|
42
|
+
const item = fieldMap[key];
|
|
43
43
|
if (item) {
|
|
44
44
|
// TODO: 优化
|
|
45
45
|
const itemConf = {
|
|
@@ -79,8 +79,6 @@ function QueryRender(props, parentRef) {
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
console.log("queryProperties", queryProperties);
|
|
83
|
-
|
|
84
82
|
setSchema({
|
|
85
83
|
form: {},
|
|
86
84
|
schema: {
|
|
@@ -94,7 +92,6 @@ function QueryRender(props, parentRef) {
|
|
|
94
92
|
function onSearch() {
|
|
95
93
|
let query = _.cloneDeep(formRef?.current?.formRender?.values);
|
|
96
94
|
if (props.filters?.includes("$timerange")) {
|
|
97
|
-
console.log("query.$timerange?.[0]", query.$timerange?.[0]);
|
|
98
95
|
if (query.$timerange?.[0] instanceof dayjs) {
|
|
99
96
|
query.beginTime = query.$timerange?.[0]?.format("YYYY-MM-DD HH:mm:ss");
|
|
100
97
|
query.endTime = query.$timerange?.[1]?.format("YYYY-MM-DD HH:mm:ss");
|
package/CHANGELOG
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# @hzab/list-render@0.0.9
|
|
2
|
-
|
|
3
|
-
- DataModel response.data.data 为空报错问题处理
|
|
4
|
-
|
|
5
|
-
# @hzab/list-render@0.0.8
|
|
6
|
-
|
|
7
|
-
- 编辑中的详情请求,支持配置是否使用 id 作为入参的
|
|
8
|
-
|
|
9
|
-
# @hzab/list-render@0.0.7
|
|
10
|
-
|
|
11
|
-
- 修复 query display 问题
|
|
12
|
-
- query allowClear: true
|
|
13
|
-
|
|
14
|
-
# @hzab/list-render@0.0.3
|
|
15
|
-
|
|
16
|
-
- 支持 FormGrid 表单项
|
|
17
|
-
|
|
18
|
-
# @hzab/list-render@0.0.2
|
|
19
|
-
|
|
20
|
-
- DidMount 问题修复
|
|
21
|
-
- dialog catch
|
|
22
|
-
- form render components
|
|
23
|
-
- data-model
|
|
24
|
-
|
|
25
|
-
# @hzab/list-render@0.0.1
|
|
26
|
-
|
|
27
|
-
组件初始化
|