优化 post 岗位的逻辑实现代码

This commit is contained in:
YunaiV 2023-02-11 15:54:44 +08:00
parent 5e47af9327
commit d985ef194e
6 changed files with 56 additions and 42 deletions

View File

@ -16,7 +16,7 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
const selectMap = ['Select', 'SelectV2', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
if (textMap.includes(schema?.component as string)) {
return {
placeholder: t('common.inputText')
placeholder: t('common.inputText') + schema.label
}
}
if (selectMap.includes(schema?.component as string)) {
@ -34,7 +34,7 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
}
} else {
return {
placeholder: t('common.selectText')
placeholder: t('common.selectText') + schema.label
}
}
}

View File

@ -281,6 +281,7 @@ export default {
create: 'Create',
add: 'Add',
del: 'Delete',
delete: 'Delete',
edit: 'Edit',
update: 'Update',
preview: 'Preview',

View File

@ -281,6 +281,7 @@ export default {
create: '新增',
add: '新增',
del: '删除',
delete: '删除',
edit: '编辑',
update: '编辑',
preview: '预览',

View File

@ -1,6 +1,6 @@
<template>
<!-- 弹窗 -->
<XModal id="PostForm" :loading="modelLoading" v-model="modelVisible" :title="modelTitle">
<XModal :title="modelTitle" :loading="modelLoading" v-model="modelVisible" height="270px">
<!-- 表单添加/修改 -->
<Form
ref="formRef"
@ -35,22 +35,21 @@ import { rules, allSchemas } from './post.data'
const { t } = useI18n() //
const message = useMessage() //
const emit = defineEmits(['success'])
//
const modelVisible = ref(false) //
const modelTitle = ref('update') //
const modelTitle = ref('') //
const modelLoading = ref(false) // loading
const actionType = ref('') //
const actionLoading = ref(false) // Loading
const formRef = ref<FormExpose>() // Ref
const detailData = ref() // Ref
//
const openModal = async (type: string, rowId?: number) => {
modelVisible.value = true
modelLoading.value = true
modelTitle.value = t('action.' + type)
actionType.value = type
modelVisible.value = true
//
if (rowId) {
const res = await PostApi.getPostApi(rowId)
@ -62,15 +61,20 @@ const openModal = async (type: string, rowId?: number) => {
}
modelLoading.value = false
}
defineExpose({ openModal: openModal }) // openModal
// /
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
const valid = await elForm.validate()
if (valid) {
actionLoading.value = true
if (!valid) {
return
}
//
actionLoading.value = true
try {
const data = unref(formRef)?.formModel as PostApi.PostVO
if (actionType.value === 'create') {
@ -85,8 +89,5 @@ const submitForm = async () => {
} finally {
actionLoading.value = false
}
}
}
defineExpose({ openModal: openModal })
</script>

View File

@ -13,7 +13,8 @@
/>
<!-- 操作导出 -->
<XButton
type="warning"
type="primary"
plain
preIcon="ep:download"
:title="t('action.export')"
v-hasPermi="['system:post:export']"
@ -24,44 +25,48 @@
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:post:update']"
@click="openModal('update', row.id)"
@click="openModal('update', row?.id)"
/>
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['system:post:query']"
@click="openModal('detail', row.id)"
@click="openModal('detail', row?.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.delete')"
v-hasPermi="['system:post:delete']"
@click="deleteData(row.id)"
@click="deleteData(row?.id)"
/>
</template>
</XTable>
</ContentWrap>
<!-- 表单弹窗添加/修改/详情 -->
<PostForm ref="modalRef" @success="reload()" />
</template>
<script setup lang="ts" name="Post">
// import
import * as PostApi from '@/api/system/post'
import { allSchemas } from './post.data'
import PostForm from './PostForm.vue'
import PostForm from './form.vue'
const { t } = useI18n() //
//
const [registerTable, { reload, deleteData, exportList }] = useXTable({
allSchemas: allSchemas,
getListApi: PostApi.getPostPageApi,
deleteApi: PostApi.deletePostApi,
exportListApi: PostApi.exportPostApi
allSchemas: allSchemas, //
getListApi: PostApi.getPostPageApi, // API
deleteApi: PostApi.deletePostApi, // API
exportListApi: PostApi.exportPostApi // API
})
//
const modalRef = ref()
const openModal = (type: string, rowId?: number) => {
modalRef.value.openModal(type, rowId)
const openModal = (actionType: string, id?: number) => {
modalRef.value.openModal(actionType, id)
}
</script>

View File

@ -8,10 +8,10 @@ export const rules = reactive({
sort: [required]
})
// CrudSchema
// 增删改查 CrudSchema 配置
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'seq',
primaryType: 'id',
primaryTitle: '岗位编号',
action: true,
columns: [
@ -27,7 +27,10 @@ const crudSchemas = reactive<VxeCrudSchema>({
},
{
title: '岗位顺序',
field: 'sort'
field: 'sort',
form: {
component: 'InputNumber'
}
},
{
title: t('common.status'),
@ -45,7 +48,10 @@ const crudSchemas = reactive<VxeCrudSchema>({
title: t('common.createTime'),
field: 'createTime',
formatter: 'formatDate',
isForm: false
isForm: false,
table: {
width: 180
}
}
]
})