Commit 424520490dc0e35539c307f97e98a6937186a19c
1 parent
301b66d3
vue3:【post】
1. 添加 TODO 修改建议 2. 增加注释 3. 调整一些 import、const 的顺序
Showing
3 changed files
with
30 additions
and
12 deletions
yudao-ui-admin-vue3/src/api/system/post/index.ts
| @@ -31,6 +31,7 @@ export const deletePostApi = async (id: number) => { | @@ -31,6 +31,7 @@ export const deletePostApi = async (id: number) => { | ||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | // 导出岗位 | 33 | // 导出岗位 |
| 34 | +// TODO @星语:导出这块,咱怎么弄哈 | ||
| 34 | export const exportPostApi = async (params: PostExportReqVO) => { | 35 | export const exportPostApi = async (params: PostExportReqVO) => { |
| 35 | return await request.download({ url: '/system/post/export', params }) | 36 | return await request.download({ url: '/system/post/export', params }) |
| 36 | } | 37 | } |
yudao-ui-admin-vue3/src/api/system/post/types.ts
| @@ -8,6 +8,7 @@ export type PostVO = { | @@ -8,6 +8,7 @@ export type PostVO = { | ||
| 8 | createTime?: string | 8 | createTime?: string |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | +// TODO @星语:要不要搞个 Page 基类呀?和后端对应 | ||
| 11 | export type PostPageReqVO = { | 12 | export type PostPageReqVO = { |
| 12 | code: string | 13 | code: string |
| 13 | name: string | 14 | name: string |
yudao-ui-admin-vue3/src/views/system/post/index.vue
| 1 | <template> | 1 | <template> |
| 2 | <ContentWrap> | 2 | <ContentWrap> |
| 3 | + <!-- 列表 --> | ||
| 3 | <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar"> | 4 | <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar"> |
| 5 | + <!-- 操作:新增 --> | ||
| 4 | <template #toolbar_buttons> | 6 | <template #toolbar_buttons> |
| 5 | <XButton | 7 | <XButton |
| 6 | type="primary" | 8 | type="primary" |
| @@ -11,18 +13,21 @@ | @@ -11,18 +13,21 @@ | ||
| 11 | /> | 13 | /> |
| 12 | </template> | 14 | </template> |
| 13 | <template #actionbtns_default="{ row }"> | 15 | <template #actionbtns_default="{ row }"> |
| 16 | + <!-- 操作:修改 --> | ||
| 14 | <XTextButton | 17 | <XTextButton |
| 15 | preIcon="ep:edit" | 18 | preIcon="ep:edit" |
| 16 | :title="t('action.edit')" | 19 | :title="t('action.edit')" |
| 17 | v-hasPermi="['system:post:update']" | 20 | v-hasPermi="['system:post:update']" |
| 18 | @click="handleUpdate(row.id)" | 21 | @click="handleUpdate(row.id)" |
| 19 | /> | 22 | /> |
| 23 | + <!-- 操作:详情 --> | ||
| 20 | <XTextButton | 24 | <XTextButton |
| 21 | preIcon="ep:view" | 25 | preIcon="ep:view" |
| 22 | :title="t('action.detail')" | 26 | :title="t('action.detail')" |
| 23 | v-hasPermi="['system:post:update']" | 27 | v-hasPermi="['system:post:update']" |
| 24 | @click="handleDetail(row)" | 28 | @click="handleDetail(row)" |
| 25 | /> | 29 | /> |
| 30 | + <!-- 操作:删除 --> | ||
| 26 | <XTextButton | 31 | <XTextButton |
| 27 | preIcon="ep:delete" | 32 | preIcon="ep:delete" |
| 28 | :title="t('action.del')" | 33 | :title="t('action.del')" |
| @@ -32,15 +37,17 @@ | @@ -32,15 +37,17 @@ | ||
| 32 | </template> | 37 | </template> |
| 33 | </vxe-grid> | 38 | </vxe-grid> |
| 34 | </ContentWrap> | 39 | </ContentWrap> |
| 40 | + <!-- 弹窗 --> | ||
| 35 | <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle"> | 41 | <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle"> |
| 36 | <template #default> | 42 | <template #default> |
| 37 | - <!-- 对话框(添加 / 修改) --> | 43 | + <!-- 表单:添加/修改 --> |
| 38 | <Form | 44 | <Form |
| 39 | v-if="['create', 'update'].includes(actionType)" | 45 | v-if="['create', 'update'].includes(actionType)" |
| 40 | :schema="allSchemas.formSchema" | 46 | :schema="allSchemas.formSchema" |
| 41 | :rules="rules" | 47 | :rules="rules" |
| 42 | ref="formRef" | 48 | ref="formRef" |
| 43 | /> | 49 | /> |
| 50 | + <!-- 表单:详情 --> | ||
| 44 | <Descriptions | 51 | <Descriptions |
| 45 | v-if="actionType === 'detail'" | 52 | v-if="actionType === 'detail'" |
| 46 | :schema="allSchemas.detailSchema" | 53 | :schema="allSchemas.detailSchema" |
| @@ -48,6 +55,7 @@ | @@ -48,6 +55,7 @@ | ||
| 48 | /> | 55 | /> |
| 49 | </template> | 56 | </template> |
| 50 | <template #footer> | 57 | <template #footer> |
| 58 | + <!-- 按钮:保存 --> | ||
| 51 | <XButton | 59 | <XButton |
| 52 | v-if="['create', 'update'].includes(actionType)" | 60 | v-if="['create', 'update'].includes(actionType)" |
| 53 | type="primary" | 61 | type="primary" |
| @@ -55,36 +63,40 @@ | @@ -55,36 +63,40 @@ | ||
| 55 | :loading="actionLoading" | 63 | :loading="actionLoading" |
| 56 | @click="submitForm" | 64 | @click="submitForm" |
| 57 | /> | 65 | /> |
| 66 | + <!-- 按钮:关闭 --> | ||
| 58 | <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" /> | 67 | <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" /> |
| 59 | </template> | 68 | </template> |
| 60 | </XModal> | 69 | </XModal> |
| 61 | </template> | 70 | </template> |
| 62 | <script setup lang="ts"> | 71 | <script setup lang="ts"> |
| 72 | +// 全局相关的 import | ||
| 63 | import { ref, unref } from 'vue' | 73 | import { ref, unref } from 'vue' |
| 64 | -import * as PostApi from '@/api/system/post' | ||
| 65 | -import { PostVO } from '@/api/system/post/types' | ||
| 66 | -import { rules, allSchemas } from './post.data' | ||
| 67 | import { useI18n } from '@/hooks/web/useI18n' | 74 | import { useI18n } from '@/hooks/web/useI18n' |
| 68 | import { useMessage } from '@/hooks/web/useMessage' | 75 | import { useMessage } from '@/hooks/web/useMessage' |
| 69 | import { useVxeGrid } from '@/hooks/web/useVxeGrid' | 76 | import { useVxeGrid } from '@/hooks/web/useVxeGrid' |
| 70 | import { VxeGridInstance } from 'vxe-table' | 77 | import { VxeGridInstance } from 'vxe-table' |
| 71 | import { FormExpose } from '@/components/Form' | 78 | import { FormExpose } from '@/components/Form' |
| 79 | +// 业务相关的 import | ||
| 80 | +import * as PostApi from '@/api/system/post' | ||
| 81 | +import { PostVO } from '@/api/system/post/types' | ||
| 82 | +import { rules, allSchemas } from './post.data' | ||
| 72 | 83 | ||
| 73 | const { t } = useI18n() // 国际化 | 84 | const { t } = useI18n() // 国际化 |
| 74 | const message = useMessage() // 消息弹窗 | 85 | const message = useMessage() // 消息弹窗 |
| 86 | +// 列表相关的变量 | ||
| 87 | +const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref | ||
| 88 | +const { gridOptions } = useVxeGrid<PostVO>({ | ||
| 89 | + allSchemas: allSchemas, | ||
| 90 | + getListApi: PostApi.getPostPageApi | ||
| 91 | +}) | ||
| 92 | +// 弹窗相关的变量 | ||
| 75 | const dialogVisible = ref(false) // 是否显示弹出层 | 93 | const dialogVisible = ref(false) // 是否显示弹出层 |
| 76 | const dialogTitle = ref('edit') // 弹出层标题 | 94 | const dialogTitle = ref('edit') // 弹出层标题 |
| 77 | const actionType = ref('') // 操作按钮的类型 | 95 | const actionType = ref('') // 操作按钮的类型 |
| 78 | -const actionLoading = ref(false) // 按钮Loading | ||
| 79 | -const xGrid = ref<VxeGridInstance>() // grid Ref | 96 | +const actionLoading = ref(false) // 按钮 Loading |
| 80 | const formRef = ref<FormExpose>() // 表单 Ref | 97 | const formRef = ref<FormExpose>() // 表单 Ref |
| 81 | const detailRef = ref() // 详情 Ref | 98 | const detailRef = ref() // 详情 Ref |
| 82 | 99 | ||
| 83 | -const { gridOptions } = useVxeGrid<PostVO>({ | ||
| 84 | - allSchemas: allSchemas, | ||
| 85 | - getListApi: PostApi.getPostPageApi | ||
| 86 | -}) | ||
| 87 | - | ||
| 88 | // 设置标题 | 100 | // 设置标题 |
| 89 | const setDialogTile = (type: string) => { | 101 | const setDialogTile = (type: string) => { |
| 90 | dialogTitle.value = t('action.' + type) | 102 | dialogTitle.value = t('action.' + type) |
| @@ -110,6 +122,7 @@ const handleUpdate = async (rowId: number) => { | @@ -110,6 +122,7 @@ const handleUpdate = async (rowId: number) => { | ||
| 110 | // 详情操作 | 122 | // 详情操作 |
| 111 | const handleDetail = (row: PostVO) => { | 123 | const handleDetail = (row: PostVO) => { |
| 112 | setDialogTile('detail') | 124 | setDialogTile('detail') |
| 125 | + // TODO @星语:要不读取下后端? | ||
| 113 | detailRef.value = row | 126 | detailRef.value = row |
| 114 | } | 127 | } |
| 115 | 128 | ||
| @@ -122,14 +135,16 @@ const handleDelete = async (rowId: number) => { | @@ -122,14 +135,16 @@ const handleDelete = async (rowId: number) => { | ||
| 122 | message.success(t('common.delSuccess')) | 135 | message.success(t('common.delSuccess')) |
| 123 | }) | 136 | }) |
| 124 | .finally(() => { | 137 | .finally(() => { |
| 138 | + // 刷新列表 | ||
| 125 | xGrid.value?.commitProxy('query') | 139 | xGrid.value?.commitProxy('query') |
| 126 | }) | 140 | }) |
| 127 | } | 141 | } |
| 128 | 142 | ||
| 129 | -// 提交按钮 | 143 | +// 提交新增/修改的表单 |
| 130 | const submitForm = async () => { | 144 | const submitForm = async () => { |
| 131 | const elForm = unref(formRef)?.getElFormRef() | 145 | const elForm = unref(formRef)?.getElFormRef() |
| 132 | if (!elForm) return | 146 | if (!elForm) return |
| 147 | + // TODO @星语:这个告警,要不要解决下? | ||
| 133 | elForm.validate(async (valid) => { | 148 | elForm.validate(async (valid) => { |
| 134 | if (valid) { | 149 | if (valid) { |
| 135 | actionLoading.value = true | 150 | actionLoading.value = true |
| @@ -146,6 +161,7 @@ const submitForm = async () => { | @@ -146,6 +161,7 @@ const submitForm = async () => { | ||
| 146 | dialogVisible.value = false | 161 | dialogVisible.value = false |
| 147 | } finally { | 162 | } finally { |
| 148 | actionLoading.value = false | 163 | actionLoading.value = false |
| 164 | + // 刷新列表 | ||
| 149 | xGrid.value?.commitProxy('query') | 165 | xGrid.value?.commitProxy('query') |
| 150 | } | 166 | } |
| 151 | } | 167 | } |