Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 优化onActivated事件 #181

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading