fix: 取消vue原生钩子函数,对接系统管理页面中的接口

This commit is contained in:
ZhuRui
2026-08-05 14:33:21 +08:00
parent 2e6f7ca552
commit 503ee266b0
22 changed files with 569 additions and 447 deletions
+4 -8
View File
@@ -1,4 +1,4 @@
import { defineComponent, onMounted } from 'vue';
import { defineComponent } from 'vue';
import {
Button,
Input,
@@ -171,10 +171,6 @@ export default defineComponent({
},
];
onMounted(() => {
handleSearch();
});
return () => (
<div class={pageStyles.containerMain}>
<div class={pageStyles.filter}>
@@ -237,9 +233,9 @@ export default defineComponent({
<div class={pageStyles.pagination}>
<Pagination
current={pagination.value.current}
pageSize={pagination.value.pageSize}
total={pagination.value.total}
current={(pagination as any).current.value}
pageSize={(pagination as any).pageSize.value}
total={(pagination as any).total.value}
showSizeChanger
showTotal={(total: number) => `${total}`}
onChange={handlePageChange}
+32 -40
View File
@@ -2,6 +2,9 @@ import { computed, reactive, toRef, Ref, h } from 'vue';
import { message } from 'ant-design-vue';
import { StatusTag, type StatusTagTone } from '@/components';
import { useState, useDebounce, useThrottleFn } from '@/hooks';
import { useRequest } from '@/hooks/useRequest';
import { useEffect } from '@/hooks/useEffect';
import { usePagination } from '@/hooks/usePagination';
import {
getBannerList,
delBanner,
@@ -61,21 +64,32 @@ export function useBannerModel() {
{ delay: 300 },
);
// ===== 表格状态(API 返回全量,前端分页) =====
const [loading, setLoading] = useState<boolean>(false);
const [allData, setAllData] = useState<TournamentAdminBannerListVO[]>([]);
const [pagination, setPagination] = useState({
current: 1,
pageSize: 10,
total: 0,
// ===== 数据请求(API 返回全量,前端分页) =====
const {
data,
loading,
run: fetchList,
} = useRequest<TournamentAdminBannerListVO[]>(() => getBannerList(buildQueryParams()), {
refreshDeps: [],
formatResult: (res) => (res.code == 200 ? res.data : []),
});
const allData = computed(() => data.value || []);
// ===== 前端分页 =====
const pagination = usePagination({ defaultCurrent: 1, defaultPageSize: 10 });
/** 当前页数据(客户端切片) */
const dataSource = computed(() => {
const start = (pagination.value.current - 1) * pagination.value.pageSize;
return allData.value.slice(start, start + pagination.value.pageSize);
const start = ((pagination as any).current.value - 1) * (pagination as any).pageSize.value;
return allData.value.slice(start, start + (pagination as any).pageSize.value);
});
// 同步前端分页 total
useEffect(() => {
pagination.setTotal(allData.value.length);
}, [allData]);
// ===== 弹窗状态 =====
const [modalVisible, setModalVisible] = useState<boolean>(false);
const [editingRecord, setEditingRecord] = useState<any>(null);
@@ -119,37 +133,21 @@ export function useBannerModel() {
// ===== 方法 =====
/** 查询 */
const handleSearch = useThrottleFn(async () => {
setLoading(true);
try {
const queryParams = buildQueryParams();
console.log('Banner列表查询参数:', queryParams);
const res = await getBannerList(queryParams);
if (res.code == 200) {
setAllData(res.data);
setPagination({ current: 1, pageSize: 10, total: res.data.length });
} else {
message.error(res.msg || '查询失败');
}
} catch (error: any) {
console.error('Banner查询失败:', error);
} finally {
setLoading(false);
}
}, 500);
const handleSearch = () => fetchList();
/** 重置 */
const handleReset = useThrottleFn(() => {
filterForm.title = '';
filterForm.status = '';
setPagination({ current: 1, pageSize: 10, total: 0 });
setAllData([]);
setTimeout(() => handleSearch(), 350);
pagination.reset();
setTimeout(fetchList, 350);
}, 500);
const handlePageChange = (page: number, pageSize: number) => {
setPagination({ ...pagination.value, current: page, pageSize });
pagination.setCurrent(page);
if (pageSize !== (pagination as any).pageSize.value) {
pagination.setPageSize(pageSize);
}
};
/** 打开新增弹窗 */
@@ -214,39 +212,33 @@ export function useBannerModel() {
/** 删除 */
const handleDelete = useThrottleFn(async (record: any) => {
setLoading(true);
try {
const res = await delBanner(record.id);
if (res.code == 200) {
message.success('删除成功');
handleSearch();
fetchList();
} else {
message.error(res.msg || '删除失败');
}
} catch (e: any) {
console.error('Banner删除失败:', e);
} finally {
setLoading(false);
}
}, 500);
/** 启用/禁用切换 */
const handleToggleStatus = useThrottleFn(async (record: any) => {
setLoading(true);
try {
const newStatus = record.status === '1' ? '0' : '1';
const actionText = newStatus === '1' ? '启用' : '禁用';
const res = await toggleBannerActive({ id: record.id, status: newStatus });
if (res.code == 200) {
message.success(`${actionText}成功`);
handleSearch();
fetchList();
} else {
message.error(res.msg || '操作失败');
}
} catch (e: any) {
console.error('Banner状态切换失败:', e);
} finally {
setLoading(false);
}
}, 500);
+12 -10
View File
@@ -1,4 +1,4 @@
import { defineComponent, ref, onMounted, onUnmounted, nextTick } from 'vue';
import { defineComponent, ref, nextTick } from 'vue';
import {
Button,
Input,
@@ -12,7 +12,7 @@ import {
} from 'ant-design-vue';
import { useLogModel, ACTION_TYPE_OPTIONS, ACTION_SOURCE_OPTIONS } from './model/useLogModel';
import { useLogColumns } from './model/useLogColumns';
import { useState, useContainerSize } from '@/hooks';
import { useState, useEffect, useContainerSize } from '@/hooks';
import pageStyles from '@/assets/styles/pageLayout.module.less';
import './index.module.less';
@@ -29,15 +29,17 @@ const LogContentCell = defineComponent({
if (el) setOverflow(el.scrollHeight > el.clientHeight);
};
let observer: ResizeObserver | null = null;
onMounted(() => {
nextTick(checkOverflow);
useEffect(() => {
const el = textRef.value;
if (el) {
observer = new ResizeObserver(checkOverflow);
observer.observe(el);
}
});
onUnmounted(() => observer?.disconnect());
if (!el) return;
nextTick(checkOverflow);
observer = new ResizeObserver(checkOverflow);
observer.observe(el);
return () => {
observer?.disconnect();
observer = null;
};
}, [() => textRef.value]);
return () => {
const raw = props.text;
return (