form-driver 0.4.19 → 0.4.20
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 +15 -0
- package/dist/m3.js +1 -1
- package/es/m3.js +353 -120
- package/lib/m3.js +352 -118
- package/package.json +2 -2
- package/src/framework/Init.tsx +6 -0
- package/src/framework/Schema.ts +16 -2
- package/src/index.ts +0 -1
- package/src/types/MDateRangeType.ts +65 -24
- package/src/types/MDateTimeType.ts +73 -29
- package/src/ui/editor/basic/ACascadePicker.tsx +23 -15
- package/src/ui/editor/basic/ADatetimePicker.tsx +103 -39
- package/src/ui/editor/basic/AGB2260.tsx +25 -14
- package/src/ui/editor/basic/ARangePicker.tsx +86 -22
- package/src/ui/widget/SelectBox.tsx +35 -15
- package/types/framework/Init.d.ts +1 -0
- package/types/framework/Schema.d.ts +11 -0
- package/types/index.d.ts +0 -1
- package/types/types/MDateTimeType.d.ts +2 -2
- package/types/ui/editor/basic/ADatetimePicker.d.ts +2 -1
- package/types/ui/editor/basic/AGB2260.d.ts +1 -0
- package/types/ui/editor/basic/ARangePicker.d.ts +5 -3
- package/types/ui/widget/SelectBox.d.ts +10 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "form-driver",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.20",
|
|
4
4
|
"description": "An efficient framework for creating forms.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"authors": [
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@babel/runtime": "^7.9.2",
|
|
62
62
|
"ali-oss": "^6.17.1",
|
|
63
63
|
"antd": "4.18.7",
|
|
64
|
-
"antd-mobile": "^
|
|
64
|
+
"antd-mobile": "^5.37.1",
|
|
65
65
|
"clsx": "^2.1.1",
|
|
66
66
|
"lodash": "^4.17.20",
|
|
67
67
|
"moment": "^2.29.1",
|
package/src/framework/Init.tsx
CHANGED
|
@@ -45,6 +45,8 @@ import { ATable } from "../ui/editor/complex/ATable";
|
|
|
45
45
|
import { ARemoteSelector } from "../ui/editor/basic/ARemoteSelector";
|
|
46
46
|
import { JsonEditor } from "../ui/editor/complex/JsonEditor";
|
|
47
47
|
import _ from "lodash";
|
|
48
|
+
import moment from "moment";
|
|
49
|
+
import "moment/locale/zh-cn";
|
|
48
50
|
import { A } from "../ui/readable/A";
|
|
49
51
|
import { ADialogForm } from "../ui/editor/complex/ADialogForm";
|
|
50
52
|
import { MVLPairType } from "../types/MVLPairType";
|
|
@@ -68,9 +70,11 @@ export function ensureM3() {
|
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
70
72
|
init = true;
|
|
73
|
+
moment.locale('zh-cn');
|
|
71
74
|
assembly.types = _.merge(assembly.types, {
|
|
72
75
|
enum: MEnumType,
|
|
73
76
|
gb2260: MGB2260Type,
|
|
77
|
+
date: MDateTimeType,
|
|
74
78
|
datetime: MDateTimeType,
|
|
75
79
|
year: MDateTimeType,
|
|
76
80
|
yearMonth: MDateTimeType,
|
|
@@ -138,6 +142,7 @@ export function ensureM3() {
|
|
|
138
142
|
editor: {
|
|
139
143
|
enum: "ASelector",
|
|
140
144
|
gb2260: "AGB2260",
|
|
145
|
+
date: "ADatetimePicker",
|
|
141
146
|
datetime: "ADatetimePicker",
|
|
142
147
|
year: "ADatetimePicker",
|
|
143
148
|
yearMonth: "ADatetimePicker",
|
|
@@ -171,6 +176,7 @@ export function ensureM3() {
|
|
|
171
176
|
readable: {
|
|
172
177
|
enum: "DivViewer",
|
|
173
178
|
gb2260: "DivViewer",
|
|
179
|
+
date: "DivViewer",
|
|
174
180
|
datetime: "DivViewer",
|
|
175
181
|
year: "DivViewer",
|
|
176
182
|
yearMonth: "DivViewer",
|
package/src/framework/Schema.ts
CHANGED
|
@@ -183,14 +183,28 @@ export interface MFieldSchema {
|
|
|
183
183
|
overlap?: boolean;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
+
/** date 类型配置 */
|
|
187
|
+
date?: {
|
|
188
|
+
/** 日期精度:month=年月, day=年月日(默认), minute=年月日时分 */
|
|
189
|
+
precision?: "month" | "day" | "minute";
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** 日期精度(扁平化属性):year=年, month=年月, day=年月日(默认), minute=年月日时分 */
|
|
193
|
+
datePrecision?: string;
|
|
194
|
+
|
|
186
195
|
/** dateRange 类型配置 */
|
|
187
196
|
dateRange?: {
|
|
188
197
|
/** 是否隐藏至今按钮 */
|
|
189
198
|
hideTillNow?: boolean;
|
|
190
199
|
/** 是否能选择时间 */
|
|
191
200
|
showTime?: boolean;
|
|
201
|
+
/** 日期精度:month=年月, day=年月日(默认), minute=年月日时分 */
|
|
202
|
+
precision?: "month" | "day" | "minute";
|
|
192
203
|
};
|
|
193
204
|
|
|
205
|
+
/** 日期范围精度(扁平化属性) */
|
|
206
|
+
dateRangePrecision?: string;
|
|
207
|
+
|
|
194
208
|
/** 数据格式 */
|
|
195
209
|
dataFormat?:
|
|
196
210
|
| "x"
|
|
@@ -320,7 +334,7 @@ export interface MFieldSchema {
|
|
|
320
334
|
export type AFTER_CHANGE_CALLBACK = (
|
|
321
335
|
path: string,
|
|
322
336
|
v: any,
|
|
323
|
-
final: boolean
|
|
337
|
+
final: boolean,
|
|
324
338
|
) => void;
|
|
325
339
|
|
|
326
340
|
export type CHANGE_SCHEMA_CALLBACK = (v: any) => void;
|
|
@@ -384,7 +398,7 @@ export interface M3UISpecSegmentItem {
|
|
|
384
398
|
onSubmit?: (
|
|
385
399
|
segment: M3UISpecSegmentItem,
|
|
386
400
|
segmentData: any,
|
|
387
|
-
done: () => void
|
|
401
|
+
done: () => void,
|
|
388
402
|
) => void;
|
|
389
403
|
|
|
390
404
|
/** 设置分段根元素的style */
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import 'antd/dist/antd.css';
|
|
2
|
-
import 'antd-mobile/dist/antd-mobile.css';
|
|
3
2
|
import { Ajax } from './framework/Ajax';
|
|
4
3
|
import { M3UISpecSegmentItem, MFieldSchema, M3UISpec, MFieldSchemaAnonymity } from './framework/Schema';
|
|
5
4
|
import { MViewerDebug } from './framework/MViewerDebug';
|
|
@@ -1,52 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
1
|
import { MFieldSchemaAnonymity } from "../framework/Schema";
|
|
5
|
-
import { EmtpyType, MType} from "./MType";
|
|
2
|
+
import { EmtpyType, MType } from "./MType";
|
|
6
3
|
import { validateRequired } from "../framework/Validator";
|
|
7
4
|
import { Assembly } from "../framework/Assembly";
|
|
8
5
|
import moment from "moment";
|
|
9
6
|
import _ from "lodash";
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/** 根据 precision 获取可读格式 */
|
|
9
|
+
function getReadableFormat(precision?: string, showTime?: boolean): string {
|
|
10
|
+
switch (precision) {
|
|
11
|
+
case "year":
|
|
12
|
+
return "YYYY年";
|
|
13
|
+
case "month":
|
|
14
|
+
return "YYYY年MM月";
|
|
15
|
+
case "minute":
|
|
16
|
+
return "YYYY年MM月DD日 HH:mm";
|
|
17
|
+
default:
|
|
18
|
+
return showTime ? "YYYY年MM月DD日 HH:mm:ss" : "YYYY年MM月DD日";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function timeExpr(
|
|
23
|
+
assembly: Assembly,
|
|
24
|
+
v: any,
|
|
25
|
+
tillNow: boolean,
|
|
26
|
+
readableFormat,
|
|
27
|
+
): string {
|
|
28
|
+
if (tillNow) {
|
|
13
29
|
return "至今";
|
|
14
30
|
}
|
|
15
|
-
if(!v){
|
|
31
|
+
if (!v) {
|
|
16
32
|
return assembly.theme.READABLE_UNKNOWN;
|
|
17
33
|
}
|
|
18
34
|
return moment(v, "x").format(readableFormat);
|
|
19
35
|
}
|
|
20
36
|
|
|
21
|
-
export function timeRangeExpr(
|
|
22
|
-
|
|
37
|
+
export function timeRangeExpr(
|
|
38
|
+
assembly: Assembly,
|
|
39
|
+
from: number | string,
|
|
40
|
+
to: number | string,
|
|
41
|
+
tillNow: boolean,
|
|
42
|
+
readableFormat: string = "YYYY年MM月DD日",
|
|
43
|
+
): string {
|
|
44
|
+
return (
|
|
45
|
+
timeExpr(assembly, from, false, readableFormat) +
|
|
46
|
+
" ~ " +
|
|
47
|
+
timeExpr(assembly, to, tillNow, readableFormat)
|
|
48
|
+
);
|
|
23
49
|
}
|
|
24
50
|
|
|
25
|
-
export const MDateRangeType: MType & {
|
|
51
|
+
export const MDateRangeType: MType & {
|
|
52
|
+
toReadableN: (
|
|
53
|
+
assembly: Assembly,
|
|
54
|
+
s: MFieldSchemaAnonymity,
|
|
55
|
+
vs: any,
|
|
56
|
+
) => string | undefined;
|
|
57
|
+
} = _.assign({}, EmtpyType, {
|
|
26
58
|
validators: [validateRequired],
|
|
27
|
-
|
|
28
|
-
toReadable: (
|
|
29
|
-
|
|
30
|
-
|
|
59
|
+
|
|
60
|
+
toReadable: (
|
|
61
|
+
assembly: Assembly,
|
|
62
|
+
s: MFieldSchemaAnonymity,
|
|
63
|
+
vs: any,
|
|
64
|
+
): string => {
|
|
65
|
+
if (_.isNil(vs)) {
|
|
66
|
+
return assembly.theme.READABLE_BLANK;
|
|
31
67
|
}
|
|
32
|
-
if(!_.isArray(vs)){
|
|
68
|
+
if (!_.isArray(vs)) {
|
|
33
69
|
return assembly.theme.READABLE_INVALID;
|
|
34
70
|
}
|
|
35
71
|
|
|
36
|
-
|
|
72
|
+
const fmt = getReadableFormat(s.dateRangePrecision, s.dateRange?.showTime);
|
|
73
|
+
return timeRangeExpr(assembly, vs[0], vs[1], vs[2], fmt);
|
|
37
74
|
},
|
|
38
75
|
|
|
39
76
|
/**
|
|
40
77
|
* 同toReadable,但数据无效时返回nil
|
|
41
|
-
* @param assembly
|
|
42
|
-
* @param s
|
|
43
|
-
* @param vs
|
|
44
|
-
* @returns
|
|
45
78
|
*/
|
|
46
|
-
toReadableN: (
|
|
47
|
-
|
|
48
|
-
|
|
79
|
+
toReadableN: (
|
|
80
|
+
assembly: Assembly,
|
|
81
|
+
s: MFieldSchemaAnonymity,
|
|
82
|
+
vs: any,
|
|
83
|
+
): string | undefined => {
|
|
84
|
+
if (!_.isNil(vs) && _.isArray(vs)) {
|
|
85
|
+
const fmt = getReadableFormat(
|
|
86
|
+
s.dateRangePrecision,
|
|
87
|
+
s.dateRange?.showTime,
|
|
88
|
+
);
|
|
89
|
+
return timeRangeExpr(assembly, vs[0], vs[1], vs[2], fmt);
|
|
49
90
|
}
|
|
50
91
|
return undefined;
|
|
51
|
-
}
|
|
92
|
+
},
|
|
52
93
|
});
|
|
@@ -1,53 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import _ from 'lodash';
|
|
1
|
+
import { validateDateMinMax, validateRequired } from "../framework/Validator";
|
|
2
|
+
import { MFieldSchemaAnonymity } from "../framework/Schema";
|
|
3
|
+
import { EmtpyType, MType } from "./MType";
|
|
4
|
+
import moment from "moment";
|
|
5
|
+
import { Assembly } from "../framework/Assembly";
|
|
6
|
+
import _ from "lodash";
|
|
8
7
|
|
|
9
8
|
export interface MDateTimeAntConf {
|
|
10
|
-
dataFormat: string
|
|
11
|
-
readableFormat: string
|
|
12
|
-
mode: undefined |
|
|
9
|
+
dataFormat: string;
|
|
10
|
+
readableFormat: string;
|
|
11
|
+
mode: undefined | "date" | "year" | "month" | "time";
|
|
13
12
|
showTime: boolean;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export const MDateTimeType:MType & {
|
|
15
|
+
export const MDateTimeType: MType & {
|
|
16
|
+
antConf: (schema: MFieldSchemaAnonymity) => MDateTimeAntConf | undefined;
|
|
17
|
+
} = _.assign({}, EmtpyType, {
|
|
17
18
|
validators: [validateRequired, validateDateMinMax],
|
|
18
19
|
|
|
19
|
-
antConf: (schema:MFieldSchemaAnonymity):MDateTimeAntConf|undefined => {
|
|
20
|
-
let dataFormat:string|undefined = schema.dataFormat;
|
|
20
|
+
antConf: (schema: MFieldSchemaAnonymity): MDateTimeAntConf | undefined => {
|
|
21
|
+
let dataFormat: string | undefined = schema.dataFormat;
|
|
21
22
|
let readableFormat: string;
|
|
22
|
-
let mode: undefined |
|
|
23
|
+
let mode: undefined | "date" | "year" | "month" | "time";
|
|
23
24
|
let showTime = false;
|
|
24
|
-
switch(schema.type) {
|
|
25
|
-
case "year":
|
|
26
|
-
mode = "year";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
switch (schema.type) {
|
|
26
|
+
case "year":
|
|
27
|
+
mode = "year";
|
|
28
|
+
dataFormat = dataFormat ?? "YYYY";
|
|
29
|
+
readableFormat = "YYYY";
|
|
30
|
+
break;
|
|
31
|
+
case "yearMonth":
|
|
32
|
+
mode = "month";
|
|
33
|
+
dataFormat = dataFormat ?? "YYYYMM";
|
|
34
|
+
readableFormat = "YYYY-MM";
|
|
35
|
+
break;
|
|
36
|
+
case "yearMonthDay":
|
|
37
|
+
mode = "date";
|
|
38
|
+
dataFormat = dataFormat ?? "YYYYMMDD";
|
|
39
|
+
readableFormat = "YYYY-MM-DD";
|
|
40
|
+
break;
|
|
41
|
+
case "datetime":
|
|
42
|
+
mode = undefined;
|
|
43
|
+
dataFormat = dataFormat ?? "x";
|
|
44
|
+
readableFormat = "YYYY-MM-DD HH:mm";
|
|
45
|
+
showTime = true;
|
|
46
|
+
break;
|
|
47
|
+
case "date":
|
|
48
|
+
switch (schema.datePrecision) {
|
|
49
|
+
case "year":
|
|
50
|
+
mode = "year";
|
|
51
|
+
dataFormat = dataFormat ?? "YYYY";
|
|
52
|
+
readableFormat = "YYYY";
|
|
53
|
+
break;
|
|
54
|
+
case "month":
|
|
55
|
+
mode = "month";
|
|
56
|
+
dataFormat = dataFormat ?? "YYYYMM";
|
|
57
|
+
readableFormat = "YYYY-MM";
|
|
58
|
+
break;
|
|
59
|
+
case "minute":
|
|
60
|
+
mode = undefined;
|
|
61
|
+
dataFormat = dataFormat ?? "x";
|
|
62
|
+
readableFormat = "YYYY-MM-DD HH:mm";
|
|
63
|
+
showTime = true;
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
// "day" 或未指定
|
|
67
|
+
mode = "date";
|
|
68
|
+
dataFormat = dataFormat ?? "YYYYMMDD";
|
|
69
|
+
readableFormat = "YYYY-MM-DD";
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
33
73
|
// case "yearAndQuarter":
|
|
34
74
|
// case "yearAndWeek":
|
|
35
75
|
// return MUtil.error(`移动端不支持${this.props.schema.type}`, this.props.schema);
|
|
36
76
|
default:
|
|
37
77
|
return undefined;
|
|
38
78
|
}
|
|
39
|
-
return {dataFormat, readableFormat, mode, showTime};
|
|
79
|
+
return { dataFormat, readableFormat, mode, showTime };
|
|
40
80
|
},
|
|
41
81
|
|
|
42
|
-
toReadable: (
|
|
43
|
-
|
|
82
|
+
toReadable: (
|
|
83
|
+
assembly: Assembly,
|
|
84
|
+
schema: MFieldSchemaAnonymity,
|
|
85
|
+
v: any,
|
|
86
|
+
): string => {
|
|
87
|
+
if (_.isNil(v)) {
|
|
44
88
|
return assembly.theme.READABLE_BLANK;
|
|
45
89
|
}
|
|
46
90
|
let c = MDateTimeType.antConf(schema);
|
|
47
|
-
if(!c) {
|
|
91
|
+
if (!c) {
|
|
48
92
|
return assembly.theme.READABLE_INVALID;
|
|
49
93
|
}
|
|
50
|
-
let asMoment = moment(v, c.dataFormat)
|
|
94
|
+
let asMoment = moment(v, c.dataFormat);
|
|
51
95
|
return asMoment.format(c.readableFormat);
|
|
52
|
-
}
|
|
96
|
+
},
|
|
53
97
|
});
|
|
@@ -4,7 +4,7 @@ import _ from "lodash";
|
|
|
4
4
|
import { MUtil } from "../../../framework/MUtil";
|
|
5
5
|
import { Cascader } from "antd";
|
|
6
6
|
import { MFieldSchema } from "../../../framework/Schema";
|
|
7
|
-
import {
|
|
7
|
+
import { CascadePicker } from "antd-mobile";
|
|
8
8
|
import { BaseViewer } from "../../..";
|
|
9
9
|
|
|
10
10
|
export function labelExpr(d: any, remote: MFieldSchema["remote"]) {
|
|
@@ -75,23 +75,31 @@ export class ACascadePicker extends BaseViewer {
|
|
|
75
75
|
if (MUtil.phoneLike()) {
|
|
76
76
|
return (
|
|
77
77
|
<>
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
<div className="backfill" onClick={() => this.setState({ cascadeVisible: true } as any)}>
|
|
79
|
+
{show.length > 0 ? show.map(item => item.label || item.value || item).join('-') : '请点击选择'}
|
|
80
|
+
</div>
|
|
81
|
+
<CascadePicker
|
|
82
|
+
options={candidate}
|
|
83
|
+
value={show.map((item: any) => item.value || item)}
|
|
84
|
+
visible={(this.state as any)?.cascadeVisible}
|
|
85
|
+
onConfirm={(v) => {
|
|
86
|
+
const vLabel: any[] = [];
|
|
87
|
+
(v as any[]).forEach((item) => {
|
|
88
|
+
candidate.forEach((dataItem: any) => {
|
|
89
|
+
const findItem = findById(dataItem, item, "label", "value", "children");
|
|
90
|
+
if (findItem !== -1) {
|
|
91
|
+
vLabel.push(findItem);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
super.changeValue(vLabel);
|
|
96
|
+
this.setState({ cascadeVisible: false } as any);
|
|
86
97
|
}}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
super.changeValue(v);
|
|
98
|
+
onClose={() => {
|
|
99
|
+
this.setState({ cascadeVisible: false } as any);
|
|
90
100
|
}}
|
|
91
101
|
{...p}
|
|
92
|
-
|
|
93
|
-
<div className="backfill"> {show.length > 0 ? show.join('-') : '请点击选择' } </div>
|
|
94
|
-
</Picker> */}
|
|
102
|
+
/>
|
|
95
103
|
</>
|
|
96
104
|
);
|
|
97
105
|
} else {
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { DatePicker } from "antd";
|
|
3
|
-
import { DatePicker as DatePickerM } from
|
|
2
|
+
import { DatePicker, ConfigProvider } from "antd";
|
|
3
|
+
import { DatePicker as DatePickerM } from "antd-mobile";
|
|
4
4
|
import moment from "moment";
|
|
5
|
-
import zhCN from
|
|
5
|
+
import zhCN from "antd/es/locale/zh_CN";
|
|
6
6
|
import _ from "lodash";
|
|
7
7
|
import { MDateTimeType } from "../../../types/MDateTimeType";
|
|
8
8
|
import { MUtil } from "../../../framework/MUtil";
|
|
9
|
-
import { BaseViewer } from
|
|
9
|
+
import { BaseViewer } from "../../BaseViewer";
|
|
10
|
+
|
|
11
|
+
// antd-mobile v5 DatePicker precision 映射
|
|
12
|
+
function toPrecision(
|
|
13
|
+
mode: string | undefined,
|
|
14
|
+
): "year" | "month" | "day" | "hour" | "minute" | "second" {
|
|
15
|
+
switch (mode) {
|
|
16
|
+
case "year":
|
|
17
|
+
return "year";
|
|
18
|
+
case "month":
|
|
19
|
+
return "month";
|
|
20
|
+
case "date":
|
|
21
|
+
return "day";
|
|
22
|
+
default:
|
|
23
|
+
return "minute"; // datetime 场景
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
10
27
|
/**
|
|
11
28
|
* 日期选择框
|
|
12
29
|
* 配置示例:
|
|
@@ -18,10 +35,18 @@ import { BaseViewer } from '../../BaseViewer';
|
|
|
18
35
|
* 类型是dateTime时,dataFormat默认是x,例如1608897466955
|
|
19
36
|
*/
|
|
20
37
|
export class ADatetimePicker extends BaseViewer {
|
|
38
|
+
constructor(props: any) {
|
|
39
|
+
super(props);
|
|
40
|
+
(this.state as any).pickerVisible = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
21
43
|
element() {
|
|
22
44
|
const antConf = MDateTimeType.antConf(this.props.schema);
|
|
23
45
|
if (!antConf) {
|
|
24
|
-
return MUtil.error(
|
|
46
|
+
return MUtil.error(
|
|
47
|
+
`无效的类型${this.props.schema.type}`,
|
|
48
|
+
this.props.schema,
|
|
49
|
+
);
|
|
25
50
|
}
|
|
26
51
|
|
|
27
52
|
let data = this.getValue();
|
|
@@ -31,46 +56,85 @@ export class ADatetimePicker extends BaseViewer {
|
|
|
31
56
|
const onChange = (vv: Date | moment.Moment | null) => {
|
|
32
57
|
if (vv) {
|
|
33
58
|
const vvAsM = _.isDate(vv) ? moment(vv) : vv;
|
|
34
|
-
super.changeValue(vvAsM.format(antConf.dataFormat))
|
|
59
|
+
super.changeValue(vvAsM.format(antConf.dataFormat));
|
|
35
60
|
} else {
|
|
36
61
|
super.changeValue(undefined);
|
|
37
62
|
}
|
|
38
63
|
};
|
|
39
64
|
const p = this.props.schema.props ?? {};
|
|
40
65
|
// 构造元素
|
|
41
|
-
if (MUtil.phoneLike()) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
if (MUtil.phoneLike()) {
|
|
67
|
+
// 手机
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<div
|
|
71
|
+
className="backfill"
|
|
72
|
+
onClick={() => {
|
|
73
|
+
if (!this.props.disable)
|
|
74
|
+
this.setState({ pickerVisible: true } as any);
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{dataAsDate
|
|
78
|
+
? moment(dataAsDate).format(antConf.readableFormat)
|
|
79
|
+
: "请点击选择"}
|
|
80
|
+
</div>
|
|
81
|
+
<DatePickerM
|
|
82
|
+
visible={(this.state as any).pickerVisible}
|
|
83
|
+
value={dataAsDate}
|
|
84
|
+
min={
|
|
85
|
+
this.props.schema.min
|
|
86
|
+
? moment(this.props.schema.min, antConf.dataFormat).toDate()
|
|
87
|
+
: undefined
|
|
88
|
+
}
|
|
89
|
+
max={
|
|
90
|
+
this.props.schema.max
|
|
91
|
+
? moment(this.props.schema.max, antConf.dataFormat).toDate()
|
|
92
|
+
: undefined
|
|
93
|
+
}
|
|
94
|
+
precision={toPrecision(antConf.mode)}
|
|
95
|
+
onConfirm={(val) => {
|
|
96
|
+
onChange(val);
|
|
97
|
+
this.setState({ pickerVisible: false } as any);
|
|
98
|
+
}}
|
|
99
|
+
onClose={() => {
|
|
100
|
+
this.setState({ pickerVisible: false } as any);
|
|
101
|
+
}}
|
|
102
|
+
{...p}
|
|
103
|
+
/>
|
|
104
|
+
</>
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
// 大屏
|
|
108
|
+
// key 中加入 mode 信息,确保精度切换时组件重新挂载
|
|
109
|
+
const pickerKey = `${this.props.path}_${antConf.mode ?? "datetime"}`;
|
|
110
|
+
return (
|
|
111
|
+
<ConfigProvider locale={zhCN}>
|
|
112
|
+
<DatePicker
|
|
113
|
+
key={pickerKey}
|
|
114
|
+
disabled={this.props.disable}
|
|
115
|
+
bordered={this.props.hideBorder ? false : true}
|
|
116
|
+
disabledDate={(m) => {
|
|
117
|
+
const d =
|
|
118
|
+
(this.props.schema.min &&
|
|
119
|
+
moment(this.props.schema.min, antConf.dataFormat).isAfter(
|
|
120
|
+
m,
|
|
121
|
+
)) ||
|
|
122
|
+
(this.props.schema.max &&
|
|
123
|
+
moment(this.props.schema.max, antConf.dataFormat).isBefore(
|
|
124
|
+
m,
|
|
125
|
+
));
|
|
126
|
+
return !!d;
|
|
127
|
+
}}
|
|
128
|
+
format={antConf.readableFormat}
|
|
129
|
+
style={{ width: "300px" }}
|
|
130
|
+
defaultValue={dataAsMoment}
|
|
131
|
+
showTime={antConf.showTime}
|
|
132
|
+
picker={antConf.mode}
|
|
133
|
+
onChange={onChange}
|
|
134
|
+
{...p}
|
|
135
|
+
/>
|
|
136
|
+
</ConfigProvider>
|
|
137
|
+
);
|
|
74
138
|
}
|
|
75
139
|
}
|
|
76
140
|
}
|
|
@@ -5,12 +5,18 @@ import { Picker } from 'antd-mobile';
|
|
|
5
5
|
import { MUtil } from "../../../framework/MUtil";
|
|
6
6
|
import { BaseViewer } from '../../BaseViewer';
|
|
7
7
|
import { MGB2260Type } from '../../../types/MGB2260Type';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* 选择中国的省市县
|
|
10
11
|
* 示例:{label:"1.5 您目前的居住地",name:"reside", type:"gb2260"},
|
|
11
12
|
* 数据是gb2260的地区代码
|
|
12
13
|
*/
|
|
13
14
|
export class AGB2260 extends BaseViewer {
|
|
15
|
+
constructor(props: any) {
|
|
16
|
+
super(props);
|
|
17
|
+
(this.state as any).pickerVisible = false;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
element() {
|
|
15
21
|
const v = super.getValue();
|
|
16
22
|
const empty = { label: ["请选择"], code: undefined };
|
|
@@ -18,20 +24,25 @@ export class AGB2260 extends BaseViewer {
|
|
|
18
24
|
const p = this.props.schema.props ?? {};
|
|
19
25
|
|
|
20
26
|
if (MUtil.phoneLike()) { // 手机
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
return <>
|
|
28
|
+
<div className="backfill" style={this.props.style}
|
|
29
|
+
onClick={() => { if (!this.props.disable) this.setState({ pickerVisible: true } as any) }}>
|
|
30
|
+
{looked?.label?.join("/")}
|
|
31
|
+
</div>
|
|
32
|
+
<Picker
|
|
33
|
+
columns={MGB2260Type.gb2260}
|
|
34
|
+
value={looked.code}
|
|
35
|
+
visible={(this.state as any).pickerVisible}
|
|
36
|
+
onConfirm={e => {
|
|
37
|
+
super.changeValue(_.last(e));
|
|
38
|
+
this.setState({ pickerVisible: false } as any);
|
|
39
|
+
}}
|
|
40
|
+
onClose={() => {
|
|
41
|
+
this.setState({ pickerVisible: false } as any);
|
|
42
|
+
}}
|
|
43
|
+
{...p}
|
|
44
|
+
/>
|
|
45
|
+
</>
|
|
35
46
|
} else { // PC
|
|
36
47
|
return <Cascader
|
|
37
48
|
options={MGB2260Type.gb2260}
|