瀏覽代碼

feat: 增加xgrid注释和判断

xingyu4j 2 年之前
父節點
當前提交
66476412bd
共有 2 個文件被更改,包括 63 次插入8 次删除
  1. 62 7
      yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts
  2. 1 1
      yudao-ui-admin-vue3/src/views/system/post/index.vue

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

@@ -37,6 +37,9 @@ const currentSize = computed(() => {
 })
 
 export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
+  /**
+   * grid options 初始化
+   */
   const gridOptions = reactive<VxeGridProps>({
     loading: true,
     size: currentSize as any,
@@ -113,24 +116,49 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => {
     }
   })
 
-  // 刷新列表
+  /**
+   * 刷新列表
+   * @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 = <T = any>(config?: UseVxeGridConfig<T>) => {
         })
         .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 = <T = any>(config?: UseVxeGridConfig<T>) => {
       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
   }
 }

+ 1 - 1
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)
 }
 
 // 提交新增/修改的表单