Commit 8488933ec40731d0e33e3baf6661d5fe3aeb9e8a
1 parent
f2d2dc4d
refactor: Xtable
Showing
1 changed file
with
14 additions
and
29 deletions
yudao-ui-admin-vue3/src/views/system/dict/index.vue
| @@ -7,12 +7,7 @@ | @@ -7,12 +7,7 @@ | ||
| 7 | <span>字典分类</span> | 7 | <span>字典分类</span> |
| 8 | </div> | 8 | </div> |
| 9 | </template> | 9 | </template> |
| 10 | - <vxe-grid | ||
| 11 | - ref="xTypeGrid" | ||
| 12 | - v-bind="typeGridOptions" | ||
| 13 | - @cell-click="cellClickEvent" | ||
| 14 | - class="xtable-scrollbar" | ||
| 15 | - > | 10 | + <XTable @register="registerType" @cell-click="cellClickEvent"> |
| 16 | <!-- 操作:新增类型 --> | 11 | <!-- 操作:新增类型 --> |
| 17 | <template #toolbar_buttons> | 12 | <template #toolbar_buttons> |
| 18 | <XButton | 13 | <XButton |
| @@ -39,7 +34,7 @@ | @@ -39,7 +34,7 @@ | ||
| 39 | @click="handleTypeDelete(row.id)" | 34 | @click="handleTypeDelete(row.id)" |
| 40 | /> | 35 | /> |
| 41 | </template> | 36 | </template> |
| 42 | - </vxe-grid> | 37 | + </XTable> |
| 43 | <!-- @星语:分页和列表重叠在一起了 --> | 38 | <!-- @星语:分页和列表重叠在一起了 --> |
| 44 | </el-card> | 39 | </el-card> |
| 45 | <!-- ====== 字典数据 ====== --> | 40 | <!-- ====== 字典数据 ====== --> |
| @@ -55,7 +50,7 @@ | @@ -55,7 +50,7 @@ | ||
| 55 | </div> | 50 | </div> |
| 56 | <div v-if="tableTypeSelect"> | 51 | <div v-if="tableTypeSelect"> |
| 57 | <!-- 列表 --> | 52 | <!-- 列表 --> |
| 58 | - <vxe-grid ref="xDataGrid" v-bind="dataGridOptions" class="xtable-scrollbar"> | 53 | + <XTable @register="registerData"> |
| 59 | <!-- 操作:新增数据 --> | 54 | <!-- 操作:新增数据 --> |
| 60 | <template #toolbar_buttons> | 55 | <template #toolbar_buttons> |
| 61 | <XButton | 56 | <XButton |
| @@ -82,7 +77,7 @@ | @@ -82,7 +77,7 @@ | ||
| 82 | @click="handleDataDelete(row.id)" | 77 | @click="handleDataDelete(row.id)" |
| 83 | /> | 78 | /> |
| 84 | </template> | 79 | </template> |
| 85 | - </vxe-grid> | 80 | + </XTable> |
| 86 | </div> | 81 | </div> |
| 87 | </el-card> | 82 | </el-card> |
| 88 | <XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle"> | 83 | <XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle"> |
| @@ -130,8 +125,8 @@ | @@ -130,8 +125,8 @@ | ||
| 130 | import { ref, unref, reactive } from 'vue' | 125 | import { ref, unref, reactive } from 'vue' |
| 131 | import { useI18n } from '@/hooks/web/useI18n' | 126 | import { useI18n } from '@/hooks/web/useI18n' |
| 132 | import { useMessage } from '@/hooks/web/useMessage' | 127 | import { useMessage } from '@/hooks/web/useMessage' |
| 133 | -import { useVxeGrid } from '@/hooks/web/useVxeGrid' | ||
| 134 | -import { VxeGridInstance, VxeTableEvents } from 'vxe-table' | 128 | +import { useXTable } from '@/hooks/web/useXTable' |
| 129 | +import { VxeTableEvents } from 'vxe-table' | ||
| 135 | import { FormExpose } from '@/components/Form' | 130 | import { FormExpose } from '@/components/Form' |
| 136 | import { ElInput, ElTag, ElCard } from 'element-plus' | 131 | import { ElInput, ElTag, ElCard } from 'element-plus' |
| 137 | import * as DictTypeSchemas from './dict.type' | 132 | import * as DictTypeSchemas from './dict.type' |
| @@ -143,28 +138,18 @@ import { DictDataVO, DictTypeVO } from '@/api/system/dict/types' | @@ -143,28 +138,18 @@ import { DictDataVO, DictTypeVO } from '@/api/system/dict/types' | ||
| 143 | const { t } = useI18n() // 国际化 | 138 | const { t } = useI18n() // 国际化 |
| 144 | const message = useMessage() // 消息弹窗 | 139 | const message = useMessage() // 消息弹窗 |
| 145 | 140 | ||
| 146 | -const xTypeGrid = ref<VxeGridInstance>() // 列表 Grid Ref | ||
| 147 | -const { | ||
| 148 | - gridOptions: typeGridOptions, | ||
| 149 | - getList: typeGetList, | ||
| 150 | - deleteData: typeDeleteData | ||
| 151 | -} = useVxeGrid<DictTypeVO>({ | 141 | +const [registerType, { reload: typeGetList, deleteData: typeDeleteData }] = useXTable({ |
| 152 | allSchemas: DictTypeSchemas.allSchemas, | 142 | allSchemas: DictTypeSchemas.allSchemas, |
| 153 | getListApi: DictTypeApi.getDictTypePageApi, | 143 | getListApi: DictTypeApi.getDictTypePageApi, |
| 154 | deleteApi: DictTypeApi.deleteDictTypeApi | 144 | deleteApi: DictTypeApi.deleteDictTypeApi |
| 155 | }) | 145 | }) |
| 156 | 146 | ||
| 157 | -const xDataGrid = ref<VxeGridInstance>() // 列表 Grid Ref | ||
| 158 | const queryParams = reactive({ | 147 | const queryParams = reactive({ |
| 159 | dictType: null | 148 | dictType: null |
| 160 | }) | 149 | }) |
| 161 | -const { | ||
| 162 | - gridOptions: dataGridOptions, | ||
| 163 | - getList: dataGetList, | ||
| 164 | - deleteData: dataDeleteData | ||
| 165 | -} = useVxeGrid<DictDataVO>({ | 150 | +const [registerData, { reload: dataGetList, deleteData: dataDeleteData }] = useXTable({ |
| 166 | allSchemas: DictDataSchemas.allSchemas, | 151 | allSchemas: DictDataSchemas.allSchemas, |
| 167 | - queryParams: queryParams, | 152 | + params: queryParams, |
| 168 | getListApi: DictDataApi.getDictDataPageApi, | 153 | getListApi: DictDataApi.getDictDataPageApi, |
| 169 | deleteApi: DictDataApi.deleteDictDataApi | 154 | deleteApi: DictDataApi.deleteDictDataApi |
| 170 | }) | 155 | }) |
| @@ -199,7 +184,7 @@ const tableTypeSelect = ref(false) | @@ -199,7 +184,7 @@ const tableTypeSelect = ref(false) | ||
| 199 | const cellClickEvent: VxeTableEvents.CellClick = async ({ row }) => { | 184 | const cellClickEvent: VxeTableEvents.CellClick = async ({ row }) => { |
| 200 | tableTypeSelect.value = true | 185 | tableTypeSelect.value = true |
| 201 | queryParams.dictType = row['type'] | 186 | queryParams.dictType = row['type'] |
| 202 | - await dataGetList(xDataGrid) | 187 | + await dataGetList() |
| 203 | parentType.value = row['type'] | 188 | parentType.value = row['type'] |
| 204 | } | 189 | } |
| 205 | // 弹出框 | 190 | // 弹出框 |
| @@ -219,11 +204,11 @@ const setDialogTile = (type: string) => { | @@ -219,11 +204,11 @@ const setDialogTile = (type: string) => { | ||
| 219 | 204 | ||
| 220 | // 删除操作 | 205 | // 删除操作 |
| 221 | const handleTypeDelete = async (rowId: number) => { | 206 | const handleTypeDelete = async (rowId: number) => { |
| 222 | - await typeDeleteData(xTypeGrid, rowId) | 207 | + await typeDeleteData(rowId) |
| 223 | } | 208 | } |
| 224 | 209 | ||
| 225 | const handleDataDelete = async (rowId: number) => { | 210 | const handleDataDelete = async (rowId: number) => { |
| 226 | - await dataDeleteData(xDataGrid, rowId) | 211 | + await dataDeleteData(rowId) |
| 227 | } | 212 | } |
| 228 | 213 | ||
| 229 | // 提交按钮 | 214 | // 提交按钮 |
| @@ -247,7 +232,7 @@ const submitTypeForm = async () => { | @@ -247,7 +232,7 @@ const submitTypeForm = async () => { | ||
| 247 | dialogVisible.value = false | 232 | dialogVisible.value = false |
| 248 | } finally { | 233 | } finally { |
| 249 | actionLoading.value = false | 234 | actionLoading.value = false |
| 250 | - typeGetList(xTypeGrid) | 235 | + typeGetList() |
| 251 | } | 236 | } |
| 252 | } | 237 | } |
| 253 | }) | 238 | }) |
| @@ -272,7 +257,7 @@ const submitDataForm = async () => { | @@ -272,7 +257,7 @@ const submitDataForm = async () => { | ||
| 272 | dialogVisible.value = false | 257 | dialogVisible.value = false |
| 273 | } finally { | 258 | } finally { |
| 274 | actionLoading.value = false | 259 | actionLoading.value = false |
| 275 | - dataGetList(xDataGrid) | 260 | + dataGetList() |
| 276 | } | 261 | } |
| 277 | } | 262 | } |
| 278 | }) | 263 | }) |