Commit ecb7ade767bed920ae9b065cad315ef5493b1a0a
1 parent
c7972f9a
feat: 增加 刷新列表 删除行 获取查询参数 方法
Showing
3 changed files
with
40 additions
and
28 deletions
yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
| 1 | -import { computed, reactive } from 'vue' | 1 | +import { computed, nextTick, reactive } from 'vue' |
| 2 | import { SizeType, VxeGridProps } from 'vxe-table' | 2 | import { SizeType, VxeGridProps } from 'vxe-table' |
| 3 | import { useAppStore } from '@/store/modules/app' | 3 | import { useAppStore } from '@/store/modules/app' |
| 4 | import { VxeAllSchemas } from './useVxeCrudSchemas' | 4 | import { VxeAllSchemas } from './useVxeCrudSchemas' |
| @@ -112,17 +112,43 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { | @@ -112,17 +112,43 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { | ||
| 112 | } | 112 | } |
| 113 | }) | 113 | }) |
| 114 | 114 | ||
| 115 | - const delList = (ids: string | number | string[] | number[]) => { | 115 | + // 刷新列表 |
| 116 | + const getList = async (ref) => { | ||
| 117 | + await nextTick() | ||
| 118 | + ref.value?.commitProxy('query') | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + // 获取查询参数 | ||
| 122 | + const getSearchData = async (ref) => { | ||
| 123 | + await nextTick() | ||
| 124 | + const queryParams = Object.assign( | ||
| 125 | + {}, | ||
| 126 | + JSON.parse(JSON.stringify(ref.value?.getProxyInfo()?.form)) | ||
| 127 | + ) | ||
| 128 | + return queryParams | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + // 删除 | ||
| 132 | + const delList = async (ref, ids: string | number | string[] | number[]) => { | ||
| 133 | + await nextTick() | ||
| 116 | return new Promise(async () => { | 134 | return new Promise(async () => { |
| 117 | - message.delConfirm().then(() => { | ||
| 118 | - config?.delListApi && config?.delListApi(ids) | ||
| 119 | - message.success(t('common.delSuccess')) | ||
| 120 | - }) | 135 | + message |
| 136 | + .delConfirm() | ||
| 137 | + .then(() => { | ||
| 138 | + config?.delListApi && config?.delListApi(ids) | ||
| 139 | + message.success(t('common.delSuccess')) | ||
| 140 | + }) | ||
| 141 | + .finally(async () => { | ||
| 142 | + // 刷新列表 | ||
| 143 | + ref.value?.commitProxy('query') | ||
| 144 | + }) | ||
| 121 | }) | 145 | }) |
| 122 | } | 146 | } |
| 123 | 147 | ||
| 124 | return { | 148 | return { |
| 125 | gridOptions, | 149 | gridOptions, |
| 150 | + getList, | ||
| 151 | + getSearchData, | ||
| 126 | delList | 152 | delList |
| 127 | } | 153 | } |
| 128 | } | 154 | } |
yudao-ui-admin-vue3/src/views/system/operatelog/index.vue
| @@ -57,7 +57,7 @@ const { t } = useI18n() // 国际化 | @@ -57,7 +57,7 @@ const { t } = useI18n() // 国际化 | ||
| 57 | const message = useMessage() // 消息弹窗 | 57 | const message = useMessage() // 消息弹窗 |
| 58 | // 列表相关的变量 | 58 | // 列表相关的变量 |
| 59 | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref | 59 | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref |
| 60 | -const { gridOptions } = useVxeGrid<OperateLogApi.OperateLogVO>({ | 60 | +const { gridOptions, getSearchData } = useVxeGrid<OperateLogApi.OperateLogVO>({ |
| 61 | allSchemas: allSchemas, | 61 | allSchemas: allSchemas, |
| 62 | getListApi: OperateLogApi.getOperateLogPageApi | 62 | getListApi: OperateLogApi.getOperateLogPageApi |
| 63 | }) | 63 | }) |
| @@ -77,10 +77,7 @@ const handleDetail = (row: OperateLogApi.OperateLogVO) => { | @@ -77,10 +77,7 @@ const handleDetail = (row: OperateLogApi.OperateLogVO) => { | ||
| 77 | // 导出操作 | 77 | // 导出操作 |
| 78 | const handleExport = async () => { | 78 | const handleExport = async () => { |
| 79 | message.exportConfirm().then(async () => { | 79 | message.exportConfirm().then(async () => { |
| 80 | - const queryParams = Object.assign( | ||
| 81 | - {}, | ||
| 82 | - JSON.parse(JSON.stringify(xGrid.value?.getRefMaps().refForm.value.data)) // TODO @星语:这个有没办法,封装个 util 获取哈? | ||
| 83 | - ) | 80 | + const queryParams = await getSearchData(xGrid) |
| 84 | const res = await OperateLogApi.exportOperateLogApi(queryParams) | 81 | const res = await OperateLogApi.exportOperateLogApi(queryParams) |
| 85 | download.excel(res, '岗位列表.xls') | 82 | download.excel(res, '岗位列表.xls') |
| 86 | }) | 83 | }) |
yudao-ui-admin-vue3/src/views/system/post/index.vue
| @@ -90,9 +90,10 @@ const { t } = useI18n() // 国际化 | @@ -90,9 +90,10 @@ const { t } = useI18n() // 国际化 | ||
| 90 | const message = useMessage() // 消息弹窗 | 90 | const message = useMessage() // 消息弹窗 |
| 91 | // 列表相关的变量 | 91 | // 列表相关的变量 |
| 92 | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref | 92 | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref |
| 93 | -const { gridOptions } = useVxeGrid<PostApi.PostVO>({ | 93 | +const { gridOptions, getList, delList, getSearchData } = useVxeGrid<PostApi.PostVO>({ |
| 94 | allSchemas: allSchemas, | 94 | allSchemas: allSchemas, |
| 95 | - getListApi: PostApi.getPostPageApi | 95 | + getListApi: PostApi.getPostPageApi, |
| 96 | + delListApi: PostApi.deletePostApi | ||
| 96 | }) | 97 | }) |
| 97 | // 弹窗相关的变量 | 98 | // 弹窗相关的变量 |
| 98 | const dialogVisible = ref(false) // 是否显示弹出层 | 99 | const dialogVisible = ref(false) // 是否显示弹出层 |
| @@ -116,10 +117,7 @@ const handleCreate = () => { | @@ -116,10 +117,7 @@ const handleCreate = () => { | ||
| 116 | 117 | ||
| 117 | // 导出操作 | 118 | // 导出操作 |
| 118 | const handleExport = async () => { | 119 | const handleExport = async () => { |
| 119 | - const queryParams = Object.assign( | ||
| 120 | - {}, | ||
| 121 | - JSON.parse(JSON.stringify(xGrid.value?.getRefMaps().refForm.value.data)) | ||
| 122 | - ) | 120 | + const queryParams = await getSearchData(xGrid) |
| 123 | const res = await PostApi.exportPostApi(queryParams) | 121 | const res = await PostApi.exportPostApi(queryParams) |
| 124 | download.excel(res, '岗位列表.xls') | 122 | download.excel(res, '岗位列表.xls') |
| 125 | } | 123 | } |
| @@ -141,16 +139,7 @@ const handleDetail = async (rowId: number) => { | @@ -141,16 +139,7 @@ const handleDetail = async (rowId: number) => { | ||
| 141 | 139 | ||
| 142 | // 删除操作 | 140 | // 删除操作 |
| 143 | const handleDelete = async (rowId: number) => { | 141 | const handleDelete = async (rowId: number) => { |
| 144 | - message | ||
| 145 | - .delConfirm() | ||
| 146 | - .then(async () => { | ||
| 147 | - await PostApi.deletePostApi(rowId) | ||
| 148 | - message.success(t('common.delSuccess')) | ||
| 149 | - }) | ||
| 150 | - .finally(() => { | ||
| 151 | - // 刷新列表 | ||
| 152 | - xGrid.value?.commitProxy('query') | ||
| 153 | - }) | 142 | + delList(xGrid, rowId) |
| 154 | } | 143 | } |
| 155 | 144 | ||
| 156 | // 提交新增/修改的表单 | 145 | // 提交新增/修改的表单 |
| @@ -174,7 +163,7 @@ const submitForm = async () => { | @@ -174,7 +163,7 @@ const submitForm = async () => { | ||
| 174 | } finally { | 163 | } finally { |
| 175 | actionLoading.value = false | 164 | actionLoading.value = false |
| 176 | // 刷新列表 | 165 | // 刷新列表 |
| 177 | - xGrid.value?.commitProxy('query') | 166 | + getList(xGrid) |
| 178 | } | 167 | } |
| 179 | } | 168 | } |
| 180 | }) | 169 | }) |