Skip to content

Commit

Permalink
Merge pull request #141 from liujiayii/feature/table
Browse files Browse the repository at this point in the history
feat: pro-field
  • Loading branch information
liujiayii authored Nov 14, 2024
2 parents eef6ef8 + 901ed44 commit f95b66f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions packages/field/src/components/date-time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineComponent({
name: "DateTime",
setup() {
const mode = inject<ProFieldProps["mode"]>("mode", "read");
const value = inject<ProFieldProps["value"]>("value", "-");
const value = inject<ProFieldProps["value"]>("value", computed(() => "-"));
const formState = inject<ProFieldProps["formState"]>("formState", {});
const column = inject<ComputedRef<ProColumns>>("column", computed(() => ({}) as ProColumns));
return () => {
Expand All @@ -27,7 +27,7 @@ export default defineComponent({
/>
);
default:
return <>{value === "-" ? value : dayjs(value).format(VALUE_FORMAT)}</>;
return <>{value.value === "-" ? value : dayjs(value.value).format(VALUE_FORMAT)}</>;
}
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/field/src/components/date/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineComponent({
name: "DateTime",
setup() {
const mode = inject<ProFieldProps["mode"]>("mode", "read");
const value = inject<ProFieldProps["value"]>("value", "-");
const value = inject<ProFieldProps["value"]>("value", computed(() => "-"));
const formState = inject<ProFieldProps["formState"]>("formState", {});
const column = inject<ComputedRef<ProColumns>>("column", computed(() => ({}) as ProColumns));
return () => {
Expand All @@ -26,7 +26,7 @@ export default defineComponent({
/>
);
default:
return <>{value === "-" ? value : dayjs(value).format(VALUE_FORMAT)}</>;
return <>{value.value === "-" ? value : dayjs(value.value).format(VALUE_FORMAT)}</>;
}
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/field/src/components/money/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineComponent({
name: "Money",
setup() {
const mode = inject<ProFieldProps["mode"]>("mode", "read");
const value = inject<ProFieldProps["value"]>("value", "-");
const value = inject<ProFieldProps["value"]>("value", computed(() => "-"));
const formState = inject<ProFieldProps["formState"]>("formState", {});
const column = inject<ComputedRef<ProColumns>>("column", computed(() => ({}) as ProColumns));
return () => {
Expand All @@ -22,7 +22,7 @@ export default defineComponent({
/>
);
default:
return <>{value === "-" ? "-" : `¥${value}`}</>;
return <>{value.value === "-" ? "-" : `¥${value.value}`}</>;
}
};
},
Expand Down
6 changes: 3 additions & 3 deletions packages/field/src/components/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineComponent({
name: "Select",
setup() {
const mode = inject<ProFieldProps["mode"]>("mode", "read");
const value = inject<ProFieldProps["value"]>("value", "-");
const value = inject<ProFieldProps["value"]>("value", computed(() => "-"));
const formState = inject<ProFieldProps["formState"]>("formState", {});
const column = inject<ComputedRef<ProColumns>>("column", computed(() => ({}) as ProColumns));

Expand All @@ -25,8 +25,8 @@ export default defineComponent({
return [];
});
const fieldValue = computed(() => {
if (column.value?.valueEnum && value !== "-") {
const item = (column.value?.valueEnum as ValueEnum)[value];
if (column.value?.valueEnum && value.value !== "-") {
const item = (column.value?.valueEnum as ValueEnum)[value.value];
return (typeof item === "object" ? <Badge {...item} /> : item) || "-";
}
return "-";
Expand Down
4 changes: 2 additions & 2 deletions packages/field/src/components/text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineComponent({
name: "Text",
setup() {
const mode = inject<ProFieldProps["mode"]>("mode", "read");
const value = inject<ProFieldProps["value"]>("value", "-");
const value = inject<ProFieldProps["value"]>("value", computed(() => "-"));
const formState = inject<ProFieldProps["formState"]>("formState", {});
const column = inject<ComputedRef<ProColumns>>("column", computed(() => ({}) as ProColumns));
return () => {
Expand All @@ -22,7 +22,7 @@ export default defineComponent({
/>
);
default:
return <>{value}</>;
return <>{value.value}</>;
}
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/field/src/components/time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineComponent({
name: "DateTime",
setup() {
const mode = inject<ProFieldProps["mode"]>("mode", "read");
const value = inject<ProFieldProps["value"]>("value", "-");
const value = inject<ProFieldProps["value"]>("value", computed(() => "-"));
const formState = inject<ProFieldProps["formState"]>("formState", {});
const column = inject<ComputedRef<ProColumns>>("column", computed(() => ({}) as ProColumns));
return () => {
Expand All @@ -27,7 +27,7 @@ export default defineComponent({
/>
);
default:
return <>{value === "-" ? value : dayjs(value).format(VALUE_FORMAT)}</>;
return <>{value.value === "-" ? value : dayjs(value.value).format(VALUE_FORMAT)}</>;
}
};
},
Expand Down
3 changes: 2 additions & 1 deletion packages/field/src/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export default defineComponent({
},
},
setup(props) {
const value = computed(() => props.value);
const column = computed(() => props.column);
const valueType = computed<ValueType>(() => props.column.valueType || "text");
provide("value", props.value);
provide("value", value);
provide("mode", props.mode);
provide("column", column);
// console.log(props, "props");
Expand Down
4 changes: 3 additions & 1 deletion packages/field/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { ComputedRef } from "vue";

export interface ProFieldProps {
/** @name 模式 */
mode: "edit" | "read";
/** @name 值 */
value: any;
value: ComputedRef<any>;
/** @name 表单值 */
formState: Record<string, any>;
}
38 changes: 17 additions & 21 deletions packages/table/src/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SearchConfig } from "@antd-vc/pro-form";
import type { SizeType } from "ant-design-vue/es/config-provider";
import type { TablePaginationConfig } from "ant-design-vue/es/table";
import type { ActionType, ProColumns } from "./typing";
import type { ActionType } from "./typing";
import { ProField } from "@antd-vc/pro-field";
import { QueryFilter } from "@antd-vc/pro-form";
import { Card, Table } from "ant-design-vue";
Expand All @@ -12,25 +12,6 @@ import ToolBar from "./components/ToolBar";
import { ProTableProps } from "./typing";
import { pageConfig } from "./utils";

function formatTableColumns(data: ProColumns[]) {
return data
.map((item) => {
if (item.hideInTable) {
return undefined;
}
const row = {
...item,
customRender: item.customRender ?? function ({ text }) {
return <ProField mode="read" value={text} column={item} />;
},
};
;
delete row.colSpan;
return row;
})
.filter(Boolean);
}

export default defineComponent({
name: "ProTable",
props: ProTableProps,
Expand All @@ -41,7 +22,22 @@ export default defineComponent({
const tableSize = ref<SizeType[]>(["middle"]);
const formState = reactive<Record<any, any>>({});
provide("tableSize", tableSize);
const tableColumns = computed(() => formatTableColumns(props.columns as any));

const tableColumns = computed(() => {
return props.columns.map((item) => {
if (item.hideInTable) {
return undefined;
}
const row = {
...item,
customRender: item.customRender ?? function ({ text }) {
return <ProField mode="read" value={text} column={item} />;
},
};
delete row.colSpan;
return row;
}).filter(Boolean);
});
const useFetchData = (
params: { current?: number; pageSize?: number } = { current: 1, pageSize: 10 },
) => {
Expand Down

0 comments on commit f95b66f

Please sign in to comment.