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 | 7 | <span>字典分类</span> |
| 8 | 8 | </div> |
| 9 | 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 | 12 | <template #toolbar_buttons> |
| 18 | 13 | <XButton |
| ... | ... | @@ -39,7 +34,7 @@ |
| 39 | 34 | @click="handleTypeDelete(row.id)" |
| 40 | 35 | /> |
| 41 | 36 | </template> |
| 42 | - </vxe-grid> | |
| 37 | + </XTable> | |
| 43 | 38 | <!-- @星语:分页和列表重叠在一起了 --> |
| 44 | 39 | </el-card> |
| 45 | 40 | <!-- ====== 字典数据 ====== --> |
| ... | ... | @@ -55,7 +50,7 @@ |
| 55 | 50 | </div> |
| 56 | 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 | 55 | <template #toolbar_buttons> |
| 61 | 56 | <XButton |
| ... | ... | @@ -82,7 +77,7 @@ |
| 82 | 77 | @click="handleDataDelete(row.id)" |
| 83 | 78 | /> |
| 84 | 79 | </template> |
| 85 | - </vxe-grid> | |
| 80 | + </XTable> | |
| 86 | 81 | </div> |
| 87 | 82 | </el-card> |
| 88 | 83 | <XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle"> |
| ... | ... | @@ -130,8 +125,8 @@ |
| 130 | 125 | import { ref, unref, reactive } from 'vue' |
| 131 | 126 | import { useI18n } from '@/hooks/web/useI18n' |
| 132 | 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 | 130 | import { FormExpose } from '@/components/Form' |
| 136 | 131 | import { ElInput, ElTag, ElCard } from 'element-plus' |
| 137 | 132 | import * as DictTypeSchemas from './dict.type' |
| ... | ... | @@ -143,28 +138,18 @@ import { DictDataVO, DictTypeVO } from '@/api/system/dict/types' |
| 143 | 138 | const { t } = useI18n() // 国际化 |
| 144 | 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 | 142 | allSchemas: DictTypeSchemas.allSchemas, |
| 153 | 143 | getListApi: DictTypeApi.getDictTypePageApi, |
| 154 | 144 | deleteApi: DictTypeApi.deleteDictTypeApi |
| 155 | 145 | }) |
| 156 | 146 | |
| 157 | -const xDataGrid = ref<VxeGridInstance>() // 列表 Grid Ref | |
| 158 | 147 | const queryParams = reactive({ |
| 159 | 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 | 151 | allSchemas: DictDataSchemas.allSchemas, |
| 167 | - queryParams: queryParams, | |
| 152 | + params: queryParams, | |
| 168 | 153 | getListApi: DictDataApi.getDictDataPageApi, |
| 169 | 154 | deleteApi: DictDataApi.deleteDictDataApi |
| 170 | 155 | }) |
| ... | ... | @@ -199,7 +184,7 @@ const tableTypeSelect = ref(false) |
| 199 | 184 | const cellClickEvent: VxeTableEvents.CellClick = async ({ row }) => { |
| 200 | 185 | tableTypeSelect.value = true |
| 201 | 186 | queryParams.dictType = row['type'] |
| 202 | - await dataGetList(xDataGrid) | |
| 187 | + await dataGetList() | |
| 203 | 188 | parentType.value = row['type'] |
| 204 | 189 | } |
| 205 | 190 | // 弹出框 |
| ... | ... | @@ -219,11 +204,11 @@ const setDialogTile = (type: string) => { |
| 219 | 204 | |
| 220 | 205 | // 删除操作 |
| 221 | 206 | const handleTypeDelete = async (rowId: number) => { |
| 222 | - await typeDeleteData(xTypeGrid, rowId) | |
| 207 | + await typeDeleteData(rowId) | |
| 223 | 208 | } |
| 224 | 209 | |
| 225 | 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 | 232 | dialogVisible.value = false |
| 248 | 233 | } finally { |
| 249 | 234 | actionLoading.value = false |
| 250 | - typeGetList(xTypeGrid) | |
| 235 | + typeGetList() | |
| 251 | 236 | } |
| 252 | 237 | } |
| 253 | 238 | }) |
| ... | ... | @@ -272,7 +257,7 @@ const submitDataForm = async () => { |
| 272 | 257 | dialogVisible.value = false |
| 273 | 258 | } finally { |
| 274 | 259 | actionLoading.value = false |
| 275 | - dataGetList(xDataGrid) | |
| 260 | + dataGetList() | |
| 276 | 261 | } |
| 277 | 262 | } |
| 278 | 263 | }) | ... | ... |