feat: 更新依赖包版本,添加编辑发行期功能,优化时间验证逻辑

This commit is contained in:
2025-12-23 02:29:37 +07:00
parent 54a7e17c95
commit c1076b5e98
5 changed files with 249 additions and 30 deletions

View File

@@ -91,15 +91,14 @@ function handleCreateDraftAndSubmit() {
window.$message?.error(timeError);
return;
}
// await safeClient(
// client.api.admin.rwa.issuance.editions.post({
// ...form.value,
// launchDate: form.value.launchDate ? new Date(form.value.launchDate) : undefined,
// subscriptionStartDate: form.value.subscriptionStartDate ? new Date(form.value.subscriptionStartDate) : undefined,
// subscriptionEndDate: form.value.subscriptionEndDate ? new Date(form.value.subscriptionEndDate) : undefined,
// submitForReview: true
// })
// );
await safeClient(
client.api.admin.rwa.issuance.editions.post({
...form.value,
launchDate: new Date(form.value.launchDate!),
subscriptionStartDate: new Date(form.value.subscriptionStartDate!),
subscriptionEndDate: new Date(form.value.subscriptionEndDate!)
} as Body)
);
emit('close');
}
});
@@ -185,8 +184,8 @@ function handleCreateDraftAndSubmit() {
</NFormItem>
<NSpace justify="end" class="mt-5">
<NButton type="primary" ghost @click="handleCreateDraftAndSubmit">创建草稿并发布</NButton>
<NButton type="primary" @click="handleCreateDraft">创建草稿</NButton>
<NButton type="primary" ghost @click="handleCreateDraftAndSubmit">创建并发布</NButton>
<NButton type="primary" @click="handleCreateDraft">创建</NButton>
</NSpace>
</NForm>
</div>

View File

@@ -0,0 +1,177 @@
<script lang="ts" setup>
import { ref, useTemplateRef } from 'vue';
import type { FormInst, FormRules } from 'naive-ui';
import dayjs from 'dayjs';
import { client, safeClient } from '@/service/api';
type Body = CommonType.TreatyBody<typeof client.api.admin.rwa.issuance.editions.post>;
defineOptions({ name: 'RwaEditionAdd' });
const emit = defineEmits<{
(e: 'close'): void;
}>();
const props = defineProps<{
data: Body;
}>();
const formInst = useTemplateRef<FormInst>('formInst');
const form = ref<Body>({
productId: props.data.productId,
editionName: props.data.editionName,
perUserLimit: props.data.perUserLimit,
totalSupply: props.data.totalSupply,
unitPrice: props.data.unitPrice,
dividendRate: props.data.dividendRate,
launchDate: dayjs(props.data.launchDate).toDate(),
subscriptionStartDate: props.data.subscriptionStartDate ? dayjs(props.data.subscriptionStartDate).toDate() : null,
subscriptionEndDate: props.data.subscriptionEndDate ? dayjs(props.data.subscriptionEndDate).toDate() : null
});
const rules: FormRules = {
editionName: [{ required: true, message: '请输入发行期名称', trigger: ['blur', 'input'] }],
perUserLimit: [{ required: true, message: '请输入个人申购上限', trigger: ['blur', 'input'] }],
totalSupply: [{ required: true, message: '请输入发行总量', trigger: ['blur', 'input'] }],
unitPrice: [{ required: true, message: '请输入单价', trigger: ['blur', 'input'] }],
dividendRate: [{ required: true, message: '请输入分红率', trigger: ['blur', 'input'] }],
launchDate: [{ required: true, type: 'number', message: '请选择预热时间', trigger: ['blur', 'change'] }],
subscriptionStartDate: [
{ required: true, type: 'number', message: '请选择申购开始时间', trigger: ['blur', 'change'] }
],
subscriptionEndDate: [{ required: true, type: 'number', message: '请选择申购结束时间', trigger: ['blur', 'change'] }]
};
// 手动验证时间逻辑
function validateTimes() {
const now = dayjs();
if (form.value.launchDate && dayjs(form.value.launchDate).isBefore(now)) {
return '预热时间必须在当前时间之后';
}
if (form.value.subscriptionStartDate && form.value.launchDate) {
if (dayjs(form.value.subscriptionStartDate).isBefore(dayjs(form.value.launchDate))) {
return '申购开始时间必须在预热时间之后';
}
}
if (form.value.subscriptionEndDate && form.value.subscriptionStartDate) {
if (dayjs(form.value.subscriptionEndDate).isBefore(dayjs(form.value.subscriptionStartDate))) {
return '申购结束时间必须在开始时间之后';
}
}
return null;
}
function handleSubmit() {
formInst.value?.validate(async errors => {
if (!errors) {
const timeError = validateTimes();
if (timeError) {
window.$message?.error(timeError);
return;
}
await safeClient(
client.api.admin.rwa.issuance.editions.post({
...form.value,
launchDate: new Date(form.value.launchDate!),
subscriptionStartDate: new Date(form.value.subscriptionStartDate!),
subscriptionEndDate: new Date(form.value.subscriptionEndDate!)
} as Body)
);
emit('close');
}
});
}
</script>
<template>
<div class="my-10">
<NForm
ref="formInst"
:model="form"
label-width="150"
label-placement="left"
label-align="left"
:rules="rules"
require-mark-placement="left"
>
<NFormItem path="editionName" label="发行期名称">
<NInput v-model:value="form.editionName" />
</NFormItem>
<NFormItem path="perUserLimit" label="个人申购上限(份)">
<NInputNumber
:min="1"
:step="10"
:value="Number(form.perUserLimit)"
@update:value="val => (form.perUserLimit = String(val))"
/>
</NFormItem>
<NFormItem path="totalSupply" label="发行总量(份)">
<NInputNumber
:min="1"
:step="100"
:value="Number(form.totalSupply)"
@update:value="val => (form.totalSupply = String(val))"
/>
</NFormItem>
<NFormItem path="unitPrice" label="单价($)">
<NInputNumber :min="0" :value="Number(form.unitPrice)" @update:value="val => (form.unitPrice = String(val))" />
</NFormItem>
<NFormItem path="dividendRate" label="分红率(0.01 = 1%)">
<NInputNumber
:max="1"
:min="0"
:step="0.01"
:value="Number(form.dividendRate)"
@update:value="val => (form.dividendRate = String(val))"
/>
</NFormItem>
<NFormItem path="launchDate" label="预热时间">
<NDatePicker
:value="dayjs(form.launchDate).valueOf()"
type="datetime"
format="yyyy-MM-dd HH:mm"
:is-date-disabled="(ts: number) => ts < Date.now()"
value-format="x"
@update:value="val => (form.launchDate = new Date(val))"
/>
</NFormItem>
<NFormItem>
<NSpace vertical class="w-full">
<NFormItem path="subscriptionStartDate" label="申购开始时间" label-width="150">
<NDatePicker
:value="dayjs(form.subscriptionStartDate).valueOf()"
type="datetime"
format="yyyy-MM-dd HH:mm"
:is-date-disabled="(ts: number) => (form.launchDate ? ts < Number(form.launchDate) : false)"
value-format="x"
class="w-full"
@update:value="val => (form.subscriptionStartDate = new Date(val))"
/>
</NFormItem>
<NFormItem path="subscriptionEndDate" label="申购结束时间" label-width="150">
<NDatePicker
:value="dayjs(form.subscriptionEndDate).valueOf()"
type="datetime"
format="yyyy-MM-dd HH:mm"
:is-date-disabled="
(ts: number) => (form.subscriptionStartDate ? ts < Number(form.subscriptionStartDate) : false)
"
value-format="x"
class="w-full"
@update:value="val => (form.subscriptionEndDate = new Date(val))"
/>
</NFormItem>
</NSpace>
</NFormItem>
<NSpace justify="end" class="mt-5">
<NButton type="primary" @click="handleSubmit">修 改</NButton>
</NSpace>
</NForm>
</div>
</template>
<style lang="css" scoped></style>

View File

@@ -7,6 +7,7 @@ import { client, safeClient } from '@/service/api';
import type { TableBaseColumns, TableFetchData, TableInst } from '@/components/table';
import { RwaEditionStatusEnum } from '@/enum';
import AddEdition from './add-edition.vue';
import EditEdition from './edit-edition.vue';
defineOptions({ name: 'RwaProductEditions' });
@@ -98,19 +99,37 @@ const columns: TableBaseColumns = [
type: 'primary',
ghost: true,
size: 'small',
visible: row.status === 'draft',
onClick: () => {
console.log(row);
visible: row.status === 'draft' || row.status === 'cancelled',
onClick: async () => {
dialog.create({
title: '确认发布该发行期吗?',
content: '发布后该发行期将对投资者可见,且不可修改。',
positiveText: '确认',
negativeText: '取消',
onPositiveClick: async () => {
await safeClient(client.api.admin.rwa.issuance.editions({ id: row.id }).publish.post());
tableInst.value?.reload();
}
});
}
},
{
contentText: '取消',
contentText: '取消发布',
type: 'primary',
ghost: true,
size: 'small',
visible: row.status === 'draft',
onClick: () => {
console.log(row);
visible: row.status === 'scheduled',
onClick: async () => {
dialog.create({
title: '确认取消发布该发行期吗?',
content: '取消发布后该发行期将对投资者不可见,且不可修改。',
positiveText: '确认',
negativeText: '取消',
onPositiveClick: async () => {
await safeClient(client.api.admin.rwa.issuance.editions({ id: row.id }).cancel.post());
tableInst.value?.reload();
}
});
}
},
{
@@ -119,15 +138,14 @@ const columns: TableBaseColumns = [
ghost: true,
size: 'small',
visible: row.status === 'draft',
onClick: () => {
console.log(row);
}
onClick: () => handleEdit(row)
},
{
contentText: '删除',
type: 'error',
ghost: true,
size: 'small',
visible: row.status === 'draft',
onClick: () => {
tableInst.value?.reload();
}
@@ -138,8 +156,33 @@ const columns: TableBaseColumns = [
function handleAdd() {
const dialogInstance = dialog.create({
title: '发行期列表',
content: () => h(AddEdition, { productId: props.data.id }),
title: '添加发行期',
content: () =>
h(AddEdition, {
productId: props.data.id,
onClose: () => {
dialogInstance.destroy();
tableInst.value?.reload();
}
}),
style: { width: '600px' },
showIcon: false,
onPositiveClick: () => {
tableInst.value?.reload();
}
});
}
function handleEdit(row: any) {
const dialogInstance = dialog.create({
title: '编辑发行期',
content: () =>
h(EditEdition, {
data: row,
onClose: () => {
dialogInstance.destroy();
tableInst.value?.reload();
}
}),
style: { width: '600px' },
showIcon: false,
onPositiveClick: () => {