Эх сурвалжийг харах

修复刷新按钮不能正确获取数据的BUG;修复详情页带有表格的情况下,第一次进入无法获取数据的BUG(现在表格会在初次加载的时候主动获取一次数据,但是会导致有些页面出现两次请求)

fxs 7 сар өмнө
parent
commit
c01bb58f90

+ 27 - 7
src/components/Table.vue

@@ -2,7 +2,7 @@
  * @Author: fxs bjnsfxs@163.com
  * @Date: 2024-08-20 18:16:18
  * @LastEditors: fxs bjnsfxs@163.com
- * @LastEditTime: 2024-10-12 18:40:06
+ * @LastEditTime: 2024-10-14 11:06:43
  * @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
  * @Description: 
  * 
@@ -70,7 +70,7 @@ const backupQueryFormData = reactive<{ [key: string]: any }>({})
 
 // 分页数据
 const paginationConfig2 = reactive<TablePaginationSetting>({
-  currentPage: 0,
+  currentPage: 1,
   limit: 0,
   total: 0,
   pagesizeList: []
@@ -140,6 +140,7 @@ const handleSizeChange = (val: number) => {
  * @return {*}
  */
 const getData = () => {
+  console.trace()
   return new Promise(async (resolve, reject) => {
     try {
       const loadTableData = async () => {
@@ -225,6 +226,9 @@ const getData = () => {
   })
 }
 
+// 包装一下获取数据
+const throttleGetData = throttleFunc(getData, 1000)
+
 /**
  * @description: 清空表格数据
  * @return {*}
@@ -370,6 +374,7 @@ watch(
   (newGid, oldGid) => {
     if (newGid != oldGid) {
       reqconfig.otherOptions.gid = newGid
+
       getData()
     }
   },
@@ -384,7 +389,8 @@ const watchPf = watch(
       reqconfig.otherOptions.pf = newPf
       getData()
     }
-  }
+  },
+  { deep: true }
 )
 
 // 监听传入的datalist的变化,然后去更新数据
@@ -511,6 +517,19 @@ const outGetTableData = () => {
   return toRaw(tableData).flat()
 }
 
+// const registerWatchProps = () => {
+//   props.watchReqProps?.forEach((item) => {
+//     watch(
+//       () => props.requestConfig?.otherOptions?.[item],
+//       () => {
+//         // getData()
+//         reqconfig.otherOptions[item] = props.requestConfig?.otherOptions?.[item]
+//       },
+//       { deep: true }
+//     )
+//   })
+// }
+
 // 定义暴露出去的方法
 defineExpose({
   getData,
@@ -524,12 +543,13 @@ onMounted(() => {
   initpageConfig()
   initReqConfig()
   initFormData()
+  // registerWatchProps()
   if (props.loadingState !== undefined) {
     loading.value = props.loadingState
   }
-  // if (!props.openPageQuery) {
-  //   getData()
-  // }
+  // 这里会造成有的table页第一次进来刷新两次,因为有的页面gid或者平台等数据会变化,导致请求第二次
+  // 但是这里又必须请求一次,因为有的页面数据是没有变化的
+  getData()
   // 去加载所有需要的资源
   initLoadResouce(resourceInfo).then((data) => {
     Object.assign(blobUrlInfo, data)
@@ -638,7 +658,7 @@ onMounted(() => {
           <el-icon><Download /></el-icon>下载
         </el-button>
         <!-- throttleFunc(queryTableData, 200) -->
-        <RegreshBtn @refresh-table="throttleQueryTableData" :icon-size="toolsIconSize"></RegreshBtn>
+        <RegreshBtn @refresh-table="throttleGetData" :icon-size="toolsIconSize"></RegreshBtn>
 
         <FilterPopover
           :table-fields-info="tableFieldsInfo"

+ 2 - 1
src/hooks/useAnalysis.ts

@@ -2,7 +2,7 @@
  * @Author: fxs bjnsfxs@163.com
  * @Date: 2024-08-20 17:15:49
  * @LastEditors: fxs bjnsfxs@163.com
- * @LastEditTime: 2024-09-11 15:27:44
+ * @LastEditTime: 2024-10-14 10:03:35
  * @FilePath: \Game-Backstage-Management-System\src\hooks\useAnalysis.ts
  * @Description:
  *
@@ -15,6 +15,7 @@ export function useAnalysis() {
    * @return {*}
    */
   const updateReqConfig = (config: ReqConfig, newVal: any) => {
+    console.log(config, newVal)
     Object.keys(newVal).map((k) => {
       config.otherOptions[k] = newVal[k]
     })

+ 3 - 1
src/types/dataAnalysis.ts

@@ -29,7 +29,9 @@ export interface DropDownInfo {
  */
 export interface ReqConfig {
   url: string
-  otherOptions: any
+  otherOptions: {
+    [key: string]: any
+  }
 }
 
 // 数据展示的字段信息

+ 2 - 0
src/types/table.ts

@@ -92,6 +92,8 @@ export interface PropsParams {
   paginationConfig: TablePaginationSetting // 表格分页的信息
   tableFieldsInfo: Array<TableFieldInfo> // 表格字段信息
   requestConfig?: ReqConfig
+
+  watchReqProps?: Array<string> // 需要被监听的属性
 }
 
 // 选择下拉框的信息格式

+ 1 - 1
src/views/Home/Analysis/EventAnalysisDetail.vue

@@ -2,7 +2,7 @@
  * @Author: fxs bjnsfxs@163.com
  * @Date: 2024-08-27 17:11:23
  * @LastEditors: fxs bjnsfxs@163.com
- * @LastEditTime: 2024-09-28 16:21:52
+ * @LastEditTime: 2024-10-14 11:07:56
  * @FilePath: \Game-Backstage-Management-System\src\views\Home\Analysis\EventAnalysisDetail.vue
  * @Description: 
  *