Skip to content

Commit d985ef1

Browse files
committed
优化 post 岗位的逻辑实现代码
1 parent 5e47af9 commit d985ef1

File tree

6 files changed

+56
-42
lines changed

6 files changed

+56
-42
lines changed

src/components/Form/src/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
1616
const selectMap = ['Select', 'SelectV2', 'TimePicker', 'DatePicker', 'TimeSelect', 'TimeSelect']
1717
if (textMap.includes(schema?.component as string)) {
1818
return {
19-
placeholder: t('common.inputText')
19+
placeholder: t('common.inputText') + schema.label
2020
}
2121
}
2222
if (selectMap.includes(schema?.component as string)) {
@@ -34,7 +34,7 @@ export const setTextPlaceholder = (schema: FormSchema): PlaceholderMoel => {
3434
}
3535
} else {
3636
return {
37-
placeholder: t('common.selectText')
37+
placeholder: t('common.selectText') + schema.label
3838
}
3939
}
4040
}

src/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export default {
281281
create: 'Create',
282282
add: 'Add',
283283
del: 'Delete',
284+
delete: 'Delete',
284285
edit: 'Edit',
285286
update: 'Update',
286287
preview: 'Preview',

src/locales/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export default {
281281
create: '新增',
282282
add: '新增',
283283
del: '删除',
284+
delete: '删除',
284285
edit: '编辑',
285286
update: '编辑',
286287
preview: '预览',

src/views/system/post/PostForm.vue renamed to src/views/system/post/form.vue

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<!-- 弹窗 -->
3-
<XModal id="PostForm" :loading="modelLoading" v-model="modelVisible" :title="modelTitle">
3+
<XModal :title="modelTitle" :loading="modelLoading" v-model="modelVisible" height="270px">
44
<!-- 表单:添加/修改 -->
55
<Form
66
ref="formRef"
@@ -35,22 +35,21 @@ import { rules, allSchemas } from './post.data'
3535
const { t } = useI18n() // 国际化
3636
const message = useMessage() // 消息弹窗
3737
38-
const emit = defineEmits(['success'])
39-
4038
// 弹窗相关的变量
4139
const modelVisible = ref(false) // 是否显示弹出层
42-
const modelTitle = ref('update') // 弹出层标题
40+
const modelTitle = ref('') // 弹出层标题
4341
const modelLoading = ref(false) // 弹出层loading
4442
const actionType = ref('') // 操作按钮的类型
4543
const actionLoading = ref(false) // 按钮 Loading
4644
const formRef = ref<FormExpose>() // 表单 Ref
4745
const detailData = ref() // 详情 Ref
4846
47+
// 打开弹窗
4948
const openModal = async (type: string, rowId?: number) => {
49+
modelVisible.value = true
5050
modelLoading.value = true
5151
modelTitle.value = t('action.' + type)
5252
actionType.value = type
53-
modelVisible.value = true
5453
// 设置数据
5554
if (rowId) {
5655
const res = await PostApi.getPostApi(rowId)
@@ -62,31 +61,33 @@ const openModal = async (type: string, rowId?: number) => {
6261
}
6362
modelLoading.value = false
6463
}
64+
defineExpose({ openModal: openModal }) // 提供 openModal 方法,用于打开弹窗
6565
6666
// 提交新增/修改的表单
67+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
6768
const submitForm = async () => {
69+
// 校验表单
6870
const elForm = unref(formRef)?.getElFormRef()
6971
if (!elForm) return
7072
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'))
82-
}
83-
modelVisible.value = false
84-
emit('success')
85-
} finally {
86-
actionLoading.value = false
73+
if (!valid) {
74+
return
75+
}
76+
// 提交请求
77+
actionLoading.value = true
78+
try {
79+
const data = unref(formRef)?.formModel as PostApi.PostVO
80+
if (actionType.value === 'create') {
81+
await PostApi.createPostApi(data)
82+
message.success(t('common.createSuccess'))
83+
} else {
84+
await PostApi.updatePostApi(data)
85+
message.success(t('common.updateSuccess'))
8786
}
87+
modelVisible.value = false
88+
emit('success')
89+
} finally {
90+
actionLoading.value = false
8891
}
8992
}
90-
91-
defineExpose({ openModal: openModal })
9293
</script>

src/views/system/post/index.vue

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
/>
1414
<!-- 操作:导出 -->
1515
<XButton
16-
type="warning"
16+
type="primary"
17+
plain
1718
preIcon="ep:download"
1819
:title="t('action.export')"
1920
v-hasPermi="['system:post:export']"
@@ -24,44 +25,48 @@
2425
<!-- 操作:修改 -->
2526
<XTextButton
2627
preIcon="ep:edit"
28+
:title="t('action.edit')"
2729
v-hasPermi="['system:post:update']"
28-
@click="openModal('update', row.id)"
30+
@click="openModal('update', row?.id)"
2931
/>
3032
<!-- 操作:详情 -->
3133
<XTextButton
3234
preIcon="ep:view"
35+
:title="t('action.detail')"
3336
v-hasPermi="['system:post:query']"
34-
@click="openModal('detail', row.id)"
37+
@click="openModal('detail', row?.id)"
3538
/>
3639
<!-- 操作:删除 -->
3740
<XTextButton
3841
preIcon="ep:delete"
42+
:title="t('action.delete')"
3943
v-hasPermi="['system:post:delete']"
40-
@click="deleteData(row.id)"
44+
@click="deleteData(row?.id)"
4145
/>
4246
</template>
4347
</XTable>
4448
</ContentWrap>
49+
50+
<!-- 表单弹窗:添加/修改/详情 -->
4551
<PostForm ref="modalRef" @success="reload()" />
4652
</template>
4753
<script setup lang="ts" name="Post">
48-
// 业务相关的 import
4954
import * as PostApi from '@/api/system/post'
5055
import { allSchemas } from './post.data'
51-
import PostForm from './PostForm.vue'
52-
56+
import PostForm from './form.vue'
5357
const { t } = useI18n() // 国际化
5458
5559
// 列表相关的变量
5660
const [registerTable, { reload, deleteData, exportList }] = useXTable({
57-
allSchemas: allSchemas,
58-
getListApi: PostApi.getPostPageApi,
59-
deleteApi: PostApi.deletePostApi,
60-
exportListApi: PostApi.exportPostApi
61+
allSchemas: allSchemas, // 列表配置
62+
getListApi: PostApi.getPostPageApi, // 加载列表的 API
63+
deleteApi: PostApi.deletePostApi, // 删除数据的 API
64+
exportListApi: PostApi.exportPostApi // 导出数据的 API
6165
})
66+
6267
// 表单相关的变量
6368
const modalRef = ref()
64-
const openModal = (type: string, rowId?: number) => {
65-
modalRef.value.openModal(type, rowId)
69+
const openModal = (actionType: string, id?: number) => {
70+
modalRef.value.openModal(actionType, id)
6671
}
6772
</script>

src/views/system/post/post.data.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export const rules = reactive({
88
sort: [required]
99
})
1010

11-
// CrudSchema
11+
// 增删改查 CrudSchema 配置
1212
const crudSchemas = reactive<VxeCrudSchema>({
1313
primaryKey: 'id',
14-
primaryType: 'seq',
14+
primaryType: 'id',
1515
primaryTitle: '岗位编号',
1616
action: true,
1717
columns: [
@@ -27,7 +27,10 @@ const crudSchemas = reactive<VxeCrudSchema>({
2727
},
2828
{
2929
title: '岗位顺序',
30-
field: 'sort'
30+
field: 'sort',
31+
form: {
32+
component: 'InputNumber'
33+
}
3134
},
3235
{
3336
title: t('common.status'),
@@ -45,7 +48,10 @@ const crudSchemas = reactive<VxeCrudSchema>({
4548
title: t('common.createTime'),
4649
field: 'createTime',
4750
formatter: 'formatDate',
48-
isForm: false
51+
isForm: false,
52+
table: {
53+
width: 180
54+
}
4955
}
5056
]
5157
})

0 commit comments

Comments
 (0)