Skip to content

Commit

Permalink
Merge pull request #181 from liujiayii/feature/table
Browse files Browse the repository at this point in the history
feat: 优化onActivated事件
  • Loading branch information
liujiayii authored Dec 6, 2024
2 parents a17f4d7 + a77dcb8 commit d029f0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 1 addition & 12 deletions packages/form/src/layouts/QueryFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,17 @@ import type { FormInstance } from "ant-design-vue/es/form";
import { DownOutlined } from "@ant-design/icons-vue";
import { ProField } from "@antd-vc/pro-field";
import { Button, Card, Col, Form, Row, Space } from "ant-design-vue";
import { computed, defineComponent, onActivated, provide, reactive, ref, watch } from "vue";
import { computed, defineComponent, provide, reactive, ref, watch } from "vue";
import { useWindowWidth } from "./hooks";
import { ProFormProps } from "./types";
import { getSpanConfig } from "./utils";

const layout = "horizontal";

// 缓存首次渲染
let isFirstShow = true;

export default defineComponent({
name: "QueryFilter",
props: ProFormProps,
setup(props) {
// 在页面激活时刷新数据
onActivated(() => {
if (isFirstShow) {
isFirstShow = false;
return;
}
props.useFetchData?.();
});
const isCollapsed = ref(false);
const formRef = ref<FormInstance>();
const formState = props.formState || reactive<Record<string, any>>({});
Expand Down
13 changes: 12 additions & 1 deletion packages/table/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { ProField } from "@antd-vc/pro-field";
import { QueryFilter } from "@antd-vc/pro-form";
import { Card, Table } from "ant-design-vue";
import { cloneDeep, isFunction } from "lodash-es";
import { computed, defineComponent, onMounted, provide, reactive, ref, watch } from "vue";
import { computed, defineComponent, onActivated, onMounted, provide, reactive, ref, watch } from "vue";
import EmptyPagination from "./components/empty-pagination";
import ToolBar from "./components/ToolBar";
import { ProTableProps } from "./typing";
import { pageConfig } from "./utils";

// 缓存首次渲染
let isFirstShow = true;

export default defineComponent({
name: "ProTable",
props: ProTableProps,
Expand Down Expand Up @@ -90,6 +93,14 @@ export default defineComponent({
},
});

// 在页面激活时刷新数据
onActivated(() => {
if (isFirstShow) {
isFirstShow = false;
return;
}
actionRef.value?.reload();
});
/** 聚焦的时候重新请求数据,这样可以保证数据都是最新的。 */
onMounted(() => {
// 手动模式和 request 为空都不生效
Expand Down

0 comments on commit d029f0a

Please sign in to comment.