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, }; }