@tmagic/form 1.7.6 → 1.7.7
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/dist/tmagic-form.js +71 -32
- package/dist/tmagic-form.umd.cjs +71 -32
- package/package.json +4 -4
- package/src/fields/Timerange.vue +80 -36
package/dist/tmagic-form.js
CHANGED
|
@@ -4560,44 +4560,81 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
4560
4560
|
useAddField(props.prop);
|
|
4561
4561
|
const { names } = props.config;
|
|
4562
4562
|
const value = ref([]);
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4563
|
+
const getFullDatetime = (item) => item ? `${dayjs().format("YYYY/MM/DD")} ${item}` : "";
|
|
4564
|
+
const getFormat = () => `YYYY/MM/DD ${props.config.valueFormat || "HH:mm:ss"}`;
|
|
4565
|
+
const timeFormatter = (time, format) => datetimeFormatter(getFullDatetime(time), "", format).substring(11);
|
|
4566
|
+
if (props.model !== void 0) {
|
|
4567
|
+
if (names?.length) {
|
|
4568
|
+
const unWatch = watch(
|
|
4569
|
+
[() => props.model[names[0]], () => props.model[names[1]]],
|
|
4570
|
+
([start, end], [preStart, preEnd]) => {
|
|
4571
|
+
if (!value.value) {
|
|
4572
|
+
value.value = [];
|
|
4573
|
+
}
|
|
4574
|
+
const format = getFormat();
|
|
4575
|
+
if (!start || !end) value.value = [];
|
|
4576
|
+
if (start !== preStart) value.value[0] = timeFormatter(start, format);
|
|
4577
|
+
if (end !== preEnd) value.value[1] = timeFormatter(end, format);
|
|
4578
|
+
},
|
|
4579
|
+
{
|
|
4580
|
+
immediate: true
|
|
4569
4581
|
}
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
}
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4582
|
+
);
|
|
4583
|
+
onUnmounted(() => {
|
|
4584
|
+
unWatch();
|
|
4585
|
+
});
|
|
4586
|
+
} else if (props.name) {
|
|
4587
|
+
const unWatch = watch(
|
|
4588
|
+
() => props.model[props.name],
|
|
4589
|
+
(v = []) => {
|
|
4590
|
+
if (Array.isArray(v)) {
|
|
4591
|
+
value.value = v.map((item) => item ? timeFormatter(item, getFormat()) : void 0);
|
|
4592
|
+
} else {
|
|
4593
|
+
value.value = [];
|
|
4594
|
+
}
|
|
4595
|
+
},
|
|
4596
|
+
{
|
|
4597
|
+
immediate: true
|
|
4598
|
+
}
|
|
4599
|
+
);
|
|
4600
|
+
onUnmounted(() => {
|
|
4601
|
+
unWatch();
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4578
4604
|
}
|
|
4579
|
-
const setValue = (v) => {
|
|
4580
|
-
names?.forEach((item, index) => {
|
|
4581
|
-
if (!props.model) {
|
|
4582
|
-
return;
|
|
4583
|
-
}
|
|
4584
|
-
if (Array.isArray(v)) {
|
|
4585
|
-
props.model[item] = v[index];
|
|
4586
|
-
} else {
|
|
4587
|
-
props.model[item] = void 0;
|
|
4588
|
-
}
|
|
4589
|
-
});
|
|
4590
|
-
};
|
|
4591
4605
|
const changeHandler = (v) => {
|
|
4592
4606
|
const value2 = v || [];
|
|
4593
|
-
if (
|
|
4594
|
-
|
|
4607
|
+
if (props.name) {
|
|
4608
|
+
emit("change", value2);
|
|
4609
|
+
} else {
|
|
4610
|
+
if (props.config.names?.length) {
|
|
4611
|
+
const newChangeRecords = [];
|
|
4612
|
+
props.config.names.forEach((item, index) => {
|
|
4613
|
+
if (!props.model) {
|
|
4614
|
+
return;
|
|
4615
|
+
}
|
|
4616
|
+
if (Array.isArray(v)) {
|
|
4617
|
+
newChangeRecords.push({
|
|
4618
|
+
propPath: props.prop ? `${props.prop}.${item}` : item,
|
|
4619
|
+
value: v[index]
|
|
4620
|
+
});
|
|
4621
|
+
} else {
|
|
4622
|
+
newChangeRecords.push({
|
|
4623
|
+
propPath: props.prop ? `${props.prop}.${item}` : item,
|
|
4624
|
+
value: void 0
|
|
4625
|
+
});
|
|
4626
|
+
}
|
|
4627
|
+
});
|
|
4628
|
+
emit("change", props.model, {
|
|
4629
|
+
changeRecords: newChangeRecords
|
|
4630
|
+
});
|
|
4631
|
+
}
|
|
4595
4632
|
}
|
|
4596
|
-
emit("change", value2);
|
|
4597
4633
|
};
|
|
4598
4634
|
return (_ctx, _cache) => {
|
|
4599
4635
|
return openBlock(), createBlock(unref(TMagicTimePicker), {
|
|
4600
|
-
|
|
4636
|
+
modelValue: value.value,
|
|
4637
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => value.value = $event),
|
|
4601
4638
|
"is-range": "",
|
|
4602
4639
|
"range-separator": "-",
|
|
4603
4640
|
"start-placeholder": "开始时间",
|
|
@@ -4606,8 +4643,10 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
4606
4643
|
"unlink-panels": true,
|
|
4607
4644
|
disabled: __props.disabled,
|
|
4608
4645
|
"default-time": __props.config.defaultTime,
|
|
4609
|
-
"
|
|
4610
|
-
|
|
4646
|
+
format: __props.config.format || "HH:mm:ss",
|
|
4647
|
+
"value-format": __props.config.valueFormat || "HH:mm:ss",
|
|
4648
|
+
onChange: changeHandler
|
|
4649
|
+
}, null, 8, ["modelValue", "size", "disabled", "default-time", "format", "value-format"]);
|
|
4611
4650
|
};
|
|
4612
4651
|
}
|
|
4613
4652
|
});
|
package/dist/tmagic-form.umd.cjs
CHANGED
|
@@ -7490,44 +7490,81 @@
|
|
|
7490
7490
|
useAddField(props.prop);
|
|
7491
7491
|
const { names } = props.config;
|
|
7492
7492
|
const value = vue.ref([]);
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7493
|
+
const getFullDatetime = (item) => item ? `${dayjs().format("YYYY/MM/DD")} ${item}` : "";
|
|
7494
|
+
const getFormat = () => `YYYY/MM/DD ${props.config.valueFormat || "HH:mm:ss"}`;
|
|
7495
|
+
const timeFormatter = (time, format) => datetimeFormatter(getFullDatetime(time), "", format).substring(11);
|
|
7496
|
+
if (props.model !== void 0) {
|
|
7497
|
+
if (names?.length) {
|
|
7498
|
+
const unWatch = vue.watch(
|
|
7499
|
+
[() => props.model[names[0]], () => props.model[names[1]]],
|
|
7500
|
+
([start, end], [preStart, preEnd]) => {
|
|
7501
|
+
if (!value.value) {
|
|
7502
|
+
value.value = [];
|
|
7503
|
+
}
|
|
7504
|
+
const format = getFormat();
|
|
7505
|
+
if (!start || !end) value.value = [];
|
|
7506
|
+
if (start !== preStart) value.value[0] = timeFormatter(start, format);
|
|
7507
|
+
if (end !== preEnd) value.value[1] = timeFormatter(end, format);
|
|
7508
|
+
},
|
|
7509
|
+
{
|
|
7510
|
+
immediate: true
|
|
7499
7511
|
}
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
}
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7512
|
+
);
|
|
7513
|
+
vue.onUnmounted(() => {
|
|
7514
|
+
unWatch();
|
|
7515
|
+
});
|
|
7516
|
+
} else if (props.name) {
|
|
7517
|
+
const unWatch = vue.watch(
|
|
7518
|
+
() => props.model[props.name],
|
|
7519
|
+
(v = []) => {
|
|
7520
|
+
if (Array.isArray(v)) {
|
|
7521
|
+
value.value = v.map((item) => item ? timeFormatter(item, getFormat()) : void 0);
|
|
7522
|
+
} else {
|
|
7523
|
+
value.value = [];
|
|
7524
|
+
}
|
|
7525
|
+
},
|
|
7526
|
+
{
|
|
7527
|
+
immediate: true
|
|
7528
|
+
}
|
|
7529
|
+
);
|
|
7530
|
+
vue.onUnmounted(() => {
|
|
7531
|
+
unWatch();
|
|
7532
|
+
});
|
|
7533
|
+
}
|
|
7508
7534
|
}
|
|
7509
|
-
const setValue = (v) => {
|
|
7510
|
-
names?.forEach((item, index) => {
|
|
7511
|
-
if (!props.model) {
|
|
7512
|
-
return;
|
|
7513
|
-
}
|
|
7514
|
-
if (Array.isArray(v)) {
|
|
7515
|
-
props.model[item] = v[index];
|
|
7516
|
-
} else {
|
|
7517
|
-
props.model[item] = void 0;
|
|
7518
|
-
}
|
|
7519
|
-
});
|
|
7520
|
-
};
|
|
7521
7535
|
const changeHandler = (v) => {
|
|
7522
7536
|
const value2 = v || [];
|
|
7523
|
-
if (
|
|
7524
|
-
|
|
7537
|
+
if (props.name) {
|
|
7538
|
+
emit("change", value2);
|
|
7539
|
+
} else {
|
|
7540
|
+
if (props.config.names?.length) {
|
|
7541
|
+
const newChangeRecords = [];
|
|
7542
|
+
props.config.names.forEach((item, index) => {
|
|
7543
|
+
if (!props.model) {
|
|
7544
|
+
return;
|
|
7545
|
+
}
|
|
7546
|
+
if (Array.isArray(v)) {
|
|
7547
|
+
newChangeRecords.push({
|
|
7548
|
+
propPath: props.prop ? `${props.prop}.${item}` : item,
|
|
7549
|
+
value: v[index]
|
|
7550
|
+
});
|
|
7551
|
+
} else {
|
|
7552
|
+
newChangeRecords.push({
|
|
7553
|
+
propPath: props.prop ? `${props.prop}.${item}` : item,
|
|
7554
|
+
value: void 0
|
|
7555
|
+
});
|
|
7556
|
+
}
|
|
7557
|
+
});
|
|
7558
|
+
emit("change", props.model, {
|
|
7559
|
+
changeRecords: newChangeRecords
|
|
7560
|
+
});
|
|
7561
|
+
}
|
|
7525
7562
|
}
|
|
7526
|
-
emit("change", value2);
|
|
7527
7563
|
};
|
|
7528
7564
|
return (_ctx, _cache) => {
|
|
7529
7565
|
return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicTimePicker), {
|
|
7530
|
-
|
|
7566
|
+
modelValue: value.value,
|
|
7567
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => value.value = $event),
|
|
7531
7568
|
"is-range": "",
|
|
7532
7569
|
"range-separator": "-",
|
|
7533
7570
|
"start-placeholder": "开始时间",
|
|
@@ -7536,8 +7573,10 @@
|
|
|
7536
7573
|
"unlink-panels": true,
|
|
7537
7574
|
disabled: __props.disabled,
|
|
7538
7575
|
"default-time": __props.config.defaultTime,
|
|
7539
|
-
"
|
|
7540
|
-
|
|
7576
|
+
format: __props.config.format || "HH:mm:ss",
|
|
7577
|
+
"value-format": __props.config.valueFormat || "HH:mm:ss",
|
|
7578
|
+
onChange: changeHandler
|
|
7579
|
+
}, null, 8, ["modelValue", "size", "disabled", "default-time", "format", "value-format"]);
|
|
7541
7580
|
};
|
|
7542
7581
|
}
|
|
7543
7582
|
});
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.7.
|
|
2
|
+
"version": "1.7.7",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"vue": "^3.5.24",
|
|
53
53
|
"typescript": "^5.9.3",
|
|
54
|
-
"@tmagic/utils": "1.7.
|
|
55
|
-
"@tmagic/
|
|
56
|
-
"@tmagic/
|
|
54
|
+
"@tmagic/utils": "1.7.7",
|
|
55
|
+
"@tmagic/design": "1.7.7",
|
|
56
|
+
"@tmagic/form-schema": "1.7.7"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"typescript": {
|
package/src/fields/Timerange.vue
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<TMagicTimePicker
|
|
3
|
-
|
|
3
|
+
v-model="value"
|
|
4
4
|
is-range
|
|
5
5
|
range-separator="-"
|
|
6
6
|
start-placeholder="开始时间"
|
|
@@ -9,16 +9,20 @@
|
|
|
9
9
|
:unlink-panels="true"
|
|
10
10
|
:disabled="disabled"
|
|
11
11
|
:default-time="config.defaultTime"
|
|
12
|
-
|
|
12
|
+
:format="config.format || 'HH:mm:ss'"
|
|
13
|
+
:value-format="config.valueFormat || 'HH:mm:ss'"
|
|
14
|
+
@change="changeHandler"
|
|
13
15
|
></TMagicTimePicker>
|
|
14
16
|
</template>
|
|
15
17
|
|
|
16
18
|
<script lang="ts" setup>
|
|
17
|
-
import { ref, watch } from 'vue';
|
|
19
|
+
import { onUnmounted, ref, watch } from 'vue';
|
|
20
|
+
import dayjs from 'dayjs';
|
|
18
21
|
|
|
19
22
|
import { TMagicTimePicker } from '@tmagic/design';
|
|
20
23
|
|
|
21
|
-
import type { DaterangeConfig, FieldProps } from '../schema';
|
|
24
|
+
import type { ChangeRecord, DaterangeConfig, FieldProps } from '../schema';
|
|
25
|
+
import { datetimeFormatter } from '../utils/form';
|
|
22
26
|
import { useAddField } from '../utils/useAddField';
|
|
23
27
|
|
|
24
28
|
defineOptions({
|
|
@@ -32,43 +36,83 @@ const emit = defineEmits(['change']);
|
|
|
32
36
|
useAddField(props.prop);
|
|
33
37
|
|
|
34
38
|
const { names } = props.config;
|
|
35
|
-
const value = ref<(Date | undefined)[] | null>([]);
|
|
39
|
+
const value = ref<(Date | string | undefined)[] | null>([]);
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!value.value) {
|
|
42
|
-
value.value = [];
|
|
43
|
-
}
|
|
44
|
-
if (!start || !end) value.value = [];
|
|
45
|
-
if (start !== preStart) value.value[0] = start;
|
|
46
|
-
if (end !== preEnd) value.value[1] = end;
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
immediate: true,
|
|
50
|
-
},
|
|
51
|
-
);
|
|
52
|
-
}
|
|
41
|
+
const getFullDatetime = (item: string) => (item ? `${dayjs().format('YYYY/MM/DD')} ${item}` : '');
|
|
42
|
+
const getFormat = () => `YYYY/MM/DD ${props.config.valueFormat || 'HH:mm:ss'}`;
|
|
43
|
+
const timeFormatter = (time: string, format: string) =>
|
|
44
|
+
(datetimeFormatter(getFullDatetime(time), '', format) as string).substring(11);
|
|
53
45
|
|
|
54
|
-
|
|
55
|
-
names?.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
if (props.model !== undefined) {
|
|
47
|
+
if (names?.length) {
|
|
48
|
+
const unWatch = watch(
|
|
49
|
+
[() => props.model[names[0]], () => props.model[names[1]]],
|
|
50
|
+
([start, end], [preStart, preEnd]) => {
|
|
51
|
+
if (!value.value) {
|
|
52
|
+
value.value = [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const format = getFormat();
|
|
56
|
+
if (!start || !end) value.value = [];
|
|
57
|
+
if (start !== preStart) value.value[0] = timeFormatter(start, format);
|
|
58
|
+
if (end !== preEnd) value.value[1] = timeFormatter(end, format);
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
immediate: true,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
onUnmounted(() => {
|
|
65
|
+
unWatch();
|
|
66
|
+
});
|
|
67
|
+
} else if (props.name) {
|
|
68
|
+
const unWatch = watch(
|
|
69
|
+
() => props.model[props.name],
|
|
70
|
+
(v = []) => {
|
|
71
|
+
if (Array.isArray(v)) {
|
|
72
|
+
value.value = v.map((item: string) => (item ? timeFormatter(item, getFormat()) : undefined));
|
|
73
|
+
} else {
|
|
74
|
+
value.value = [];
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
immediate: true,
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
onUnmounted(() => {
|
|
82
|
+
unWatch();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
66
86
|
|
|
67
87
|
const changeHandler = (v: Date[]) => {
|
|
68
88
|
const value = v || [];
|
|
69
|
-
|
|
70
|
-
|
|
89
|
+
|
|
90
|
+
if (props.name) {
|
|
91
|
+
emit('change', value);
|
|
92
|
+
} else {
|
|
93
|
+
if (props.config.names?.length) {
|
|
94
|
+
const newChangeRecords: ChangeRecord[] = [];
|
|
95
|
+
props.config.names.forEach((item, index) => {
|
|
96
|
+
if (!props.model) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (Array.isArray(v)) {
|
|
100
|
+
newChangeRecords.push({
|
|
101
|
+
propPath: props.prop ? `${props.prop}.${item}` : item,
|
|
102
|
+
value: v[index],
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
newChangeRecords.push({
|
|
106
|
+
propPath: props.prop ? `${props.prop}.${item}` : item,
|
|
107
|
+
value: undefined,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
emit('change', props.model, {
|
|
113
|
+
changeRecords: newChangeRecords,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
71
116
|
}
|
|
72
|
-
emit('change', value);
|
|
73
117
|
};
|
|
74
118
|
</script>
|