diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts index 56597ce39..168445d3d 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts @@ -37,6 +37,9 @@ const currentSize = computed(() => { }) export const useVxeGrid = (config?: UseVxeGridConfig) => { + /** + * grid options 初始化 + */ const gridOptions = reactive({ loading: true, size: currentSize as any, @@ -113,24 +116,49 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { } }) - // 刷新列表 + /** + * 刷新列表 + * @param ref + * @returns + */ const reloadList = async (ref) => { + if (!ref) { + console.error('未传入gridRef') + return + } await nextTick() - ref.value?.commitProxy('query') + ref.value.commitProxy('query') } // 获取查询参数 const getSearchData = async (ref) => { + if (!ref) { + console.error('未传入gridRef') + return + } await nextTick() const queryParams = Object.assign( {}, - JSON.parse(JSON.stringify(ref.value?.getProxyInfo()?.form)) + JSON.parse(JSON.stringify(ref.value.getProxyInfo()?.form)) ) return queryParams } - // 删除 + /** + * 删除 + * @param ref + * @param ids rowid + * @returns + */ const delList = async (ref, ids: string | number | string[] | number[]) => { + if (!ref) { + console.error('未传入gridRef') + return + } + if (!config?.delListApi) { + console.error('未传入delListApi') + return + } await nextTick() return new Promise(async () => { message @@ -141,12 +169,25 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { }) .finally(async () => { // 刷新列表 - ref.value?.commitProxy('query') + ref.value.commitProxy('query') }) }) } - // 导出 + /** + * 导出 + * @param ref + * @param fileName 文件名,默认excel.xls + * @returns + */ const exportList = async (ref, fileName?: string) => { + if (!ref) { + console.error('未传入gridRef') + return + } + if (!config?.exportListApi) { + console.error('未传入exportListApi') + return + } await nextTick() const queryParams = Object.assign( {}, @@ -157,12 +198,26 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { download.excel(res as unknown as Blob, fileName ? fileName : 'excel.xls') }) } + /** + * 表格最大/最小化 + * @param ref + * @returns + */ + const zoom = async (ref) => { + if (!ref) { + console.error('未传入gridRef') + return + } + await nextTick() + ref.value.zoom(!ref.value.isMaximized()) + } return { gridOptions, reloadList, getSearchData, delList, - exportList + exportList, + zoom } } diff --git a/yudao-ui-admin-vue3/src/views/system/post/index.vue b/yudao-ui-admin-vue3/src/views/system/post/index.vue index c8723793c..189607422 100644 --- a/yudao-ui-admin-vue3/src/views/system/post/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/post/index.vue @@ -137,7 +137,7 @@ const handleDetail = async (rowId: number) => { // 删除操作 const handleDelete = async (rowId: number) => { - delList(xGrid, rowId) + await delList(xGrid, rowId) } // 提交新增/修改的表单