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

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

View File

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

View File

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

View File

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

View File

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

View File

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