Browse Source

refactor: reloadList

xingyu4j 2 years ago
parent
commit
9794d1cfd7

+ 2 - 2
yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts

@@ -113,7 +113,7 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
   })
 
   // 刷新列表
-  const getList = async (ref) => {
+  const reloadList = async (ref) => {
     await nextTick()
     ref.value?.commitProxy('query')
   }
@@ -147,7 +147,7 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
 
   return {
     gridOptions,
-    getList,
+    reloadList,
     getSearchData,
     delList
   }

+ 5 - 13
yudao-ui-admin-vue3/src/views/system/errorCode/index.vue

@@ -83,9 +83,10 @@ const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 // 列表相关的变量
 const xGrid = ref<VxeGridInstance>() // grid Ref
-const { gridOptions } = useVxeGrid<ErrorCodeApi.ErrorCodeVO>({
+const { gridOptions, reloadList, delList } = useVxeGrid<ErrorCodeApi.ErrorCodeVO>({
   allSchemas: allSchemas,
-  getListApi: ErrorCodeApi.getErrorCodePageApi
+  getListApi: ErrorCodeApi.getErrorCodePageApi,
+  delListApi: ErrorCodeApi.deleteErrorCodeApi
 })
 // 弹窗相关的变量
 const dialogVisible = ref(false) // 是否显示弹出层
@@ -125,16 +126,7 @@ const handleDetail = async (rowId: number) => {
 
 // 删除操作
 const handleDelete = async (rowId: number) => {
-  message
-    .delConfirm()
-    .then(async () => {
-      await ErrorCodeApi.deleteErrorCodeApi(rowId)
-      message.success(t('common.delSuccess'))
-    })
-    .finally(() => {
-      // 刷新列表
-      xGrid.value?.commitProxy('query')
-    })
+  delList(xGrid, rowId)
 }
 
 // 提交新增/修改的表单
@@ -158,7 +150,7 @@ const submitForm = async () => {
       } finally {
         actionLoading.value = false
         // 刷新列表
-        xGrid.value?.commitProxy('query')
+        reloadList(xGrid)
       }
     }
   })

+ 2 - 5
yudao-ui-admin-vue3/src/views/system/loginlog/index.vue

@@ -42,7 +42,7 @@ const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 // 列表相关的变量
 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
-const { gridOptions } = useVxeGrid<LoginLogVO>({
+const { gridOptions, getSearchData } = useVxeGrid<LoginLogVO>({
   allSchemas: allSchemas,
   getListApi: getLoginLogPageApi
 })
@@ -61,10 +61,7 @@ const handleDetail = async (row: LoginLogVO) => {
 // 导出操作
 const handleExport = async () => {
   message.exportConfirm().then(async () => {
-    const queryParams = Object.assign(
-      {},
-      JSON.parse(JSON.stringify(xGrid.value?.getRefMaps().refForm.value.data)) // TODO @星语:这个有没办法,封装个 util 获取哈?
-    )
+    const queryParams = await getSearchData(xGrid)
     const res = await exportLoginLogApi(queryParams)
     download.excel(res, '登录列表.xls')
   })

+ 5 - 13
yudao-ui-admin-vue3/src/views/system/notice/index.vue

@@ -82,9 +82,10 @@ const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 // 列表相关的变量
 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
-const { gridOptions } = useVxeGrid<NoticeApi.NoticeVO>({
+const { gridOptions, reloadList, delList } = useVxeGrid<NoticeApi.NoticeVO>({
   allSchemas: allSchemas,
-  getListApi: NoticeApi.getNoticePageApi
+  getListApi: NoticeApi.getNoticePageApi,
+  delListApi: NoticeApi.deleteNoticeApi
 })
 // 弹窗相关的变量
 const dialogVisible = ref(false) // 是否显示弹出层
@@ -124,16 +125,7 @@ const handleDetail = async (rowId: number) => {
 
 // 删除操作
 const handleDelete = async (rowId: number) => {
-  message
-    .delConfirm()
-    .then(async () => {
-      await NoticeApi.deleteNoticeApi(rowId)
-      message.success(t('common.delSuccess'))
-    })
-    .finally(() => {
-      // 刷新列表
-      xGrid.value?.commitProxy('query')
-    })
+  delList(xGrid, rowId)
 }
 
 // 提交新增/修改的表单
@@ -157,7 +149,7 @@ const submitForm = async () => {
       } finally {
         actionLoading.value = false
         // 刷新列表
-        xGrid.value?.commitProxy('query')
+        reloadList(xGrid)
       }
     }
   })

+ 5 - 13
yudao-ui-admin-vue3/src/views/system/oauth2/client/index.vue

@@ -94,9 +94,10 @@ const message = useMessage() // 消息弹窗
 
 // 列表相关的变量
 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
-const { gridOptions } = useVxeGrid<ClientApi.OAuth2ClientVO>({
+const { gridOptions, reloadList, delList } = useVxeGrid<ClientApi.OAuth2ClientVO>({
   allSchemas: allSchemas,
-  getListApi: ClientApi.getOAuth2ClientPageApi
+  getListApi: ClientApi.getOAuth2ClientPageApi,
+  delListApi: ClientApi.deleteOAuth2ClientApi
 })
 // 弹窗相关的变量
 const dialogVisible = ref(false) // 是否显示弹出层
@@ -135,16 +136,7 @@ const handleDetail = async (rowId: number) => {
 
 // 删除操作
 const handleDelete = async (rowId: number) => {
-  message
-    .delConfirm()
-    .then(async () => {
-      await ClientApi.deleteOAuth2ClientApi(rowId)
-      message.success(t('common.delSuccess'))
-    })
-    .finally(() => {
-      // 刷新列表
-      xGrid.value?.commitProxy('query')
-    })
+  delList(xGrid, rowId)
 }
 
 // 提交新增/修改的表单
@@ -168,7 +160,7 @@ const submitForm = async () => {
       } finally {
         actionLoading.value = false
         // 刷新列表
-        xGrid.value?.commitProxy('query')
+        reloadList(xGrid)
       }
     }
   })

+ 2 - 2
yudao-ui-admin-vue3/src/views/system/oauth2/token/index.vue

@@ -39,7 +39,7 @@ const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 // 列表相关的变量
 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
-const { gridOptions } = useVxeGrid<TokenApi.OAuth2TokenVO>({
+const { gridOptions, reloadList } = useVxeGrid<TokenApi.OAuth2TokenVO>({
   allSchemas: allSchemas,
   getListApi: TokenApi.getAccessTokenPageApi
 })
@@ -65,7 +65,7 @@ const handleForceLogout = (rowId: number) => {
     })
     .finally(() => {
       // 刷新列表
-      xGrid.value?.commitProxy('query')
+      reloadList(xGrid)
     })
 }
 </script>

+ 2 - 2
yudao-ui-admin-vue3/src/views/system/post/index.vue

@@ -90,7 +90,7 @@ const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 // 列表相关的变量
 const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
-const { gridOptions, getList, delList, getSearchData } = useVxeGrid<PostApi.PostVO>({
+const { gridOptions, reloadList, delList, getSearchData } = useVxeGrid<PostApi.PostVO>({
   allSchemas: allSchemas,
   getListApi: PostApi.getPostPageApi,
   delListApi: PostApi.deletePostApi
@@ -163,7 +163,7 @@ const submitForm = async () => {
       } finally {
         actionLoading.value = false
         // 刷新列表
-        getList(xGrid)
+        reloadList(xGrid)
       }
     }
   })