Commit 424520490dc0e35539c307f97e98a6937186a19c

Authored by YunaiV
1 parent 301b66d3

vue3:【post】

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