Commit ecb7ade767bed920ae9b065cad315ef5493b1a0a

Authored by xingyu4j
1 parent c7972f9a

feat: 增加 刷新列表 删除行 获取查询参数 方法

yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
1   -import { computed, reactive } from 'vue'
  1 +import { computed, nextTick, reactive } from 'vue'
2 2 import { SizeType, VxeGridProps } from 'vxe-table'
3 3 import { useAppStore } from '@/store/modules/app'
4 4 import { VxeAllSchemas } from './useVxeCrudSchemas'
... ... @@ -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 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 148 return {
125 149 gridOptions,
  150 + getList,
  151 + getSearchData,
126 152 delList
127 153 }
128 154 }
... ...
yudao-ui-admin-vue3/src/views/system/operatelog/index.vue
... ... @@ -57,7 +57,7 @@ const { t } = useI18n() // 国际化
57 57 const message = useMessage() // 消息弹窗
58 58 // 列表相关的变量
59 59 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
60   -const { gridOptions } = useVxeGrid<OperateLogApi.OperateLogVO>({
  60 +const { gridOptions, getSearchData } = useVxeGrid<OperateLogApi.OperateLogVO>({
61 61 allSchemas: allSchemas,
62 62 getListApi: OperateLogApi.getOperateLogPageApi
63 63 })
... ... @@ -77,10 +77,7 @@ const handleDetail = (row: OperateLogApi.OperateLogVO) =&gt; {
77 77 // 导出操作
78 78 const handleExport = async () => {
79 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 81 const res = await OperateLogApi.exportOperateLogApi(queryParams)
85 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 90 const message = useMessage() // 消息弹窗
91 91 // 列表相关的变量
92 92 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
93   -const { gridOptions } = useVxeGrid<PostApi.PostVO>({
  93 +const { gridOptions, getList, delList, getSearchData } = useVxeGrid<PostApi.PostVO>({
94 94 allSchemas: allSchemas,
95   - getListApi: PostApi.getPostPageApi
  95 + getListApi: PostApi.getPostPageApi,
  96 + delListApi: PostApi.deletePostApi
96 97 })
97 98 // 弹窗相关的变量
98 99 const dialogVisible = ref(false) // 是否显示弹出层
... ... @@ -116,10 +117,7 @@ const handleCreate = () =&gt; {
116 117  
117 118 // 导出操作
118 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 121 const res = await PostApi.exportPostApi(queryParams)
124 122 download.excel(res, '岗位列表.xls')
125 123 }
... ... @@ -141,16 +139,7 @@ const handleDetail = async (rowId: number) =&gt; {
141 139  
142 140 // 删除操作
143 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 () =&gt; {
174 163 } finally {
175 164 actionLoading.value = false
176 165 // 刷新列表
177   - xGrid.value?.commitProxy('query')
  166 + getList(xGrid)
178 167 }
179 168 }
180 169 })
... ...