1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { listEnterpriseNewsPage } from "@/api/officeProcessAutomation/enterpriseNews.js";
import { ElMessage } from "element-plus";
import { reactive, ref } from "vue";
import {
  buildEnterpriseNewsListParams,
  mapEnterpriseNewsFromApi,
  unwrapEnterpriseNewsPage,
} from "./enterpriseNewsMappers.js";
 
/** 企业新闻列表:分页查询 /enterpriseNews/listPage */
export function useEnterpriseNewsList() {
  const tableData = ref([]);
  const tableLoading = ref(false);
  const page = reactive({ current: 1, size: 10, total: 0 });
  let lastSearchForm = null;
 
  async function fetchList(searchForm = {}) {
    tableLoading.value = true;
    try {
      const res = await listEnterpriseNewsPage(
        buildEnterpriseNewsListParams({ page, searchForm })
      );
      const { records, total } = unwrapEnterpriseNewsPage(res);
      tableData.value = records.map(mapEnterpriseNewsFromApi);
      page.total = total;
    } catch {
      tableData.value = [];
      page.total = 0;
      ElMessage.error("企业新闻列表加载失败");
    } finally {
      tableLoading.value = false;
    }
  }
 
  function handleQuery(searchForm) {
    lastSearchForm = searchForm;
    page.current = 1;
    return fetchList(searchForm);
  }
 
  function pagination({ page: p, limit }, searchForm) {
    page.current = p;
    page.size = limit;
    return fetchList(searchForm ?? lastSearchForm ?? {});
  }
 
  return {
    tableData,
    tableLoading,
    page,
    fetchList,
    handleQuery,
    pagination,
  };
}