refactor: 优化 antd 模板代码生成示例提到的一些问题
							parent
							
								
									5c4b95b01e
								
							
						
					
					
						commit
						994b444319
					
				|  | @ -1,3 +1,5 @@ | ||||||
|  | import type { Dayjs } from 'dayjs'; | ||||||
|  | 
 | ||||||
| import type { PageParam, PageResult } from '@vben/request'; | import type { PageParam, PageResult } from '@vben/request'; | ||||||
| 
 | 
 | ||||||
| import { requestClient } from '#/api/request'; | import { requestClient } from '#/api/request'; | ||||||
|  | @ -7,8 +9,8 @@ export namespace Demo01ContactApi { | ||||||
|   export interface Demo01Contact { |   export interface Demo01Contact { | ||||||
|     id: number; // 编号
 |     id: number; // 编号
 | ||||||
|     name?: string; // 名字
 |     name?: string; // 名字
 | ||||||
|     sex?: number; // 性别
 |     sex?: boolean; // 性别
 | ||||||
|     birthday?: Date; // 出生年
 |     birthday?: Dayjs | string; // 出生年
 | ||||||
|     description?: string; // 简介
 |     description?: string; // 简介
 | ||||||
|     avatar: string; // 头像
 |     avatar: string; // 头像
 | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import dayjs from 'dayjs'; | ||||||
| // TODO @芋艿:后续整理下 迁移至 packages/core/base/shared/src/utils/date.ts,后续删除 使用 @vben/utils 的 getRangePickerDefaultProps
 | // TODO @芋艿:后续整理下 迁移至 packages/core/base/shared/src/utils/date.ts,后续删除 使用 @vben/utils 的 getRangePickerDefaultProps
 | ||||||
| 
 | 
 | ||||||
| /** 时间段选择器拓展  */ | /** 时间段选择器拓展  */ | ||||||
| export function getRangePickerDefaultProps() { | export function getRangePickerDefaultProps(): any { | ||||||
|   return { |   return { | ||||||
|     showTime: { |     showTime: { | ||||||
|       format: 'HH:mm:ss', |       format: 'HH:mm:ss', | ||||||
|  |  | ||||||
|  | @ -1,10 +1,12 @@ | ||||||
| <script lang="ts" setup> | <script lang="ts" setup> | ||||||
|  | import type { VxeTableInstance } from 'vxe-table'; | ||||||
|  | 
 | ||||||
| import type { Demo01ContactApi } from '#/api/infra/demo/demo01'; | 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 { 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 { cloneDeep, formatDateTime } from '@vben/utils'; | ||||||
| 
 | 
 | ||||||
| import { | import { | ||||||
|  | @ -25,6 +27,7 @@ import { | ||||||
| } from '#/api/infra/demo/demo01'; | } from '#/api/infra/demo/demo01'; | ||||||
| import { ContentWrap } from '#/components/content-wrap'; | import { ContentWrap } from '#/components/content-wrap'; | ||||||
| import { DictTag } from '#/components/dict-tag'; | import { DictTag } from '#/components/dict-tag'; | ||||||
|  | import { TableToolbar } from '#/components/table-toolbar'; | ||||||
| import { $t } from '#/locales'; | import { $t } from '#/locales'; | ||||||
| import { getRangePickerDefaultProps } from '#/utils/date'; | import { getRangePickerDefaultProps } from '#/utils/date'; | ||||||
| import { DICT_TYPE, getDictOptions } from '#/utils/dict'; | 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(() => { | onMounted(async () => { | ||||||
|   getList(); |   await getList(); | ||||||
|  |   await nextTick(); | ||||||
|  |   // 挂载 $toolbar 工具栏 | ||||||
|  |   const $table = tableRef.value; | ||||||
|  |   const tableToolbar = tableToolbarRef.value; | ||||||
|  |   if ($table && tableToolbar) { | ||||||
|  |     await $table.connect(tableToolbar.getToolbarRef()!); | ||||||
|  |   } | ||||||
| }); | }); | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
|  | @ -128,15 +142,10 @@ onMounted(() => { | ||||||
|   <Page auto-content-height> |   <Page auto-content-height> | ||||||
|     <FormModal @success="getList" /> |     <FormModal @success="getList" /> | ||||||
| 
 | 
 | ||||||
|     <ContentWrap> |     <ContentWrap v-if="!hiddenSearchBar"> | ||||||
|       <!-- 搜索工作栏 --> |       <!-- 搜索工作栏 --> | ||||||
|       <!-- TODO @puhui999:貌似 -mb-15px 没效果?可能和 ContentWrap 有关系? --> |       <!-- TODO @puhui999:貌似 -mb-15px 没效果?可能和 ContentWrap 有关系? --> | ||||||
|       <Form |       <Form :model="queryParams" ref="queryFormRef" layout="inline"> | ||||||
|         class="-mb-15px" |  | ||||||
|         :model="queryParams" |  | ||||||
|         ref="queryFormRef" |  | ||||||
|         layout="inline" |  | ||||||
|       > |  | ||||||
|         <Form.Item label="名字" name="name"> |         <Form.Item label="名字" name="name"> | ||||||
|           <!-- TODO @puhui999:貌似不一定 240?看着和 schema 还是不太一样 --> |           <!-- TODO @puhui999:貌似不一定 240?看着和 schema 还是不太一样 --> | ||||||
|           <Input |           <Input | ||||||
|  | @ -144,7 +153,7 @@ onMounted(() => { | ||||||
|             placeholder="请输入名字" |             placeholder="请输入名字" | ||||||
|             allow-clear |             allow-clear | ||||||
|             @press-enter="handleQuery" |             @press-enter="handleQuery" | ||||||
|             class="!w-240px" |             class="w-full" | ||||||
|           /> |           /> | ||||||
|         </Form.Item> |         </Form.Item> | ||||||
|         <Form.Item label="性别" name="sex"> |         <Form.Item label="性别" name="sex"> | ||||||
|  | @ -152,7 +161,7 @@ onMounted(() => { | ||||||
|             v-model:value="queryParams.sex" |             v-model:value="queryParams.sex" | ||||||
|             placeholder="请选择性别" |             placeholder="请选择性别" | ||||||
|             allow-clear |             allow-clear | ||||||
|             class="!w-240px" |             class="w-full" | ||||||
|           > |           > | ||||||
|             <Select.Option |             <Select.Option | ||||||
|               v-for="dict in getDictOptions( |               v-for="dict in getDictOptions( | ||||||
|  | @ -166,23 +175,30 @@ onMounted(() => { | ||||||
|           </Select> |           </Select> | ||||||
|         </Form.Item> |         </Form.Item> | ||||||
|         <Form.Item label="创建时间" name="createTime"> |         <Form.Item label="创建时间" name="createTime"> | ||||||
|           <!-- TODO @puhui999:这里有个红色的告警,看看有办法处理哇? --> |  | ||||||
|           <RangePicker |           <RangePicker | ||||||
|             v-model:value="queryParams.createTime" |             v-model:value="queryParams.createTime" | ||||||
|             v-bind="getRangePickerDefaultProps()" |             v-bind="getRangePickerDefaultProps()" | ||||||
|             class="!w-220px" |             class="w-full" | ||||||
|           /> |           /> | ||||||
|         </Form.Item> |         </Form.Item> | ||||||
|         <Form.Item> |         <Form.Item> | ||||||
|           <!-- TODO @puhui999:搜索和重置;貌似样子和位置不太一样,有木有办法一致 --> |           <!-- TODO @puhui999:搜索和重置;貌似样子和位置不太一样,有木有办法一致 --> | ||||||
|           <!-- 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> | ||||||
|           <Button class="ml-2" @click="resetQuery" :icon="h(RefreshCw)"> |         </Form.Item> | ||||||
|             重置 |       </Form> | ||||||
|           </Button> |     </ContentWrap> | ||||||
|           <!-- TODO @puhui999:有办法放到 VxeTable 哪里么? --> | 
 | ||||||
|  |     <!-- 列表 --> | ||||||
|  |     <ContentWrap title="你好"> | ||||||
|  |       <template #extra> | ||||||
|  |         <TableToolbar | ||||||
|  |           ref="tableToolbarRef" | ||||||
|  |           v-model:hidden-search="hiddenSearchBar" | ||||||
|  |         > | ||||||
|           <Button |           <Button | ||||||
|             class="ml-2" |             class="ml-2" | ||||||
|             :icon="h(Plus)" |             :icon="h(Plus)" | ||||||
|  | @ -202,14 +218,9 @@ onMounted(() => { | ||||||
|           > |           > | ||||||
|             {{ $t('ui.actionTitle.export') }} |             {{ $t('ui.actionTitle.export') }} | ||||||
|           </Button> |           </Button> | ||||||
|         </Form.Item> |         </TableToolbar> | ||||||
|       </Form> |       </template> | ||||||
|     </ContentWrap> |       <VxeTable ref="tableRef" :data="list" show-overflow :loading="loading"> | ||||||
| 
 |  | ||||||
|     <!-- 列表 --> |  | ||||||
|     <!-- TODO @puhui999:title 要不还是假起来? --> |  | ||||||
|     <ContentWrap> |  | ||||||
|       <VxeTable :data="list" show-overflow :loading="loading"> |  | ||||||
|         <VxeColumn field="id" title="编号" align="center" /> |         <VxeColumn field="id" title="编号" align="center" /> | ||||||
|         <VxeColumn field="name" title="名字" align="center" /> |         <VxeColumn field="name" title="名字" align="center" /> | ||||||
|         <VxeColumn field="sex" title="性别" align="center"> |         <VxeColumn field="sex" title="性别" align="center"> | ||||||
|  |  | ||||||
|  | @ -26,11 +26,9 @@ import { ImageUpload } from '#/components/upload'; | ||||||
| import { $t } from '#/locales'; | import { $t } from '#/locales'; | ||||||
| import { DICT_TYPE, getDictOptions } from '#/utils/dict'; | import { DICT_TYPE, getDictOptions } from '#/utils/dict'; | ||||||
| 
 | 
 | ||||||
| const emit = defineEmits(['success']); // TODO @puhui999:emit 和下面空一行? | const emit = defineEmits(['success']); | ||||||
|  | 
 | ||||||
| const formRef = ref(); | const formRef = ref(); | ||||||
| // TODO @puhui999:labelCol、wrapperCol 直接写?不用单独定义变量, |  | ||||||
| const labelCol = { span: 5 }; |  | ||||||
| const wrapperCol = { span: 13 }; |  | ||||||
| const formData = ref<Partial<Demo01ContactApi.Demo01Contact>>({ | const formData = ref<Partial<Demo01ContactApi.Demo01Contact>>({ | ||||||
|   id: undefined, |   id: undefined, | ||||||
|   name: undefined, |   name: undefined, | ||||||
|  | @ -90,8 +88,7 @@ const [Modal, modalApi] = useVbenModal({ | ||||||
|       resetForm(); |       resetForm(); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| 
 |     // 加载数据 | ||||||
|     // 加载数据 TODO @puhui999:这里不用空行 |  | ||||||
|     let data = modalApi.getData<Demo01ContactApi.Demo01Contact>(); |     let data = modalApi.getData<Demo01ContactApi.Demo01Contact>(); | ||||||
|     if (!data) { |     if (!data) { | ||||||
|       return; |       return; | ||||||
|  | @ -115,8 +112,8 @@ const [Modal, modalApi] = useVbenModal({ | ||||||
|       ref="formRef" |       ref="formRef" | ||||||
|       :model="formData" |       :model="formData" | ||||||
|       :rules="rules" |       :rules="rules" | ||||||
|       :label-col="labelCol" |       :label-col="{ span: 5 }" | ||||||
|       :wrapper-col="wrapperCol" |       :wrapper-col="{ span: 18 }" | ||||||
|     > |     > | ||||||
|       <Form.Item label="名字" name="name"> |       <Form.Item label="名字" name="name"> | ||||||
|         <Input v-model:value="formData.name" placeholder="请输入名字" /> |         <Input v-model:value="formData.name" placeholder="请输入名字" /> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 puhui999
						puhui999