Commit 563eb8ba906a93b5acdfadd392dc1269f780e174
1 parent
a379e3a2
feat: 优化post界面
Showing
2 changed files
with
21 additions
and
21 deletions
yudao-ui-admin-vue3/src/views/system/post/PostForm.vue
| @@ -39,7 +39,7 @@ const emit = defineEmits(['success']) | @@ -39,7 +39,7 @@ const emit = defineEmits(['success']) | ||
| 39 | 39 | ||
| 40 | // 弹窗相关的变量 | 40 | // 弹窗相关的变量 |
| 41 | const modelVisible = ref(false) // 是否显示弹出层 | 41 | const modelVisible = ref(false) // 是否显示弹出层 |
| 42 | -const modelTitle = ref('edit') // 弹出层标题 | 42 | +const modelTitle = ref('update') // 弹出层标题 |
| 43 | const modelLoading = ref(false) // 弹出层loading | 43 | const modelLoading = ref(false) // 弹出层loading |
| 44 | const actionType = ref('') // 操作按钮的类型 | 44 | const actionType = ref('') // 操作按钮的类型 |
| 45 | const actionLoading = ref(false) // 按钮 Loading | 45 | const actionLoading = ref(false) // 按钮 Loading |
| @@ -67,26 +67,25 @@ const openModal = async (type: string, rowId?: number) => { | @@ -67,26 +67,25 @@ const openModal = async (type: string, rowId?: number) => { | ||
| 67 | const submitForm = async () => { | 67 | const submitForm = async () => { |
| 68 | const elForm = unref(formRef)?.getElFormRef() | 68 | const elForm = unref(formRef)?.getElFormRef() |
| 69 | if (!elForm) return | 69 | if (!elForm) return |
| 70 | - elForm.validate(async (valid) => { | ||
| 71 | - if (valid) { | ||
| 72 | - actionLoading.value = true | ||
| 73 | - // 提交请求 | ||
| 74 | - try { | ||
| 75 | - const data = unref(formRef)?.formModel as PostApi.PostVO | ||
| 76 | - if (actionType.value === 'create') { | ||
| 77 | - await PostApi.createPostApi(data) | ||
| 78 | - message.success(t('common.createSuccess')) | ||
| 79 | - } else { | ||
| 80 | - await PostApi.updatePostApi(data) | ||
| 81 | - message.success(t('common.updateSuccess')) | ||
| 82 | - } | ||
| 83 | - modelVisible.value = false | ||
| 84 | - emit('success') | ||
| 85 | - } finally { | ||
| 86 | - actionLoading.value = false | 70 | + const valid = await elForm.validate() |
| 71 | + if (valid) { | ||
| 72 | + actionLoading.value = true | ||
| 73 | + // 提交请求 | ||
| 74 | + try { | ||
| 75 | + const data = unref(formRef)?.formModel as PostApi.PostVO | ||
| 76 | + if (actionType.value === 'create') { | ||
| 77 | + await PostApi.createPostApi(data) | ||
| 78 | + message.success(t('common.createSuccess')) | ||
| 79 | + } else { | ||
| 80 | + await PostApi.updatePostApi(data) | ||
| 81 | + message.success(t('common.updateSuccess')) | ||
| 87 | } | 82 | } |
| 83 | + modelVisible.value = false | ||
| 84 | + emit('success') | ||
| 85 | + } finally { | ||
| 86 | + actionLoading.value = false | ||
| 88 | } | 87 | } |
| 89 | - }) | 88 | + } |
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | defineExpose({ openModal: openModal }) | 91 | defineExpose({ openModal: openModal }) |
yudao-ui-admin-vue3/src/views/system/post/index.vue
| @@ -51,7 +51,7 @@ import { allSchemas } from './post.data' | @@ -51,7 +51,7 @@ import { allSchemas } from './post.data' | ||
| 51 | import PostForm from './PostForm.vue' | 51 | import PostForm from './PostForm.vue' |
| 52 | 52 | ||
| 53 | const { t } = useI18n() // 国际化 | 53 | const { t } = useI18n() // 国际化 |
| 54 | -const modalRef = ref() | 54 | + |
| 55 | // 列表相关的变量 | 55 | // 列表相关的变量 |
| 56 | const [registerTable, { reload, deleteData, exportList }] = useXTable({ | 56 | const [registerTable, { reload, deleteData, exportList }] = useXTable({ |
| 57 | allSchemas: allSchemas, | 57 | allSchemas: allSchemas, |
| @@ -59,7 +59,8 @@ const [registerTable, { reload, deleteData, exportList }] = useXTable({ | @@ -59,7 +59,8 @@ const [registerTable, { reload, deleteData, exportList }] = useXTable({ | ||
| 59 | deleteApi: PostApi.deletePostApi, | 59 | deleteApi: PostApi.deletePostApi, |
| 60 | exportListApi: PostApi.exportPostApi | 60 | exportListApi: PostApi.exportPostApi |
| 61 | }) | 61 | }) |
| 62 | - | 62 | +// 表单相关的变量 |
| 63 | +const modalRef = ref() | ||
| 63 | const openModal = (type: string, rowId?: number) => { | 64 | const openModal = (type: string, rowId?: number) => { |
| 64 | modalRef.value.openModal(type, rowId) | 65 | modalRef.value.openModal(type, rowId) |
| 65 | } | 66 | } |