mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	perf: vxe demo
This commit is contained in:
		| @@ -44,12 +44,11 @@ | ||||
|   <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle"> | ||||
|     <template #default> | ||||
|       <!-- 对话框(添加 / 修改) --> | ||||
|       <vxe-form | ||||
|         ref="xForm" | ||||
|       <Form | ||||
|         v-if="['create', 'update'].includes(actionType)" | ||||
|         :data="formData" | ||||
|         :items="formItems" | ||||
|         :schema="allSchemas.formSchema" | ||||
|         :rules="rules" | ||||
|         ref="formRef" | ||||
|       /> | ||||
|       <Descriptions | ||||
|         v-if="actionType === 'detail'" | ||||
| @@ -77,7 +76,7 @@ | ||||
|   </XModal> | ||||
| </template> | ||||
| <script setup lang="ts"> | ||||
| import { ref } from 'vue' | ||||
| import { ref, unref } from 'vue' | ||||
| import dayjs from 'dayjs' | ||||
| import { DICT_TYPE } from '@/utils/dict' | ||||
| import * as PostApi from '@/api/system/post' | ||||
| @@ -86,20 +85,22 @@ import { rules, allSchemas } from './post.data' | ||||
| import { useI18n } from '@/hooks/web/useI18n' | ||||
| import { useMessage } from '@/hooks/web/useMessage' | ||||
| import { useVxeGrid } from '@/hooks/web/useVxeGrid' | ||||
| import { VxeFormEvents, VxeFormInstance, VxeFormItemProps, VxeGridInstance } from 'vxe-table' | ||||
| import { VxeFormEvents, VxeGridInstance } from 'vxe-table' | ||||
| import { FormExpose } from '@/components/Form' | ||||
|  | ||||
| const { t } = useI18n() // 国际化 | ||||
| const message = useMessage() // 消息弹窗 | ||||
| const xGrid = ref<VxeGridInstance>() | ||||
| const xForm = ref<VxeFormInstance>() | ||||
| const formRef = ref<FormExpose>() // 表单 Ref | ||||
| const dialogVisible = ref(false) // 是否显示弹出层 | ||||
| const dialogTitle = ref('edit') // 弹出层标题 | ||||
| const actionType = ref('') // 操作按钮的类型 | ||||
| const actionLoading = ref(false) // 按钮Loading | ||||
|  | ||||
| const gridOptions = useVxeGrid(allSchemas, PostApi.getPostPageApi) | ||||
| const formData = ref<PostVO>() | ||||
| const formItems = ref<VxeFormItemProps[]>(allSchemas.formSchema) | ||||
| const { gridOptions } = useVxeGrid<PostVO>({ | ||||
|   allSchemas: allSchemas, | ||||
|   getListApi: PostApi.getPostPageApi | ||||
| }) | ||||
| // 设置标题 | ||||
| const setDialogTile = (type: string) => { | ||||
|   dialogTitle.value = t('action.' + type) | ||||
| @@ -116,7 +117,8 @@ const handleDetail = (row: PostVO) => { | ||||
| // 新增操作 | ||||
| const handleCreate = () => { | ||||
|   setDialogTile('create') | ||||
|   formData.value = undefined | ||||
|   // 重置表单 | ||||
|   unref(formRef)?.getElFormRef()?.resetFields() | ||||
| } | ||||
|  | ||||
| // 修改操作 | ||||
| @@ -124,10 +126,10 @@ const handleUpdate = async (rowId: number) => { | ||||
|   setDialogTile('update') | ||||
|   // 设置数据 | ||||
|   const res = await PostApi.getPostApi(rowId) | ||||
|   formData.value = res | ||||
|   unref(formRef)?.setValues(res) | ||||
| } | ||||
| // 删除操作 | ||||
| const handleDelete = (rowId: number) => { | ||||
| const handleDelete = async (rowId: number) => { | ||||
|   message | ||||
|     .delConfirm() | ||||
|     .then(async () => { | ||||
| @@ -140,22 +142,28 @@ const handleDelete = (rowId: number) => { | ||||
| } | ||||
| // 提交按钮 | ||||
| const submitForm: VxeFormEvents.Submit = async () => { | ||||
|   actionLoading.value = true | ||||
|   // 提交请求 | ||||
|   try { | ||||
|     const data = formData.value as PostVO | ||||
|     if (actionType.value === 'create') { | ||||
|       await PostApi.createPostApi(data) | ||||
|       message.success(t('common.createSuccess')) | ||||
|     } else { | ||||
|       await PostApi.updatePostApi(data) | ||||
|       message.success(t('common.updateSuccess')) | ||||
|   const elForm = unref(formRef)?.getElFormRef() | ||||
|   if (!elForm) return | ||||
|   elForm.validate(async (valid) => { | ||||
|     if (valid) { | ||||
|       actionLoading.value = true | ||||
|       // 提交请求 | ||||
|       try { | ||||
|         const data = unref(formRef)?.formModel as PostVO | ||||
|         if (actionType.value === 'create') { | ||||
|           await PostApi.createPostApi(data) | ||||
|           message.success(t('common.createSuccess')) | ||||
|         } else { | ||||
|           await PostApi.updatePostApi(data) | ||||
|           message.success(t('common.updateSuccess')) | ||||
|         } | ||||
|         // 操作成功,重新加载列表 | ||||
|         dialogVisible.value = false | ||||
|       } finally { | ||||
|         actionLoading.value = false | ||||
|         xGrid.value?.commitProxy('query') | ||||
|       } | ||||
|     } | ||||
|     // 操作成功,重新加载列表 | ||||
|     dialogVisible.value = false | ||||
|   } finally { | ||||
|     actionLoading.value = false | ||||
|     xGrid.value?.commitProxy('query') | ||||
|   } | ||||
|   }) | ||||
| } | ||||
| </script> | ||||
|   | ||||
| @@ -56,9 +56,17 @@ const crudSchemas = reactive<VxeCrudSchema[]>([ | ||||
|       show: true | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     title: '备注', | ||||
|     field: 'remark', | ||||
|     table: { | ||||
|       show: false | ||||
|     } | ||||
|   }, | ||||
|   { | ||||
|     title: t('common.createTime'), | ||||
|     field: 'createTime', | ||||
|     formatter: 'formatDate', | ||||
|     form: { | ||||
|       show: false | ||||
|     } | ||||
| @@ -66,10 +74,8 @@ const crudSchemas = reactive<VxeCrudSchema[]>([ | ||||
|   { | ||||
|     title: t('table.action'), | ||||
|     field: 'action', | ||||
|     width: '240px', | ||||
|     table: { | ||||
|       width: '240px', | ||||
|       showOverflow: true, | ||||
|       slots: { | ||||
|         default: 'action_default' | ||||
|       } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 xingyu4j
					xingyu4j