refactor: 优化 antd 模板代码生成示例提到的一些问题

pull/87/head
puhui999 2025-04-27 18:16:38 +08:00
parent 5c4b95b01e
commit 994b444319
4 changed files with 49 additions and 39 deletions

View File

@ -1,3 +1,5 @@
import type { Dayjs } from 'dayjs';
import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request';
@ -7,8 +9,8 @@ export namespace Demo01ContactApi {
export interface Demo01Contact {
id: number; // 编号
name?: string; // 名字
sex?: number; // 性别
birthday?: Date; // 出生年
sex?: boolean; // 性别
birthday?: Dayjs | string; // 出生年
description?: string; // 简介
avatar: string; // 头像
}

View File

@ -3,7 +3,7 @@ import dayjs from 'dayjs';
// TODO @芋艿:后续整理下 迁移至 packages/core/base/shared/src/utils/date.ts,后续删除 使用 @vben/utils 的 getRangePickerDefaultProps
/** 时间段选择器拓展 */
export function getRangePickerDefaultProps() {
export function getRangePickerDefaultProps(): any {
return {
showTime: {
format: 'HH:mm:ss',

View File

@ -1,10 +1,12 @@
<script lang="ts" setup>
import type { VxeTableInstance } from 'vxe-table';
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
import { h, onMounted, reactive, ref } from 'vue';
import { h, nextTick, onMounted, reactive, ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { Download, Plus, RefreshCw, Search } from '@vben/icons';
import { Download, Plus } from '@vben/icons';
import { cloneDeep, formatDateTime } from '@vben/utils';
import {
@ -25,6 +27,7 @@ import {
} from '#/api/infra/demo/demo01';
import { ContentWrap } from '#/components/content-wrap';
import { DictTag } from '#/components/dict-tag';
import { TableToolbar } from '#/components/table-toolbar';
import { $t } from '#/locales';
import { getRangePickerDefaultProps } from '#/utils/date';
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
@ -118,9 +121,20 @@ async function onExport() {
}
}
/** 隐藏搜索栏 */
const hiddenSearchBar = ref(false);
const tableToolbarRef = ref<InstanceType<typeof TableToolbar>>();
const tableRef = ref<VxeTableInstance>();
/** 初始化 */
onMounted(() => {
getList();
onMounted(async () => {
await getList();
await nextTick();
// $toolbar
const $table = tableRef.value;
const tableToolbar = tableToolbarRef.value;
if ($table && tableToolbar) {
await $table.connect(tableToolbar.getToolbarRef()!);
}
});
</script>
@ -128,15 +142,10 @@ onMounted(() => {
<Page auto-content-height>
<FormModal @success="getList" />
<ContentWrap>
<ContentWrap v-if="!hiddenSearchBar">
<!-- 搜索工作栏 -->
<!-- TODO @puhui999貌似 -mb-15px 没效果可能和 ContentWrap 有关系 -->
<Form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
layout="inline"
>
<Form :model="queryParams" ref="queryFormRef" layout="inline">
<Form.Item label="名字" name="name">
<!-- TODO @puhui999貌似不一定 240看着和 schema 还是不太一样 -->
<Input
@ -144,7 +153,7 @@ onMounted(() => {
placeholder="请输入名字"
allow-clear
@press-enter="handleQuery"
class="!w-240px"
class="w-full"
/>
</Form.Item>
<Form.Item label="性别" name="sex">
@ -152,7 +161,7 @@ onMounted(() => {
v-model:value="queryParams.sex"
placeholder="请选择性别"
allow-clear
class="!w-240px"
class="w-full"
>
<Select.Option
v-for="dict in getDictOptions(
@ -166,23 +175,30 @@ onMounted(() => {
</Select>
</Form.Item>
<Form.Item label="创建时间" name="createTime">
<!-- TODO @puhui999这里有个红色的告警看看有办法处理哇 -->
<RangePicker
v-model:value="queryParams.createTime"
v-bind="getRangePickerDefaultProps()"
class="!w-220px"
class="w-full"
/>
</Form.Item>
<Form.Item>
<!-- TODO @puhui999搜索和重置貌似样子和位置不太一样有木有办法一致 -->
<!-- TODO @puhui999收齐展开好弄哇 -->
<Button class="ml-2" @click="handleQuery" :icon="h(Search)">
<Button class="ml-2" @click="resetQuery"> </Button>
<Button class="ml-2" @click="handleQuery" type="primary">
搜索
</Button>
<Button class="ml-2" @click="resetQuery" :icon="h(RefreshCw)">
重置
</Button>
<!-- TODO @puhui999有办法放到 VxeTable 哪里么 -->
</Form.Item>
</Form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap title="你好">
<template #extra>
<TableToolbar
ref="tableToolbarRef"
v-model:hidden-search="hiddenSearchBar"
>
<Button
class="ml-2"
:icon="h(Plus)"
@ -202,14 +218,9 @@ onMounted(() => {
>
{{ $t('ui.actionTitle.export') }}
</Button>
</Form.Item>
</Form>
</ContentWrap>
<!-- 列表 -->
<!-- TODO @puhui999title 要不还是假起来 -->
<ContentWrap>
<VxeTable :data="list" show-overflow :loading="loading">
</TableToolbar>
</template>
<VxeTable ref="tableRef" :data="list" show-overflow :loading="loading">
<VxeColumn field="id" title="编号" align="center" />
<VxeColumn field="name" title="名字" align="center" />
<VxeColumn field="sex" title="性别" align="center">

View File

@ -26,11 +26,9 @@ import { ImageUpload } from '#/components/upload';
import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
const emit = defineEmits(['success']); // TODO @puhui999emit
const emit = defineEmits(['success']);
const formRef = ref();
// TODO @puhui999labelColwrapperCol
const labelCol = { span: 5 };
const wrapperCol = { span: 13 };
const formData = ref<Partial<Demo01ContactApi.Demo01Contact>>({
id: undefined,
name: undefined,
@ -90,8 +88,7 @@ const [Modal, modalApi] = useVbenModal({
resetForm();
return;
}
// TODO @puhui999
//
let data = modalApi.getData<Demo01ContactApi.Demo01Contact>();
if (!data) {
return;
@ -115,8 +112,8 @@ const [Modal, modalApi] = useVbenModal({
ref="formRef"
:model="formData"
:rules="rules"
:label-col="labelCol"
:wrapper-col="wrapperCol"
:label-col="{ span: 5 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="名字" name="name">
<Input v-model:value="formData.name" placeholder="请输入名字" />