feat: 添加日期验证功能,确保发行日期不早于当前日期,申购截止日期不早于发行日期
This commit is contained in:
@@ -2,16 +2,23 @@
|
||||
import type { FieldBindingObject } from "vee-validate";
|
||||
|
||||
interface Props extends FieldBindingObject {
|
||||
datetime: string;
|
||||
label?: string;
|
||||
formatterValue?: (value: string) => string;
|
||||
format?: (value: string) => string;
|
||||
min?: string;
|
||||
max?: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<{
|
||||
(e: "update:value", value: string): void;
|
||||
}>();
|
||||
|
||||
function handleChange(value: string) {
|
||||
const formattedValue = props.formatterValue ? props.formatterValue(value) : new Date(value).toISOString();
|
||||
props.onChange(formattedValue);
|
||||
emit("update:value", formattedValue);
|
||||
}
|
||||
|
||||
function formatDisplay(value: string) {
|
||||
@@ -24,18 +31,20 @@ function formatDisplay(value: string) {
|
||||
<ion-label class="text-sm font-bold color-(--ion-text-color-secondary) mb-3.5">
|
||||
{{ props.label }}
|
||||
</ion-label>
|
||||
<ion-datetime-button datetime="datetime" color="primary">
|
||||
<ion-datetime-button :datetime="datetime" color="primary">
|
||||
<div slot="date-target">
|
||||
{{ formatDisplay(props.value) }}
|
||||
</div>
|
||||
</ion-datetime-button>
|
||||
<ion-modal :keep-contents-mounted="true">
|
||||
<ion-datetime
|
||||
id="datetime"
|
||||
:id="datetime"
|
||||
class="ui-datetime"
|
||||
done-text="Done"
|
||||
presentation="date"
|
||||
:show-default-buttons="true"
|
||||
:min="props.min"
|
||||
:max="props.max"
|
||||
@ion-change="handleChange($event.detail.value as string)"
|
||||
/>
|
||||
</ion-modal>
|
||||
|
||||
@@ -176,9 +176,11 @@
|
||||
"categoryRequired": "Type is required",
|
||||
"editionNameRequired": "Edition name is required",
|
||||
"launchDateRequired": "Launch date is required",
|
||||
"launchDateNotPast": "Launch date cannot be earlier than current date",
|
||||
"perUserLimitRequired": "Per user limit is required",
|
||||
"totalSupplyRequired": "Total supply is required",
|
||||
"subscriptionDeadlineRequired": "Subscription deadline is required",
|
||||
"deadlineAfterLaunch": "Subscription deadline cannot be earlier than launch date",
|
||||
"unitPriceRequired": "Unit price is required",
|
||||
"dividendRateRequired": "Dividend rate is required"
|
||||
},
|
||||
|
||||
@@ -176,9 +176,11 @@
|
||||
"categoryRequired": "产品类型是必填项",
|
||||
"editionNameRequired": "发行期名称是必填项",
|
||||
"launchDateRequired": "发行日期是必填项",
|
||||
"launchDateNotPast": "发行日期不能小于当前日期",
|
||||
"perUserLimitRequired": "个人申购上限是必填项",
|
||||
"totalSupplyRequired": "发行总量是必填项",
|
||||
"subscriptionDeadlineRequired": "申购截止日期是必填项",
|
||||
"deadlineAfterLaunch": "申购截止日期不能小于发行日期",
|
||||
"unitPriceRequired": "单价是必填项",
|
||||
"dividendRateRequired": "分红率是必填项"
|
||||
},
|
||||
|
||||
@@ -34,10 +34,23 @@ const schema = toTypedSchema(yup.object({
|
||||
editions: yup.array().of(
|
||||
yup.object({
|
||||
editionName: yup.string().required(t("asset.issue.apply.validation.editionNameRequired")),
|
||||
launchDate: yup.string().required(t("asset.issue.apply.validation.launchDateRequired")),
|
||||
launchDate: yup.string()
|
||||
.required(t("asset.issue.apply.validation.launchDateRequired"))
|
||||
.test("not-past", t("asset.issue.apply.validation.launchDateNotPast"), (value) => {
|
||||
if (!value)
|
||||
return true;
|
||||
return new Date(value) >= new Date(now.value.toDateString());
|
||||
}),
|
||||
perUserLimit: yup.string().required(t("asset.issue.apply.validation.perUserLimitRequired")),
|
||||
totalSupply: yup.string().required(t("asset.issue.apply.validation.totalSupplyRequired")),
|
||||
subscriptionDeadline: yup.string().required(t("asset.issue.apply.validation.subscriptionDeadlineRequired")),
|
||||
subscriptionDeadline: yup.string()
|
||||
.required(t("asset.issue.apply.validation.subscriptionDeadlineRequired"))
|
||||
.test("after-launch", t("asset.issue.apply.validation.deadlineAfterLaunch"), function (value) {
|
||||
const { launchDate } = this.parent;
|
||||
if (!value || !launchDate)
|
||||
return true;
|
||||
return new Date(value) >= new Date(launchDate);
|
||||
}),
|
||||
unitPrice: yup.string().required(t("asset.issue.apply.validation.unitPriceRequired")),
|
||||
dividendRate: yup.string().required(t("asset.issue.apply.validation.dividendRateRequired")),
|
||||
}),
|
||||
@@ -47,11 +60,6 @@ const schema = toTypedSchema(yup.object({
|
||||
function handleSubmit(values: GenericObject) {
|
||||
emit("submit", values.editions);
|
||||
}
|
||||
function handleChange(event: Event) {
|
||||
debugger;
|
||||
const input = event.target as HTMLInputElement;
|
||||
return new Date(input.value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -70,18 +78,6 @@ function handleChange(event: Event) {
|
||||
</Field>
|
||||
<ErrorMessage :name="`editions[${idx}].editionName`" />
|
||||
</div>
|
||||
<div>
|
||||
<Field :name="`editions[${idx}].launchDate`">
|
||||
<template #default="{ field }">
|
||||
<ui-datetime
|
||||
v-bind="field"
|
||||
:label="t('asset.issue.apply.launchDate')"
|
||||
:formatter-value="(val) => new Date(val).toISOString()"
|
||||
/>
|
||||
</template>
|
||||
</Field>
|
||||
<ErrorMessage :name="`editions[${idx}].launchDate`" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Field :name="`editions[${idx}].perUserLimit`" type="text">
|
||||
@@ -115,15 +111,41 @@ function handleChange(event: Event) {
|
||||
|
||||
<div>
|
||||
<Field :name="`editions[${idx}].subscriptionDeadline`">
|
||||
<template #default="{ field }">
|
||||
<ui-datetime
|
||||
v-bind="field"
|
||||
:label="t('asset.issue.apply.subscriptionDeadline')"
|
||||
:formatter-value="(val) => new Date(val).toISOString()"
|
||||
/>
|
||||
<template #default="{ setValue }">
|
||||
<Field :name="`editions[${idx}].launchDate`">
|
||||
<template #default="{ field }">
|
||||
<ui-datetime
|
||||
datetime="launchDate"
|
||||
v-bind="field"
|
||||
:label="t('asset.issue.apply.launchDate')"
|
||||
:min="now.toISOString()"
|
||||
@update:value="(val) => {
|
||||
setValue(val);
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
</Field>
|
||||
<ErrorMessage :name="`editions[${idx}].launchDate`" />
|
||||
</template>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Field :name="`editions[${idx}].launchDate`">
|
||||
<template #default="{ value: launchDate }">
|
||||
<Field :name="`editions[${idx}].subscriptionDeadline`">
|
||||
<template #default="{ field }">
|
||||
<ui-datetime
|
||||
datetime="subscriptionDeadline"
|
||||
v-bind="field"
|
||||
:label="t('asset.issue.apply.subscriptionDeadline')"
|
||||
:min="launchDate ? new Date(launchDate).toISOString() : now.toISOString()"
|
||||
/>
|
||||
</template>
|
||||
</Field>
|
||||
<ErrorMessage :name="`editions[${idx}].subscriptionDeadline`" />
|
||||
</template>
|
||||
</Field>
|
||||
<ErrorMessage :name="`editions[${idx}].subscriptionDeadline`" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user